adafruit / Adafruit_nRF52_Bootloader

USB-enabled bootloaders for the nRF52 BLE SoC chips
MIT License
438 stars 393 forks source link

Unable to flash UF2 where flash is >512kb #213

Closed tannewt closed 3 years ago

tannewt commented 3 years ago

Set up Feather nRF52840 Express with 6.0.0 bootloader. CircuitPython e9369d50e16e557ccd1a98c06d6e36bb87b908b7 . UF2s for the opt build flash ok but DEBUG=1 builds do not.

Describe the bug

Only part of the >512k UF2 is flashed leaving the higher end of the flash incorrect. In CircuitPython this means the .data section is not correct and assertions in DEBUG=1 mode fail as a result.

To Reproduce

Steps to reproduce the behavior:

  1. Enter the bootloader
  2. Drag on firmware-debug.uf2.zip after unzipping.
  3. Red LED flashes quickly and board doesn't restart.
  4. Manual restart leads to CP assertion failure.

Here is an opt build that works: firmware-opt.uf2.zip

Note that the broken UF2 is >1MB in size.

tannewt commented 3 years ago

Two other things:

  1. I wrote a script to compare the RAM version of .data to the flash version and they were the same. They were not the same as the .data version from the .elf file.
  2. The debug build of CircuitPython works when I flash it via pyocd instead of with the bootloader.
dhalbert commented 3 years ago

Thank you for figuring this out!

hathach commented 3 years ago

yeah, I could reproduce the issue, troubleshooting on the way, will post more update when available.

hathach commented 3 years ago
Write addr = 0x000ACD00, block = 2142 (2142 of 2191)
Write addr = 0x000ACE00, block = 2143 (2143 of 2191)
Write addr = 0x000ACF00, block = 2144 (2144 of 2191)

I found the issue, the bootloader is limited its size to 512KB since it reserved the rest for internal file system ( for all boards), since the very first implementation of the bootloader.

For that I think we will increase reserved size to 40KB. The overflow to fatfs should be checked by circuitpyhon linker, just try DEBUG=1 with boards internal flash, it overflows and won't linked which is good.