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

18 posts / 0 new
Last post
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.

Pages