Skip to content

Commit

Permalink
Merge branch 'feature/flasher-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Nov 18, 2023
2 parents f2bea5a + 946d9cd commit 867ba87
Show file tree
Hide file tree
Showing 27 changed files with 2,198 additions and 423 deletions.
27 changes: 15 additions & 12 deletions ltchiptool/commands/flash/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ltchiptool import Family, SocInterface
from ltchiptool.models import FamilyParamType
from ltchiptool.util.cli import AutoIntParamType, DevicePortParamType
from ltchiptool.util.flash import FlashConnection
from ltchiptool.util.flash import FlashConnection, FlashMemoryType
from ltchiptool.util.logging import graph
from ltchiptool.util.misc import sizeof
from ltchiptool.util.streams import ClickProgressCallback
Expand Down Expand Up @@ -62,8 +62,16 @@
@click.option(
"-R",
"--rom",
"memory",
flag_value=FlashMemoryType.ROM,
help="Read from ROM instead of Flash (default: False)",
is_flag=True,
)
@click.option(
"-E",
"--efuse",
"memory",
flag_value=FlashMemoryType.EFUSE,
help="Read from eFuse instead of Flash (default: False)",
)
def cli(
family: Family,
Expand All @@ -74,7 +82,7 @@ def cli(
length: int,
timeout: float,
check: bool,
rom: bool,
memory: FlashMemoryType,
):
"""
Read flash contents to a file.
Expand All @@ -94,10 +102,8 @@ def cli(
soc.flash_set_connection(FlashConnection(device, baudrate))
flash_link_interactive(soc, timeout)

if rom:
max_length = soc.flash_get_rom_size()
else:
max_length = soc.flash_get_size()
memory = memory or FlashMemoryType.FLASH
max_length = soc.flash_get_size(memory)

offset = offset or 0
length = length or (max_length - offset)
Expand All @@ -108,17 +114,14 @@ def cli(
f"chip capacity ({sizeof(max_length)})",
)

if rom:
graph(0, f"Reading ROM ({sizeof(length)}) to '{file.name}'")
else:
graph(0, f"Reading {sizeof(length)} @ 0x{offset:X} to '{file.name}'")
graph(0, f"Reading {memory.value} ({sizeof(length)}) to '{file.name}'")

with ClickProgressCallback(length) as callback:
for chunk in soc.flash_read_raw(
offset=offset,
length=length,
verify=check,
use_rom=rom,
memory=memory,
callback=callback,
):
file.write(chunk)
Expand Down
1 change: 1 addition & 0 deletions ltchiptool/commands/soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
COMMANDS = {
"bkpackager": "ltchiptool/soc/bk72xx/bkpackager.py",
"rtltool": "ltchiptool/soc/ambz/util/rtltool.py",
"ambztool": "ltchiptool/soc/ambz/util/ambztool.py",
"ambz2tool": "ltchiptool/soc/ambz2/util/ambz2tool.py",
}

Expand Down
17 changes: 16 additions & 1 deletion ltchiptool/gui/base/panel.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# Copyright (c) Kuba Szczodrzyński 2023-1-3.

import threading
from logging import warning
from queue import Queue
from typing import Any, Callable, Tuple

import wx
import wx.xrc

from ltchiptool.gui.utils import on_event

from .window import BaseWindow


# noinspection PyPep8Naming
class BasePanel(wx.Panel, BaseWindow):
_components: list[wx.Window]
_events: Queue[wx.Window | None]

def __init__(self, parent: wx.Window, frame):
super().__init__(parent)
self.InitWindow(frame)
self.Frame = frame
self.Xrc: wx.xrc.XmlResource = frame.Xrc
self._components = []
self._events = Queue()
self.Bind(wx.EVT_IDLE, self.OnIdle)

def OnShow(self):
self.OnUpdate()
Expand All @@ -41,10 +48,18 @@ def _OnUpdate(self, event: wx.Event | None):
def DoUpdate(self, target: wx.Window = None):
if self._in_update:
return
if threading.current_thread() != threading.main_thread():
self._events.put(target)
return
self._in_update = True
self.OnUpdate(target)
self._in_update = False

@on_event
def OnIdle(self):
while not self._events.empty():
self.OnUpdate(self._events.get())

def OnUpdate(self, target: wx.Window = None):
pass

Expand Down Expand Up @@ -131,7 +146,7 @@ def EnableAll(self):
return
for window in self._components:
window.Enable()
self.OnUpdate()
self.DoUpdate()

def DisableAll(self):
if self.is_closing:
Expand Down
14 changes: 14 additions & 0 deletions ltchiptool/gui/base/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from os.path import dirname, isfile, join

import wx.lib.agw.genericmessagedialog as GMD
import wx.xrc

from ltchiptool.gui.colors import ColorPalette
Expand Down Expand Up @@ -77,3 +78,16 @@ def EnableAll(self):

def DisableAll(self):
pass

def MessageDialogMonospace(self, message: str, caption: str):
dialog = GMD.GenericMessageDialog(
parent=self,
message=message,
caption=caption,
agwStyle=wx.ICON_INFORMATION | wx.OK,
)
# noinspection PyUnresolvedReferences
font = wx.Font(wx.FontInfo(10).Family(wx.MODERN))
dialog.SetFont(font)
dialog.ShowModal()
dialog.Destroy()
44 changes: 36 additions & 8 deletions ltchiptool/gui/ltchiptool.wxui
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@
var_name="radio_baudrate_921600" />
</node>
<node
class="wxBoxSizer"
var_name="sizer_operation"
class="wxGridSizer"
cols="3"
column="1"
flags="wxEXPAND"
row="2">
<node
class="wxRadioButton"
Expand All @@ -274,10 +273,22 @@
class="wxRadioButton"
label="Read flash"
var_name="radio_read" />
<node
class="wxStaticText"
label=""
var_name="text_dummy" />
<node
class="wxRadioButton"
label="Get chip info"
var_name="radio_read_info" />
<node
class="wxRadioButton"
label="Read ROM"
var_name="radio_read_rom" />
<node
class="wxRadioButton"
label="Read eFuse"
var_name="radio_read_efuse" />
</node>
<node
class="wxStaticText"
Expand Down Expand Up @@ -329,7 +340,6 @@
class="wxComboBox"
style="wxCB_READONLY"
var_name="combo_family"
disabled="1"
borders="wxBOTTOM|wxRIGHT|wxLEFT"
colspan="3"
flags="wxEXPAND"
Expand Down Expand Up @@ -374,25 +384,25 @@
row="2" />
<node
class="wxTextCtrl"
hint="0x0"
var_name="input_offset"
disabled="1"
borders="wxBOTTOM|wxRIGHT|wxLEFT"
colspan="2"
flags="wxEXPAND"
row="3" />
<node
class="wxTextCtrl"
hint="0x0"
var_name="input_skip"
disabled="1"
borders="wxBOTTOM|wxRIGHT|wxLEFT"
colspan="2"
column="2"
flags="wxEXPAND"
row="3" />
<node
class="wxTextCtrl"
hint="All data"
var_name="input_length"
disabled="1"
borders="wxBOTTOM|wxRIGHT|wxLEFT"
colspan="2"
column="4"
Expand All @@ -401,11 +411,29 @@
</node>
<node
class="wxGridSizer"
var_name="sizer_buttons"
var_name="sizer_guides"
border_size="0"
column="1"
flags="wxEXPAND"
row="7">
<node
class="wxButton"
label="Connection guide"
var_name="button_guide"
flags="wxEXPAND" />
<node
class="wxButton"
label="Open flashing docs"
var_name="button_docs"
flags="wxEXPAND" />
</node>
<node
class="wxGridSizer"
var_name="sizer_buttons"
border_size="0"
column="1"
flags="wxEXPAND"
row="8">
<node
class="wxCommandLinkButton"
main_label="Start"
Expand Down
63 changes: 56 additions & 7 deletions ltchiptool/gui/ltchiptool.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,13 @@
<object class="sizeritem">
<cellpos>2,1</cellpos>
<cellspan>1,1</cellspan>
<flag>wxALL|wxEXPAND</flag>
<flag>wxALL</flag>
<border>5</border>
<object class="wxBoxSizer" name="sizer_operation">
<orient>wxHORIZONTAL</orient>
<object class="wxGridSizer" name="grid_sizer">
<rows>0</rows>
<cols>3</cols>
<vgap>0</vgap>
<hgap>0</hgap>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
Expand All @@ -300,13 +303,34 @@
<label>Read flash</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="text_dummy">
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
<object class="wxRadioButton" name="radio_read_info">
<label>Get chip info</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
<object class="wxRadioButton" name="radio_read_rom">
<label>Read ROM</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
<object class="wxRadioButton" name="radio_read_efuse">
<label>Read eFuse</label>
</object>
</object>
</object>
</object>
<object class="sizeritem">
Expand Down Expand Up @@ -376,7 +400,6 @@
<border>5</border>
<object class="wxComboBox" name="combo_family">
<style>wxCB_READONLY</style>
<enabled>0</enabled>
</object>
</object>
<object class="sizeritem">
Expand Down Expand Up @@ -426,21 +449,21 @@
<flag>wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</flag>
<border>5</border>
<object class="wxTextCtrl" name="input_offset">
<enabled>0</enabled>
<hint>0x0</hint>
</object>
</object>
<object class="sizeritem">
<flag>wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</flag>
<border>5</border>
<object class="wxTextCtrl" name="input_skip">
<enabled>0</enabled>
<hint>0x0</hint>
</object>
</object>
<object class="sizeritem">
<flag>wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</flag>
<border>5</border>
<object class="wxTextCtrl" name="input_length">
<enabled>0</enabled>
<hint>All data</hint>
</object>
</object>
</object>
Expand All @@ -450,6 +473,32 @@
<cellspan>1,1</cellspan>
<flag>wxALL|wxEXPAND</flag>
<border>0</border>
<object class="wxGridSizer" name="sizer_guides">
<rows>0</rows>
<cols>2</cols>
<vgap>0</vgap>
<hgap>0</hgap>
<object class="sizeritem">
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="button_guide">
<label>Connection guide</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="button_docs">
<label>Open flashing docs</label>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<cellpos>8,1</cellpos>
<cellspan>1,1</cellspan>
<flag>wxALL|wxEXPAND</flag>
<border>0</border>
<object class="wxGridSizer" name="sizer_buttons">
<rows>0</rows>
<cols>2</cols>
Expand Down
Loading

0 comments on commit 867ba87

Please sign in to comment.