From e8275d400937a061848073a03e2d36fc0fab44e2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 10 Mar 2023 00:02:53 +0800 Subject: [PATCH] update tools to work with a debug-less SoC it will automatically determine which reset/halt approach should be used based on the available registers. --- .../precursorupdater/precursorupdater.py | 8 ++--- .../precursorusb/precursorusb.py | 16 ++++++++++ tools/updater/setup.py | 2 +- tools/usb_update.py | 29 ++++++++++++++----- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/tools/updater/precursorupdater/precursorupdater.py b/tools/updater/precursorupdater/precursorupdater.py index 56b48c7f6..2ea0c8bf7 100755 --- a/tools/updater/precursorupdater/precursorupdater.py +++ b/tools/updater/precursorupdater/precursorupdater.py @@ -734,9 +734,8 @@ def main(): print("\nPhase 2: Apply the update") print("Halting CPU for update.") - vexdbg_addr = int(pc_usb.regions['vexriscv_debug'][0], 0) pc_usb.ping_wdt() - pc_usb.poke(vexdbg_addr, 0x00020000) + pc_usb.halt() for work in worklist: retry_usb = False @@ -750,9 +749,8 @@ def main(): print("Abort by user request!\n\nSystem may not be bootable, but you can retry an update as long as you do not power-off or hard-reset the device.") exit(0) - vexdbg_addr = int(pc_usb.regions['vexriscv_debug'][0], 0) pc_usb.ping_wdt() - pc_usb.poke(vexdbg_addr, 0x00020000) + pc_usb.halt() retry_usb = False try: @@ -781,7 +779,7 @@ def main(): retry_usb = True print("Resuming CPU.") - pc_usb.poke(vexdbg_addr, 0x02000000) + pc_usb.unhalt() print("Resetting SOC...") try: diff --git a/tools/updater/precursorupdater/precursorusb/precursorusb.py b/tools/updater/precursorupdater/precursorusb/precursorusb.py index dac66f0fe..7247db209 100644 --- a/tools/updater/precursorupdater/precursorusb/precursorusb.py +++ b/tools/updater/precursorupdater/precursorusb/precursorusb.py @@ -20,6 +20,22 @@ class PrecursorUsb: self.regions = {} self.gitrev = '' + def halt(self): + if 'vexriscv_debug' in self.regions: + self.poke(int(self.regions['vexriscv_debug'][0], 0), 0x00020000) + elif 'reboot_cpu_hold_reset' in self.registers: + self.poke(self.register('reboot_cpu_hold_reset'), 1) + else: + print("Can't find reset CSR. Try updating to the latest version of this program") + + def unhalt(self): + if 'vexriscv_debug' in self.regions: + self.poke(int(self.regions['vexriscv_debug'][0], 0), 0x02000000) + elif 'reboot_cpu_hold_reset' in self.registers: + self.poke(self.register('reboot_cpu_hold_reset'), 0) + else: + print("Can't find reset CSR. Try updating to the latest version of this program") + def register(self, name): return int(self.registers[name], 0) diff --git a/tools/updater/setup.py b/tools/updater/setup.py index 9fc366c4d..73b060c90 100644 --- a/tools/updater/setup.py +++ b/tools/updater/setup.py @@ -7,7 +7,7 @@ with open('README.md') as f: setup( name="precursorupdater", - version="0.1.2", + version="0.1.3", author="bunnie", description="Precursor USB Updater", long_description=long_description, diff --git a/tools/usb_update.py b/tools/usb_update.py index 532b189c2..593b18097 100644 --- a/tools/usb_update.py +++ b/tools/usb_update.py @@ -365,6 +365,22 @@ class PrecursorUsb: def register(self, name): return int(self.registers[name], 0) + def halt(self): + if 'vexriscv_debug' in self.regions: + self.poke(int(self.regions['vexriscv_debug'][0], 0), 0x00020000) + elif 'reboot_cpu_hold_reset' in self.registers: + self.poke(self.register('reboot_cpu_hold_reset'), 1) + else: + print("Can't find reset CSR. Try updating to the latest version of this program") + + def unhalt(self): + if 'vexriscv_debug' in self.regions: + self.poke(int(self.regions['vexriscv_debug'][0], 0), 0x02000000) + elif 'reboot_cpu_hold_reset' in self.registers: + self.poke(self.register('reboot_cpu_hold_reset'), 0) + else: + print("Can't find reset CSR. Try updating to the latest version of this program") + def peek(self, addr, display=False): _dummy_s = '\x00'.encode('utf-8') data = array.array('B', _dummy_s * 4) @@ -1066,7 +1082,6 @@ def main(): print("SoC is from an unknown rev '{}', use --force to continue anyways with v0.9 firmware offsets".format(pc_usb.load_csrs())) exit(1) - vexdbg_addr = int(pc_usb.regions['vexriscv_debug'][0], 0) pc_usb.ping_wdt() if args.dump: @@ -1083,14 +1098,14 @@ def main(): exit(0) with open(args.dump_file, 'wb') as f: for page in table: - pc_usb.poke(vexdbg_addr, 0x00020000) + pc_usb.halt() data = pc_usb.burst_read(page, 4096) - pc_usb.poke(vexdbg_addr, 0x02000000) + pc_usb.unhalt() f.write(data) exit(0) print("Halting CPU.") - pc_usb.poke(vexdbg_addr, 0x00020000) + pc_usb.halt() if args.erase_pddb: print("Erasing PDDB region") @@ -1127,7 +1142,7 @@ def main(): pc_usb.erase_region(locs['LOC_PDDB'][0], 1024 * 1024) print("Resuming CPU.") - pc_usb.poke(vexdbg_addr, 0x02000000) + pc_usb.unhalt() print("Resetting SOC...") try: @@ -1154,7 +1169,7 @@ def main(): pc_usb.flash_program(locs['LOC_STAGING'][0], image, verify=verify) print("Resuming CPU.") - pc_usb.poke(vexdbg_addr, 0x02000000) + pc_usb.unhalt() print("Resetting SOC...") try: @@ -1262,7 +1277,7 @@ def main(): print("Resuming CPU.") - pc_usb.poke(vexdbg_addr, 0x02000000) + pc_usb.unhalt() print("Resetting SOC...") try: