Merging Bootloader HEX-File and Application HEX-File to one

Last post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
is there a way to merge the Bootloader Hex-file with the Application Hex-File to one Hex-File (Intel-Hex)?
So I could program both in one step.

Regards

Andre

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

Supposedly using the Srecord tool.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.
Please read the `General information...' article before.

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

Here is the rule in the makefile that I use to produce a combined .hex file:

$(DOWNLOAD) : $(TARGET).hex $(BOOTLDR)
	cat $(TARGET).hex $(BOOTLDR) | awk -f combine.awk > $(DOWNLOAD)
	rm $(BOOTLDR:.hex=.elf)

This rule just copies the two .hex files to stdout which is piped to an awk script that strips out the extra end record. The awk script, shown below, actually strips out both end records and then adds one at the end. Simple but effective.

BEGIN {}

# add a record end marker
END { print ":00000001FF" }

# delete the record end marker
/^:00000001FF/{ $0 = ""}

# default action: output all non-blank lines
{ if ($0 != ""){ print } }

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

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

Hint: "awk" is spelled "gawk" in WinAVR.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.
Please read the `General information...' article before.

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

You could also link the bootloader object file with the program and avoid awk scripting.

It would look like:

LDFLAGS=bootloader.o \
  -Wl,-Map=$(TRG).map,--section-start=.bls=$(BOOTLOADER_START)

where .bls is the name of your bootloader section.

___(°)^(°)___
A(VR)staroth

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

with hex2bin and bin2hex it sould also work:

hex2bin /q /L75000 Code.hex CodeBoot.bin
hex2bin /q /O60000 /M Boot.hex CodeBoot.bin
bin2hex /q /4 CodeBoot.bin CodeBoot.hex

/q is quite
/L is length (of the binfile)
/O is origin/Offset
/4 is Extended Adress (>64k)
/M is merge file into the other

You must flash then CodeBoot.hex....
This solution is fine, also if you want to link other binary data to your hexfile....
write it down in a bacthfile.
perhaps :
make all
make extcoff

and all your stuff is done automatically.... :-)

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

Astaroth wrote:
You could also link the bootloader object file with the program and avoid awk scripting.
Quote:

In my case, I need to build two .hex files: one with the bootloader and one without. The one without the bootloader is used to produce an encrypted "field update" file and the combined one is used to initially program devices.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

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

And what about

BIN=avr-objcopy

%.hex: %.elf 
	$(BIN) -O $(FORMAT) -R .eeprom $< $@

%.field.hex: %.elf 
	$(BIN) -O $(FORMAT) -R .eeprom -R .bls $< $@

___(°)^(°)___
A(VR)staroth

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

dl8dtl wrote:
Hint: "awk" is spelled "gawk" in WinAVR.

For those who don't know, that's because it is the Gnu AWK program.

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

I try some some of your solutions

regards

Andre

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

OK, I know this is an old thread, but I got here looking for help so others may still end up here as well.

There is another solution, the manual one: Use a text editor to cut off the last line of each file, copy and past the second file into the end of the first, and add pack an end of file record ":00000001FF".

Don's response using AWK hints at this as well.

Maybe this is too obvious, but I thought it was worth adding to the thread.

Dave.

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

Except that, as Joerg hinted, Srecord is the most obvious way to do this (srec_cat in fact)

 

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

Hi All,
I have a USB bootloader image in .a90 format (no source code for USB bootloader )and the application image in .abs format (from avr studio).
Can anybody guide me and tell how to merge both the images into one.
Is this possible using s-record tool?
Please help me out.

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

Quote:

the application image in .abs format (from avr studio).

Studio does not have a .abs file type? It does use .aps but that's actually an XML project settings file - nothing to do with source or binary.

Anyway srec_cat can read virtuall every hex format there is so start by identifying what format is in the .a90 - looking at some I've built on my machine with the IAR trial version it looks like Motorola S-Record format. srec_cat has no problem reading this format.

From AVR Sudio it's very likely that what you actually have is a .hex file containing Intel Hex records. srec_cat can read that too. So just use it to read both files and join them to an output format of your choice (probably Intel Hex).

 

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

Hi clawson,
You were right. The image of the application generated by the AVR studio is in .hex format.
I will try using S-record tool to merge the application(.hex) and the bootloader(.a90).

Thanks for the post.

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

The key thing is to have a peek inside the .a90 and just confirm that it is in Srecord format - the clue is in the name - each line starts with "S" followed by a lot of ASCII hex couplets. You then need to specify to srec_cat the format of the two input files based on this knowledge together with specifying which format you want output.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
full.hex: main.hex boot.hex
	@cat main.hex | awk '/^:00000001FF/ == 0' > $@
	@cat boot.hex >> $@
	@$(AVR_SIZE) $@
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great!

all: full.hex

...code from above...

PHONY: full.hex