I am using the Atmel ARM M0+ MCU (ATSAMD20J18). I have written a bootload for it. The bootloader will check the first few bytes (lets call it magic key) from an external SPI flash memory to determine whether to enter the bootload mode. If the bytes are correct, it will copy data from the same SPI flash to the MCU's internal flash.
The problem is for the first time programming (for example in manufacturing), I need to have both the bootloader and the first version application firmware programmed in the MCU before we send out the product. Therefore I am thinking that if there is any method so that I can program the bootloader at address 0x0000, and the application firmware starting at address 0x4000?
Another method is I can program the bootloader to the MCU, and then using some method to program the external SPI flash with the application firmware and the magic key. The question is how can I program the extenal SPI flash? I know there are tools that can program a SPI flash. However besides to write the binary format application firmware, I also need to write the magic key and the length of the application firmware to the first few bytes of the flash.