FOTB - Firmware Over The Bus

From KONNEKTING Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

See: https://github.com/arduino/ArduinoCore-samd/pull/220

Steps:

Get SDUBoot.ino from https://github.com/arduino/ArduinoCore-samd/tree/master/libraries/SDU/extras/SDUBoot. Use this as starting point for an own version, let's say we name our version "EFUBoot"

So we will have

EFUBoot\
EFUBoot\EFUBoot.ino

and we also need

EFUBoot\boot
EFUBoot\build.sh

build.sh should contain something like this:

 1#!/bin/sh -x
 2
 3ARDUINO=$ARDUINO_HOME/arduino
 4SKETCH_NAME="EFUBoot.ino"
 5SKETCH="$PWD/$SKETCH_NAME"
 6BUILD_PATH="$PWD/build"
 7OUTPUT_PATH="./boot"
 8
 9if [[ "$OSTYPE" == "darwin"* ]]; then
10	ARDUINO="/Applications/Arduino.app/Contents/MacOS/Arduino"
11fi
12
13buildSDUBootSketch() {
14	BOARD=$1
15	DESTINATION=$2
16
17	$ARDUINO --verify --board $BOARD --preserve-temp-files --pref build.path="$BUILD_PATH" $SKETCH
18	cat "$BUILD_PATH/$SKETCH_NAME.bin" | xxd -i > $DESTINATION
19	rm -rf "$BUILD_PATH"
20}
21
22mkdir -p "$OUTPUT_PATH"
23
24buildSDUBootSketch "arduino:samd:arduino_zero_edbg" "$OUTPUT_PATH/zero.h"

Make it executable with help of

chmod g+x build.sh

And finally run it with

./build.sh

After that, you have a .h file in your boot-folder.

Copy/paste SDU.cpp/SDU.h and let them point to the .h file you just created.

Write your sketch and include your version of SDU.h/SDU.cpp with "#include". Upload your sketch as usual.

If you now apply you update according to your own SDUBoot variant and reboot your arduino, the new sketch is applied to main memory and arduino starts up with the new sketch.


Some additional information: https://github.com/arduino/ArduinoCore-samd/issues/247

Normaly the ardunio Bootloader is placed on 0x0000 address on internal flash and a user sketch starts on 0x2000.

With the so called "2nd stage bootloader" you have:

  1. the normal arduino bootloader on 0x0000, which is resposible for USB-Sketch updates
  2. 2nd stage bootloader placed on 0x2000 instead of user sketch
  3. user sketch placed on 0x6000

linker script, that builds firmware file for arduino update, has two sections:

KEEP(*(.sketch_boot))
. = ALIGN(0x2000);
KEEP(*(.isr_vector))
*(.text*)

.sketch_boot will be used only with/for 2nd stage bootloader. this section is defined in sdu.cpp:

__attribute__ ((section(".sketch_boot")))
unsigned char sduBoot[0x4000] = {
#if defined(ARDUINO_SAMD_ZERO)
  #include "boot/zero.h"

zero.h is compiled SDUBoot.ino sketch => .bin file converted to a .h file. array of size 0x4000 will be placed on 0x2000. So the user sketch starts at 0x6000

.isr_vector is user sketch. if 2nd stage doesn't exist, user sketch will be placed on 0x2000, other way it will be placed right after 2nd stage bootloader (0x2000 + 0x4000(size of 2nd stage bootloader) => 0x6000).


KONNEKTING FOTB Workflow

to be done