Update high-memory bootloader and build for 128k and 64k boards#23
Update high-memory bootloader and build for 128k and 64k boards#23dmsc wants to merge 3 commits intodevanlai:masterfrom
Conversation
The bootloader now lives at the high end of flash, allowing an non- bootloader-aware application to run without modifications. The bootloader modifies the application's vector table to point to the bootloader's reset stub. The actual reset vector is stored in unused entries in the application's vector table. Based on ideas from: http://stm32duino.com/viewtopic.php?t=687 This is based on code from commit cf21dc3 fixing DFU upload and rebasing on current master branch. Co-authored-by: Daniel Serpell <daniel.serpell@gmail.com>
|
Hi @dmsc, I see three paths forward for the high-memory variant of the bootloader:
|
|
Hi!
I liked the idea of the high-memory bootloader because can upload the same binary either with my st-link-v2 clone, allowing faster development, debugging and testing; or via the bootloader once the code is mostly stable - so I don't need two USB devices connected to my PC. IMHO, the idea of storing the original stack and reset vectors in the unused slots is clever, and makes this code almost transparent, so it only has upsides compared to the normal bootloader. Also, improvements on the bootloader size can be done without backward incompatibilities, it just allows bigger firmware to be used.
All three paths work for me. If you want to do option 2, I can modify my code to make conditional compilation of the changed parts. Also, what do you think of commit 5f160ec , you can cherry-pick it if you want, or I could send it as a new pull-request. Thanks! |
For me, the main reasons to prefer a conventional bootloader are:
These are not unreasonable tradeoffs to make, but they're important enough that I wouldn't consider the high-memory bootloader a strict improvement.
I think option 2 would be the best approach if you're up for it.
I'm surprised that replacing the standard (probably newlib-nano) implementations of those functions saves so much space. I might take a look at the linker map and asm output later to see what's going on there, but otherwise I'm fine with the size-optimized versions you've added. |
|
Hi!
Yes, this should be documented in the docs.
Ok, when I have more free time I will work on it.
Ah, but I just realized, you are not using newlib-nano, the Makefile does not add the -specs=nano.specs flag. The newlib memcpy try to copy 64 bytes at a time, so they have a lot of code to test alignment and handle odd sizes. You can see using "arm-none-eabi-objdump -S src/dapboot.elf", 236 bytes for memcpy!!: If you use newlib-nano, current memcpy is same size as mine, strlen is 2 bytes bigger and strncpy is 80 bytes bigger. So, you gain 82 bytes. |
Great, I'm looking forward to it 👍
Ah, I didn't realize that I wasn't requesting newlib nano (the perils of copying and pasting the Makefile and not paying close attention to the options being inherited). Personally, if using newlib-nano instead gets to within 82 bytes of the manually replaced version, I would use that instead unless the firmware was right on the cusp of not fitting into the next smallest number of whole flash sectors. |
|
Superseded by #24. |
Hi!
This is the bootloader that I'm using now in my bluepill boards (I have three boards to test), tested also in one stm32-mini and one olimexino-stm32 (maple compatible)
The three commits are:
I rebased your high-memory code fixing a bug on the DFU upload (the original code was overwriting RAM when patching the data to send).
Added targets for 128kB and 64kB boards, as the high-memory bootloader needs to reside on the top of FLASH. If your bluepill reports 64kB of flash, you can try flashing the 128kB image regardless (using "st-flash --flash=0x20000"), as most chips internally have 128kB of flash. This works in all my bluepills.
Use small versions of the three libc funciones called: memcpy, strlen and strncpy. This reduces the bootloader size considerably.
Posting here to see if you are interested.