Re: Version/Signature in Flash
Michael Stocker <[email protected]> Wed, 19 Jan 2022 13:48:57 +0100
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_D043343F-C786-4FDE-9819-9A7EF6C5A91C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
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 =3D 0xCAFEBABE;
The linker then needs an additional argument to know where this section =
is:
-Wl,--section-start=3D. my_signature =3D0x7FFC
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 <[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
>=20
--Apple-Mail=_D043343F-C786-4FDE-9819-9A7EF6C5A91C
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"">Hallo=
Klaus,<div class=3D""><br class=3D""></div><div class=3D"">you can =
always define your own sections at a fixed location in flash and write =
anything you like in there.</div><div class=3D"">But every time you =
start a new section the previous one is closed implicitly. So it cannot =
be in the middle of another section.</div><div class=3D"">It also cannot =
go at the beginning of flash because the interrupt vectors are expected =
to be there.</div><div class=3D""><br class=3D""></div><div class=3D"">You=
can put anything into a section as long as it fits. Here for example a =
32-bit signature:</div><div class=3D""><br class=3D""></div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span><span style=3D"color: rgba(0, 0, 0, 0.85098); font-family: Menlo; =
background-color: rgb(255, 255, 255);" class=3D"">const uint32_t =
__attribute__((section(".my_signature"))) signature =3D =
0xCAFEBABE;</span></div><div class=3D""><br class=3D""></div><div =
class=3D"">The linker then needs an additional argument to know where =
this section is:</div><div class=3D""><br class=3D""></div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span><span style=3D"color: rgba(0, 0, 0, 0.85098); font-family: Menlo; =
background-color: rgb(255, 255, 255);" =
class=3D"">-Wl,--section-start=3D.</span> <span style=3D"caret-color:=
rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098); font-family: =
Menlo; background-color: rgb(255, 255, 255);" =
class=3D"">my_signature</span> <span style=3D"color: rgba(0, 0, 0, =
0.85098); font-family: Menlo; background-color: rgb(255, 255, 255);" =
class=3D"">=3D0x7FFC</span></div><div class=3D""><br class=3D""></div><div=
class=3D"">Where 0x7FFC is the byte-offset in flash not the =
word-offset. 0x7FFC would mean the end of flash on an =
ATmega328P.</div><div class=3D""><br class=3D""></div><div class=3D"">Hope=
this helps.</div><div class=3D""><br class=3D""></div><div =
class=3D"">Michael</div><div class=3D""><br class=3D""></div><div =
class=3D""><br class=3D""><div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D"">Am 2022-01-18 um 11:21 schrieb Klaus Rudolph =
<<a href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>>:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div 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<br =
class=3D""><br class=3D""></div></div></blockquote></div><br =
class=3D""></div></body></html>=
--Apple-Mail=_D043343F-C786-4FDE-9819-9A7EF6C5A91C--