Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

[FORTRAN] will persist for some time -- probably for at least the next decade. -- T. Cheatham


devel / comp.arch.embedded / Re: Embedding a Checksum in an Image File

SubjectAuthor
* Embedding a Checksum in an Image FileRick C
+* Re: Embedding a Checksum in an Image FileNiklas Holsti
|`- Re: Embedding a Checksum in an Image FileRick C
+- Re: Embedding a Checksum in an Image FilePeter Heitzer
+* Re: Embedding a Checksum in an Image Filedalai lamah
|`- Re: Embedding a Checksum in an Image FileRick C
+- Re: Embedding a Checksum in an Image FileDavid Brown
+* Re: Embedding a Checksum in an Image FileGeorge Neuner
|+* Re: Embedding a Checksum in an Image FileRick C
||+* Re: Embedding a Checksum in an Image FileDavid Brown
|||`* Re: Embedding a Checksum in an Image FileUlf Samuelsson
||| `* Re: Embedding a Checksum in an Image FileDavid Brown
|||  `- Re: Embedding a Checksum in an Image FileUlf Samuelsson
||`* Re: Embedding a Checksum in an Image FileGeorge Neuner
|| +* Re: Embedding a Checksum in an Image FileDon Y
|| |`* Re: Embedding a Checksum in an Image FileDavid Brown
|| | `* Re: Embedding a Checksum in an Image FileDon Y
|| |  `* Re: Embedding a Checksum in an Image FileDavid Brown
|| |   `* Re: Embedding a Checksum in an Image FileDon Y
|| |    `* Re: Embedding a Checksum in an Image FileDavid Brown
|| |     `* Re: Embedding a Checksum in an Image FileDon Y
|| |      `* Re: Embedding a Checksum in an Image FileDavid Brown
|| |       `* Re: Embedding a Checksum in an Image FileDon Y
|| |        `* Re: Embedding a Checksum in an Image FileDavid Brown
|| |         +* Re: Embedding a Checksum in an Image FileUlf Samuelsson
|| |         |`* Re: Embedding a Checksum in an Image FileDavid Brown
|| |         | `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
|| |         |  `- Re: Embedding a Checksum in an Image FileDon Y
|| |         `- Re: Embedding a Checksum in an Image FileDon Y
|| `- Re: Embedding a Checksum in an Image FileStefan Reuther
|`* Re: Embedding a Checksum in an Image FileTauno Voipio
| `- Re: Embedding a Checksum in an Image FileGeorge Neuner
+* Re: Embedding a Checksum in an Image FileRichard Damon
|`* Re: Embedding a Checksum in an Image FileRick C
| `- Re: Embedding a Checksum in an Image FileRichard Damon
+* Re: Embedding a Checksum in an Image FileBrian Cockburn
|`* Re: Embedding a Checksum in an Image FileRick C
| +* Re: Embedding a Checksum in an Image FileDavid Brown
| |+* Re: Embedding a Checksum in an Image FileBrian Cockburn
| ||`- Re: Embedding a Checksum in an Image FileDavid Brown
| |`* Re: Embedding a Checksum in an Image FileRick C
| | +* Re: Embedding a Checksum in an Image FileDavid Brown
| | |`* Re: Embedding a Checksum in an Image FileRick C
| | | `* Re: Embedding a Checksum in an Image FileDavid Brown
| | |  +* Re: Embedding a Checksum in an Image FileGrant Edwards
| | |  |`* Re: Embedding a Checksum in an Image FileDavid Brown
| | |  | `* Re: Embedding a Checksum in an Image FileGrant Edwards
| | |  |  `* Re: Embedding a Checksum in an Image FileDavid Brown
| | |  |   `* Re: Embedding a Checksum in an Image FileRichard Damon
| | |  |    `- Re: Embedding a Checksum in an Image FileDavid Brown
| | |  +- Re: Embedding a Checksum in an Image FileboB
| | |  `* Re: Embedding a Checksum in an Image FileRick C
| | |   `* Re: Embedding a Checksum in an Image FileDavid Brown
| | |    `* Re: Embedding a Checksum in an Image FileRick C
| | |     `* Re: Embedding a Checksum in an Image FileDavid Brown
| | |      `- Re: Embedding a Checksum in an Image FileRick C
| | `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
| |  `* Re: Embedding a Checksum in an Image FileDavid Brown
| |   `- Re: Embedding a Checksum in an Image FileUlf Samuelsson
| `* Re: Embedding a Checksum in an Image FileBrian Cockburn
|  `* Re: Embedding a Checksum in an Image FileRick C
|   `* Re: Embedding a Checksum in an Image FileBrian Cockburn
|    +- Re: Embedding a Checksum in an Image FileRichard Damon
|    `- Re: Embedding a Checksum in an Image FileRick C
+* Re: Embedding a Checksum in an Image FileUlf Samuelsson
|+* Re: Embedding a Checksum in an Image FileRick C
||+* Re: Embedding a Checksum in an Image FileNiklas Holsti
|||+- Re: Embedding a Checksum in an Image FileNiklas Holsti
|||+* Re: Embedding a Checksum in an Image FileUlf Samuelsson
||||`* Re: Embedding a Checksum in an Image FileDavid Brown
|||| `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
||||  `* Re: Embedding a Checksum in an Image FileDavid Brown
||||   `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
||||    `* Re: Embedding a Checksum in an Image FileDavid Brown
||||     `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
||||      `- Re: Embedding a Checksum in an Image FileDavid Brown
|||`- Re: Embedding a Checksum in an Image FileDavid Brown
||`* Re: Embedding a Checksum in an Image FileUlf Samuelsson
|| `* Re: Embedding a Checksum in an Image FileNiklas Holsti
||  `- Re: Embedding a Checksum in an Image FileUlf Samuelsson
|`* Re: Embedding a Checksum in an Image FileDavid Brown
| `* Re: Embedding a Checksum in an Image FileUlf Samuelsson
|  `* Re: Embedding a Checksum in an Image FileDavid Brown
|   `- Re: Embedding a Checksum in an Image FileUlf Samuelsson
`- Re: Embedding a Checksum in an Image FileUlf Samuelsson

Pages:1234
Re: Embedding a Checksum in an Image File

<99aaf8df-1f0e-4911-9706-0bac770e3d1cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1487&group=comp.arch.embedded#1487

  copy link   Newsgroups: comp.arch.embedded
X-Received: by 2002:ae9:e40c:0:b0:74e:1090:8906 with SMTP id q12-20020ae9e40c000000b0074e10908906mr2296820qkc.0.1682271241337;
Sun, 23 Apr 2023 10:34:01 -0700 (PDT)
X-Received: by 2002:a05:622a:1793:b0:3e3:8172:ff21 with SMTP id
s19-20020a05622a179300b003e38172ff21mr3889351qtk.8.1682271241051; Sun, 23 Apr
2023 10:34:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.embedded
Date: Sun, 23 Apr 2023 10:34:00 -0700 (PDT)
In-Reply-To: <u2171f$3cbcu$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=63.114.57.174; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 63.114.57.174
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<66e9fb2a-b9e6-4597-9afa-6572caaa8ca1n@googlegroups.com> <a4495c87-c68d-4c87-94aa-701c21bdd19cn@googlegroups.com>
<u1u8hu$2ps79$1@dont-email.me> <ef5ad4e6-57ed-4950-baed-3a6746b9d16en@googlegroups.com>
<u20tin$3alrj$1@dont-email.me> <3986aac8-aec3-4cde-8bb8-8a61c20084c9n@googlegroups.com>
<u2171f$3cbcu$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <99aaf8df-1f0e-4911-9706-0bac770e3d1cn@googlegroups.com>
Subject: Re: Embedding a Checksum in an Image File
From: gnuarm.deletethisbit@gmail.com (Rick C)
Injection-Date: Sun, 23 Apr 2023 17:34:01 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Rick C - Sun, 23 Apr 2023 17:34 UTC

On Saturday, April 22, 2023 at 1:55:01 PM UTC-4, David Brown wrote:
> On 22/04/2023 18:56, Rick C wrote:
> > On Saturday, April 22, 2023 at 11:13:32 AM UTC-4, David Brown wrote:
> >> On 22/04/2023 05:14, Rick C wrote:
> >>> On Friday, April 21, 2023 at 11:02:28 AM UTC-4, David Brown wrote:
> >>>> On 21/04/2023 14:12, Rick C wrote:
> >>>>>
> >>>>> This is simply to be able to say this version is unique,
> >>>>> regardless of what the version number says. Version numbers are
> >>>>> set manually and not always done correctly. I'm looking for
> >>>>> something as a backup so that if the checksums are different, I
> >>>>> can be sure the versions are not the same.
> >>>>>
> >>>>> The less work involved, the better.
> >>>>>
> >>>> Run a simple 32-bit crc over the image. The result is a hash of
> >>>> the image. Any change in the image will show up as a change in the
> >>>> crc.
> >>>
> >>> No one is trying to detect changes in the image. I'm trying to label
> >>> the image in a way that can be read in operation. I'm using the
> >>> checksum simply because that is easy to generate. I've had problems
> >>> with version numbering in the past. It will be used, but I want it
> >>> supplemented with a number that will change every time the design
> >>> changes, at least with a high probability, such as 1 in 64k.
> >>>
> >> Again - use a CRC. It will give you what you want.
> >
> > Again - as will a simple addition checksum.
> A simple addition checksum might be okay much of the time, but it
> doesn't have the resolving power of a CRC. If the source code changes
> "a = 1; b = 2;" to "a = 2; b = 1;", the addition checksum is likely to
> be exactly the same despite the change in the source. In general, you
> will have much higher chance of collisions, though I think it would be
> very hard to quantify that.
>
> Maybe it will be good enough for you. Simple checksums were popular
> once, and can still make sense if you are very short on program space.
> But there are good reasons why they fell out of favour in many uses.
> >
> >
> >> You might want to go for 32-bit CRC rather than a 16-bit CRC, depending
> >> on the kind of program, how often you build it, and what consequences a
> >> hash collision could have. With a 16-bit CRC, you have a 5% chance of a
> >> collision after 82 builds. If collisions only matter for releases, and
> >> you only release a couple of updates, fine - but if they matter during
> >> development builds, you are getting a more significant risk. Since a
> >> 32-bit CRC is quick and easy, it's worth using.
> >
> > Or, I might want to go with a simple checksum.
> >
> > Thanks for your comments.
> >
> It's your choice (obviously). I only point out the weaknesses in case
> anyone else is listening in to the thread.
>
> If you like, I can post code for a 32-bit CRC. It's a table, and a few
> lines of C code.

You know nothing of the project I am working on or those that I typically work on. But thanks for the advice.

--

Rick C.

+-- Get 1,000 miles of free Supercharging
+-- Tesla referral code - https://ts.la/richard11209

Re: Embedding a Checksum in an Image File

<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1503&group=comp.arch.embedded#1503

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 18:26:37 +0200
Organization: eMagii
Lines: 36
Message-ID: <105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2102917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hOH7r/DwxPJ/+V9g8uNKr"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:S8i0biu0Co06e1yQkf4sfVXUyx8=
Content-Language: sv
In-Reply-To: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
 by: Ulf Samuelsson - Thu, 27 Apr 2023 16:26 UTC

Den 2023-04-20 kl. 04:06, skrev Rick C:
> This is a bit of the chicken and egg thing. If you want a embed a checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.
>
The proper way to do this is to have a directive in the linker.
This reserves space for the CRC and defines the area where the CRC is
calculated.
I am not aware of any linker which support this.

Two months ago, I added the DIGEST directive to binutils aka the GNU
linker. It was committed, but then people realized that I had not signed
an agreement with Free Software Foundation.
Since part of the code I pushed was from a third party which released
their code under MIT, the licensing has not been resolved yet
but the patch is in binutils git, but reverted.

You would write (IIRC):
DIGEST "CRC64-ECMA", (from, to)
and the linker would reserve 8 bytes which is filled with the CRC in the
final link stage.

/Ulf

> I'm not thinking anything too fancy, like a CRC, but rather a simple modulo N addition, maybe N being 2^16.
>
> I keep thinking of using a placeholder, but that doesn't seem to work out in any useful way. Even if you try to anticipate the impact of adding the checksum, that only gives you a different checksum, that you then need to anticipate further... ad infinitum.
>
> I'm not thinking of any special checksum generator that excludes the checksum data. That would be too messy.
>
> I keep thinking there is a different way of looking at this to achieve the result I want...
>
> Maybe I can prove it is impossible. Assume the file checksums to X when the checksum data is zero. The goal would then be to include the checksum data value Y in the file, that would change X to Y. Given the properties of the module N checksum, this would appear to be impossible for the general case, unless... Add another data value, called, checksum normalizer. This data value checksums with the original checksum to give the result zero. Then, when the checksum is also added, the resulting checksum is, in fact, the checksum. Another way of looking at this is to add a value that combines with the added checksum, to be zero, leaving the original checksum intact.
>
> This might be inordinately hard for a CRC, but a simple checksum would not be an issue, I think. At least, this could work in software, where data can be included in an image file as itself. In a device like an FPGA, it might not be included in the bit stream file so directly... but that might depend on where in the device it is inserted. Memory might have data that is stored as itself. I'll need to look into that.
>

Re: Embedding a Checksum in an Image File

<u2e7p3$205k5$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1504&group=comp.arch.embedded#1504

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 18:27:11 +0200
Organization: eMagii
Lines: 36
Message-ID: <u2e7p3$205k5$2@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 27 Apr 2023 16:27:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2102917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Qgg2DKm7UqNyJfkofPW/R"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:cEXgUQaOtrYa5yrZx+83VSJgLFM=
In-Reply-To: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
Content-Language: sv
 by: Ulf Samuelsson - Thu, 27 Apr 2023 16:27 UTC

Den 2023-04-20 kl. 04:06, skrev Rick C:
> This is a bit of the chicken and egg thing. If you want a embed a checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.
>
The proper way to do this is to have a directive in the linker.
This reserves space for the CRC and defines the area where the CRC is
calculated.
I am not aware of any linker which support this.

Two months ago, I added the DIGEST directive to binutils aka the GNU
linker. It was committed, but then people realized that I had not signed
an agreement with Free Software Foundation.
Since part of the code I pushed was from a third party which released
their code under MIT, the licensing has not been resolved yet
but the patch is in binutils git, but reverted.

You would write (IIRC):
DIGEST "CRC64-ECMA", (from, to)
and the linker would reserve 8 bytes which is filled with the CRC in the
final link stage.

/Ulf

> I'm not thinking anything too fancy, like a CRC, but rather a simple modulo N addition, maybe N being 2^16.
>
> I keep thinking of using a placeholder, but that doesn't seem to work out in any useful way. Even if you try to anticipate the impact of adding the checksum, that only gives you a different checksum, that you then need to anticipate further... ad infinitum.
>
> I'm not thinking of any special checksum generator that excludes the checksum data. That would be too messy.
>
> I keep thinking there is a different way of looking at this to achieve the result I want...
>
> Maybe I can prove it is impossible. Assume the file checksums to X when the checksum data is zero. The goal would then be to include the checksum data value Y in the file, that would change X to Y. Given the properties of the module N checksum, this would appear to be impossible for the general case, unless... Add another data value, called, checksum normalizer. This data value checksums with the original checksum to give the result zero. Then, when the checksum is also added, the resulting checksum is, in fact, the checksum. Another way of looking at this is to add a value that combines with the added checksum, to be zero, leaving the original checksum intact.
>
> This might be inordinately hard for a CRC, but a simple checksum would not be an issue, I think. At least, this could work in software, where data can be included in an image file as itself. In a device like an FPGA, it might not be included in the bit stream file so directly... but that might depend on where in the device it is inserted. Memory might have data that is stored as itself. I'll need to look into that.
>

Re: Embedding a Checksum in an Image File

<u2e8ba$205k5$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1505&group=comp.arch.embedded#1505

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 18:36:55 +0200
Organization: eMagii
Lines: 88
Message-ID: <u2e8ba$205k5$3@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<pvl24i57aef4vc7bbdk9mvj7sic9dsh64t@4ax.com>
<f0afa198-e735-4da1-a16a-82764af3de4dn@googlegroups.com>
<u1s76b$o11h$1@dont-email.me>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Apr 2023 16:36:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2102917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FJFHaoXs4r2srjC8L7jnZ"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:+Gw4Q69iZ+bJy9jSbtnXiVUoVC8=
Content-Language: sv
In-Reply-To: <u1s76b$o11h$1@dont-email.me>
 by: Ulf Samuelsson - Thu, 27 Apr 2023 16:36 UTC

Den 2023-04-20 kl. 22:26, skrev David Brown:
> On 20/04/2023 18:45, Rick C wrote:
>> On Thursday, April 20, 2023 at 11:33:28 AM UTC-4, George Neuner
>> wrote:
>>> On Wed, 19 Apr 2023 19:06:33 -0700 (PDT), Rick C
>>> <gnuarm.del...@gmail.com> wrote:
>>>
>>>> This is a bit of the chicken and egg thing. If you want a embed
>>>> a checksum in a code module to report the checksum, is there a
>>>> way of doing this? It's a bit like being your own grandfather, I
>>>> think.
>>> Take a look at the old xmodem/ymodem CRC. It was designed such
>>> that when the CRC was sent immediately following the data, a
>>> receiver computing CRC over the whole incoming packet (data and CRC
>>> both) would get a result of zero.
>>>
>>> But AFAIK it doesn't work with CCITT equation(s) - you have to use
>>> xmodem/ymodem.
>>>> I'm not thinking anything too fancy, like a CRC, but rather a
>>>> simple modulo N addition, maybe N being 2^16.
>>> Sorry, I don't know a way to do it with a modular checksum. YMMV,
>>> but I think 16-bit CRC is pretty simple.
>>>
>>> George
>>
>> CRC is not complicated, but I would not know how to calculate an
>> inserted value to force the resulting CRC to zero.  How do you do
>> that?
>
> You "insert" the value at the end.  Anything else is insane.

In all projects I have been involved with, the application binary starts
with a header looking like this.

MAGIC WORD 1
CRC
Entry Point
Size
other info...
MAGIC WORD 2
APPLICATION_START
....
APPLICATION_END (aligned with flash sector)

The bootloader first checks the two magic words.
It then computes CRC on the header (from Entry Point) to APPLICATION_END

I ported the IAR ielftool (open source) to Linux at
https://github.com/emagii/ielftool

This can insert the CRC in the ELF file, but needs tweaks to work
with an ELF file generated by the GNU tools.

/Ulf

>
> CRC's are quite good hashes, for suitable sized data.  There are perhaps
> some special cases, but basically you'd be doing trial-and-error
> searches to find an inserted value that gives you a zero CRC overall.
> 2^16 is not an overwhelming search space, but the whole idea is pointless.
>
>>
>> Even so, I'm not trying to validate the file.  I'm trying to come up
>> with a substitute for a time stamp or version number.  I don't want
>> to have to rely on my consistency in handling the version number
>> correctly.  This would be a backup in case there was more than one
>> version released, even only within the "lab", that were different.  A
>> checksum that could be read by the controlling software would do the
>> job.
>
> A CRC is fine for that.
>
>>
>> I have run into this before, where the version number was not a 100%
>> indication of the uniqueness of an executable.  The checksum would be
>> a second indicator.
>>
>> I should mention that I'm not looking for a solution that relies on
>> any specific details of the tools.
>>
>
> A table-based CRC is easy, runs quickly, and can be quickly ported to
> pretty much any language (the C and Python code, for example, is almost
> the same).

Re: Embedding a Checksum in an Image File

<u2e8lu$205k5$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1506&group=comp.arch.embedded#1506

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 18:42:34 +0200
Organization: eMagii
Lines: 24
Message-ID: <u2e8lu$205k5$4@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<66e9fb2a-b9e6-4597-9afa-6572caaa8ca1n@googlegroups.com>
<a4495c87-c68d-4c87-94aa-701c21bdd19cn@googlegroups.com>
<u1u8hu$2ps79$1@dont-email.me>
<ef5ad4e6-57ed-4950-baed-3a6746b9d16en@googlegroups.com>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Apr 2023 16:42:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2102917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wLpFi/2JtwbACh6JXQ0+Q"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:+UMGBEB2Y/mhEmmHerH4KLbICV0=
In-Reply-To: <ef5ad4e6-57ed-4950-baed-3a6746b9d16en@googlegroups.com>
Content-Language: sv
 by: Ulf Samuelsson - Thu, 27 Apr 2023 16:42 UTC

Den 2023-04-22 kl. 05:14, skrev Rick C:
> On Friday, April 21, 2023 at 11:02:28 AM UTC-4, David Brown wrote:
>> On 21/04/2023 14:12, Rick C wrote:
>>>
>>> This is simply to be able to say this version is unique, regardless
>>> of what the version number says. Version numbers are set manually
>>> and not always done correctly. I'm looking for something as a backup
>>> so that if the checksums are different, I can be sure the versions
>>> are not the same.
>>>
>>> The less work involved, the better.
>>>
>> Run a simple 32-bit crc over the image. The result is a hash of the
>> image. Any change in the image will show up as a change in the crc.
>
> No one is trying to detect changes in the image. I'm trying to label the image in a way that can be read in operation. I'm using the checksum simply because that is easy to generate. I've had problems with version numbering in the past. It will be used, but I want it supplemented with a number that will change every time the design changes, at least with a high probability, such as 1 in 64k.
>

Another thing I added (and was later removed) was a timestamp directive.
A 64 bit integer with the number of seconds since 1970-01-01 00:00.

/Ulf

Re: Embedding a Checksum in an Image File

<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1507&group=comp.arch.embedded#1507

  copy link   Newsgroups: comp.arch.embedded
X-Received: by 2002:ac8:7d13:0:b0:3ef:3204:5158 with SMTP id g19-20020ac87d13000000b003ef32045158mr814703qtb.7.1682615367544;
Thu, 27 Apr 2023 10:09:27 -0700 (PDT)
X-Received: by 2002:a05:622a:15c1:b0:3ef:499a:dd95 with SMTP id
d1-20020a05622a15c100b003ef499add95mr739328qty.7.1682615367241; Thu, 27 Apr
2023 10:09:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.embedded
Date: Thu, 27 Apr 2023 10:09:27 -0700 (PDT)
In-Reply-To: <105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
Injection-Info: google-groups.googlegroups.com; posting-host=65.207.89.54; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 65.207.89.54
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com> <105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
Subject: Re: Embedding a Checksum in an Image File
From: gnuarm.deletethisbit@gmail.com (Rick C)
Injection-Date: Thu, 27 Apr 2023 17:09:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 41
 by: Rick C - Thu, 27 Apr 2023 17:09 UTC

On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
> Den 2023-04-20 kl. 04:06, skrev Rick C:
> > This is a bit of the chicken and egg thing. If you want a embed a checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.
> >
> The proper way to do this is to have a directive in the linker.
> This reserves space for the CRC and defines the area where the CRC is
> calculated.

That assumes there is a linker. How does the application access this information?

> I am not aware of any linker which support this.
>
> Two months ago, I added the DIGEST directive to binutils aka the GNU
> linker. It was committed, but then people realized that I had not signed
> an agreement with Free Software Foundation.
> Since part of the code I pushed was from a third party which released
> their code under MIT, the licensing has not been resolved yet
> but the patch is in binutils git, but reverted.
>
> You would write (IIRC):
> DIGEST "CRC64-ECMA", (from, to)
> and the linker would reserve 8 bytes which is filled with the CRC in the
> final link stage.

You are making a lot of assumptions about the tools. I'm pretty sure they don't apply to my case. I'm not at all clear how this is workable, anyway. Adding the checksum to the file, changes the checksum, which is where this conversation started... unless I'm missing something significant.

--

Rick C.

+++ Get 1,000 miles of free Supercharging
+++ Tesla referral code - https://ts.la/richard11209

Re: Embedding a Checksum in an Image File

<kavt7iFlvc5U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1509&group=comp.arch.embedded#1509

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 21:29:05 +0300
Organization: Tidorum Ltd
Lines: 56
Message-ID: <kavt7iFlvc5U1@mid.individual.net>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net VWgrIikAZ6SOAqu1P9O3eQfTr9E30UUyfNRkeCnId/pRyHL0K3
Cancel-Lock: sha1:u3Z3LidXklZL4GUaT8bEYJ00P/E=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
 by: Niklas Holsti - Thu, 27 Apr 2023 18:29 UTC

On 2023-04-27 20:09, Rick C wrote:
> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>> This is a bit of the chicken and egg thing. If you want a embed a checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.
>>>
>> The proper way to do this is to have a directive in the linker.
>> This reserves space for the CRC and defines the area where the CRC is
>> calculated.
>
> That assumes there is a linker.

Almost all toolchains have a linker.

> How does the application access this information?

In Ulf's suggestion, it seems the DIGEST directive emits 8 bytes of
checksum at the current point (usually the linker "." symbol). I assume
one can give that point in the image a linkage symbol, perhaps like

_checksum DIGEST "CRC64-ECMA", (from, to)

or like

_checksum EQU. .
DIGEST "CRC64-ECMA", (from, to)

(This is schematic linker code, not necessarily proper syntax.)

One can then from the application code access the "checksum" location as
an externally defined object, say:

extern uint8[8] checksum;

The linker will connect that C identifier to the actual address of the
DIGEST checksum. Here I assumed that the C compiler mangles C
identifiers into linkage symbols by prefixing an underscore; YMMV.

> You are making a lot of assumptions about the tools. I'm pretty sure
> they don't apply to my case. I'm not at all clear how this is
> workable, anyway. Adding the checksum to the file, changes the
> checksum, which is where this conversation started... unless I'm
> missing something significant.

But you have insisted that your "checksum" is for the purpose of
identifying the version of the program, not for checking the integrity
of the memory image. If so, that checksum does not have to be the
checksum of the whole memory image, as long as it is the checksum of the
part of the image that contains the actual code and constant data, and
so will change according to changes in those parts of the image.

Re: Embedding a Checksum in an Image File

<kavtrnFlvc5U2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1510&group=comp.arch.embedded#1510

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 21:39:51 +0300
Organization: Tidorum Ltd
Lines: 18
Message-ID: <kavtrnFlvc5U2@mid.individual.net>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net ekm21ivTAVX/vvduGtIMEQliEE2UBYjofDepnVE7//FkornHxb
Cancel-Lock: sha1:WMfQJUvmfnWp+errq4JyWE1yzG0=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <kavt7iFlvc5U1@mid.individual.net>
 by: Niklas Holsti - Thu, 27 Apr 2023 18:39 UTC

Um, just noting some typos in my last, with apologies:

On 2023-04-27 21:29, Niklas Holsti wrote:

>   _checksum  EQU.   .

should be

_checksum EQU .

(Thunderbird inserted an extra period out of "friendliness"...)

>    extern uint8[8] checksum;

should be (my C is rusty):

extern uint8 checksum[8];

Re: Embedding a Checksum in an Image File

<u2emd2$22pgk$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1511&group=comp.arch.embedded#1511

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 22:36:46 +0200
Organization: eMagii
Lines: 56
Message-ID: <u2emd2$22pgk$1@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Apr 2023 20:36:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2188820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vzTgA/F1SKYptnraCucFe"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:WsC6OMnIwYccgHrOIafB9RFoJlY=
Content-Language: sv
In-Reply-To: <b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
 by: Ulf Samuelsson - Thu, 27 Apr 2023 20:36 UTC

Den 2023-04-27 kl. 19:09, skrev Rick C:
> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>> This is a bit of the chicken and egg thing. If you want a embed a checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.
>>>
>> The proper way to do this is to have a directive in the linker.
>> This reserves space for the CRC and defines the area where the CRC is
>> calculated.
>
> That assumes there is a linker. How does the application access this information?
>
>
Linker command file
public CRC64; start, stop
HEADER = .;
QUAD(MAGIC);
CRC64 = .;
DIGEST "CRC64-ECMA", (start, stop)
start = .;
# Your data to be protected
...
stop = .;

C source code.

extern uint64_t CRC64;
extern char* start;
extern char* stop;

uint64_t crc;

crc64 = calc_crc64_ecma(start, stop);
if (crc64 == CRC64) {
/* everything is OK */
}

>> I am not aware of any linker which support this.
>>
>> Two months ago, I added the DIGEST directive to binutils aka the GNU
>> linker. It was committed, but then people realized that I had not signed
>> an agreement with Free Software Foundation.
>> Since part of the code I pushed was from a third party which released
>> their code under MIT, the licensing has not been resolved yet
>> but the patch is in binutils git, but reverted.
>>
>> You would write (IIRC):
>> DIGEST "CRC64-ECMA", (from, to)
>> and the linker would reserve 8 bytes which is filled with the CRC in the
>> final link stage.
>
> You are making a lot of assumptions about the tools. I'm pretty sure they don't apply to my case. I'm not at all clear how this is workable, anyway. Adding the checksum to the file, changes the checksum, which is where this conversation started... unless I'm missing something significant.
>
I am assuming that no tool support this off the shelg, but the patches
are inside binutils, but reverted.

/Ulf

Re: Embedding a Checksum in an Image File

<u2emsa$22pgk$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1512&group=comp.arch.embedded#1512

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 27 Apr 2023 22:44:54 +0200
Organization: eMagii
Lines: 77
Message-ID: <u2emsa$22pgk$2@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Apr 2023 20:44:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e06ed78c1495380a4807241f34669d85";
logging-data="2188820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YDFZfcHtKsjHpKszyWSu3"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:xjp9Tvt+8AX62EmWnugJNp8h6+8=
Content-Language: sv
In-Reply-To: <kavt7iFlvc5U1@mid.individual.net>
 by: Ulf Samuelsson - Thu, 27 Apr 2023 20:44 UTC

Den 2023-04-27 kl. 20:29, skrev Niklas Holsti:
> On 2023-04-27 20:09, Rick C wrote:
>> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>> This is a bit of the chicken and egg thing. If you want a embed a
>>>> checksum in a code module to report the checksum, is there a way of
>>>> doing this? It's a bit like being your own grandfather, I think.
>>>>
>>> The proper way to do this is to have a directive in the linker.
>>> This reserves space for the CRC and defines the area where the CRC is
>>> calculated.
>>
>> That assumes there is a linker.
>
>
> Almost all toolchains have a linker.
>
>
>> How does the application access this information?
>
>
> In Ulf's suggestion, it seems the DIGEST directive emits 8 bytes of
> checksum at the current point (usually the linker "." symbol). I assume
> one can give that point in the image a linkage symbol, perhaps like
>
>   _checksum  DIGEST "CRC64-ECMA", (from, to)
>
> or like
>
>   _checksum  EQU.   .
>              DIGEST "CRC64-ECMA", (from, to)
>
>
> (This is schematic linker code, not necessarily proper syntax.)
>
> One can then from the application code access the "checksum" location as
> an externally defined object, say:
>
>    extern uint8[8] checksum;
>
> The linker will connect that C identifier to the actual address of the
> DIGEST checksum. Here I assumed that the C compiler mangles C
> identifiers into linkage symbols by prefixing an underscore; YMMV.
>

Yes, that is more or less it.

>
>> You are making a lot of assumptions about the tools.  I'm pretty sure
>> they don't apply to my case.  I'm not at all clear how this is
>> workable, anyway.  Adding the checksum to the file, changes the
>> checksum, which is where this conversation started... unless I'm
>> missing something significant.
No, you reserve room for the checksum, but that needs to be outside
the checked area.
The address of the checksum needs to be known to the application.
Also the limits of the checked area.
That is why the application has a header in front in my projects.
The application is started by the bootloader, which checks
a number of things before the application is started.
The application can read the header as well to allow checking
the code area at runtime.

>
>
> But you have insisted that your "checksum" is for the purpose of
> identifying the version of the program, not for checking the integrity
> of the memory image. If so, that checksum does not have to be the
> checksum of the whole memory image, as long as it is the checksum of the
> part of the image that contains the actual code and constant data, and
> so will change according to changes in those parts of the image.
>

/Ulf

Re: Embedding a Checksum in an Image File

<kb0a5rFlvc6U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1515&group=comp.arch.embedded#1515

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 01:10:02 +0300
Organization: Tidorum Ltd
Lines: 55
Message-ID: <kb0a5rFlvc6U1@mid.individual.net>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<u2emd2$22pgk$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Z1r6UbirE2t7ernDCxvkBQf+t0t1Nrpc1s8BFw/w31c6TiaQpQ
Cancel-Lock: sha1:VCYE5glX6KfVIrCOi4EMzWmL0yI=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <u2emd2$22pgk$1@dont-email.me>
 by: Niklas Holsti - Thu, 27 Apr 2023 22:10 UTC

On 2023-04-27 23:36, Ulf Samuelsson wrote:
> Den 2023-04-27 kl. 19:09, skrev Rick C:
>> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>> This is a bit of the chicken and egg thing. If you want a embed a
>>>> checksum in a code module to report the checksum, is there a way of
>>>> doing this? It's a bit like being your own grandfather, I think.
>>>>
>>> The proper way to do this is to have a directive in the linker.
>>> This reserves space for the CRC and defines the area where the CRC is
>>> calculated.
>>
>> That assumes there is a linker.  How does the application access this
>> information?
>>
>>
> Linker command file
>         public CRC64; start, stop
>         HEADER = .;
>         QUAD(MAGIC);
>     CRC64 = .;
>         DIGEST "CRC64-ECMA", (start, stop)
>         start = .;
>         # Your data to be protected
>         ...
>         stop = .;
>
> C source code.
>
> extern uint64_t CRC64;
> extern char* start;
> extern char* stop;
>
> uint64_t crc;
>
> crc64 = calc_crc64_ecma(start, stop);
> if (crc64 == CRC64) {
>    /* everything is OK */
> }

I'm nit-picking, but that C code does not look right to me. The extern
declarations for "start" and "stop" claim them to be names of memory
locations that contain addresses, but the linker file just places them
at the starting and one-past-end locations of the block to be protected.
So the "start" variable contains the first bytes of the "data to be
protected", and the contents of the "stop" variable are not defined
because it is placed after the "data to be protected", where no code or
data is loaded (it seems).

It seems to me that the call to calc_crc64_ecma should get the addresses
of "start" and "stop" as arguments (&start, &stop), instead of their
values. But perhaps calc_crc64_ecma is not a function, but a macro that
can itself take the addresses of its parameters.

Re: Embedding a Checksum in an Image File

<u2frll$2bncf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1519&group=comp.arch.embedded#1519

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 09:12:53 +0200
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <u2frll$2bncf$1@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<pvl24i57aef4vc7bbdk9mvj7sic9dsh64t@4ax.com>
<f0afa198-e735-4da1-a16a-82764af3de4dn@googlegroups.com>
<u1s76b$o11h$1@dont-email.me> <u2e8ba$205k5$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 07:12:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2481551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nnkXAtJ2dfWF1xVq6H6BNCA8Y3/khcW0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:mFfU42h60IK3AEQ8wuq4/IH1+ro=
In-Reply-To: <u2e8ba$205k5$3@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 28 Apr 2023 07:12 UTC

On 27/04/2023 18:36, Ulf Samuelsson wrote:
> Den 2023-04-20 kl. 22:26, skrev David Brown:
>> On 20/04/2023 18:45, Rick C wrote:
>>> On Thursday, April 20, 2023 at 11:33:28 AM UTC-4, George Neuner
>>> wrote:
>>>> On Wed, 19 Apr 2023 19:06:33 -0700 (PDT), Rick C
>>>> <gnuarm.del...@gmail.com> wrote:
>>>>
>>>>> This is a bit of the chicken and egg thing. If you want a embed
>>>>> a checksum in a code module to report the checksum, is there a
>>>>> way of doing this? It's a bit like being your own grandfather, I
>>>>> think.
>>>> Take a look at the old xmodem/ymodem CRC. It was designed such
>>>> that when the CRC was sent immediately following the data, a
>>>> receiver computing CRC over the whole incoming packet (data and CRC
>>>> both) would get a result of zero.
>>>>
>>>> But AFAIK it doesn't work with CCITT equation(s) - you have to use
>>>> xmodem/ymodem.
>>>>> I'm not thinking anything too fancy, like a CRC, but rather a
>>>>> simple modulo N addition, maybe N being 2^16.
>>>> Sorry, I don't know a way to do it with a modular checksum. YMMV,
>>>> but I think 16-bit CRC is pretty simple.
>>>>
>>>> George
>>>
>>> CRC is not complicated, but I would not know how to calculate an
>>> inserted value to force the resulting CRC to zero.  How do you do
>>> that?
>>
>> You "insert" the value at the end.  Anything else is insane.
>
> In all projects I have been involved with, the application binary starts
> with a header looking like this.
>
>
> MAGIC WORD 1
> CRC
> Entry Point
> Size
> other info...
> MAGIC WORD 2
> APPLICATION_START
> ...
> APPLICATION_END (aligned with flash sector)
>
>
> The bootloader first checks the two magic words.
> It then computes CRC on the header (from Entry Point) to APPLICATION_END
>
> I ported the IAR ielftool (open source) to Linux at
> https://github.com/emagii/ielftool
>
> This can insert the CRC in the ELF file, but needs tweaks to work
> with an ELF file generated by the GNU tools.
>
> /Ulf

That can work for some microcontrollers, but is unsuitable for others -
it depends on how the flash is organised. For an msp430, for example,
it would be fine, as the interrupt vectors (including the reset vector)
are at the end of flash. But for most ARM Cortex M devices, it would
not be suitable - they expect the reset vector and initial stack pointer
at the start of the flash image. Some devices have a boot ROM, and then
you have to match their specifics for the header - or you can have your
own boot program, and make the header how ever you like.

I am absolutely a fan of having some kind of header like this (and
sometimes even a human-readable copyright notice, identifier and version
information). And having it as near the beginning as possible is good.
But for many microcontrollers, having it at the start is not feasible.
And if you can't put the CRC at the start like you do, you have to put
it at the end of the image.

I've never really thought about trying to inject a CRC into an elf file.
I use elfs (or should that be "elves" ?) for debugging, not flash
programming. And usually the main concern for having a CRC at the end
of the image is when you have an online update of some kind, to check
that nothing has gone wrong during the transfer or in-field update.

Re: Embedding a Checksum in an Image File

<u2fs41$2bnd0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1520&group=comp.arch.embedded#1520

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 09:20:33 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <u2fs41$2bnd0$1@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<66e9fb2a-b9e6-4597-9afa-6572caaa8ca1n@googlegroups.com>
<a4495c87-c68d-4c87-94aa-701c21bdd19cn@googlegroups.com>
<u1u8hu$2ps79$1@dont-email.me>
<ef5ad4e6-57ed-4950-baed-3a6746b9d16en@googlegroups.com>
<u2e8lu$205k5$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 07:20:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2481568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bEpv/kLBhxTBnC+nc0YAt6f47Dvl7prU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:7mzPd7lY4bra9J/FTj+quOZ+ILw=
Content-Language: en-GB
In-Reply-To: <u2e8lu$205k5$4@dont-email.me>
 by: David Brown - Fri, 28 Apr 2023 07:20 UTC

On 27/04/2023 18:42, Ulf Samuelsson wrote:
> Den 2023-04-22 kl. 05:14, skrev Rick C:
>> On Friday, April 21, 2023 at 11:02:28 AM UTC-4, David Brown wrote:
>>> On 21/04/2023 14:12, Rick C wrote:
>>>>
>>>> This is simply to be able to say this version is unique, regardless
>>>> of what the version number says. Version numbers are set manually
>>>> and not always done correctly. I'm looking for something as a backup
>>>> so that if the checksums are different, I can be sure the versions
>>>> are not the same.
>>>>
>>>> The less work involved, the better.
>>>>
>>> Run a simple 32-bit crc over the image. The result is a hash of the
>>> image. Any change in the image will show up as a change in the crc.
>>
>> No one is trying to detect changes in the image.  I'm trying to label
>> the image in a way that can be read in operation.  I'm using the
>> checksum simply because that is easy to generate.  I've had problems
>> with version numbering in the past.  It will be used, but I want it
>> supplemented with a number that will change every time the design
>> changes, at least with a high probability, such as 1 in 64k.
>>
>
> Another thing I added (and was later removed) was a timestamp directive.
> A 64 bit integer with the number of seconds since 1970-01-01 00:00.
>

Timestamping a build in some way (as part of the "make", using __DATE__
or __TIME__ in source code, or some feature of a revision control
system) is very tempting, and can be helpful for tracking exactly what
code you have on the system.

However, IMHO having reproducible builds is much more valuable. I am
not happy with a project build until I am getting identical binaries
built on multiple hosts (Windows and Linux). That's how you can be
absolutely sure of what code went into a particular binary, even years
or decades later.

A compromise that can work is to distinguish development builds and
production builds, and have timestamping in development builds. That
also reduces the rate at which your minor version number or build number
goes up, and avoids endless changes to your "version.h" include file.

Re: Embedding a Checksum in an Image File

<u2fsb1$2bnd0$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1522&group=comp.arch.embedded#1522

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 09:24:17 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <u2fsb1$2bnd0$2@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 07:24:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2481568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196iMzO0Q3DcO++k8VFO+MnxVmJEG1U/QM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:6CcjtR9FGA+uEK/DPgVZw/oIDR4=
In-Reply-To: <105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
Content-Language: en-GB
 by: David Brown - Fri, 28 Apr 2023 07:24 UTC

On 27/04/2023 18:26, Ulf Samuelsson wrote:
> Den 2023-04-20 kl. 04:06, skrev Rick C:
>> This is a bit of the chicken and egg thing.  If you want a embed a
>> checksum in a code module to report the checksum, is there a way of
>> doing this?  It's a bit like being your own grandfather, I think.
>>
> The proper way to do this is to have a directive in the linker.
> This reserves space for the CRC and defines the area where the CRC is
> calculated.
> I am not aware of any linker which support this.
>
> Two months ago, I added the DIGEST directive to binutils aka the GNU
> linker. It was committed, but then people realized that I had not signed
> an agreement with Free Software Foundation.
> Since part of the code I pushed was from a third party which released
> their code under MIT, the licensing has not been resolved yet
> but the patch is in binutils git, but reverted.
>
> You would write (IIRC):
>    DIGEST "CRC64-ECMA", (from, to)
> and the linker would reserve 8 bytes which is filled with the CRC in the
> final link stage.
>
> /Ulf
>

I like that. Thanks for doing that work.

Is there also a way to get the length of the final link, and insert it
near the beginning of the image? I suppose that would be another kind
of DIGEST where the algorithm is simply (to - from). (I assume that
"to" and "from" may be linker symbols.)

Re: Embedding a Checksum in an Image File

<u2fsst$2bnd0$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1523&group=comp.arch.embedded#1523

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 09:33:49 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <u2fsst$2bnd0$3@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 07:33:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2481568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NTbTDVs/1xTcFHnAsAYNCRCmLpagDvaQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:PO3PsbJHYNe5Ttp+5duULhahS84=
In-Reply-To: <kavt7iFlvc5U1@mid.individual.net>
Content-Language: en-GB
 by: David Brown - Fri, 28 Apr 2023 07:33 UTC

On 27/04/2023 20:29, Niklas Holsti wrote:
> On 2023-04-27 20:09, Rick C wrote:
>> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>> This is a bit of the chicken and egg thing. If you want a embed a
>>>> checksum in a code module to report the checksum, is there a way of
>>>> doing this? It's a bit like being your own grandfather, I think.
>>>>
>>> The proper way to do this is to have a directive in the linker.
>>> This reserves space for the CRC and defines the area where the CRC is
>>> calculated.
>>
>> That assumes there is a linker.
>
>
> Almost all toolchains have a linker.
>

It is possible that Rick is using Forth, rather than C (or other
languages traditionally compiled in a similar manner, such as C++ and
Ada). There are also some commercial C toolchains for brain-dead 8-bit
CISC devices that are monolithic and offer very little control over the
linking.

Ulf is correct that the ideal place to handle this is part of the
linking process. I do it with a post-link Python script run during the
build, because the linkers I use can't handle this at the moment. But
if Ulf's patch works its way into binutils then I'll be able to do it
directly during linking, which is neater. (I will still have post-link
scripts to handle things like renaming image files according to version,
making zips for sending to customers, etc. - linkers can't do
/everything/ !)

Re: Embedding a Checksum in an Image File

<u2ft59$2bnd0$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1524&group=comp.arch.embedded#1524

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 09:38:17 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <u2ft59$2bnd0$4@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net> <u2emsa$22pgk$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 07:38:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2481568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bEhF+r8LuekrcPJvOsmaRi0rEX+BwNTU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:EfGBuJw77N3OBTbP/I1R6HUcvA4=
Content-Language: en-GB
In-Reply-To: <u2emsa$22pgk$2@dont-email.me>
 by: David Brown - Fri, 28 Apr 2023 07:38 UTC

On 27/04/2023 22:44, Ulf Samuelsson wrote:
> Den 2023-04-27 kl. 20:29, skrev Niklas Holsti:
>> On 2023-04-27 20:09, Rick C wrote:

>
>>
>>> You are making a lot of assumptions about the tools.  I'm pretty sure
>>> they don't apply to my case.  I'm not at all clear how this is
>>> workable, anyway.  Adding the checksum to the file, changes the
>>> checksum, which is where this conversation started... unless I'm
>>> missing something significant.
> No, you reserve room for the checksum, but that needs to be outside
> the checked area.
> The address of the checksum needs to be known to the application.

The address here could have a symbol, and then declared "extern" in the
C code - it would not have to be a known numerical address. But if the
image is checked or started from another program (such as a boot
program), you need an absolute address somewhere to chain this all together.

> Also the limits of the checked area.
> That is why the application has a header in front in my projects.
> The application is started by the bootloader, which checks
> a number of things before the application is started.
> The application can read the header as well to allow checking
> the code area at runtime.
>

Or for my preferences, the CRC "DIGEST" would be put at the end of the
image, rather than near the start. Then the "from, to" range would
cover the entire image except for the final CRC. But I'd have a similar
directive for the length of the image at a specific area near the start.

Re: Embedding a Checksum in an Image File

<u2g0gc$2cdfn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1526&group=comp.arch.embedded#1526

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 10:35:20 +0200
Organization: eMagii
Lines: 107
Message-ID: <u2g0gc$2cdfn$1@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<pvl24i57aef4vc7bbdk9mvj7sic9dsh64t@4ax.com>
<f0afa198-e735-4da1-a16a-82764af3de4dn@googlegroups.com>
<u1s76b$o11h$1@dont-email.me> <u2e8ba$205k5$3@dont-email.me>
<u2frll$2bncf$1@dont-email.me>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 08:35:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b452f82109ea9c6d09e4f26752b75ae5";
logging-data="2504183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Rop+CdHSXpc4b5RruiBGT"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:zV6lqFMXu/UZbGroZNPtp2pDaIU=
Content-Language: sv
In-Reply-To: <u2frll$2bncf$1@dont-email.me>
 by: Ulf Samuelsson - Fri, 28 Apr 2023 08:35 UTC

Den 2023-04-28 kl. 09:12, skrev David Brown:
> On 27/04/2023 18:36, Ulf Samuelsson wrote:
>> Den 2023-04-20 kl. 22:26, skrev David Brown:
>>> On 20/04/2023 18:45, Rick C wrote:
>>>> On Thursday, April 20, 2023 at 11:33:28 AM UTC-4, George Neuner
>>>> wrote:
>>>>> On Wed, 19 Apr 2023 19:06:33 -0700 (PDT), Rick C
>>>>> <gnuarm.del...@gmail.com> wrote:
>>>>>
>>>>>> This is a bit of the chicken and egg thing. If you want a embed
>>>>>> a checksum in a code module to report the checksum, is there a
>>>>>> way of doing this? It's a bit like being your own grandfather, I
>>>>>> think.
>>>>> Take a look at the old xmodem/ymodem CRC. It was designed such
>>>>> that when the CRC was sent immediately following the data, a
>>>>> receiver computing CRC over the whole incoming packet (data and CRC
>>>>> both) would get a result of zero.
>>>>>
>>>>> But AFAIK it doesn't work with CCITT equation(s) - you have to use
>>>>> xmodem/ymodem.
>>>>>> I'm not thinking anything too fancy, like a CRC, but rather a
>>>>>> simple modulo N addition, maybe N being 2^16.
>>>>> Sorry, I don't know a way to do it with a modular checksum. YMMV,
>>>>> but I think 16-bit CRC is pretty simple.
>>>>>
>>>>> George
>>>>
>>>> CRC is not complicated, but I would not know how to calculate an
>>>> inserted value to force the resulting CRC to zero.  How do you do
>>>> that?
>>>
>>> You "insert" the value at the end.  Anything else is insane.
>>
>> In all projects I have been involved with, the application binary starts
>> with a header looking like this.
>>
>>
>> MAGIC WORD 1
>> CRC
>> Entry Point
>> Size
>> other info...
>> MAGIC WORD 2
>> APPLICATION_START
>> ...
>> APPLICATION_END (aligned with flash sector)
>>
>>
>> The bootloader first checks the two magic words.
>> It then computes CRC on the header (from Entry Point) to APPLICATION_END
>>
>> I ported the IAR ielftool (open source) to Linux at
>> https://github.com/emagii/ielftool
>>
>> This can insert the CRC in the ELF file, but needs tweaks to work
>> with an ELF file generated by the GNU tools.
>>
>> /Ulf
>
> That can work for some microcontrollers, but is unsuitable for others -
> it depends on how the flash is organised.  For an msp430, for example,
> it would be fine, as the interrupt vectors (including the reset vector)
> are at the end of flash.  But for most ARM Cortex M devices, it would
> not be suitable - they expect the reset vector and initial stack pointer
> at the start of the flash image.  Some devices have a boot ROM, and then
> you have to match their specifics for the header - or you can have your
> own boot program, and make the header how ever you like.

All projects I am involved with have a custom bootloader.
If there is a problem with the reset vector, then the program will fail
immediately.
The CRC is right after the initial vector table.
The bootloader application contains a copy of the vector table.

THe first thing the bootloader does is to check the CRC from right after
the CRC. Then it compares the vector table with the copy.

The header is only for the application.

>
> I am absolutely a fan of having some kind of header like this (and
> sometimes even a human-readable copyright notice, identifier and version
> information).  And having it as near the beginning as possible is good.
> But for many microcontrollers, having it at the start is not feasible.
> And if you can't put the CRC at the start like you do, you have to put
> it at the end of the image.
>
>
> I've never really thought about trying to inject a CRC into an elf file.
>  I use elfs (or should that be "elves" ?) for debugging, not flash
> programming.  And usually the main concern for having a CRC at the end
> of the image is when you have an online update of some kind, to check
> that nothing has gone wrong during the transfer or in-field update.
>
>

The last bootloader I wrote download using Y-Modem which has CRC
checking. Since it had more RAM than internal flash, the whole
application was downloaded to RAM first, and then when everything is OK,
the flash can be programmed. Finally, the header is analyzed and the
flash contents checked. There is absolutely no need to have the CRC at
the end since the CRC result is stored in a known location.

/Ulf

Re: Embedding a Checksum in an Image File

<u2g10k$2cdfn$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1528&group=comp.arch.embedded#1528

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 10:44:00 +0200
Organization: eMagii
Lines: 58
Message-ID: <u2g10k$2cdfn$2@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<66e9fb2a-b9e6-4597-9afa-6572caaa8ca1n@googlegroups.com>
<a4495c87-c68d-4c87-94aa-701c21bdd19cn@googlegroups.com>
<u1u8hu$2ps79$1@dont-email.me>
<ef5ad4e6-57ed-4950-baed-3a6746b9d16en@googlegroups.com>
<u2e8lu$205k5$4@dont-email.me> <u2fs41$2bnd0$1@dont-email.me>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 08:44:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b452f82109ea9c6d09e4f26752b75ae5";
logging-data="2504183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19S+n3MAHB5ub5K9M+q8HnL"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:0pFiUjt1aD+IuWHAbkZGyLVaAeI=
Content-Language: sv
In-Reply-To: <u2fs41$2bnd0$1@dont-email.me>
 by: Ulf Samuelsson - Fri, 28 Apr 2023 08:44 UTC

Den 2023-04-28 kl. 09:20, skrev David Brown:
> On 27/04/2023 18:42, Ulf Samuelsson wrote:
>> Den 2023-04-22 kl. 05:14, skrev Rick C:
>>> On Friday, April 21, 2023 at 11:02:28 AM UTC-4, David Brown wrote:
>>>> On 21/04/2023 14:12, Rick C wrote:
>>>>>
>>>>> This is simply to be able to say this version is unique, regardless
>>>>> of what the version number says. Version numbers are set manually
>>>>> and not always done correctly. I'm looking for something as a backup
>>>>> so that if the checksums are different, I can be sure the versions
>>>>> are not the same.
>>>>>
>>>>> The less work involved, the better.
>>>>>
>>>> Run a simple 32-bit crc over the image. The result is a hash of the
>>>> image. Any change in the image will show up as a change in the crc.
>>>
>>> No one is trying to detect changes in the image.  I'm trying to label
>>> the image in a way that can be read in operation.  I'm using the
>>> checksum simply because that is easy to generate.  I've had problems
>>> with version numbering in the past.  It will be used, but I want it
>>> supplemented with a number that will change every time the design
>>> changes, at least with a high probability, such as 1 in 64k.
>>>
>>
>> Another thing I added (and was later removed) was a timestamp directive.
>> A 64 bit integer with the number of seconds since 1970-01-01 00:00.
>>
>
> Timestamping a build in some way (as part of the "make", using __DATE__
> or __TIME__ in source code, or some feature of a revision control
> system) is very tempting, and can be helpful for tracking exactly what
> code you have on the system.
>
> However, IMHO having reproducible builds is much more valuable.  I am
> not happy with a project build until I am getting identical binaries
> built on multiple hosts (Windows and Linux).  That's how you can be
> absolutely sure of what code went into a particular binary, even years
> or decades later.

With the timestamp located in the header, you can simply compare the
non-header area.
Make with __DATE__ or __TIME__ will tell you when that module is
compiled, not when the program is generated.
That is why TIMESTAMP is best generated in the linker.

/Ulf

>
> A compromise that can work is to distinguish development builds and
> production builds, and have timestamping in development builds.  That
> also reduces the rate at which your minor version number or build number
> goes up, and avoids endless changes to your "version.h" include file.
>
>
>
>

Re: Embedding a Checksum in an Image File

<u2g1bu$2cdfn$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1529&group=comp.arch.embedded#1529

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 10:50:02 +0200
Organization: eMagii
Lines: 52
Message-ID: <u2g1bu$2cdfn$3@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net> <u2emsa$22pgk$2@dont-email.me>
<u2ft59$2bnd0$4@dont-email.me>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 08:50:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b452f82109ea9c6d09e4f26752b75ae5";
logging-data="2504183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YocL/nJ3L6oAzng3lOL1I"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:jiccs+8MzRpAHBUcfIivTuQPuzA=
In-Reply-To: <u2ft59$2bnd0$4@dont-email.me>
Content-Language: sv
 by: Ulf Samuelsson - Fri, 28 Apr 2023 08:50 UTC

Den 2023-04-28 kl. 09:38, skrev David Brown:
> On 27/04/2023 22:44, Ulf Samuelsson wrote:
>> Den 2023-04-27 kl. 20:29, skrev Niklas Holsti:
>>> On 2023-04-27 20:09, Rick C wrote:
>
>>
>>>
>>>> You are making a lot of assumptions about the tools.  I'm pretty sure
>>>> they don't apply to my case.  I'm not at all clear how this is
>>>> workable, anyway.  Adding the checksum to the file, changes the
>>>> checksum, which is where this conversation started... unless I'm
>>>> missing something significant.
>> No, you reserve room for the checksum, but that needs to be outside
>> the checked area.
>> The address of the checksum needs to be known to the application.
>
> The address here could have a symbol, and then declared "extern" in the
> C code - it would not have to be a known numerical address.  But if the
> image is checked or started from another program (such as a boot
> program), you need an absolute address somewhere to chain this all
> together.

The header is declared as a struct.

>
>> Also the limits of the checked area.
>> That is why the application has a header in front in my projects.
>> The application is started by the bootloader, which checks
>> a number of things before the application is started.
>> The application can read the header as well to allow checking
>> the code area at runtime.
>>
>
> Or for my preferences, the CRC "DIGEST" would be put at the end of the
> image, rather than near the start.  Then the "from, to" range would
> cover the entire image except for the final CRC.  But I'd have a similar
> directive for the length of the image at a specific area near the start.
>

I really do not see a benefit of splitting the meta information about
the image to two separate locations.

The bootloader uses the struct for all checks.
It is a much simpler implementation once the tools support it.

You might find it easier to write a tool which adds the CRC at the end,
but that is a different issue.

Occam's Razor!

/Ulf

Re: Embedding a Checksum in an Image File

<u2g1jk$2cdfn$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1530&group=comp.arch.embedded#1530

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 10:54:08 +0200
Organization: eMagii
Lines: 61
Message-ID: <u2g1jk$2cdfn$4@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<u2emd2$22pgk$1@dont-email.me> <kb0a5rFlvc6U1@mid.individual.net>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 08:54:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b452f82109ea9c6d09e4f26752b75ae5";
logging-data="2504183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+gJ5+j/om5fhl5gD9GEFX"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:6cheOsxzqTeyTcjgLG2BZk4IFI8=
In-Reply-To: <kb0a5rFlvc6U1@mid.individual.net>
Content-Language: sv
 by: Ulf Samuelsson - Fri, 28 Apr 2023 08:54 UTC

Den 2023-04-28 kl. 00:10, skrev Niklas Holsti:
> On 2023-04-27 23:36, Ulf Samuelsson wrote:
>> Den 2023-04-27 kl. 19:09, skrev Rick C:
>>> On Thursday, April 27, 2023 at 12:26:47 PM UTC-4, Ulf Samuelsson wrote:
>>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>>> This is a bit of the chicken and egg thing. If you want a embed a
>>>>> checksum in a code module to report the checksum, is there a way of
>>>>> doing this? It's a bit like being your own grandfather, I think.
>>>>>
>>>> The proper way to do this is to have a directive in the linker.
>>>> This reserves space for the CRC and defines the area where the CRC is
>>>> calculated.
>>>
>>> That assumes there is a linker.  How does the application access this
>>> information?
>>>
>>>
>> Linker command file
>>          public CRC64; start, stop
>>          HEADER = .;
>>          QUAD(MAGIC);
>>      CRC64 = .;
>>          DIGEST "CRC64-ECMA", (start, stop)
>>          start = .;
>>          # Your data to be protected
>>          ...
>>          stop = .;
>>
>> C source code.
>>
>> extern uint64_t CRC64;
>> extern char* start;
>> extern char* stop;
>>
>> uint64_t crc;
>>
>> crc64 = calc_crc64_ecma(start, stop);
>> if (crc64 == CRC64) {
>>     /* everything is OK */
>> }
>
>
> I'm nit-picking, but that C code does not look right to me. The extern
> declarations for "start" and "stop" claim them to be names of memory
> locations that contain addresses, but the linker file just places them
> at the starting and one-past-end locations of the block to be protected.
> So the "start" variable contains the first bytes of the "data to be
> protected", and the contents of the "stop" variable are not defined
> because it is placed after the "data to be protected", where no code or
> data is loaded (it seems).
>
> It seems to me that the call to calc_crc64_ecma should get the addresses
> of "start" and "stop" as arguments (&start, &stop), instead of their
> values. But perhaps calc_crc64_ecma is not a function, but a macro that
> can itself take the addresses of its parameters.
>
Whatever,
I did not put a lot of thought into that, and certainly did not check
it. The important thing is that you can declare labels in the linker
and use them in the code through extern declarations.
/Ulf

Re: Embedding a Checksum in an Image File

<u2g1n5$2cdfn$5@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1532&group=comp.arch.embedded#1532

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 10:56:01 +0200
Organization: eMagii
Lines: 42
Message-ID: <u2g1n5$2cdfn$5@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<u2fsb1$2bnd0$2@dont-email.me>
Reply-To: ulf.r.samuelsson@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 08:56:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b452f82109ea9c6d09e4f26752b75ae5";
logging-data="2504183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ClFOGGow2nIRl9jaAZ1kt"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:pXRNbyPMGdFH6u3IG3zzARTuiw4=
In-Reply-To: <u2fsb1$2bnd0$2@dont-email.me>
Content-Language: sv
 by: Ulf Samuelsson - Fri, 28 Apr 2023 08:56 UTC

Den 2023-04-28 kl. 09:24, skrev David Brown:
> On 27/04/2023 18:26, Ulf Samuelsson wrote:
>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>> This is a bit of the chicken and egg thing.  If you want a embed a
>>> checksum in a code module to report the checksum, is there a way of
>>> doing this?  It's a bit like being your own grandfather, I think.
>>>
>> The proper way to do this is to have a directive in the linker.
>> This reserves space for the CRC and defines the area where the CRC is
>> calculated.
>> I am not aware of any linker which support this.
>>
>> Two months ago, I added the DIGEST directive to binutils aka the GNU
>> linker. It was committed, but then people realized that I had not signed
>> an agreement with Free Software Foundation.
>> Since part of the code I pushed was from a third party which released
>> their code under MIT, the licensing has not been resolved yet
>> but the patch is in binutils git, but reverted.
>>
>> You would write (IIRC):
>>     DIGEST "CRC64-ECMA", (from, to)
>> and the linker would reserve 8 bytes which is filled with the CRC in
>> the final link stage.
>>
>> /Ulf
>>
>
> I like that.  Thanks for doing that work.
>
> Is there also a way to get the length of the final link, and insert it
> near the beginning of the image?  I suppose that would be another kind
> of DIGEST where the algorithm is simply (to - from).  (I assume that
> "to" and "from" may be linker symbols.)
>
>

app_size = .;
LONG(to-from);

should work using the GNU linker.
/Ulf

Re: Embedding a Checksum in an Image File

<u2gg9d$2ejus$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1538&group=comp.arch.embedded#1538

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 15:04:45 +0200
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <u2gg9d$2ejus$3@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net> <u2emsa$22pgk$2@dont-email.me>
<u2ft59$2bnd0$4@dont-email.me> <u2g1bu$2cdfn$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 13:04:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2576348"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qk6YOHkMYF9IEi8NcQDXbnwiCu39M/Ro="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:FysSK/VC/MoPhY/s4gjIo+OMXDk=
Content-Language: en-GB
In-Reply-To: <u2g1bu$2cdfn$3@dont-email.me>
 by: David Brown - Fri, 28 Apr 2023 13:04 UTC

On 28/04/2023 10:50, Ulf Samuelsson wrote:
> Den 2023-04-28 kl. 09:38, skrev David Brown:
>> On 27/04/2023 22:44, Ulf Samuelsson wrote:
>>> Den 2023-04-27 kl. 20:29, skrev Niklas Holsti:
>>>> On 2023-04-27 20:09, Rick C wrote:
>>
>>>
>>>>
>>>>> You are making a lot of assumptions about the tools.  I'm pretty sure
>>>>> they don't apply to my case.  I'm not at all clear how this is
>>>>> workable, anyway.  Adding the checksum to the file, changes the
>>>>> checksum, which is where this conversation started... unless I'm
>>>>> missing something significant.
>>> No, you reserve room for the checksum, but that needs to be outside
>>> the checked area.
>>> The address of the checksum needs to be known to the application.
>>
>> The address here could have a symbol, and then declared "extern" in
>> the C code - it would not have to be a known numerical address.  But
>> if the image is checked or started from another program (such as a
>> boot program), you need an absolute address somewhere to chain this
>> all together.
>
> The header is declared as a struct.
>
>>
>>> Also the limits of the checked area.
>>> That is why the application has a header in front in my projects.
>>> The application is started by the bootloader, which checks
>>> a number of things before the application is started.
>>> The application can read the header as well to allow checking
>>> the code area at runtime.
>>>
>>
>> Or for my preferences, the CRC "DIGEST" would be put at the end of the
>> image, rather than near the start.  Then the "from, to" range would
>> cover the entire image except for the final CRC.  But I'd have a
>> similar directive for the length of the image at a specific area near
>> the start.
>>
>
> I really do not see a benefit of splitting the meta information about
> the image to two separate locations.
>
> The bootloader uses the struct for all checks.
> It is a much simpler implementation once the tools support it.
>
> You might find it easier to write a tool which adds the CRC at the end,
> but that is a different issue.
>
> Occam's Razor!
>

There are different needs for different projects - and more than one way
to handle them. I find adding a CRC at the end of the image works best
for me, but I have no problem appreciating that other people have
different solutions.

Re: Embedding a Checksum in an Image File

