From 2f47ca3c49e77929f7b36c61d1119350120785d2 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Tue, 28 Nov 2023 16:58:13 +0100 Subject: [PATCH] Add support for building Raspberry pi 2B Rev1.2, 3, Zero 2 W, 4 and 5 images (#8) * add support for rpi3 and zero 2W * fix raspberry pi 2 detection * add different variants * add recipe to set wifi (only required for raspberry pi zero 2W) * support building different images * retry getting tedge-identity if it fails due to startup issues * add parameters to pi zero 2w image definition --- .github/workflows/bake-image.yml | 5 ++- .gitignore | 3 +- README.md | 18 +++++++--- rugpi-bakery.toml => images/pi23.toml | 3 ++ images/pi4-firmware.toml | 25 ++++++++++++++ images/pi45.toml | 26 ++++++++++++++ images/pizero2w.toml | 34 +++++++++++++++++++ justfile | 8 +++-- recipes/mosquitto/steps/00-install.sh | 2 +- recipes/set-wifi/recipe.toml | 6 ++++ recipes/set-wifi/steps/00-install.sh | 29 ++++++++++++++++ recipes/tedge-bootstrap/files/tedge-bootstrap | 18 +++++++++- recipes/tedge-bootstrap/files/tedge-identity | 4 +-- 13 files changed, 169 insertions(+), 12 deletions(-) rename rugpi-bakery.toml => images/pi23.toml (97%) create mode 100644 images/pi4-firmware.toml create mode 100644 images/pi45.toml create mode 100644 images/pizero2w.toml create mode 100644 recipes/set-wifi/recipe.toml create mode 100755 recipes/set-wifi/steps/00-install.sh diff --git a/.github/workflows/bake-image.yml b/.github/workflows/bake-image.yml index f3f12cd..9e0e8fb 100644 --- a/.github/workflows/bake-image.yml +++ b/.github/workflows/bake-image.yml @@ -21,11 +21,14 @@ jobs: - uses: extractions/setup-just@v1 - name: Set image name - run: echo "IMAGE_NAME=$(just generate_version)" >> $GITHUB_ENV + run: echo "IMAGE_NAME=$(just generate_version tedge_rugpi_45)" >> $GITHUB_ENV - name: Install QEMU run: docker run --privileged --rm tonistiigi/binfmt --install arm64 + - name: Set Image + run: just set-image images/pi45.toml + - name: Extract Image run: just extract diff --git a/.gitignore b/.gitignore index 5c2c3b3..b3f3509 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.rugpi /build recipes/build-info/files/.build_info -**/debian-packages.list \ No newline at end of file +**/debian-packages.list +rugpi-bakery.toml diff --git a/README.md b/README.md index 3f535cc..1903d79 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,29 @@ The repository can be used to build custom Raspberry Pi images with thin-edge.io **Compatible devices** -* Raspberry Pi 4 -* Raspberry Pi 5 +* Raspberry PI 2B Rev 1.2 (using u-boot) +* Raspberry PI Zero 2 W (using u-boot) +* Raspberry PI 3 (using u-boot) +* Raspberry Pi 4 (using tryboot) +* Raspberry Pi 5 (using tryboot) ## Building the image To run the build tasks, install [just](https://just.systems/man/en/chapter_5.html). -1. Create the image (including downloading the supported base Raspberry Pi image) using: +1. Set which image you want to build + + ```sh + just set-image images/pi45.toml + ``` + +2. Create the image (including downloading the supported base Raspberry Pi image) using: ```sh just build-all ``` -2. Using the path to the image shown in the console to flash the image to the Raspberry Pi. +3. Using the path to the image shown in the console to flash the image to the Raspberry Pi. + For further information, checkout the [Rugpi quick start guide](https://oss.silitics.com/rugpi/docs/getting-started). diff --git a/rugpi-bakery.toml b/images/pi23.toml similarity index 97% rename from rugpi-bakery.toml rename to images/pi23.toml index fbadde5..00becee 100644 --- a/rugpi-bakery.toml +++ b/images/pi23.toml @@ -4,10 +4,13 @@ recipes = [ "ssh", "zsh", ] + # Make image generic so it can be used for pi4 and pi5 # So to either pi4 or pi5 if you want to build pi specific images which include the given firmware (EEPROM) include_firmware = "none" +boot_flow = "u-boot" + [parameters.set-hostname] hostname = "tedge-rugpi" diff --git a/images/pi4-firmware.toml b/images/pi4-firmware.toml new file mode 100644 index 0000000..4f21054 --- /dev/null +++ b/images/pi4-firmware.toml @@ -0,0 +1,25 @@ +recipes = [ + # "set-hostname", + "persist-root-home", + "ssh", + "zsh", +] + +# Include firmware as some older pi4 need a firmware update before tryboot will work +include_firmware = "pi4" + +boot_flow = "tryboot" + +[parameters.set-hostname] +hostname = "tedge-rugpi" + +[parameters.apt-cleanup] +autoremove = true + +[parameters.ssh] +root_authorized_keys = """ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhQGWWw73ponAokdNSRZ5cQc9/CIX1TLQgYlr+BtObKoO4UNFP1YSbgK03GjhjeUid+QPmV+UURqxQTqLQoYWqUFP2CYkILFccVPmTvx9HLwupI+6QQKWfMDx9Djfph9GzInymaA5fT7hKppqittFrC/l3lkKgKTX5ohEOGshIbRgtgOYIaW3ByTx3urnaBbYCIgOyOZzSIyS0dUkwsiLu3XjPspgmn3Fs/+vofT/yhBe1carW0UM3ivV0JFfJzrxbCl/F7I2qwfjZXsypjkwlpNupUMuo3xPMi8YvNvyEu4d+IEAqO1dCcdGcxlkiHxrdITIpVLt5mjJ2LauHE/H bootstrap +""" + +[parameters.rugpi-ctrl] +rugpi_admin = true # Enable Rugpi Admin. \ No newline at end of file diff --git a/images/pi45.toml b/images/pi45.toml new file mode 100644 index 0000000..7b42858 --- /dev/null +++ b/images/pi45.toml @@ -0,0 +1,26 @@ +recipes = [ + # "set-hostname", + "persist-root-home", + "ssh", + "zsh", +] + +# Make image generic so it can be used for pi4 and pi5 +# So to either pi4 or pi5 if you want to build pi specific images which include the given firmware (EEPROM) +include_firmware = "none" + +boot_flow = "tryboot" + +[parameters.set-hostname] +hostname = "tedge-rugpi" + +[parameters.apt-cleanup] +autoremove = true + +[parameters.ssh] +root_authorized_keys = """ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhQGWWw73ponAokdNSRZ5cQc9/CIX1TLQgYlr+BtObKoO4UNFP1YSbgK03GjhjeUid+QPmV+UURqxQTqLQoYWqUFP2CYkILFccVPmTvx9HLwupI+6QQKWfMDx9Djfph9GzInymaA5fT7hKppqittFrC/l3lkKgKTX5ohEOGshIbRgtgOYIaW3ByTx3urnaBbYCIgOyOZzSIyS0dUkwsiLu3XjPspgmn3Fs/+vofT/yhBe1carW0UM3ivV0JFfJzrxbCl/F7I2qwfjZXsypjkwlpNupUMuo3xPMi8YvNvyEu4d+IEAqO1dCcdGcxlkiHxrdITIpVLt5mjJ2LauHE/H bootstrap +""" + +[parameters.rugpi-ctrl] +rugpi_admin = true # Enable Rugpi Admin. \ No newline at end of file diff --git a/images/pizero2w.toml b/images/pizero2w.toml new file mode 100644 index 0000000..88ca9c9 --- /dev/null +++ b/images/pizero2w.toml @@ -0,0 +1,34 @@ +recipes = [ + # "set-hostname", + "persist-root-home", + "ssh", + "zsh", + + # wifi credentials are required as Raspberry Pi Zero's don't have an ethernet adapter + "set-wifi", +] + +# Make image generic so it can be used for pi4 and pi5 +# So to either pi4 or pi5 if you want to build pi specific images which include the given firmware (EEPROM) +include_firmware = "none" + +boot_flow = "u-boot" + +[parameters.set-hostname] +hostname = "tedge-rugpi" + +[parameters.apt-cleanup] +autoremove = true + +[parameters.ssh] +root_authorized_keys = """ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhQGWWw73ponAokdNSRZ5cQc9/CIX1TLQgYlr+BtObKoO4UNFP1YSbgK03GjhjeUid+QPmV+UURqxQTqLQoYWqUFP2CYkILFccVPmTvx9HLwupI+6QQKWfMDx9Djfph9GzInymaA5fT7hKppqittFrC/l3lkKgKTX5ohEOGshIbRgtgOYIaW3ByTx3urnaBbYCIgOyOZzSIyS0dUkwsiLu3XjPspgmn3Fs/+vofT/yhBe1carW0UM3ivV0JFfJzrxbCl/F7I2qwfjZXsypjkwlpNupUMuo3xPMi8YvNvyEu4d+IEAqO1dCcdGcxlkiHxrdITIpVLt5mjJ2LauHE/H bootstrap +""" + +[parameters.set-wifi] +# These values should be modified if you want to enable default wifi credentials in the image +ssid = "onboarding_jail" +password = "onboarding_jail" + +[parameters.rugpi-ctrl] +rugpi_admin = true # Enable Rugpi Admin. \ No newline at end of file diff --git a/justfile b/justfile index 54f6550..4585f95 100644 --- a/justfile +++ b/justfile @@ -8,9 +8,13 @@ export CUSTOM_TAR := "build" / IMAGE_NAME + ".tedge.tar" export OUTPUT_IMAGE := "build" / IMAGE_NAME + ".tedge.img" export BUILD_INFO := file_stem(IMAGE_NAME) +set-image FILE="images/pi45.toml": + rm -f ./rugpi-bakery.toml + ln -s {{FILE}} ./rugpi-bakery.toml + # Generate a version name (that can be used in follow up commands) -generate_version: - @echo "tedge_rugpi_$(date +'%Y-%m-%d-%H%M')" +generate_version prefix="tedge_rugpi": + @echo "{{prefix}}_$(date +'%Y-%m-%d-%H%M')" # Show the install paths show: diff --git a/recipes/mosquitto/steps/00-install.sh b/recipes/mosquitto/steps/00-install.sh index d502b1b..c01eace 100755 --- a/recipes/mosquitto/steps/00-install.sh +++ b/recipes/mosquitto/steps/00-install.sh @@ -12,4 +12,4 @@ DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ # Remove sid afterwards to prevent unexpected packages from being installed rm -f /etc/apt/sources.list.d/debian-sid.list -apt-get update +apt-get update ||: diff --git a/recipes/set-wifi/recipe.toml b/recipes/set-wifi/recipe.toml new file mode 100644 index 0000000..55d337c --- /dev/null +++ b/recipes/set-wifi/recipe.toml @@ -0,0 +1,6 @@ +description = "Set wifi access" +default = false + +[parameters] +ssid = {} +password = {} diff --git a/recipes/set-wifi/steps/00-install.sh b/recipes/set-wifi/steps/00-install.sh new file mode 100755 index 0000000..498b711 --- /dev/null +++ b/recipes/set-wifi/steps/00-install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e +echo "Setting wifi access" + +cat << EOT > /etc/NetworkManager/system-connections/wifi.nmconnection +[connection] +id=asio uplink +uuid=354ca6a0-bc96-4a29-82f4-c7cbc6e43fac +type=wifi + +[wifi] +mode=infrastructure +ssid=${RECIPE_PARAM_SSID} + +[wifi-security] +key-mgmt=wpa-psk +psk=${RECIPE_PARAM_PASSWORD} + +[ipv4] +method=auto + +[ipv6] +addr-gen-mode=default +method=auto + +[proxy] +EOT + +chmod 600 /etc/NetworkManager/system-connections/wifi.nmconnection diff --git a/recipes/tedge-bootstrap/files/tedge-bootstrap b/recipes/tedge-bootstrap/files/tedge-bootstrap index 7109b18..a941ce9 100755 --- a/recipes/tedge-bootstrap/files/tedge-bootstrap +++ b/recipes/tedge-bootstrap/files/tedge-bootstrap @@ -4,6 +4,10 @@ set -e C8Y_URL= RAN_MARKER=/etc/tedge/.bootstrapped +log() { + echo "$@" >&2 +} + create_cert() { name="$1" if tedge cert show >/dev/null 2>&1; then @@ -73,7 +77,19 @@ if [ $# -gt 0 ]; then fi # set hostname -DEVICE_ID="$(tedge-identity)" +DEVICE_ID= +attempt=0 +while [ "$attempt" -lt 30 ]; do + DEVICE_ID="$(tedge-identity ||:)" + if [ -n "$DEVICE_ID" ]; then + log "Found valid DEVICE_ID" + break + fi + attempt=$((attempt + 1)) + log "Waiting for tedge-identity" + sleep 5 +done + set_hostname "$DEVICE_ID" create_cert "$DEVICE_ID" diff --git a/recipes/tedge-bootstrap/files/tedge-identity b/recipes/tedge-bootstrap/files/tedge-identity index 029271b..6d64132 100755 --- a/recipes/tedge-bootstrap/files/tedge-identity +++ b/recipes/tedge-bootstrap/files/tedge-identity @@ -22,7 +22,7 @@ get_mac_address() { # Skip dummy interfaces if echo "$dev" | grep -q "$SCN/dummy" 2>/dev/null; then - continue + continue fi idx=$(cat "$dev/ifindex") @@ -61,7 +61,7 @@ get_model_type() { Raspberry\ Pi\ 3*) MODEL_PREFIX=rpi3 ;; - Raspberry\ Pi\ 2\ Rev*) + Raspberry\ Pi\ 2*) MODEL_PREFIX=rpi2 ;; Raspberry\ Pi\ Model*)