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.

How to get the Image Header from .bin file?

Other Parts Discussed in Thread: CC2540

Hi experts,

I try to implement the OAD function with CC2540 on Android  Phone. I follow the OAD_for_cc2540 document.

The notification on the OAD Target can be enabled.  I shall write to the image identify with a message data . 

my question is  how could I get the image header  from  .bin.

Best regards,

  • Hi,

    The first 16bytes in the .bin holds the image header info:

    Byte 0 to 1 : check sum CRC  

    Byte 2 to 3 : 0xFFFF, reserve here to use later for OAD process finished

    Byte 4 to 5 : current image version  

    Byte 6 to 7: image size. This is number of groups of 4bytes in the image. For example, with the image size is 124KB, then the total number = 124KB /4 = (124*1024)/4 = 126976/4 = 31744 = 0x7C00.  

    Byte 8 to 11: current image type ( {‘A’, ‘A’, ‘A’, ‘A’} or {‘B’, ‘B’, ‘B’, ‘B’} )  

    Byte 12 to 15: reserve, all 0xFF

    You could read this info by using reading flash function and then send back to Central by Notification.

    Good luck,

    Jack

     

  • Thanks a lot. ;-)

  • Hi Jack, 

    Thanks for the info. 

     I'm getting a negative values while reading the bin file header. I've implemented in java. Kindly refer the below code.

    I've read the bin file into a InputStream object and using the below function tried to read the binary file version and length. But getting negative values. 

    short version = Uint16(fileBuffer[5], fileBuffer[4]);
    short length = Uint16(fileBuffer[7], fileBuffer[6]);

    public  short Uint16(byte high, byte low) {
    return (short) ((high << 8) + (low & 0xff));
    }

    Thanks in advance for your help.

    Rajiv.