#47 CRC output from linker



I would like to see the option added to the linker to be
able to have it compute a CRC on the produced code
and insert that into the output code as well. This way a
program can sanity check itself before startup. This way
one could also decide (based on an educated guess) not
to download code to a target, because it wasn't
changed, which saves development time.

To implement this, I think the following are required:
1) Generate a symbol for the CRC
2) Select an area to compute the CRC over
3) Fill unused bytes in the area with a default value (FF)
4) Compute the CRC (8/16/32)
5) Store the CRC outside this area.

Keep up the good work, hope this helps improving SDCC
further and further.



  • Frieder Ferlemann

    Logged In: YES

    Hi Maarten,

    just to make things complicated: I'm using the following
    command line to fill the unused
    bytes with 0x12 (0x12 is good for a 8051) and to insert
    several additive checksums:

    srec_cat myfile.ihx -Intel -fill 0x12 0x0000 0x006FFE
    -Big_Endian_Checksum_Negative 0x006FFE 0x02 0x02 -fill 0x12
    0x007000 0x007FFE -Big_Endian_Checksum_Negative 0x007FFE
    0x02 0x02 -fill 0x12 0x008000 0x00EFFE
    -Big_Endian_Checksum_Negative 0x00EFFE 0x02 0x02 -Output
    myfile.hex -Intel

    The link to srecord is in the manual (srecord supports CRC16
    and CRC32 in little and big-endian)

  • Maarten Brock

    Maarten Brock - 2003-12-04

    Logged In: YES

    Hi Frieder,

    I know there is something like srecord. But a quick glance
    learned me it doesn't support omf files, that's why I popped
    the question. Otherwise using srecord would be perfectly ok,
    allthough integrating into sdcc is nicer. But maybe I should
    just request this feature for srecord and not for sdcc.


  • Maarten Brock

    Maarten Brock - 2004-01-12

    Logged In: YES

    Follow up,

    So I asked at SRecord and they implemented! Sometimes, life
    is just great. I'll try to create a piece of library code that can
    be integrated into SDCC and used in conjuction with SRecord.


  • Maarten Brock

    Maarten Brock - 2005-08-25

    Logged In: YES

    SRecord supports omf files, but only the memory contents
    and it throws away all debug info. Still no good solution then :-

    But wait. With SRecord 1.22 you can generate C source files
    with the data in a "const unsigned char crc[]" array. And
    SDCC 2.5.2 can place const data in a specified segment
    with an absolute address. So this is what I do now:
    1) Compile and link all project files with SDCC.
    2) Let srecord fill unused spaces in the hex-file.
    3) Let srecord compute the length of the hex-file and store it
    inside the hex-file.
    4) Let srecord compute the crc over the hex-file and store it
    inside the hex-file.
    5) Let srecord extract the length and crc into a C source file.
    6) Compile this with SDCC --constseg CRC.
    7) Link the project again with the new file added and option -
    Wl-bCRC=0x4000 to store the crc and length data at a
    predetermined memory place.

    The result is that the CRC is included in the omf file as well
    and still fully debuggable.

    This works for me and closes this request.

  • Maarten Brock

    Maarten Brock - 2005-08-25
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed

Log in to post a comment.