FOTB - Firmware Over The Bus

From KONNEKTING Wiki
Jump to: navigation, search

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:

#!/bin/sh -x

ARDUINO=$ARDUINO_HOME/arduino
SKETCH_NAME="EFUBoot.ino"
SKETCH="$PWD/$SKETCH_NAME"
BUILD_PATH="$PWD/build"
OUTPUT_PATH="./boot"

if [[ "$OSTYPE" == "darwin"* ]]; then
	ARDUINO="/Applications/Arduino.app/Contents/MacOS/Arduino"
fi

buildSDUBootSketch() {
	BOARD=$1
	DESTINATION=$2

	$ARDUINO --verify --board $BOARD --preserve-temp-files --pref build.path="$BUILD_PATH" $SKETCH
	cat "$BUILD_PATH/$SKETCH_NAME.bin" | xxd -i > $DESTINATION
	rm -rf "$BUILD_PATH"
}

mkdir -p "$OUTPUT_PATH"

buildSDUBootSketch "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