Re: Version/Signature in Flash
Trampas Stern <[email protected]> Wed, 19 Jan 2022 10:11:25 -0500
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <CADqjcyghaKvp25DpgTaW5BSUbicQtZsC77ccnZipkcT+uJT_pA@mail.gmail.com> |
--0000000000003ab62405d5f0cd15 Content-Type: text/plain; charset="UTF-8" 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 <[email protected]> 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 <[email protected]>: > > 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 <[email protected] > <mailto:[email protected] <[email protected]>>>: > > 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 > > > --0000000000003ab62405d5f0cd15 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">I recommend creating the section in the linker file.=C2=A0= It is often easier for the next guy looking at your code to find the secti= on in the linker file.=C2=A0<div><br></div><div>That is, embedded=C2=A0deve= lopment follows a path, from writing code to make it work, to making it wor= k reliably, to making it where the next guy can understand 6 months from no= w.=C2=A0=C2=A0</div><div><br></div><div>In that respect most people use com= mand line options=C2=A0in embedded development for changing options, for ex= ample code might support two boards and you have a command line option as t= o which board,=C2=A0or if you build for debug or release.=C2=A0 Whereas the= linker file would be more for global project options that do not need to c= hange per build/board.=C2=A0=C2=A0</div><div><br></div><div>Think of embedd= ed development. It is like driving a car, sure you can make a lane change l= ocking up brakes and skidding to the next lane.=C2=A0 However the guy behin= d you expects you to turn on the turn signals and gracefully=C2=A0make lane= changes.=C2=A0 It is not always about getting the job done, but doing it w= here the guy behind you can predict what you have done and why so that ever= yone is safe and comfortable.=C2=A0</div><div><br></div><div>Like driving a= car there are numerous ways to get where you=C2=A0are going, often it is h= ow to get there so that others understand and can predict what you are doin= g and why so they can stay out of your way.=C2=A0</div><div><br></div><div>= Trampas</div><div><br></div></div><br><div class=3D"gmail_quote"><div dir= =3D"ltr" class=3D"gmail_attr">On Wed, Jan 19, 2022 at 8:13 AM Michael Stock= er <<a href=3D"mailto:[email protected]">[email protected]</a>>= wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px = 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div sty= le=3D"overflow-wrap: break-word;">You are right.<div><br></div><div><div st= yle=3D"margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;= color:rgba(0,0,0,0.85);background-color:rgb(255,255,255)"><span style=3D"wh= ite-space:pre-wrap"> </span>-Wl,--undefined=3Dsignature</div><div><br></div= ><div>This will keep it in flash and not let the linker strip its value.</d= iv><div>Also when preparing your .hex file for flashing you may need to exp= licitly tell the sections you want.</div><div><br></div><div><span style=3D= "color:rgba(0,0,0,0.85);font-family:Menlo;background-color:rgb(255,255,255)= "><span style=3D"white-space:pre-wrap"> </span>avr-objcopy=C2=A0</span><spa= n style=3D"color:rgba(0,0,0,0.85);font-family:Menlo;background-color:rgb(25= 5,255,255)">-j .text -j .data -j .my_signature -O ihex prog.elf prog.hex</s= pan>=C2=A0</div><div><br></div><div>Cheers</div><div><br></div><div>Michael= </div><div><br></div><div><br></div><div><br><blockquote type=3D"cite"><div= >Am 2022-01-19 um 14:06 schrieb Klaus Rudolph <<a href=3D"mailto:lts-rud= [email protected]" target=3D"_blank">[email protected]</a>>:</div><br><div><s= pan style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-va= riant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start= ;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;te= xt-decoration:none;float:none;display:inline">Thanks for the linker command= ! I was not aware that we are able to</span><br style=3D"font-family:Helvet= ica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:n= ormal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform= :none;white-space:normal;word-spacing:0px;text-decoration:none"><span style= =3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant-cap= s:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-ind= ent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decora= tion:none;float:none;display:inline">define a section and put the content t= o flash by simply adding something</span><br style=3D"font-family:Helvetica= ;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:norm= al;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:no= ne;white-space:normal;word-spacing:0px;text-decoration:none"><span style=3D= "font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:n= ormal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent= :0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoratio= n:none;float:none;display:inline">on the linker command. Is there no need t= o tell the linker that this</span><br style=3D"font-family:Helvetica;font-s= ize:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;lett= er-spacing:normal;text-align:start;text-indent:0px;text-transform:none;whit= e-space:normal;word-spacing:0px;text-decoration:none"><span style=3D"font-f= amily:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;f= ont-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;te= xt-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;= float:none;display:inline">section should be kept as it is typically not re= ferenced and "optimized"</span><br style=3D"font-family:Helvetica= ;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:norm= al;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:no= ne;white-space:normal;word-spacing:0px;text-decoration:none"><span style=3D= "font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:n= ormal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent= :0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoratio= n:none;float:none;display:inline">out?</span><br style=3D"font-family:Helve= tica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:= normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transfor= m:none;white-space:normal;word-spacing:0px;text-decoration:none"><br style= =3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant-cap= s:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-ind= ent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decora= tion:none"><span style=3D"font-family:Helvetica;font-size:12px;font-style:n= ormal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;tex= t-align:start;text-indent:0px;text-transform:none;white-space:normal;word-s= pacing:0px;text-decoration:none;float:none;display:inline">Thanks!</span><b= r style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-vari= ant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;t= ext-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text= -decoration:none"><span style=3D"font-family:Helvetica;font-size:12px;font-= style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:nor= mal;text-align:start;text-indent:0px;text-transform:none;white-space:normal= ;word-spacing:0px;text-decoration:none;float:none;display:inline">Klaus</sp= an><br style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font= -variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:st= art;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px= ;text-decoration:none"><br style=3D"font-family:Helvetica;font-size:12px;fo= nt-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:= normal;text-align:start;text-indent:0px;text-transform:none;white-space:nor= mal;word-spacing:0px;text-decoration:none"><span style=3D"font-family:Helve= tica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:= normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transfor= m:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;= display:inline">Am 19.01.22 um 13:48 schrieb Michael Stocker:</span><br sty= le=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant-c= aps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-i= ndent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-deco= ration:none"><blockquote type=3D"cite" style=3D"font-family:Helvetica;font-= size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;let= ter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;whi= te-space:normal;word-spacing:0px;text-decoration:none">Hallo Klaus,<br><br>= you can always define your own sections at a fixed location in flash and<br= >write anything you like in there.<br>But every time you start a new sectio= n the previous one is closed<br>implicitly. So it cannot be in the middle o= f another section.<br>It also cannot go at the beginning of flash because t= he interrupt<br>vectors are expected to be there.<br><br>You can put anythi= ng into a section as long as it fits. Here for example<br>a 32-bit signatur= e:<br><br>const uint32_t __attribute__((section(".my_signature"))= ) signature =3D<br>0xCAFEBABE;<br><br>The linker then needs an additional a= rgument to know where this section is:<br><br>-Wl,--section-start=3D. my_si= gnature =3D0x7FFC<br><br>Where 0x7FFC is the byte-offset in flash not the w= ord-offset. 0x7FFC<br>would mean the end of flash on an ATmega328P.<br><br>= Hope this helps.<br><br>Michael<br><br><br><br><blockquote type=3D"cite">Am= 2022-01-18 um 11:21 schrieb Klaus Rudolph <<a href=3D"mailto:lts-rudolp= [email protected]" target=3D"_blank">[email protected]</a><br><<a href=3D"mailto= :[email protected]" target=3D"_blank">mailto:[email protected]</a>>>= ;:<br><br>Hi,<br><br>is there already a defined wy to place a user defined = signature in the<br>flash memory?<br><br>Use Case: Simply put some version = info, maybe a a string with given<br>format or a git hash id or whatever in= a specified flash area.<br><br>I see we have a section ".signature&qu= ot; but this is in use for a predefined<br>3 byte signature. I also see in = the linker scripts that there is<br>something called "user_signatures&= quot; but that seems to be unsupported for<br>the rest of the linker script= . But maybe I looked in the wrong file...<br><br>Any suggestions?<br><br>Th= anks<br>Klaus</blockquote></blockquote></div></blockquote></div><br></div><= /div></blockquote></div> --0000000000003ab62405d5f0cd15--