Skip to content

Commit

Permalink
Add support for building Raspberry pi 2B Rev1.2, 3, Zero 2 W, 4 and 5…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
reubenmiller authored Nov 28, 2023
1 parent a14f869 commit 2f47ca3
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/bake-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.rugpi
/build
recipes/build-info/files/.build_info
**/debian-packages.list
**/debian-packages.list
rugpi-bakery.toml
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
3 changes: 3 additions & 0 deletions rugpi-bakery.toml → images/pi23.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
25 changes: 25 additions & 0 deletions images/pi4-firmware.toml
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions images/pi45.toml
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions images/pizero2w.toml
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion recipes/mosquitto/steps/00-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||:
6 changes: 6 additions & 0 deletions recipes/set-wifi/recipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description = "Set wifi access"
default = false

[parameters]
ssid = {}
password = {}
29 changes: 29 additions & 0 deletions recipes/set-wifi/steps/00-install.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion recipes/tedge-bootstrap/files/tedge-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions recipes/tedge-bootstrap/files/tedge-identity
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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*)
Expand Down

0 comments on commit 2f47ca3

Please sign in to comment.