I think it would be more useful to just state the things you need to change for your program to work with any boot loader:
- First, figure at which address your bootloader expects the user program to be. In my example this is set in flashconfig.h as FLASH_USER_BASE and is in this case 0x08005000. Remember this number.
- Now you need to change your user program to be located at this location. You need to change only 2 settings:
- Your linker script:
- By default your makefile uses a standard chibios linker script. In our case os/ports/GCC/ARMCMx/STM32F1xx/ld/STM32F107xC.ld.
- Copy it into your project folder. And modify LDSCRIPT in your makefile to point to your new linker script. (You might want to test if your project still compiles.)
- Modify the starting point of your flash in the linker script. This the flash : org = 0x08000000, len = 256k line. Just replace 0x08000000 with the address you remembered above. (You might also reduce the length of the free flash space, but it is not so important..)
- Your program should still compile - but not work.
- Your linker script:
- The start of your interrupt vector jump table. Which was originally at 0x08000000 now moved to 0x08005000. Currently there is the boot loader at that place, so we have to tell the Cortex-M3 where to too look.
- We can do this by adding the setting to chconf.h.
- Add a define for CORTEX_VTOR_INIT to chconf.h pointing to address 0x00005000. Do not worry about the missing 8 in the address. The processor does a internal mapping of the flash/ram...
You should now be able to flash the program via the bootloader. It might also work to flash it directly over jtag (if you do no flash mass erase) since you will only start writing flash at 0x08005000 and the bootloader is preserved and will just jump to your user application.