3.5 KiB
3.5 KiB
Build a Custom Raspberry Pi Image with ECU Tests
This guide walks you through building your own Raspberry Pi OS image that already contains this framework, dependencies, config, and services. It uses the official pi-gen tool (used by Raspberry Pi OS) or the simpler pi-gen-lite alternatives.
Important: BabyLin support on ARM/Linux depends on vendor SDKs. If no
.sois provided for ARM, either use the Mock interface on the Pi, or keep hardware tests on Windows.
Approach A: Using pi-gen (official)
-
Prepare a build host (Debian/Ubuntu)
sudo apt update && sudo apt install -y git coreutils quilt parted qemu-user-static debootstrap zerofree \ pxz zip dosfstools libcap2-bin grep rsync xz-utils file bc curl jq -
Clone pi-gen
git clone https://github.com/RPi-Distro/pi-gen.git cd pi-gen -
Create a custom stage for ECU Tests (e.g.,
stage2/02-ecu-tests/):00-packages(optional OS deps like python3, libusb-1.0-0)01-run.shto clone your repo, create venv, install deps, and set up systemd units
Example
01-run.shcontents:#!/bin/bash -e REPO_DIR=/home/pi/ecu_tests sudo -u pi git clone <your-repo-url> "$REPO_DIR" cd "$REPO_DIR" sudo -u pi python3 -m venv .venv sudo -u pi bash -lc "source .venv/bin/activate && pip install --upgrade pip && pip install -r requirements.txt" sudo mkdir -p "$REPO_DIR/reports" sudo chown -R pi:pi "$REPO_DIR/reports" sudo install -Dm644 "$REPO_DIR/scripts/ecu-tests.service" /etc/systemd/system/ecu-tests.service sudo install -Dm644 "$REPO_DIR/scripts/ecu-tests.timer" /etc/systemd/system/ecu-tests.timer sudo systemctl enable ecu-tests.service sudo systemctl enable ecu-tests.timer || true # Optional udev rules if [ -f "$REPO_DIR/scripts/99-babylin.rules" ]; then sudo install -Dm644 "$REPO_DIR/scripts/99-babylin.rules" /etc/udev/rules.d/99-babylin.rules fi -
Configure build options (
configfile in pi-gen root):IMG_NAME=ecu-tests-os ENABLE_SSH=1 STAGE_LIST="stage0 stage1 stage2" # include your custom stage2 additions -
Build
sudo ./build.sh -
Flash the resulting
.imgto SD card withRaspberry Pi Imagerordd.
Approach B: Preseed on first boot (lighter)
- Ship a minimal Raspberry Pi OS image and a cloud-init/user-data or first-boot script that pulls your repo and runs
scripts/pi_install.sh. - Pros: Faster iteration; you control repo URL at install time.
- Cons: Requires internet on first boot.
CI Integration (optional)
- You can automate image builds with GitHub Actions or GitLab CI using a Docker runner that executes pi-gen.
- Upload the
.imgas a release asset or pipeline artifact. - Optionally, bake environment-specific
config/test_config.yamlor keep it external and setECU_TESTS_CONFIGin the systemd unit.
Hardware Notes
- If using BabyLin, ensure:
.sofor ARM, udev rules, and any kernel modules. - Validate the SDK wrapper and libraries are present under
/opt/ecu_tests/vendor/(or your chosen path). Ensure.sofiles are on the linker path (runsudo ldconfig) andBabyLIN_library.pyis importable.
Boot-time Behavior
- The
ecu-tests.timercan schedule daily or hourly test runs; editOnUnitActiveSecas needed. - Logs are written to
reports/service.logandreports/service.erron the Pi.
Security
- Consider read-only root filesystem for robustness.
- Use a dedicated user with limited privileges for test execution.
- Keep secrets (if any) injected via environment and not committed.