Combining a bootloader with an application?

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

Greetings, folks

 

My big project is getting really close to finished (to the extent any project is ever really finished). Got some bug fixing to do, mostly small stuff.

 

EXCEPT: the subject of bootloader.

 

This will be a production product and, at least at the start, I will be "the production line" (contracted basic SMT assembly). Being adverse to spending time that does not need to be spent, I wonder whether or not the main application and the bootloader can be loaded at the same time. Logically, I would seem that it is only necessary to merge two hex files. So,....

 

1) First question: is there a tool within gcc that will do the merge of two hex files

 

2) Second: It seems logical that there would need to be two compiles since I doubt that gcc would be happy with two mains. But, does the base function in the bootloader have to even be main()? Or, is there some practical way to combine them within a single build?

 

I am going to have to recompile optiboot because I need to modify the entry mechanism slightly. There will, I think, need to be a section statement to place it at the correct address. What I was not able to tell when I read the avr-libc manual is whether the boot section address is specified in words or bytes.

 

Guess I can use some practical advice on the coarse of action. Merge two hex files resulting from two separate compiles OR somehow compile them together? And, how to properly specify the starting address of the bootloader.

 

Thanks for your input, advice, and suggestions!

 

Cheers

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sun. May 3, 2015 - 05:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've seen this many times in the past. I recall that there is no tool. People write scripts and so on to conjoin the .hex for the boot and the .hex for the app. And flash it using an ISP that does scatter-loading (copes with non-contiguous flash regions of code). I don't recall how they get the fuses programmed as well.

 

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

I simply use binary files and combine them using a throw-away Python script. You can do the same with HEX files, but why bother? What's the value of HEX in a modern world?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

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

What is the value of hex? What does AVRDUDE know how to do? Does it know more than ELF and HEX?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

According to its documentation, yes:

Quote:
Supports Intel Hex, Motorola S-Record, and raw binary files for input and output, as well as direct memory contents specification on the command-line (useful e. g. for fuse bytes). On input, the file format can be auto-detected.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

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

Learned something new!

 

Thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

One interesting fact: Atmel Studio does not support raw binaries from the device programming dialog, but command line atprogram works with raw binary files without any problems.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

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

1) First question: is there a tool within gcc that will do the merge of two hex files

It's not part of GCC but it was packaged in with WinAVR and it's called srec_cat, part of the "SRecord" group of programs. 

 

(2) there is NO QUESTION, the app and the bootloader MUST be built as two completely separate programs. Each has main(), each has its own copy of the CRT and consequently each has their own reset jump. If you don't want to waste space for an IVT that won't be used in the bootloader then build that with "-nostartfiles" but then you'll have to provide some bits of the CRT. 

 

AS6 let's you have two projects in one solution so you can have both boot and app then "build solution" builds both. 

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

Thanks, Cliff -

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

I put this together a few days ago.  It seems to work, though it hasn't been thoroughly tested.

It might be a bit arduino specific.  The actual request was for a one-step programming script that combined the app, bootloader, and assorted fuses settings into a single command.

 

Attachment(s): 

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

I'll take a close look at it. 

 

Many thanks!

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

With two -U options, avrdude can use two hex files without the need to merge them.

Moderation in all things. -- ancient proverb

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

Thats not quite what I was after, though it could work. After a little thought, that could be quite helpful!

 

Thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

CodeVision provides the facility:

The Merge data from a .ROM File for FLASH Programming option, if checked, will merge in the FLASH programming buffer the contents of the .ROM file, created by the compiler after Make, with the data from the .ROM file specified in .ROM File Path.

This is useful, for example, when adding a boot loader executable compiled in another project, to an application program that will be programmed in the FLASH memory.

 

Perhaps you can pervert it to work with your GCC-created files.  Hmm--I don't know if it >>only<< works with the CV .ROM or whether you can pick a .HEX.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

@skeeve's 'two -U' approach is the best, I'd think.  No need to merge at all.  When later you start pumping out new units with a new bootloader or new app, no need to re-merge either.

 

Another option:  Burn the first with:

avrdude -e

This will erase flash before programming.

 

Burn the second with:

avrdude -D

This will not erase flash before programming.

 

Since there is no overlap of flash usage between your bootloader and your app (there shouldn't be!), job done.  Yes it will be two separate avrdude sessions, but in a batch file that will cost you about 3 seconds.
 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Thanks, Joey -

 

Lots to digest here. At this point, 3 seconds is trivial. Won't be later, but hopefully, by that time, I'll have a process working.

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

ka7ehk wrote:
Got some bug fixing to do, mostly small stuff.

That's where 80% of the time spent goes :D

sol i sinne - brun inne

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

The first 90% of the job takes 90% of the time, and the last 10% of the job takes the other 90% of the time.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Well, I've already spent 150% of the time on 90% of the project. So, I'm in the hole even with the little stuff. As far as I can tell, there is only "testing" left to do, which of course will reveal some more bugs. 

 

Shipping date is looming and I have to get all this figured out.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Thu. May 21, 2015 - 12:02 AM