This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Changing just the value of a variable... but in .hex there is several changes

Hello, a little background of what I am doing: I have a project which uses some keys in his code in the initialization. The thing is that I would like to change these keys to generete several .hex files. It would be a set of keys, for each differente .hex. To achieve this the thing would be open the project change the keys for a new ones, and compile again, which would be repeat everytime that I need to generate another hex file. The goal of this is to have .hex tied to some hardware that just work on his particular device.

This process would be a little long and boring, so which I tried to do is a program that open the .hex file (motorola-s format), look for the old keys, and write the new ones. I have already finished the program and is working quite well, of course the program takes care of motorola-s format and checksum bytes. Well, but this is not working well because of this:

For example I have this key: char MyKey[4]={0x00,0x01,0x02,0x03} (yeah complicated key xD)

and if I just change one bye like this: char MyKey[4]={0xFF,0x01,0x02,0x03} and I compile, I obtain an .out and then I use hex2ais to generate the hex file, I really can see that the place where it was the key has obviously change the 0x00 to 0xFF value. But.... there is other bytes almost in the end of the .hex file that have changed too, and this is what my program is not doing, so I cannot generate the .hex properly. I guess that these bytes that are changing are something like a complete checksum or some kind of hash bytes... does someone know something about this?

What these bytes are changing when I am just changing the value of one byte in the code? How I could recalculate the value of these bytes? This would very helpful to me because I could automatize my work and do it very fast... I would be greateful for any help.

Thanks and best regards

 

  • Hi James,

    your writing in your post that you have a checksum calculation implemented. Because of that I'm assuming that you're using the IAR toolchain (since CCE and CCS can not generate a checksum at compile time). So, if you're changing one byte in the code the checksum will change too (since it is calculated at compile time and then stored in a segment called CHECKSUM which is located at the end of the FLASH memory).

    You can overcome this problem by placing your 'MyKey' array in a seperate area which is excluded from checksum calculation. 

    Kind regards
    G**kbuster

  • Thanks a lot for your answer! Well... I do not have idea of IAR as I am using dm6437 dps (I have just seen that IAR is for microcontrollers). The "checksum" is done by my program, and I refer to the last two caracters of every line in the motorola-s format. As I am changing values of the file, I need to recalculate these last two characters that represent the checksum. Anyway, I did not knowabout the CHECKSUM that you describe, it sounds quite logical, do you know where I can find about it?

    For instance, this is the end of my original .hex file:


    S315420123C00000000000000080000000000000000044
    S315420123D00000000000000080000000000000000034
    S315420123E00000000000000080025953583BB838AD46
    S315420123F0A8FFFFFF045953580659535840FD801010
    S30D42012400120000000000000079
    S70542000000B8

    The last two numbers (in bold) are the a motorola-s typical file checksum. Well, if for instance I change in the end of the first line the 0044 to 0143 it won't work.

    I have tried to add new lines at the end, but that does not work either.

    Any help?

     

  • Hi James,

    I'm sorry, but I've never worked with DSP's so far. From an MCU point of view you may have a look at the CRC app note for the MSP430 i.e. (http://focus.ti.com/lit/an/slaa221/slaa221.pdf). 

    Maybe some other hints/ideas may be useful for you too:

    1.) Place the key at the end of your memory (maybe some padding is required here too) and exclude this memory ranges from your CRC calculation (done by your application)
    2.) correct me when I'm wrong, but you tried to change the motorola-s typical line-checksum. Instead of this you should change the key (sorry, but I can't find your MyKey array constants in the hex-dump above) and the recalculate the line-checksum (since I do not know if it is needed somewhere else). But, if you excluded ( see 1.) ) a wrong line checksum should be not problem 

    Rgds
    G**kbuster 

  • Hi G**kbuster,

    thanks a lot for you answer, i have tried what you proposed (place the key at the end of memory) but I was not able to make it work. What I do is change the key and recalculate the checksum line, of course. But as I told it has to be another kind of checksum that is changing more bytes inside of .hex file. I would like to know how to recalculate these new byte values, of which I do not have any information. Nobody knows something about this?

     

    Thanks and regards

  • Hi James,

    well, I'm not that familiar with the motorola s-record format; so maybe one of the references below is of good use for you:

    http://www.amelek.gda.pl/avr/uisp/srecord.htm
    http://en.wikipedia.org/wiki/SREC_(file_format)

    Rgds
    G**kbuster

  •         I had already read these documents, and I am fulfilling all the rules of S-motorola files, but I think my problem is not that, I beleive that is somekind of checksum that Texas use for his files or for his DSP.

    Thanks anyway...  anymore tips?

  • Can you show the rest of your example?  That is, when you change one value in memory can you please show exactly how the resulting S record changed?

  • Ok, take this example, I have just changed this:   

    char chain[16]={16,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};   to:
    char chain[16]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

    as you can see in the image (one .hex on the left and the other on the right) in red before the 02, there is a 01 in a file and 10 in the other as expected. In the same line, the last two bytes change as expected due to checksum Motorola-S. Then you can see severeal lines below there are several bytes that change, that is what I do not understand, why this is changing? I am using hexAIS utility to generate the .hex. Any help would be very grateful

     

  • The value you see change at the end is a CRC value for that particular section.  Just before the changed value you see the digits 02595358.  That is the little endian ordering for the 32-bit value 0x58535902, which is the REQUEST_CRC command as documented in the bootloader doc.  Appendix A discusses how the CRC is calculated.  After changing that one value you need to recalculate the CRC for that section.  The section begins just before your first change.  Specifically line 1691 of your screenshot contains the SECTION_LOAD command.  So you need to recalculate the CRC for that section.

  • Ok, now I see... thanks a lot Brad!