how to convert a intel hex file to raw data like memory view

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,
I want to make a boot loader code for avr, which can update firmware over the air. Now I am able to write application area using some fixed data. I have a hex file of the new firmware to be updated. how to convert that hex file to raw data so that I can update the application are using that raw data.

Regards,
shreyas.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
avr-objcopy -I ihex -O binary file.hex file.bin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi clawson, using this command if I get the binary then how to send binary data to the micro controller using serial or RF interface?
I mean how I get the first byte to send ?for example if I want to update on the location 0x3c000, then how to get that byte wise data?
currently I am able to update the location 0x3c000 by taking a fixed array like {0x01,0x02,0x03,0x04...}. so the binary file data will be same like this way?

hope I am able to explaining what I need.
thank you,
--shreyas.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Hi clawson, using this command if I get the binary then how to send binary data to the micro controller using serial or RF interface?

Sending it from where using what?

If you are talking about a PC program then it's roughly:

FILE * fin;
FILE * fout;
int main(void) {
  fin = fopen("file.bin", "rb");
  fout = fopen ("COM7", "wb");
  while (!feof(fin)) {
    byte = fgetc(fin);
    fputc(byte, fout);
  }
  fclose(fin);
  fclose(fout);
}

That's just pseudo code and won't actually work (at least I don't think it will) but the idea is that you open the COM port that ultimately routes to the AVR for writing, open the file for reading then read a byte at a time from the input and write it to the output.

But this is assuming that the sending device is a PC and that the "device" that might do the transmission is visible there as "COM7". As you haven't actually given details this is a complete guess and I don't know what you are really using for the transmission. Maybe it isn't a PC, maybe it's another AVR, maybe it's a device that does not have a filing system so the data has to be built into the transmitting program - who knows!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you clawson,

I got the idea, I am trying to update/transmit firmaware via RF. I have to send byte by byte from that .bin file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I got the idea, I am trying to update/transmit firmaware via RF. I have to send byte by byte from that .bin file.


That still says nothing really. I assume this .bin files lives on the drive of your PC? How exactly do you envisage it getting from there and onto the RF airwaves? I assume you have some kind of radio transmitter attached directly to the PC (some kind of USB dongle perhaps?) and I'm sort of guessing that it might look like a serial port to the PC software? Is that the case?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Normally a protocol would be used like XMODEM .

Simply sending bytes across a comms medium, especially RF is prone to corruption. Xmodem sends the data in 128byte chunks and adds some error detection.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I assume you have some kind of radio transmitter attached directly to the PC (some kind of USB dongle perhaps?) and I'm sort of guessing that it might look like a serial port to the PC software? Is that the case?

yes, you can say like that. I have a board in which i will give the file through serial(I don't know how to send whole file from serial), then that board will send junk of bytes to my device(which is running boot loader) through RF.

In this case I am afraid of sync between RF link and also data loss?

Is it correct way if I receive data from serial in one board and send that data to another board using RF simultaneously?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Is it correct way if I receive data from serial in one board and send that data to another board using RF simultaneously?

I guess that depends on whether the link is half or full duplex.

But if you are going to follow Kartman's suggestion and implement an error correcting protocol like Xmodem-CRC (where the receiver ACKs/NAKs the packets and they may be resent) don't you need the link to be bidirectional?

BTW this thread now has nothing to do with GCC (or the thread title come to that!) so I'm going to move it to AVR Forum for more general discussion.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can see the OTA code or some generic bootloader...
Please see these application notes from Atmel.. AVR2058

If BitCloud seems too complicated for you.. then we can probably see the generic serial bootloader AVR2054 and add an RF touch to it...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

avr-objcopy -I ihex -O binary file.hex file.bin

I tried and converted binary from hex but it seems different then memory view of code memory and also it is different from hex file's data.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The data looks the same to me - how are you viewing it?
I used hexedit to view the bin file and read the hex file manually.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can you view binary using a text editor?!?

If I take the .hex file there and:

avr-objcopy -I ihex -O binary simpleIO.hex simpleIO.bin 

then visit this website:

http://www.x-ways.net/winhex/ind...

and download WinHex (the read only version is free) and then load in the simpleIO.bin I have created I can select the entire displayed text and use Edit-Copy Block-Editor Display and it creates this (I cut out a number of lines in the middle that were just the same repeating pattern):

Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   0C 94 00 01 18 95 18 95  18 95 18 95 18 95 18 95    ”   • • • • • •
00000010   18 95 18 95 18 95 18 95  18 95 18 95 18 95 18 95    • • • • • • • •
00000020   18 95 18 95 18 95 18 95  18 95 18 95 18 95 18 95    • • • • • • • •
00000030   18 95 18 95 18 95 18 95  18 95 18 95 18 95 18 95    • • • • • • • •
00000040   18 95 18 95 18 95 18 95  18 95 18 95 18 95 18 95    • • • • • • • •



000001E0   18 95 18 95 18 95 18 95  18 95 18 95 18 95 18 95    • • • • • • • •
000001F0   18 95 18 95 18 95 18 95  18 95 18 95 0C 94 1C 01    • • • • • • ”  
00000200   0F E4 0D BF 00 E2 0E BF  C0 E2 D0 E2 0E 94 29 01    ä ¿ â ¿ÀâÐâ ”) 
00000210   0E 94 19 01 0E 94 27 01  0C 94 FE 00 E0 E6 F6 E0    ”   ”'  ”þ àæöà
00000220   00 81 00 61 00 83 E4 E6  F6 E0 00 81 00 61 00 83      a ƒäæöà   a ƒ
00000230   08 95 F4 DF FF CF 08 95  9A 93 8A 93 22 97 C8 01    •ôßÿÏ •š“Š“"—È 
00000240   88 83 99 83 9E 01 01 E0  0E 94 1B 01 F9 CF 0C 94   ˆƒ™ƒž  à ”  ùÏ ”
00000250   FE 00 01 E0 08 95                                  þ  à •

When I compare that to the .hex file (slightly re-arranged):

:10 0000 00 0C940001189518951895189518951895 41
:10 0010 00 18951895189518951895189518951895 78
:10 0020 00 18951895189518951895189518951895 68
:10 0030 00 18951895189518951895189518951895 58
:10 0040 00 18951895189518951895189518951895 48
 
:10 01E0 00 18951895189518951895189518951895 A7
:10 01F0 00 1895189518951895189518950C941C01 34
:10 0200 00 0FE40DBF00E20EBFC0E2D0E20E942901 60
:10 0210 00 0E9419010E9427010C94FE00E0E6F6E0 1E
:10 0220 00 008100610083E4E6F6E0008100610083 64
:10 0230 00 0895F4DFFFCF08959A938A932297C801 17
:10 0240 00 888399839E0101E00E941B01F9CF0C94 E1
:06 0250 00 FE0001E00895 2C
:04 0000 03 00000000 F9
:00000001FF

that sure looks like the same data to me!!

===================================================================================

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This article explains intel hex: http://www.keil.com/support/docs/1584/

Also be aware of big endian and little endian.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
How can you view binary using a text editor?!?

that sure looks like the same data to me!!

I saw it using notepad++ hex editor plugin it saws difference at below line:
in hex:
:1001F0001895189518951895189518950C941C0134
In binary
000001f0 18 95 18 95 18 95 18 95 18 95 18 95 0c 94 3b 01

there are other different bytes also but i mentioned one only here. Have you seen same file which I uploaded ? and they show same values?

Then I Re-built the code using IAR and with linker output option to raw binary. this binary generated from IAR was same as that hex I uploaded. But the converted one from avr-objcopy was different.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
it saws difference at below line

Look at my previous post, both are identical - your viewing technique is wrong.