fdcavalcanti opened a new pull request, #3135:
URL: https://github.com/apache/nuttx-apps/pull/3135
## Summary
This example makes it possible to use a binary from local storage for
MCUBoot update. It copies the binary file to the secondary slot instead of
downloading from a remote URL. Can be used to update from a SD Card, for
example.
## Impact
- Impact on user: Yes, adds new MCUBoot example to update the image from a
local storage.
- Impact on build: No.
- Impact on hardware: No.
- Impact on documentation: Yes. Updates documentation on main NuttX repo:
link
- Impact on security: No.
- Impact on compatibility: No.
## Testing
The following example updates the firmware using a binary from a SD Card
mounted to `/data`.
### Building
- `./tools/configure.sh esp32-devkitc:mcuboot_update_agent`
- Enable `CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT`
- Merge the SD Card config: `kconfig-merge -m .config
boards/risc-v/esp32c6/esp32c6-devkitc/configs/sdmmc_spi/defconfig`
- make and flash
Now generate the 2nd image:
- Change the image target slot to 2nd slot by setting
`CONFIG_ESPRESSIF_ESPTOOL_TARGET_SECONDARY`
- Optionally change the MOTD to have a visual ID of the updated image
- make
Have the image transferred to a SD Card and mount it to `/data`:
```
nsh> mount -t vfat /dev/mmcsd0 /mnt
nsh> ls /mnt
/mnt:
nuttx.txt
nuttx_c6_ota.bin
```
### Running
Now just run the example and it should copy the binary to the 2nd slot and
MCUBoot will update the image:
```
nsh> mcuboot_local_agent /mnt/nuttx_c6_ota.bin
MCUBoot Local Update Agent
Firmware file: /mnt/nuttx_c6_ota.bin
Firmware file size: 1048576 bytes
Erasing secondary flash slot...
Copying firmware to secondary slot...
Progress: 4096/1048576 bytes [0%]
Progress: 8192/1048576 bytes [0%]
Progress: 12288/1048576 bytes [1%]
....
Progress: 1044480/1048576 bytes [99%]
Progress: 1048576/1048576 bytes [100%]
Firmware copy completed successfully!
Firmware successfully copied to secondary slot!
Update scheduled for next boot. Restarting...
reboot status=0
```
### Results
MCUBoot shows the image is updated:
```
reboot status=0
WPA: Clear old PMK and PTK
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0xc (SW_CPU),boot:0x6f (SPI_FAST_FLASH_BOOT)
Saved PC:0x40803964
SPIWP:0xee
mode:DIO, clock div:2
load:0x40860610,len:0x24c8
load:0x40869610,len:0x2870
load:0x40873bb8,len:0x1938
entry 0x4086be2a
[esp32c6] [INF] *** Booting MCUboot build v2.2.0-rc1 ***
[esp32c6] [INF] [boot] chip revision: v0.0
[esp32c6] [INF] [boot.esp32c6] SPI Speed : 80MHz
[esp32c6] [INF] [boot.esp32c6] SPI Mode : DIO
[esp32c6] [INF] [boot.esp32c6] SPI Flash Size : 4MB
[esp32c6] [INF] [boot] Enabling RNG early entropy source...
[esp32c6] [INF] Primary image: magic=good, swap_type=0x1, copy_done=0x3,
image_ok=0x1
[esp32c6] [INF] Scratch: magic=unset, swap_type=0x1, copy_done=0x3,
image_ok=0x3
[esp32c6] [INF] Boot source: primary slot
[esp32c6] [INF] Image index: 0, Swap type: test
[esp32c6] [INF] Starting swap using scratch algorithm.
[esp32c6] [INF] Disabling RNG early entropy source...
[esp32c6] [INF] br_image_off = 0x10000
[esp32c6] [INF] ih_hdr_size = 0x20
[esp32c6] [INF] Loading image 0 - slot 0 from flash, area id: 1
[esp32c6] [INF] DRAM segment: start=0x21d8c, size=0x2c48, vaddr=0x40811d10
[esp32c6] [INF] IRAM segment: start=0x10080, size=0x11d0c, vaddr=0x40800000
[esp32c6] [INF] LP_RAM segment: paddr=0010e3e0h, vaddr=50000010h,
size=00018h ( 24) load
[esp32c6] [INF] LP_IRAM segment: paddr=0010e3e0h, vaddr=50000000h,
size=00010h ( 16) load
[esp32c6] [INF] start=0x40806558
ABCDEInitializing /dev/spi2...
INFO: init MMC/SD slot 0 on SPI2: /dev/mmcsd0
INFO: MMCSD initialized
I (25584) pp: pp rom version: 5b8dcfa
I (25585) net80211: net80211 rom version: 5b8dcfa
I (25588) wifi_init: rx ba win: 6
I (25588) wifi_init: LWIP disabled
I (25590) phy_init: phy_version 331,5b89037,Mar 3 2025,16:01:12
NuttShell (NSH) NuttX-10.4.0
This is MCUBoot Updated Image!!
nsh>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]