Can you combine app/bootloader using AS7?

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

You can add multiple projects to a solution.  Is there some sort of "solution" level build events that can use tools to combine the hex and/or elf files?

 

That sort of leads to the second question, if I'm using ctrl-alt-f5 to build and flash, is there a way of doing that and having it keep/flash the bootloader from a second project at the same time?

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


alank2 wrote:
You can add multiple projects to a solution.  Is there some sort of "solution" level build events that can use tools to combine the hex and/or elf files?
The way I would recommend is srec_cat. Luckily Atmel had the foresight to include it with AS7:

C:\Program Files (x86)\Atmel\Studio\7.0>dir srec*.exe /s
 Volume in drive C is OSDISK
 Volume Serial Number is 7AF3-B2D0

 Directory of C:\Program Files (x86)\Atmel\Studio\7.0\shellutils

03/11/2020  06:21         1,450,912 srec_cat.exe
               1 File(s)      1,450,912 bytes

     Total Files Listed:
               1 File(s)      1,450,912 bytes
               0 Dir(s)  128,428,363,776 bytes free

(in fact that "shellUtils" contains lots of useful utilities!).

 

As this page (Keil not Atmel) shows:

 

https://www.keil.com/support/doc...

 

in its simplest form you would simply use:

srec_cat.exe application.hex -Intel boot.hex -Intel -o wholeFlash.hex -Intel

In AS7 you probably have two projects:

You obviously can't run the srec_cat command until both have been built so you would add the srec_cat as a "post build event" on one then tell AS7 to build the other first.

 

For example if I want it to build bootloader then application I might use:

So I right click the Solution then select Project Dependencies. If I say "mcs7_test" (my "application") depends on "bootload" then this ensures that during Build Solution it will build bootload first then mcs7_test second. So first you get to:

where ticking it means "mcs7_test" needs "bootload" to be built first. You can check that you got the build order right in:

 

 

that will now show:

 

 

(actually those two menu entries lead to the same dialog - just a different tab - so you can use either then pick the right tab).

 

The above shows that it is onw guaranteed that bootload will be built first and mcs7_test second. So all that remains now is to add a post build step to mcs7_test...

 

 

I went with:

 

that is:

srec_cat $(MSBuildProjectDirectory)\$(Configuration)\$(MSBuildProjectName).hex -Intel $(SolutionDir)..\bootload\$(Configuration)\bootload.hex -Intel -o $(MSBuildProjectDirectory)\$(Configuration)\combined.hex -Intel

though you may want to play around with the macros. I am making a bit of a gross assumption that bootload is "next to" the mcs7_test project directory so use "$(SolutionDir)..\bootload" to reach it but this may not necessarily be true.

 

Finally when I "build Solution" I see:

Target "PostBuildEvent" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Avr.common.targets" from project "D:\test\mcs7_test\mcs7_test.cproj" (target "Build" depends on it):
	Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
	Task "Exec"
		srec_cat D:\test\mcs7_test\Debug\mcs7_test.hex -Intel D:\test\mcs7_test\..\bootload\Debug\bootload.hex -Intel -o D:\test\mcs7_test\Debug\combined.hex -Intel
	Done executing task "Exec".
Done building target "PostBuildEvent" in project "mcs7_test.cproj".
Target "Build" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Avr.common.targets" from project "D:\test\mcs7_test\mcs7_test.cproj" (entry point):
Done building target "Build" in project "mcs7_test.cproj".
Done building project "mcs7_test.cproj".

Build succeeded.
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

And I end up with:

 

 

The highlighted bit is the bootloader code at 0x3800 for this mega16 I built for. That is (as the separate file during the build):

 

 

Note that the srec_cat process has changed hex format from 0x10 length lines to 0x20 length lines.

 

BTW once you start using srec_cat all kinds of things are possible. As I note here:

 

https://github.com/wrightflyer/s...

 

A command like:

srec_cat $(MSBuildProjectDirectory)\$(Configuration)\$(Output File Name).hex -intel -fill 0xFF 0x0000 0x37FE --l-e-crc16 0x37FE -o AVRAP001.bin -binary

would take a single .hex file, fill the flash space with 0xFFs in the "unused" bits between 0x0000 and 0x37FE, Run a crc16 over that and then place the result in 37FE/37FF and finally write this out as a binary (not Intel) file. You could add some of this kind of thing to the simple "file combining" process.

 

In fact you would need to read the srec_cat manual as it can do about 50 different operations (in fact pretty much anything you can think of doing to iHex, SRec, binary files !).

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

Thanks clawson; that is fantastic and will do what I am looking for!

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

This is great info. Solved a similar problem that I was having getting the bootloader to properly link into the binary. I also used the -Binary flag for '.bin' files and it works in exactly the same way.