How to rebuild SDU

Hi,

I would like to modify the SDU library in order to check if a file UPDATE.bin exists on the persistent memory instead of on the SD card.

I am no sure about the way to rebuild SDUBoot.ino.

After running build.sh in CMD shell the files in SDU\src\boot become empty.

It looks like the file SDUBoot.ino.bin is not found.

$ ./build.sh
+ ARDUINO=/c/PROJET/Arduino/Arduino.exe
+ SKETCH_NAME=SDUBoot.ino
+ SKETCH=/c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/SDUBoot.ino
+ BUILD_PATH=/c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/build
+ OUTPUT_PATH=../../src/boot
+ [[ msys == \d\a\r\w\i\n* ]]
+ mkdir -p ../../src/boot
+ buildSDUBootSketch arduino:samd:arduino_zero_edbg ../../src/boot/zero.h
+ BOARD=arduino:samd:arduino_zero_edbg
+ DESTINATION=../../src/boot/zero.h
+ /c/PROJET/Arduino/Arduino.exe --verify --board arduino:samd:arduino_zero_edbg --preserve-temp-files --pref build.path=/c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/build /c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/SDUBoot.ino
+ cat /c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/build/SDUBoot.ino.bin
+ xxd -i
cat: /c/PROJET/Arduino/portable/packages/arduino/hardware/samd/1.6.20/libraries/SDU/extras/SDUBoot/build/SDUBoot.ino.bin: No such file or directory

...

Please let me know what is the procedure to rebuild SDUBoot.ino

That build.sh is just a convenient way for Arduino to quickly build the firmware for all the SAMD boards. Likely, you only have one board type, so it's easier to just use the Arduino IDE directly to compile the sketch.

Do this:

  • In the Arduino IDE, open SDUBoot.ino
  • Select your board from the Tools > Board menu.
  • Sketch > Export Compiled Binary
  • Wait for the compilation to finish.
  • Sketch > Open Sketch Folder - This will open the folder containing SDUBoot.ino, which will also now contain the compiled .bin file.

I did your steps but the file in SDU\src\boot\mkrgsm1400.h is not changed after the compilation.

I think it is this file that is called before setup() to update the sketch running on the board.

Why would you expect SDU\src\boot\mkrgsm1400.h to be changed after the compilation? Compilation will never modify source files. That would be horrible!

If you look inside build.sh you will see that mkrgsm1400.h is build from SDUBoot.ino.

#!/bin/sh -x

ARDUINO=arduino
SKETCH_NAME="SDUBoot.ino"
SKETCH="$PWD/$SKETCH_NAME"
BUILD_PATH="$PWD/build"
OUTPUT_PATH="../../src/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"
buildSDUBootSketch "arduino:samd:mkr1000" "$OUTPUT_PATH/mkr1000.h"
buildSDUBootSketch "arduino:samd:mkrzero" "$OUTPUT_PATH/mkrzero.h"
buildSDUBootSketch "arduino:samd:mkrfox1200" "$OUTPUT_PATH/mkrfox1200.h"
buildSDUBootSketch "arduino:samd:mkrgsm1400" "$OUTPUT_PATH/mkrgsm1400.h"
buildSDUBootSketch "arduino:samd:mkrwan1300" "$OUTPUT_PATH/mkrwan1300.h"
buildSDUBootSketch "arduino:samd:mkrwifi1010" "$OUTPUT_PATH/mkrwifi1010.h"
buildSDUBootSketch "arduino:samd:mkrnb1500" "$OUTPUT_PATH/mkrnb1500.h"
buildSDUBootSketch "arduino:samd:mzero_bl" "$OUTPUT_PATH/mzero.h"

But I think I do not have the good way to run this script because it just clear the content of mkrgsm1400.h when I run it.

Ah, I feel foolish. I didn't look at the script closely enough. Thanks for straightening me out. At least my statement about the compiler not modifying the source file was true; it's the script that modifies the source file.

What happens if you do the Export Compiled Binary using the Arduino IDE and then run that cat command on the file exported .bin file?

cat SDUBoot.ino.mkrgsm1400.bin | xxd -i > mkrgsm1400.h

Do you end up with a file named mkrgsm1400.h in the same folder where the SDUBoot.ino.mkrgsm1400.bin is?

Do you end up with a file named mkrgsm1400.h in the same folder where the SDUBoot.ino.mkrgsm1400.bin is?

Yes I get a file mkrgsm1400.h where binary data is convert in hexa values.
Actually the script works without error if I comment all the buildSDUBootSketch lines except for my board then I need to run build.sh twice.
The first call builds SDUBoot.ino and generates SDUBoot.ino.bin.
The second one converts SDUBoot.ino.bin to mkrgsm1400.h in the destination directory.

#!/bin/sh -x

ARDUINO=/g/Arduino/Arduino.exe
SKETCH_NAME="SDUBoot.ino"
SKETCH="$PWD/$SKETCH_NAME"
BUILD_PATH="$PWD/build"
OUTPUT_PATH="../../src/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"
# buildSDUBootSketch "arduino:samd:mkr1000" "$OUTPUT_PATH/mkr1000.h"
# buildSDUBootSketch "arduino:samd:mkrzero" "$OUTPUT_PATH/mkrzero.h"
# buildSDUBootSketch "arduino:samd:mkrfox1200" "$OUTPUT_PATH/mkrfox1200.h"
buildSDUBootSketch "arduino:samd:mkrgsm1400" "$OUTPUT_PATH/mkrgsm1400.h"
# buildSDUBootSketch "arduino:samd:mkrwan1300" "$OUTPUT_PATH/mkrwan1300.h"
# buildSDUBootSketch "arduino:samd:mkrwifi1010" "$OUTPUT_PATH/mkrwifi1010.h"
# buildSDUBootSketch "arduino:samd:mkrnb1500" "$OUTPUT_PATH/mkrnb1500.h"
# buildSDUBootSketch "arduino:samd:mzero_bl" "$OUTPUT_PATH/mzero.h"

Thanks for the help pert :slight_smile:

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per