I would like to write my own bootloader for a arm cortex-m4 processor. Read a few articles, searched a few blogs but I'm still struggling in finding the right resources. I'm looking for a deeper dive into the instruction on how and less "here is the code".
I'll recommend two books. I don't know if these are the "best" books on the subject, but <i>I</i> found them useful for some system-level experiments I did on an Odroid. They explain both the big picture and implementation details:<p>1) <i>Professional Embedded ARM Development, by Langbridge [1]</i><p>This one is more about ARM instructions than about bootloaders or embedded OSes, but it does cover bootloaders in detail with case studies of some relatively unknown embedded boards, of the well-known Raspberry Pi, and of modern bootloader software like u-boot.<p>2) <i>Building Embedded Systems, by Gu [2]</i><p>This book is broader than the one above, covering all kinds of embedded systems. It's the better book to understand the big picture, and understand how all the components (bootloader, OS, SoC, hardware buses, storage) interact. It does cover bootloaders but not in depth and not with case studies.<p>[1]: <a href="https://www.amazon.com/Professional-Embedded-Development-James-Langbridge/dp/111878894X" rel="nofollow">https://www.amazon.com/Professional-Embedded-Development-Jam...</a><p>[2]: <a href="https://www.amazon.com/Building-Embedded-Systems-Programmable-Hardware/dp/148421918X/" rel="nofollow">https://www.amazon.com/Building-Embedded-Systems-Programmabl...</a>
Some bootloaders can be really simple. Here is one I wrote recently for my security key product (this particular code is for an ARM M3).<p><a href="https://github.com/SoloKeysSec/solo/blob/master/targets/efm32boot/src/main.c" rel="nofollow">https://github.com/SoloKeysSec/solo/blob/master/targets/efm3...</a><p><a href="https://github.com/SoloKeysSec/solo/blob/master/targets/efm32boot/src/boot.c" rel="nofollow">https://github.com/SoloKeysSec/solo/blob/master/targets/efm3...</a><p>Like what others mention, it really depends on documentation from the vendor for the chipset you're working with. I mainly copied and pasted code from a form post by the vendor.<p>And of course link to the security key product :)<p><a href="https://solokeys.com/" rel="nofollow">https://solokeys.com/</a>
I'm not sure what you're actually looking for. It might help if you defined what you considered a "bootloader" to be. Are you trying to bring up an existing OS or app? Are you trying to initialize the processor prior to running your own code?
A couple of times I wrote bootloaders for new chips. I relied heavily on the chip vendors documentation. It was usually almost non-existent, and no more than text saying what things I had to do in what sequence. But taking that info, then looking at other bootloaders for operating systems (to see if there was environment specific things I should be considering) I was able to create boot loaders.
At the end of the day, a bootloader is just memcpy, and a jump (with a few details like setting up a stack, any serial ports etc).<p>You usually can have quite a bit of help by looking at the generated code from your compiler that sets up a simple 'main(...){ while(1); }' program. Often it'll be in your toolchain as a .S file or similar.