You are right. -Wl,--undefined=signature
This will keep it in flash and not let the linker strip its value. Also when preparing your .hex file for flashing you may need to explicitly tell the sections you want. avr-objcopy -j .text -j .data -j .my_signature -O ihex prog.elf prog.hex Cheers Michael > Am 2022-01-19 um 14:06 schrieb Klaus Rudolph <lts-rudo...@gmx.de>: > > Thanks for the linker command! I was not aware that we are able to > define a section and put the content to flash by simply adding something > on the linker command. Is there no need to tell the linker that this > section should be kept as it is typically not referenced and "optimized" > out? > > Thanks! > Klaus > > Am 19.01.22 um 13:48 schrieb Michael Stocker: >> Hallo Klaus, >> >> you can always define your own sections at a fixed location in flash and >> write anything you like in there. >> But every time you start a new section the previous one is closed >> implicitly. So it cannot be in the middle of another section. >> It also cannot go at the beginning of flash because the interrupt >> vectors are expected to be there. >> >> You can put anything into a section as long as it fits. Here for example >> a 32-bit signature: >> >> const uint32_t __attribute__((section(".my_signature"))) signature = >> 0xCAFEBABE; >> >> The linker then needs an additional argument to know where this section is: >> >> -Wl,--section-start=. my_signature =0x7FFC >> >> Where 0x7FFC is the byte-offset in flash not the word-offset. 0x7FFC >> would mean the end of flash on an ATmega328P. >> >> Hope this helps. >> >> Michael >> >> >> >>> Am 2022-01-18 um 11:21 schrieb Klaus Rudolph <lts-rudo...@gmx.de >>> <mailto:lts-rudo...@gmx.de <mailto:lts-rudo...@gmx.de>>>: >>> >>> Hi, >>> >>> is there already a defined wy to place a user defined signature in the >>> flash memory? >>> >>> Use Case: Simply put some version info, maybe a a string with given >>> format or a git hash id or whatever in a specified flash area. >>> >>> I see we have a section ".signature" but this is in use for a predefined >>> 3 byte signature. I also see in the linker scripts that there is >>> something called "user_signatures" but that seems to be unsupported for >>> the rest of the linker script. But maybe I looked in the wrong file... >>> >>> Any suggestions? >>> >>> Thanks >>> Klaus