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 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 found a similar thread here: "How do I write to 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. I prefer to do In-circuit-Programming if possible.