Re: Version/Signature in Flash

Michael Kwasnicki <[email protected]> Wed, 19 Jan 2022 17:05:46 +0100
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
--Apple-Mail=_29929155-A56E-4A7A-AF8A-9D707537031C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

I am not sure if I got it right.
The linker is only involved until the .elf file has been created.
If the question is to pad out the content of the .hex file so it is one =
continuous block then it can be done with :

	avr-objcopy -j .text -j .data -j .my_signature --gap-fill 0xFF =
-O ihex prog.elf prog.hex=20

The gap-fill argument fills the blanks with a specific value (0xFF in =
this case).

Cheers

Michael


> Am 2022-01-19 um 16:30 schrieb Jim Brain <[email protected]>:
>=20
> On 1/19/2022 7:13 AM, Michael Stocker wrote:
>> You are right.
>>=20
>> 	-Wl,--undefined=3Dsignature
>>=20
>> 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.
>>=20
>> 	avr-objcopy -j .text -j .data -j .my_signature -O ihex prog.elf =
prog.hex=20
>>=20
>> Cheers
>>=20
>> Michael
>>=20
> This may be a naive question, but is it possible to "place" the =
signature in a specific location in the resulting output file, padding =
the file to the required size to include the signature?
>=20
> Use case:
>=20
> One of the projects I utilize defines a 4 byte signature at the end of =
the AVR code space (top 4 bytes), and it checks that signature in the =
bootloader to see if an update on storage is newer than the one =
installed.  Right now, the main developer has created a Perl script that =
pulls the resulting object file, padds it out, and puts the 4 bytes at =
the end.  It would be nice to do all of that in the linker.
>=20
>=20


--Apple-Mail=_29929155-A56E-4A7A-AF8A-9D707537031C
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""><div =
class=3D"">I am not sure if I got it right.</div><div class=3D"">The =
linker is only involved until the .elf file has been created.</div><div =
class=3D"">If the question is to pad out the content of the .hex file so =
it is one continuous block then it can be done with :</div><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><span class=3D"">avr-objcopy&nbsp;</span><span class=3D"">-j =
.text -j .data -j .my_signature <b class=3D"">--gap-fill 0xFF</b> -O =
ihex prog.elf prog.hex</span>&nbsp;</div></div><div class=3D""><br =
class=3D""></div><div class=3D"">The gap-fill argument fills the blanks =
with a specific value (0xFF in this case).</div><div class=3D""><br =
class=3D""></div><div class=3D"">Cheers</div><div class=3D""><br =
class=3D""></div><div class=3D"">Michael</div><br class=3D""><div><br =
class=3D""><blockquote type=3D"cite" class=3D""><div class=3D"">Am =
2022-01-19 um 16:30 schrieb Jim Brain &lt;<a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt;:</div><br =
class=3D"Apple-interchange-newline"><div class=3D"">
 =20
    <meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3DUTF-8" class=3D"">
 =20
  <div class=3D"">
    <div class=3D"moz-cite-prefix">On 1/19/2022 7:13 AM, Michael Stocker
      wrote:<br class=3D"">
    </div>
    <blockquote type=3D"cite" =
cite=3D"mid:[email protected]" class=3D"">=

      <meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3DUTF-8" 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; 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 class=3D""><br class=3D"">
        </div>
        <div class=3D"">This will keep it in flash and not let the =
linker strip its
          value.</div>
        <div class=3D"">Also when preparing your .hex file for flashing =
you may
          need to explicitly tell the sections you want.</div>
        <div class=3D""><br class=3D"">
        </div>
        <div class=3D""><span style=3D"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"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 class=3D""><br class=3D"">
        </div>
        <div class=3D"">Cheers</div>
        <div class=3D""><br class=3D"">
        </div>
        <div class=3D"">Michael</div>
        <div class=3D""><br class=3D"">
        </div>
      </div>
    </blockquote><p class=3D"">This may be a naive question, but is it =
possible to "place" the
      signature in a specific location in the resulting output file,
      padding the file to the required size to include the =
signature?</p><p class=3D"">Use case:</p><p class=3D"">One of the =
projects I utilize defines a 4 byte signature at the
      end of the AVR code space (top 4 bytes), and it checks that
      signature in the bootloader to see if an update on storage is
      newer than the one installed.&nbsp; Right now, the main developer =
has
      created a Perl script that pulls the resulting object file, padds
      it out, and puts the 4 bytes at the end.&nbsp; It would be nice to =
do
      all of that in the linker.</p>
    <br class=3D"">
  </div>

</div></blockquote></div><br class=3D""></body></html>=

--Apple-Mail=_29929155-A56E-4A7A-AF8A-9D707537031C--