I recommend creating the section in the linker file. It is often easier for the next guy looking at your code to find the section in the linker file.
That is, embedded development follows a path, from writing code to make it work, to making it work reliably, to making it where the next guy can understand 6 months from now. In that respect most people use command line options in embedded development for changing options, for example code might support two boards and you have a command line option as to which board, or if you build for debug or release. Whereas the linker file would be more for global project options that do not need to change per build/board. Think of embedded development. It is like driving a car, sure you can make a lane change locking up brakes and skidding to the next lane. However the guy behind you expects you to turn on the turn signals and gracefully make lane changes. It is not always about getting the job done, but doing it where the guy behind you can predict what you have done and why so that everyone is safe and comfortable. Like driving a car there are numerous ways to get where you are going, often it is how to get there so that others understand and can predict what you are doing and why so they can stay out of your way. Trampas On Wed, Jan 19, 2022 at 8:13 AM Michael Stocker <avr-...@kwasi-ich.de> wrote: > 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 <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 > > >