Re: Version/Signature in Flash

Michael Stocker <[email protected]> Wed, 19 Jan 2022 14:13:43 +0100
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
--Apple-Mail=_84E7F971-75F0-4FCD-B1E5-647B3D416514
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

You are right.

	-Wl,--undefined=3Dsignature

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=20

Cheers

Michael



> Am 2022-01-19 um 14:06 schrieb Klaus Rudolph <[email protected]>:
>=20
> 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?
>=20
> Thanks!
> Klaus
>=20
> Am 19.01.22 um 13:48 schrieb Michael Stocker:
>> Hallo Klaus,
>>=20
>> 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.
>>=20
>> You can put anything into a section as long as it fits. Here for =
example
>> a 32-bit signature:
>>=20
>> const uint32_t __attribute__((section(".my_signature"))) signature =3D
>> 0xCAFEBABE;
>>=20
>> The linker then needs an additional argument to know where this =
section is:
>>=20
>> -Wl,--section-start=3D. my_signature =3D0x7FFC
>>=20
>> Where 0x7FFC is the byte-offset in flash not the word-offset. 0x7FFC
>> would mean the end of flash on an ATmega328P.
>>=20
>> Hope this helps.
>>=20
>> Michael
>>=20
>>=20
>>=20
>>> Am 2022-01-18 um 11:21 schrieb Klaus Rudolph <[email protected]
>>> <mailto:[email protected] <mailto:[email protected]>>>:
>>>=20
>>> Hi,
>>>=20
>>> is there already a defined wy to place a user defined signature in =
the
>>> flash memory?
>>>=20
>>> 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.
>>>=20
>>> 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...
>>>=20
>>> Any suggestions?
>>>=20
>>> Thanks
>>> Klaus


--Apple-Mail=_84E7F971-75F0-4FCD-B1E5-647B3D416514
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D"">You =
are right.<div class=3D""><br class=3D""></div><div class=3D""><div =
style=3D"margin: 0px; font-stretch: normal; line-height: normal; =
font-family: Menlo; color: rgba(0, 0, 0, 0.85098); background-color: =
rgb(255, 255, 255);" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>-Wl,--undefined=3Dsignature</div><div><br =
class=3D""></div><div>This will keep it in flash and not let the linker =
strip its value.</div><div>Also when preparing your .hex file for =
flashing you may need to explicitly tell the sections you =
want.</div><div><br class=3D""></div><div><span style=3D"color: rgba(0, =
0, 0, 0.85098); font-family: Menlo; background-color: rgb(255, 255, =
255);" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>avr-objcopy&nbsp;</span><span =
style=3D"color: rgba(0, 0, 0, 0.85098); font-family: Menlo; =
background-color: rgb(255, 255, 255);" class=3D"">-j .text -j .data -j =
.my_signature -O ihex prog.elf prog.hex</span>&nbsp;</div><div><br =
class=3D""></div><div>Cheers</div><div><br =
class=3D""></div><div>Michael</div><div><br class=3D""></div><div><br =
class=3D""></div><div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D"">Am 2022-01-19 um 14:06 schrieb Klaus Rudolph =
&lt;<a href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt;:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;" class=3D"">Thanks for the linker command! I =
was not aware that we are able to</span><br style=3D"caret-color: rgb(0, =
0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">define a section and put the content to flash by simply =
adding something</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">on the linker command. Is there no need to tell the linker =
that this</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: normal; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: normal; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" class=3D"">section =
should be kept as it is typically not referenced and =
"optimized"</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: normal; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: normal; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" class=3D"">out?</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;" class=3D"">Thanks!</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;" class=3D"">Klaus</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: =
normal; letter-spacing: normal; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;" class=3D"">Am 19.01.22 um 13:48 schrieb =
Michael Stocker:</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><blockquote type=3D"cite" =
style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
orphans: auto; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D"">Hallo Klaus,<br class=3D""><br =
class=3D"">you can always define your own sections at a fixed location =
in flash and<br class=3D"">write anything you like in there.<br =
class=3D"">But every time you start a new section the previous one is =
closed<br class=3D"">implicitly. So it cannot be in the middle of =
another section.<br class=3D"">It also cannot go at the beginning of =
flash because the interrupt<br class=3D"">vectors are expected to be =
there.<br class=3D""><br class=3D"">You can put anything into a section =
as long as it fits. Here for example<br class=3D"">a 32-bit =
signature:<br class=3D""><br class=3D"">const uint32_t =
__attribute__((section(".my_signature"))) signature =3D<br =
class=3D"">0xCAFEBABE;<br class=3D""><br class=3D"">The linker then =
needs an additional argument to know where this section is:<br =
class=3D""><br class=3D"">-Wl,--section-start=3D. my_signature =
=3D0x7FFC<br class=3D""><br class=3D"">Where 0x7FFC is the byte-offset =
in flash not the word-offset. 0x7FFC<br class=3D"">would mean the end of =
flash on an ATmega328P.<br class=3D""><br class=3D"">Hope this helps.<br =
class=3D""><br class=3D"">Michael<br class=3D""><br class=3D""><br =
class=3D""><br class=3D""><blockquote type=3D"cite" class=3D"">Am =
2022-01-18 um 11:21 schrieb Klaus Rudolph &lt;<a =
href=3D"mailto:[email protected]" class=3D"">[email protected]</a><br =
class=3D"">&lt;<a href=3D"mailto:[email protected]" =
class=3D"">mailto:[email protected]</a>&gt;&gt;:<br class=3D""><br =
class=3D"">Hi,<br class=3D""><br class=3D"">is there already a defined =
wy to place a user defined signature in the<br class=3D"">flash =
memory?<br class=3D""><br class=3D"">Use Case: Simply put some version =
info, maybe a a string with given<br class=3D"">format or a git hash id =
or whatever in a specified flash area.<br class=3D""><br class=3D"">I =
see we have a section ".signature" but this is in use for a =
predefined<br class=3D"">3 byte signature. I also see in the linker =
scripts that there is<br class=3D"">something called "user_signatures" =
but that seems to be unsupported for<br class=3D"">the rest of the =
linker script. But maybe I looked in the wrong file...<br class=3D""><br =
class=3D"">Any suggestions?<br class=3D""><br class=3D"">Thanks<br =
class=3D"">Klaus</blockquote></blockquote></div></blockquote></div><br =
class=3D""></div></body></html>=

--Apple-Mail=_84E7F971-75F0-4FCD-B1E5-647B3D416514--