4

I want to make boot loader code for AVR, which can update firmware over the air.

Now I am able to write to the application area using some fixed data. I have a hex file of the new firmware to be updated. How do I convert that hex file to raw data so that I can update the application using that raw data?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shreyas_patel21
  • 317
  • 1
  • 4
  • 14

3 Answers3

12

If you're using WinAVR for compilation you may do this using included avr-objcopy:

C:\WinAVR-20100110\bin> avr-objcopy.exe -I ihex -O binary input_file.hex output.bin

If you're developing on Linux, there's a package, avr-binutils, with the avr-objcopy program.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kissiel
  • 1,925
  • 1
  • 13
  • 11
  • Using `objcopy -I ihex -O binary input.hex output.bin` worked for me in Ubuntu 20.10 – Adil Jun 04 '21 at 18:42
3

As you pointed out, the hex file is encoded in Intel Hex format. You have to extract the flash data from the data records. Each record (line) holds up to 16 bytes (common, but may vary) of data. Note that that there are different record types and some may introduce an address offset, depending on how the flash data is distributed. The Wiki description should be enough to get the concept.

Rev
  • 5,827
  • 4
  • 27
  • 51
3

You may use some tool (http://hex2bin.sourceforge.net/ or another hex2bin converter) or write your own hex parser that may have some caveats when coming to files > 64 KB.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
  • Ok, If I get binary file using some tools like hex2bin, then how to download that binary file to the micro controller? for example I am using RF interface then via RF how can I send the content of the binary file? does the binary file have information like first byte is put into the first location of the flash of the micro-controller? – shreyas_patel21 Feb 13 '14 at 09:16
  • i thought the part about transferring binary programm data to the bootloader is already working? if you transformed the hex file to bin you should be able read it and transfer it byte by byte to the controller. usually hex2bin generate files that are as big as the last address in the hexfile and write the bytes they found in hex to the correct position. what values adresses have that are not defined in hex file may be an parameter or some fix constant that may depend on implementation – vlad_tepesch Feb 13 '14 at 09:28