Combined bootloader and sketch

Information on the latest releases
Post Reply
User avatar
RogerClark
Posts: 7440
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Combined bootloader and sketch

Post by RogerClark » Sat Jul 22, 2017 4:44 am

Because we continually have problems where people expect the bootloader to appear as a serial device, I have created a system to merge the bootloader with a simple sketch (which prints some text) into a single binary, which will eventually replace the raw bootloader.

Currently these combined files are in a different folder

https://github.com/rogerclarkmelbourne/ ... erged_bins

So I'd appreciate it if anyone could try them on their hardware and confirm they work as would be expected for a bootloader combined with a sketch, in that the bootloader will run briefly, and then jump to the sketch code.

If testing goes well, I will replace the raw bootloader files with these versions.

Actually, I'll rename the exiting "binaries" folder so that they will still be available to anyone who has problem with the combined version.
But I think as the binaries folder is linked to and referenced by numerous places on the web, that its best if this folder eventually contains the combined files.

BTW. To combine the sketch with the bootloader binaries, I had to write a simple (windows exe) program to do the merging of binaries as I could not find an existing tool that did this.
I have included the source for the merge tool in the repo, as well as the windows bat file I use to automatically merge all the existing bootloader binary files.

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Combined bootloader and sketch

Post by goran.mahovlic » Sat Jul 22, 2017 8:51 am

Great,
I do now know on windows, but on linux we can use cat for combining two files.
http://community.silabs.com/t5/Simplici ... d-p/127640

Code: Select all

objcopy foo.elf -O ihex foo.hex
objcopy bar.elf -O ihex bar.hex
cat foo.hex bar.hex >combined.hex
objcopy -I ihex combined.hex -O elf32-littlearm combined.elf
On windows I see they are using copy...

http://infocenter.arm.com/help/index.js ... 15171.html

zmemw16
Posts: 1484
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Combined bootloader and sketch

Post by zmemw16 » Sat Jul 22, 2017 9:59 am

is this an example for cat ? if foo.hex and bar.hex are generated from sketches surely the addresses involved will clash and then as i don't know the result of flashing it, is indeterminate (for me)
stephen

User avatar
RogerClark
Posts: 7440
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Combined bootloader and sketch

Post by RogerClark » Sat Jul 22, 2017 10:25 am

Its not a simple matter of concatenating the files because the bootloader is not 0x2000 long.

Thats why I wrote a exe to do it.

I published the source and I suspect it would compile with very little modification on Linux

Anyway, its only me thats likely to be combining the binaries as I've never received PR that contained binaries

fredbox
Posts: 95
Joined: Tue Jul 07, 2015 4:44 pm

Re: Combined bootloader and sketch

Post by fredbox » Sat Jul 22, 2017 2:45 pm

The code compiles with no changes on Linux.

For Windows, you can use tcc if Visual Studio is not installed. I use that quite a lot for Windows exe files.

Linux:

Code: Select all

$ make main
cc     main.c   -o main
$ ls -la  main*
-rwxr-xr-x 1 fred fred 8930 Jul 22 09:12 main
-rw-r--r-- 1 fred fred 2136 Jul 22 09:11 main.c
$ ./main
Usage. mergebin bootloader.bin sketch.bin output.bin - Incorrect number of args
Windows:

Code: Select all

C:\src> "\Program Files (x86)\tcc\tcc.exe" main.c

C:\src> dir
 Volume in drive C has no label.
 Volume Serial Number is 580A-C049

 Directory of C:\src

07/22/2017  09:34 AM    <DIR>          .
07/22/2017  09:34 AM    <DIR>          ..
07/22/2017  09:32 AM             2,218 main.c
07/22/2017  09:34 AM             3,584 main.exe
               2 File(s)          5,802 bytes
               2 Dir(s)  20,325,081,088 bytes free

C:\src> main

Usage. mergebin bootloader.bin sketch.bin output.bin - Incorrect number of args

fredbox
Posts: 95
Joined: Tue Jul 07, 2015 4:44 pm

Re: Combined bootloader and sketch

Post by fredbox » Sat Jul 22, 2017 5:01 pm

Change line 18 to

Code: Select all

printf("\nUsage. %s bootloader.bin sketch.bin output.bin - Incorrect number of args\n\n", argv[0]);

$ ./main

Usage. ./main bootloader.bin sketch.bin output.bin - Incorrect number of args
That will allow usage to use the name of the executable program.

User avatar
RogerClark
Posts: 7440
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Combined bootloader and sketch

Post by RogerClark » Sat Jul 22, 2017 9:37 pm

Thanks

I will change that line.

If I had more time, I was hoping to write a general purpose program to merge binaries, where the start address would be specified in the command line, rather than the sketch address of 0x2000 being hard coded.

But the main purpose of this was to combine the bootloader with a sketch, as the bootloader on its own, when first installed, seems to confuse a lot of people as there isn't a serial device

User avatar
RogerClark
Posts: 7440
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Combined bootloader and sketch

Post by RogerClark » Sun Jul 23, 2017 5:13 am

I've not moved the merged bins to the original "binaries" folder and I've moved the binaries that are just the bootloader to a new folder called "bootloader_only_binaries"

Post Reply