You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by marko kiiskila <ma...@runtime.io> on 2018/12/18 10:34:19 UTC

flash_loader

Hi all,

this might be worth mentioning: https://github.com/apache/mynewt-core/pull/1557 <https://github.com/apache/mynewt-core/pull/1557>.

flash_loader app runs on MCU, and expects commands to be written directly to RAM.
Commands like ‘write data to flash’, ‘erase’, ‘write-and-verify’ and ‘read’.

So now there’s now tooling to populate external flash for platforms which either
a) have external SPI flash in addition to internal flash, and you need to get data there. Or
b) MCUs which execute from RAM, and have only external SPI flash to store it’s
images.
If your JTAG programmer can do this automatically, great. If not, you could use this
to do the programming.

flash_loader, like other mynewt apps, is built using a specific BSP. And it will be
able to do this operations on any flash which appears in the BSP flash device table.
You could think of it as hal_flash interface which is exported to JTAG programmer.

I assume people will always execute this from RAM, and an example on how this
could work using nordic_pca10040 BSP.  See https://github.com/apache/mynewt-core/pull/1547 <https://github.com/apache/mynewt-core/pull/1547>.

Of course, you’ll want to have scripting on the programmer side to feed data in/out of
the flash_loader app. I implemented this using gdb scripts (as that’s the debugger
of choice for us, and can run over openocd and Segger JLink).

These helper routines are located here:
https://github.com/apache/mynewt-core/blob/master/compiler/gdbmacros/flash_loader.gdb <https://github.com/apache/mynewt-core/blob/master/compiler/gdbmacros/flash_loader.gdb>
You can, of course, replace these with openocd/JLink scripts. Contributions always welcome.

Here’s a gdb script I use to populate the image slot1 with these scripts for nordic_pca10040:

—8<—cut-start—
set pagination off

shell sh -c "trap '' 2; JLinkGDBServer -device nRF52 -speed 4000 -if SWD -port 3333 -singlerun > logfile.txt 2>&1 &"
target remote localhost:3333
mon reset
restore bin/targets/fl_nrf52dk/app/apps/flash_loader/flash_loader.elf.bin binary 0x20000000
symbol-file bin/targets/fl_nrf52dk/app/apps/flash_loader/flash_loader.elf
set $sp=*(int *)0x20000000
set $pc=*(int *)0x20000004
b blink_led
c

source repos/apache-mynewt-core/compiler/gdbmacros/flash_loader.gdb
mon go

fl_load nrf52.img 0 0x42000
mon halt
mon reset
quit
—8<—cut-end---

And here’s my flash loader app target for that BSP.
targets/fl_nrf52dk
    app=@apache-mynewt-core/apps/flash_loader
    bsp=@apache-mynewt-core/hw/bsp/nordic_pca10040
    build_profile=optimized
    syscfg=FLASH_LOADER_DL_SZ=0x8000:RAM_RESIDENT=1