Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Patch) add "boot" command #26

Open
rogueeve575 opened this issue Dec 22, 2024 · 0 comments
Open

(Patch) add "boot" command #26

rogueeve575 opened this issue Dec 22, 2024 · 0 comments

Comments

@rogueeve575
Copy link

rogueeve575 commented Dec 22, 2024

Recently I had an opportunity to port some of (my custom) firmware to a BK7231N-based device -- I only have one of these devices, a Tuya CB2S, that I pulled out of the IOT device, and it's kind of in a janky setup on the bench with lots of bodge wires and serial adapters tacked on since I don't have the proper programmer board. So it was helpful to develop & test application code for it remotely.

We can cause the device to enter the bootloader without any physical interaction now (at least after the initial flash of PlatformIO) using LibreTiny's auto-download-reboot, but the only way I've found to get back to application code is by uploading new firmware with pio run -e cb2s --target upload which auto-reboots the device after flashing. Most other embedded tools I've seen have a "boot" command to get out of the bootloader without modifying anything.

ltchiptool seems to be calling in to bk7231tools as an optional dependency to do this restart, so I added a "boot" command to bk7231tools so I could restart the device/get out of the bootloader if I ever wanted to without flashing any new firmware.

I'm not going to clone the repo and make a PR for such a small thing, but I did want to share the patch in case it's interesting to others. You can also run "bk7231tools boot" while the device is in application code to do a software reboot by taking it into bootloader then back out.

 ▶ git diff HEAD~1..HEAD
diff --git a/bk7231tools/__main__.py b/bk7231tools/__main__.py
index 16293fe..04340d6 100644
--- a/bk7231tools/__main__.py
+++ b/bk7231tools/__main__.py
@@ -477,6 +477,11 @@ def write_flash(device: BK7231Serial, args):
             pass


+def boot(device: BK7231Serial, args):
+    print("Booting device.")
+    device.reboot_chip()
+
+
 def parse_args():
     parser = argparse.ArgumentParser(
         prog="bk7231tools",
@@ -612,6 +617,11 @@ def parse_args():
     parser_dissect_dump.set_defaults(handler=dissect_dump_file)
     parser_dissect_dump.set_defaults(device_required=False)

+    parser_boot = subparsers.add_parser("boot", help="Boot device into application code")
+    parser_boot = __add_serial_args(parser_boot)
+    parser_boot.set_defaults(handler=boot)
+    parser_boot.set_defaults(device_required=True)
+
     return parser.parse_args()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant