32 bit flash checksums

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

32 bit flash checksums

Adam Yergovich
Hello all,

Long time reader, first time poster.  Redboot is a great little program
and i've been enjoying it immensely.

I'm currently looking at accessing the redboot partitions from within
Linux, which is in itself none too difficult with the mtd tools. In
order for Redboot to "like" any changed image though, it has to have a
proper checksum or key at the end.  It looks to me like the last 32 bits
of the image partition (say "redbootconfig") make up this magic number
that is needed to ensure validity.  I looked through the source code,
but i am still unsure of the algorithm used to generate this checksum.  
Anyone know what algorithm is used?

Many thanks,
-Adam

--
Adam Yergovich
Engineer
JK Microsystems

1403 Fifth St. Suite D
Davis, CA 95616

Tel:(530) 297-6073



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: 32 bit flash checksums

Andrew Lunn-2
On Fri, Jan 06, 2006 at 05:29:51PM -0800, Adam Yergovich wrote:

> Hello all,
>
> Long time reader, first time poster.  Redboot is a great little program
> and i've been enjoying it immensely.
>
> I'm currently looking at accessing the redboot partitions from within
> Linux, which is in itself none too difficult with the mtd tools. In
> order for Redboot to "like" any changed image though, it has to have a
> proper checksum or key at the end.  It looks to me like the last 32 bits
> of the image partition (say "redbootconfig") make up this magic number
> that is needed to ensure validity.  I looked through the source code,
> but i am still unsure of the algorithm used to generate this checksum.  
> Anyone know what algorithm is used?

It uses cyg_crc32(). You can find the implementation in
packages/services/crc/current/src/crc32.c.

        Andrew


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: 32 bit flash checksums

Adam Yergovich
In reply to this post by Adam Yergovich
Hello all,

After a few problems with my client throwing in html code in the email,
i've got some additional questions and clarification of the problem.

I'll preface this by saying i have a port of Redboot for the Cirrus
Logic EP93XX family of chips.  While many things are different, with
regards to checksumming and the areas of memory i'm looking at there
shouldn't be much different.

I think the place to start with is to explain what i am seeing.  Most of
the "Magic numbers" are stored in the FIS Directory partition.  This is
not the case though for the Redboot Config partition.  Through some
experimentation i've noted that it appears to store the checksum for
this partition in the last 4 bytes of the partition, preceded by what
looks like an identifier of 0xADDEADED . (So the final 8 bytes are
0xADDEADEDZZZZZZZZ where ZZZZZZZZ coresponds to the magic number).

The question is how to deal with this checksum in particular.  Is it the
same algorithm, and if so, what does it use as its length?  Does it
reduce the 0x1000 partition to cut off the last 4 bytes?  Treat them as
0's, 1's?

Many thanks again, and apologies for the confusion and problems earlier,

-Adam

--
Adam Yergovich
Engineer
JK Microsystems

1403 Fifth St. Suite D
Davis, CA 95616

Tel:(530) 297-6073


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: 32 bit flash checksums

Gary Thomas
On Mon, 2006-01-09 at 17:10 -0800, Adam Yergovich wrote:

> Hello all,
>
> After a few problems with my client throwing in html code in the email,
> i've got some additional questions and clarification of the problem.
>
> I'll preface this by saying i have a port of Redboot for the Cirrus
> Logic EP93XX family of chips.  While many things are different, with
> regards to checksumming and the areas of memory i'm looking at there
> shouldn't be much different.
>
> I think the place to start with is to explain what i am seeing.  Most of
> the "Magic numbers" are stored in the FIS Directory partition.  This is
> not the case though for the Redboot Config partition.  Through some
> experimentation i've noted that it appears to store the checksum for
> this partition in the last 4 bytes of the partition, preceded by what
> looks like an identifier of 0xADDEADED . (So the final 8 bytes are
> 0xADDEADEDZZZZZZZZ where ZZZZZZZZ coresponds to the magic number).
>
> The question is how to deal with this checksum in particular.  Is it the
> same algorithm, and if so, what does it use as its length?  Does it
> reduce the 0x1000 partition to cut off the last 4 bytes?  Treat them as
> 0's, 1's?

Have you read the source?  The answers are all there :-)

The fconfig data is represented by a structure:
        struct _config {
            unsigned long len;
            unsigned long key1;
            unsigned char config_data[MAX_CONFIG_DATA-(4*4)];
            unsigned long key2;
            unsigned long cksum;
        };

The checksum is simply the crc32 sum over everything except the checksum
itself:
    crc = cyg_crc32((unsigned char *)conf, sizeof(*conf)-sizeof(conf->cksum));

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss