From 6f19b9c08d7d8c03981a999d4eddeb3c500125ab Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 26 Aug 2021 12:35:16 +1000 Subject: [PATCH] stm32/boards/LEGO_HUB_NO6: Add make commands to backup/restore firmware. Signed-off-by: Damien George --- ports/stm32/boards/LEGO_HUB_NO6/README.md | 22 +++++++++++++++++- .../boards/LEGO_HUB_NO6/mpconfigboard.mk | 23 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/README.md b/ports/stm32/boards/LEGO_HUB_NO6/README.md index c566ada9d0..0b88cd837b 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/README.md +++ b/ports/stm32/boards/LEGO_HUB_NO6/README.md @@ -28,6 +28,26 @@ firmware at 0x08010000. When mboot is installed it can be entered programatical via machine.bootloader(), or by holding down the left arrow button when powering on the Hub and waiting until the display says "B" before releasing the button. +Backing up original Hub firmware +-------------------------------- + +Before install MicroPython it is advised to backup the original LEGO firmware that +the Hub comes installed with. To do this, enter the built-in bootloader by holding +down the Bluetooth button for 5 seconds while powering up the Hub via USB. Then +run the following command from the root of this repository: + + $ cd ports/stm32 + $ make BOARD=LEGO_HUB_NO6 backup-hub-firmware + +This will create a file called `lego_hub_firmware.dfu`. Put this file in a safe +location. To restore it, enter the built-in bootloader again and run: + + $ make BOARD=LEGO_HUB_NO6 restore-hub-firmware + +This will restore the original firmware but not the filesystem. To recreate the +original filesystem the Hub must be updated using the appropriate LEGO PC +application. + Installing MicroPython ---------------------- @@ -76,4 +96,4 @@ To scan for BLE devices: >>> ble.active(1) >>> ble.gap_scan(2000, 625, 625) -Use help("modules") to see available built-in modules. \ No newline at end of file +Use help("modules") to see available built-in modules. diff --git a/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.mk b/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.mk index 56527af7d3..8f8695a9cf 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.mk +++ b/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.mk @@ -20,3 +20,26 @@ endif # Bootloader settings MBOOT_TEXT0_ADDR = 0x08008000 MBOOT_LD_FILES = ../boards/LEGO_HUB_NO6/mboot_memory.ld stm32_sections.ld + +# Backup/restore original Hub firmware + +HUB_FIRMWARE = lego_hub_firmware.dfu +HUB_FIRMWARE_ADDR = $(MBOOT_TEXT0_ADDR) +HUB_FIRMWARE_SIZE = 0xf8000 + +backup-hub-firmware: + $(Q)$(DFU_UTIL) -a 0 \ + -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) \ + -U $(HUB_FIRMWARE).bin \ + -s $(HUB_FIRMWARE_ADDR):$(HUB_FIRMWARE_SIZE) + $(Q)$(PYTHON) $(DFU) \ + -b $(HUB_FIRMWARE_ADDR):$(HUB_FIRMWARE).bin \ + -D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) \ + $(HUB_FIRMWARE) + $(Q)$(RM) $(HUB_FIRMWARE).bin + $(ECHO) "Backup created in $(HUB_FIRMWARE)" + +restore-hub-firmware: + $(Q)$(DFU_UTIL) -a 0 \ + -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) \ + -D $(HUB_FIRMWARE)