I'm trying to add a serial number to the bootloader's flash area of Adafruit Feather m0 board. Seems like feather m0 0-0x2000 area on the flash is non writable by the arduino sketch. i wanted to add a serial number to address 0x2000 - 8 on the flash. The idea is for the data to be included in the bootloader elf\bin so i can easily flash it on devices and later on access it using flash address (0x2000 - 8) with NVMCTRL.
I've started out with this solution:
downloaded the code from samd21 arduino bootloader github directory and in ./bootloaders/zero edited the boololoader ld script, first the "Memory" section
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x2000 /* First 8KB used by bootloader */
FLASHID (rx) : ORIGIN = 0x00002000 - 0x0008, LENGTH = 8
Then the 'sections' section:
.id_sec :
{
KEEP(*(.myid))
} > FLASHID
This should have saved some room in the end of the flash for the id. now in the main.c file:
__attribute__ ((section(".myid"))) const unsigned long ID = 0xdead1234;
Which should have saved the 0xdead1234 hex value in the (0x2000-8) address.
The issue is this:
I compiled this code and linked it just fine, got .hex,.bin,.elf files.
If i'm correct (unless they are somehow compressed) i should be able to see the code 0xdead in the binary.
BUT i don't.
After objdump on the binary(any of them) i can't find the 0xde 0xad in any order anywhere.
The arm-none-eabi-size" --format=sysv -t -x build/.elf
does not show the new section i added no where.
Also i do wonder, as i said the 0x2000 address on the flash is non writable once i flashed with atmel-ice \j-link even the bootloader code cannot write to it, i did define in the ld script that i want that memory region part of the flash so i do expect that the compiler + linker + jlink flasher will know to write that data to the right place but not sure.
Anyone got some experience with it ? did it before ?