Add all python code run on the device to the manifest.py to freeze it. This has two benefits: - It precompiles the bytecode, so it is smaller and faster - All code (C and python) is now in the firmware image, leaving the littlefs filesystem on the flash free for user settings. This requires changing the way the hardware variants are handled. There is now only one _filesystem_ image, but instead there are different _firmware_ images for each variant. Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
95 lines
2.3 KiB
Bash
Executable File
95 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
TOPDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
check_command()
|
|
{
|
|
name=$1
|
|
if ! command -v "$name" > /dev/null 2>&1; then
|
|
echo "'$name' is required, please install"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_command udisksctl
|
|
check_command lsusb
|
|
check_command picotool
|
|
|
|
DEVICEPATH=/dev/disk/by-label/RPI-RP2
|
|
IMAGEPATH=${TOPDIR}/build
|
|
REVISION=Rev1
|
|
|
|
flash_via_mountpoint()
|
|
{
|
|
while [ ! -e "$DEVICEPATH" ] ; do sleep 1; echo 'Waiting for RP2...'; done
|
|
|
|
udisksctl mount -b "$DEVICEPATH"
|
|
cp "$IMAGEFILE" "$(findmnt "$DEVICEPATH" -n -o TARGET)"
|
|
}
|
|
|
|
PID="2e8a"
|
|
VID="0003"
|
|
|
|
flash_via_picotool()
|
|
{
|
|
while [ ! "$(lsusb -d $PID:$VID)" ] ; do sleep 1; echo 'Waiting for RP2 (USB)...'; done
|
|
|
|
local serial
|
|
serial="$(lsusb -d $PID:$VID -v | grep "iSerial" | awk '{print $3}')"
|
|
mapfile -t bus_device < <(lsusb -d 2e8a:0003 | awk '{print $2"\n"$4}')
|
|
local bus="${bus_device[0]}"
|
|
local device="${bus_device[1]//[!0-9]/}"
|
|
echo "Found RP2 with serial $serial on Bus $bus Device $device"
|
|
|
|
picotool load --update --bus "$bus" --address "$device" "$IMAGEFILE"
|
|
}
|
|
|
|
FLASH_VIA_MOUNTPOINT=0
|
|
|
|
usage()
|
|
{
|
|
echo "Usage: $0 [ -m | --via-mountpoint ]"
|
|
echo " [ -h | --help ]"
|
|
echo
|
|
echo " -m, --via-mountpoint Mount first found RP2 and flash image by"
|
|
echo " copying to mountpoint."
|
|
echo " -r, --revision <rev> Hardware revision to flash. Default is Rev1"
|
|
echo " -h, --help Print this text and exit."
|
|
exit 2
|
|
}
|
|
|
|
PARSED_ARGUMENTS=$(getopt -a -n "$0" -o mhr: --long via-mountpoint,revision:,help -- "$@")
|
|
# shellcheck disable=SC2181
|
|
# Indirect getopt return value checking is okay here
|
|
if [ "$?" != "0" ]; then
|
|
usage
|
|
fi
|
|
|
|
eval set -- "$PARSED_ARGUMENTS"
|
|
while :
|
|
do
|
|
case "$1" in
|
|
-m | --via-mountpoint) FLASH_VIA_MOUNTPOINT=1 ; shift ;;
|
|
-r | --revision) REVISION=$2 ; shift 2 ;;
|
|
-h | --help) usage ;;
|
|
--) shift; break ;;
|
|
*) echo "Unexpected option: $1"
|
|
usage ;;
|
|
esac
|
|
done
|
|
|
|
if [ $# -gt 0 ]; then
|
|
echo "Unexpected positional arguments: $1"
|
|
usage
|
|
fi
|
|
|
|
IMAGEFILE="$IMAGEPATH"/firmware-$REVISION.uf2
|
|
|
|
if [ "$FLASH_VIA_MOUNTPOINT" -eq 0 ]; then
|
|
flash_via_picotool
|
|
else
|
|
flash_via_mountpoint
|
|
fi
|