<u2gghc$2ejus$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1539&group=comp.arch.embedded#1539

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Fri, 28 Apr 2023 15:09:00 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <u2gghc$2ejus$4@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<u2fsb1$2bnd0$2@dont-email.me> <u2g1n5$2cdfn$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 13:09:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d1097169b2902b2a75ddccb5ac1bd12";
logging-data="2576348"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193nLNa17iy9ZrJoabE3lnaFZBufiv+OLc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:IYTKG2QznxFoJkzTc48qTEITnVw=
Content-Language: en-GB
In-Reply-To: <u2g1n5$2cdfn$5@dont-email.me>
 by: David Brown - Fri, 28 Apr 2023 13:09 UTC

On 28/04/2023 10:56, Ulf Samuelsson wrote:
> Den 2023-04-28 kl. 09:24, skrev David Brown:
>> On 27/04/2023 18:26, Ulf Samuelsson wrote:
>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>> This is a bit of the chicken and egg thing.  If you want a embed a
>>>> checksum in a code module to report the checksum, is there a way of
>>>> doing this?  It's a bit like being your own grandfather, I think.
>>>>
>>> The proper way to do this is to have a directive in the linker.
>>> This reserves space for the CRC and defines the area where the CRC is
>>> calculated.
>>> I am not aware of any linker which support this.
>>>
>>> Two months ago, I added the DIGEST directive to binutils aka the GNU
>>> linker. It was committed, but then people realized that I had not signed
>>> an agreement with Free Software Foundation.
>>> Since part of the code I pushed was from a third party which released
>>> their code under MIT, the licensing has not been resolved yet
>>> but the patch is in binutils git, but reverted.
>>>
>>> You would write (IIRC):
>>>     DIGEST "CRC64-ECMA", (from, to)
>>> and the linker would reserve 8 bytes which is filled with the CRC in
>>> the final link stage.
>>>
>>> /Ulf
>>>
>>
>> I like that.  Thanks for doing that work.
>>
>> Is there also a way to get the length of the final link, and insert it
>> near the beginning of the image?  I suppose that would be another kind
>> of DIGEST where the algorithm is simply (to - from).  (I assume that
>> "to" and "from" may be linker symbols.)
>>
>>
>
>    app_size = .;
>    LONG(to-from);
>
> should work using the GNU linker.

Will that work when placed earlier in the link than the definition of
"to" ? I had assumed - perhaps completely incorrectly - that the linker
would have to have established the value of "to" before its use in such
an expression.

Re: Embedding a Checksum in an Image File

<u2k0ks$33teb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1545&group=comp.arch.embedded#1545

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Sat, 29 Apr 2023 23:02:15 +0200
Organization: eMagii
Lines: 61
Message-ID: <u2k0ks$33teb$1@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<u2fsb1$2bnd0$2@dont-email.me> <u2g1n5$2cdfn$5@dont-email.me>
<u2gghc$2ejus$4@dont-email.me>
Reply-To: ulf.r.samuelsson.invalid@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 29 Apr 2023 21:02:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9df99c9307656e0fa7d1da40a76efb0c";
logging-data="3274187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oSkKJgtSc5AEmLcbsdW15"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:KMKdW+7k3ATRAMuELQGiyY47Ri0=
Content-Language: sv
In-Reply-To: <u2gghc$2ejus$4@dont-email.me>
 by: Ulf Samuelsson - Sat, 29 Apr 2023 21:02 UTC

Den 2023-04-28 kl. 15:09, skrev David Brown:
> On 28/04/2023 10:56, Ulf Samuelsson wrote:
>> Den 2023-04-28 kl. 09:24, skrev David Brown:
>>> On 27/04/2023 18:26, Ulf Samuelsson wrote:
>>>> Den 2023-04-20 kl. 04:06, skrev Rick C:
>>>>> This is a bit of the chicken and egg thing.  If you want a embed a
>>>>> checksum in a code module to report the checksum, is there a way of
>>>>> doing this?  It's a bit like being your own grandfather, I think.
>>>>>
>>>> The proper way to do this is to have a directive in the linker.
>>>> This reserves space for the CRC and defines the area where the CRC
>>>> is calculated.
>>>> I am not aware of any linker which support this.
>>>>
>>>> Two months ago, I added the DIGEST directive to binutils aka the GNU
>>>> linker. It was committed, but then people realized that I had not
>>>> signed
>>>> an agreement with Free Software Foundation.
>>>> Since part of the code I pushed was from a third party which
>>>> released their code under MIT, the licensing has not been resolved yet
>>>> but the patch is in binutils git, but reverted.
>>>>
>>>> You would write (IIRC):
>>>>     DIGEST "CRC64-ECMA", (from, to)
>>>> and the linker would reserve 8 bytes which is filled with the CRC in
>>>> the final link stage.
>>>>
>>>> /Ulf
>>>>
>>>
>>> I like that.  Thanks for doing that work.
>>>
>>> Is there also a way to get the length of the final link, and insert
>>> it near the beginning of the image?  I suppose that would be another
>>> kind of DIGEST where the algorithm is simply (to - from).  (I assume
>>> that "to" and "from" may be linker symbols.)
>>>
>>>
>>
>>     app_size = .;
>>     LONG(to-from);
>>
>> should work using the GNU linker.
>
> Will that work when placed earlier in the link than the definition of
> "to" ?  I had assumed - perhaps completely incorrectly - that the linker
> would have to have established the value of "to" before its use in such
> an expression.

Yes, the GNU linker creates a list of statements with a known size
updating the location counter for each statement.

The expressions are evaluated in a later stage
so you can add a DIGEST statement and compute the SIZE by
"LONG(to-from);" before "to" and "from" are declared.

/Ulf

>
>

Re: Embedding a Checksum in an Image File

<u2k0mp$33teb$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1546&group=comp.arch.embedded#1546

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ulf.r.samuelsson@gmail.com (Ulf Samuelsson)
Newsgroups: comp.arch.embedded
Subject: Re: Embedding a Checksum in an Image File
Date: Sat, 29 Apr 2023 23:03:16 +0200
Organization: eMagii
Lines: 64
Message-ID: <u2k0mp$33teb$2@dont-email.me>
References: <116ff07e-5e25-469a-90a0-9474108aadd3n@googlegroups.com>
<105b1cab-9e5f-91b3-1de6-99586246ecbd@gmail.com>
<b62a77f7-3a13-4d76-b7cb-c42902595751n@googlegroups.com>
<kavt7iFlvc5U1@mid.individual.net> <u2emsa$22pgk$2@dont-email.me>
<u2ft59$2bnd0$4@dont-email.me> <u2g1bu$2cdfn$3@dont-email.me>
<u2gg9d$2ejus$3@dont-email.me>
Reply-To: ulf.r.samuelsson.invalid@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 29 Apr 2023 21:03:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9df99c9307656e0fa7d1da40a76efb0c";
logging-data="3274187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZzaBjgCozPdtUJ5OFmxhm"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:3hUXOc+JQNJTL6lwogD0AfuNo50=
In-Reply-To: <u2gg9d$2ejus$3@dont-email.me>
Content-Language: sv
 by: Ulf Samuelsson - Sat, 29 Apr 2023 21:03 UTC

Den 2023-04-28 kl. 15:04, skrev David Brown:
> On 28/04/2023 10:50, Ulf Samuelsson wrote:
>> Den 2023-04-28 kl. 09:38, skrev David Brown:
>>> On 27/04/2023 22:44, Ulf Samuelsson wrote:
>>>> Den 2023-04-27 kl. 20:29, skrev Niklas Holsti:
>>>>> On 2023-04-27 20:09, Rick C wrote:
>>>
>>>>
>>>>>
>>>>>> You are making a lot of assumptions about the tools.  I'm pretty sure
>>>>>> they don't apply to my case.  I'm not at all clear how this is
>>>>>> workable, anyway.  Adding the checksum to the file, changes the
>>>>>> checksum, which is where this conversation started... unless I'm
>>>>>> missing something significant.
>>>> No, you reserve room for the checksum, but that needs to be outside
>>>> the checked area.
>>>> The address of the checksum needs to be known to the application.
>>>
>>> The address here could have a symbol, and then declared "extern" in
>>> the C code - it would not have to be a known numerical address.  But
>>> if the image is checked or started from another program (such as a
>>> boot program), you need an absolute address somewhere to chain this
>>> all together.
>>
>> The header is declared as a struct.
>>
>>>
>>>> Also the limits of the checked area.
>>>> That is why the application has a header in front in my projects.
>>>> The application is started by the bootloader, which checks
>>>> a number of things before the application is started.
>>>> The application can read the header as well to allow checking
>>>> the code area at runtime.
>>>>
>>>
>>> Or for my preferences, the CRC "DIGEST" would be put at the end of
>>> the image, rather than near the start.  Then the "from, to" range
>>> would cover the entire image except for the final CRC.  But I'd have
>>> a similar directive for the length of the image at a specific area
>>> near the start.
>>>
>>
>> I really do not see a benefit of splitting the meta information about
>> the image to two separate locations.
>>
>> The bootloader uses the struct for all checks.
>> It is a much simpler implementation once the tools support it.
>>
>> You might find it easier to write a tool which adds the CRC at the
>> end, but that is a different issue.
>>
>> Occam's Razor!
>>
>
> There are different needs for different projects - and more than one way
> to handle them.  I find adding a CRC at the end of the image works best
> for me, but I have no problem appreciating that other people have
> different solutions.
>
>
>
>
I'd be curious to know WHY it works best for you.
/Ulf


devel / comp.arch.embedded / Re: Embedding a Checksum in an Image File

Pages:1234
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor