Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c4870c6fb | ||
|
|
92d601f585 | ||
|
|
65a6800228 | ||
|
|
d01add5646 | ||
|
|
a828667b0f | ||
|
|
45569611da | ||
|
|
b18ed3888b | ||
|
|
d746ceba6d | ||
|
|
5f3db8453b | ||
|
|
85dc1ee04d | ||
|
|
6576a4a506 | ||
|
|
9b0659d30c | ||
|
|
317ae087fd | ||
|
|
07db1b9ec0 | ||
|
|
67da1141a0 | ||
|
|
5f36beb44a | ||
|
|
eb0691d84f |
@@ -111,7 +111,8 @@ jobs:
|
||||
shellcheck -x qemu/*.sh qemu/tests/*.sh build/*.sh \
|
||||
qemu/rootfs/etc/warden-lib.sh qemu/rootfs/etc/rc \
|
||||
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh \
|
||||
tests/unpack-buildroot/*.sh
|
||||
- name: cache apt archives (python3-pil)
|
||||
# Same cost class as the busybox binary cached below: a system package
|
||||
# plus its libjpeg/libpng transitive deps, downloaded fresh on every
|
||||
@@ -148,6 +149,10 @@ jobs:
|
||||
# on the debug channel. All offline (a stub qemu-system-arm on
|
||||
# PATH), so it runs on every push/PR, not only a real boot.
|
||||
run: bash qemu/tests/run-sh-args-test.sh
|
||||
- name: rig init honours reboot/poweroff/halt (#5)
|
||||
run: bash qemu/tests/init-power-signals-test.sh
|
||||
- name: rig init daemon order matches the panel (flare-edge#348)
|
||||
run: bash qemu/tests/init-daemon-order-test.sh
|
||||
- name: mkimage.sh SEED_DIR regression test
|
||||
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
|
||||
# otherwise; this builds the same unprivileged mkfs.ext4 image and
|
||||
@@ -166,6 +171,11 @@ jobs:
|
||||
# Retry-on-mismatch, cleanup, and the already-verified
|
||||
# short-circuit, against a fake curl on PATH: no network.
|
||||
run: bash tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh
|
||||
- name: unpack-buildroot regression tests
|
||||
# Fresh unpack, leave-existing-tree-alone, and every refusal path
|
||||
# (unpatched selectors, bad tarball, half-present tree, failed
|
||||
# fetch), against a stub fetch script: no network (issue #4).
|
||||
run: bash tests/unpack-buildroot/run-unpack-buildroot-tests.sh
|
||||
- name: mk-bootimg boot.img validation regression tests
|
||||
# Guards issue #22 (a missing/erroring fdtget silently skipping the
|
||||
# data-position check) plus the FIT metadata and per-image
|
||||
|
||||
@@ -12,13 +12,9 @@
|
||||
# Same shape as fetch-kernel-tarball.sh, deliberately: a version bump edits this
|
||||
# file and the pin beside it, nothing else. FAILS CLOSED on a missing pin.
|
||||
#
|
||||
# Not wired into build-firmware.sh or CI yet -- tools/build-firmware.sh stages
|
||||
# sdk-patches/buildroot/ onto whatever buildroot tree the vendor SDK already
|
||||
# has, it does not yet extract this pinned tarball over it. Exercised today by
|
||||
# tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh and by
|
||||
# running the script by hand; wiring it into the real build path is a separate
|
||||
# change (it has to reconcile the pristine tree with the existing SDK buildroot
|
||||
# checkout first).
|
||||
# Called by build/unpack-buildroot.sh, which flare-edge's
|
||||
# tools/build-firmware.sh runs after applying luckfox-sdk-patches/ (issue #4).
|
||||
# Tested by tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh.
|
||||
#
|
||||
# Usage: fetch-buildroot-tarball.sh <destination-path>
|
||||
set -euo pipefail
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
# Unpack the pinned Buildroot tree where the vendor SDK builds it.
|
||||
#
|
||||
# The vendor SDK ships buildroot-2023.02.6. WardenOS builds against
|
||||
# buildroot-2025.02.8, which is not in the vendor checkout, so a clean checkout
|
||||
# plus luckfox-sdk-patches/ had nothing to build (blueflare/bfe-core1106-sdk#4).
|
||||
# This script closes that gap: it fetches the tarball with
|
||||
# fetch-buildroot-tarball.sh (sha256-pinned, fails closed) and unpacks it to
|
||||
# sysdrv/source/buildroot/buildroot-<ver>, the path the patched project/build.sh
|
||||
# and sysdrv/Makefile select.
|
||||
#
|
||||
# Idempotent. An SDK that already has the tree is left alone, so the
|
||||
# persistent CI SDK and the workstation SDK are untouched. A partial unpack
|
||||
# never lands at the final path: the tarball is unpacked into a scratch
|
||||
# directory beside it and moved into place only when complete.
|
||||
#
|
||||
# Our own Buildroot delta (defconfigs, package patches, the busybox applet
|
||||
# patch) is NOT applied here. flare-edge's tools/build-firmware.sh stages it
|
||||
# after this script runs, the same way it applies the rest of the series.
|
||||
#
|
||||
# Usage: unpack-buildroot.sh <vendor-sdk-dir>
|
||||
#
|
||||
# The tarball is cached at sysdrv/source/buildroot/buildroot-<ver>.tar.xz
|
||||
# (inside a directory the vendor .gitignore already ignores); set
|
||||
# WARDEN_BUILDROOT_TARBALL to use another path.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
|
||||
FETCH="$HERE/fetch-buildroot-tarball.sh"
|
||||
SDK="${1:?usage: unpack-buildroot.sh <vendor-sdk-dir>}"
|
||||
|
||||
die() { echo "unpack-buildroot: FATAL: $*" >&2; exit 1; }
|
||||
|
||||
[ -f "$FETCH" ] || die "missing $FETCH"
|
||||
BRVER="$(sed -n 's/^BRVER=//p' "$FETCH" | head -1)"
|
||||
case "$BRVER" in
|
||||
''|*[!0-9.]*) die "cannot read BRVER from $FETCH" ;;
|
||||
esac
|
||||
|
||||
# The SDK must already select this version. Both selectors come from
|
||||
# luckfox-sdk-patches/board/ (0006 for project/build.sh, 0009 for
|
||||
# sysdrv/Makefile); if either still names another tree the series has not
|
||||
# been applied, and unpacking would only hide that.
|
||||
BUILD_SH="$SDK/project/build.sh"
|
||||
MAKEFILE="$SDK/sysdrv/Makefile"
|
||||
[ -f "$BUILD_SH" ] || die "no vendor SDK at $SDK (missing project/build.sh)"
|
||||
[ -f "$MAKEFILE" ] || die "no vendor SDK at $SDK (missing sysdrv/Makefile)"
|
||||
# shellcheck disable=SC2016 # the literal ${SDK_SYSDRV_DIR} text in build.sh
|
||||
sel_build="$(sed -n 's|^BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/||p' "$BUILD_SH" | head -1)"
|
||||
sel_make="$(sed -n 's/^BUILDROOT_VER[[:space:]]*?=[[:space:]]*//p' "$MAKEFILE" | head -1)"
|
||||
[ "$sel_build" = "buildroot-$BRVER" ] ||
|
||||
die "project/build.sh selects '${sel_build:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
|
||||
[ "$sel_make" = "buildroot-$BRVER" ] ||
|
||||
die "sysdrv/Makefile selects '${sel_make:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
|
||||
|
||||
PARENT="$SDK/sysdrv/source/buildroot"
|
||||
TREE="$PARENT/buildroot-$BRVER"
|
||||
TB="${WARDEN_BUILDROOT_TARBALL:-$PARENT/buildroot-$BRVER.tar.xz}"
|
||||
|
||||
if [ -f "$TREE/Makefile" ] && [ -d "$TREE/configs" ] && [ -d "$TREE/package" ]; then
|
||||
echo "buildroot-$BRVER: tree already present at ${TREE#"$SDK"/}"
|
||||
exit 0
|
||||
fi
|
||||
# Something is at the path but it is not a Buildroot tree. Deleting it here
|
||||
# could destroy build output in a shared SDK, so say so and stop.
|
||||
[ ! -e "$TREE" ] || die "$TREE exists but is not a complete Buildroot tree; remove it and rerun"
|
||||
|
||||
mkdir -p "$PARENT"
|
||||
bash "$FETCH" "$TB"
|
||||
|
||||
SCRATCH="$(mktemp -d "$PARENT/.unpack-buildroot.XXXXXX")"
|
||||
[ -d "$SCRATCH" ] || die "mktemp failed under $PARENT"
|
||||
cleanup() { rm -rf "$SCRATCH"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "== unpacking buildroot-$BRVER into ${TREE#"$SDK"/}"
|
||||
tar -xJf "$TB" -C "$SCRATCH"
|
||||
[ -f "$SCRATCH/buildroot-$BRVER/Makefile" ] ||
|
||||
die "tarball did not contain buildroot-$BRVER/Makefile"
|
||||
mv "$SCRATCH/buildroot-$BRVER" "$TREE"
|
||||
echo "buildroot-$BRVER: unpacked"
|
||||
@@ -17,7 +17,8 @@
|
||||
# release tarball has no commit to name:
|
||||
#
|
||||
# linux-6.18.46 build/fetch-kernel-tarball.sh
|
||||
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh
|
||||
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh (unpacked into the
|
||||
# vendor SDK by build/unpack-buildroot.sh)
|
||||
#
|
||||
# The buildroot one matters more than it looks. The firmware builds against
|
||||
# sysdrv/source/buildroot/buildroot-2025.02.8 inside the vendor SDK, and the
|
||||
|
||||
@@ -82,7 +82,7 @@ tiered:
|
||||
behind a small injectable seam, mock its world, build
|
||||
`-fcondition-coverage`, enforce via the shared `drivers/enforce-mcdc.sh`
|
||||
(gcc-14 `gcov --conditions`) in the CI `mcdc` job (the proven flare-edge
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (40/40 conditions) and
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (50/50 conditions) and
|
||||
`freshness.c` (66/66). **Next in:** the modbus master and the RGA
|
||||
dispatch, with the ADR-0005 unification (`drivers/README.md`).
|
||||
- **Tier 2, near-mainline small drivers -> branch coverage + fault
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ execute code on private infrastructure (ADR-0007).
|
||||
| `mcdc` | ubuntu-latest | 100% MC/DC enforced on every `drivers/*/test` (gcc-14 `-fcondition-coverage`). |
|
||||
| `bench` | ubuntu-latest | Smoke-runs the sim + rs485-bridge micro-benchmarks; emits ns/op trend JSON. |
|
||||
| `patches-apply` | ubuntu-latest | Fetches pristine linux-6.18.46 (cached, sha256-verified) and applies `patches/*` in order. |
|
||||
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
|
||||
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`, `tests/unpack-buildroot/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, unpack-buildroot, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
|
||||
| `quality` | ubuntu-latest | Codacy-style grade computed in-pipeline: clippy, cppcheck, shellcheck, ruff, lizard, jscpd, cargo-audit feed `tools/quality/score.py` (SQALE debt ratio + a separate worst-of security axis; SonarQube's published thresholds). Uploads `quality.json`; fails if the security grade is worse than C. |
|
||||
| `kernel-build` | ubuntu-latest, **dispatch-only** | apt-installs the cross toolchain + qemu, `build/build-kernel.sh` -> `zImage` + `rv1106-warden.dtb`, QEMU `-M virt` boot smoke (fail-closed), artifact upload (best-effort). Trigger: `gh workflow run ci.yml`. |
|
||||
| `prune-artifacts` | ubuntu-latest, dispatch-only | Deletes `kernel-rv1106` artifacts beyond the newest 3. |
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
> **Outcome tested:** A relay is exported transparently and driven without disturbing a held contact.
|
||||
|
||||
**Coverage**: relays.c: 40/40 conditions, 100% MC/DC (CI-enforced)
|
||||
**Coverage**: relays.c: 50/50 conditions, 100% MC/DC (CI-enforced)
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[warden_relay_set idx,on] --> B{idx < COUNT?}
|
||||
B -- no --> Z[no-op]
|
||||
B -- yes --> C{exported?}
|
||||
B -- yes --> P{all sysfs paths fit PATH_MAX?}
|
||||
P -- no --> Z3[log to stderr, no-op]
|
||||
P -- yes --> C{exported?}
|
||||
C -- no --> D[write export] --> E{exported now?}
|
||||
E -- no --> Z2[give up]
|
||||
E -- yes --> F
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ Self-contained logic with a clean seam, measured to **100% MC/DC** (gcc-14
|
||||
|
||||
| Driver | Seam | MC/DC |
|
||||
|---|---|---|
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 40/40 conditions, 100% |
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 50/50 conditions, 100% |
|
||||
| `freshness/` | produce/render callbacks (the "no stale numbers" guard) | 66/66 conditions, 100% |
|
||||
|
||||
**Adding a Tier-1 driver:** copy `<name>.{c,h}` here, put the hardware/OS calls behind
|
||||
|
||||
+60
-28
@@ -1,5 +1,6 @@
|
||||
#include "relays.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,6 +9,8 @@
|
||||
/* GPIO1_A0 and GPIO1_A1; gpiochip1 base is 32. See relays.h. */
|
||||
static const int s_gpio[WARDEN_RELAY_COUNT] = { 32, 33 };
|
||||
static const char * const s_name[WARDEN_RELAY_COUNT] = { "Relay 1", "Relay 2" };
|
||||
/* The same numbers as the strings written to `export`, so no runtime formatting. */
|
||||
static const char * const s_gpio_str[WARDEN_RELAY_COUNT] = { "32", "33" };
|
||||
|
||||
/* ---- default sysfs backend (Tier-2 plumbing; covered by integration tests) ---- */
|
||||
|
||||
@@ -64,11 +67,46 @@ const char * warden_relay_name(uint32_t idx)
|
||||
return idx < WARDEN_RELAY_COUNT ? s_name[idx] : "-";
|
||||
}
|
||||
|
||||
static bool exported(int gpio)
|
||||
/**
|
||||
* Every sysfs path one relay operation can touch. Each holds PATH_MAX bytes, so
|
||||
* any root the kernel would accept fits.
|
||||
*/
|
||||
struct relay_paths {
|
||||
char gpio[PATH_MAX]; /* <root>/gpioN */
|
||||
char export_[PATH_MAX]; /* <root>/export */
|
||||
char direction[PATH_MAX]; /* <root>/gpioN/direction */
|
||||
char value[PATH_MAX]; /* <root>/gpioN/value */
|
||||
};
|
||||
|
||||
/**
|
||||
* Format the paths for relay @p idx up front. A `$WARDEN_GPIO_ROOT` too long for
|
||||
* any of them is refused with a log line, never truncated: a cut-short path
|
||||
* would silently report both relays unavailable, or name a different node.
|
||||
*/
|
||||
static bool relay_paths(uint32_t idx, struct relay_paths * rp)
|
||||
{
|
||||
char p[80];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d", gpio_root(), gpio);
|
||||
return s_io->exists(p);
|
||||
const char * root = gpio_root();
|
||||
int gpio = s_gpio[idx];
|
||||
const int n[] = {
|
||||
snprintf(rp->gpio, sizeof(rp->gpio), "%s/gpio%d", root, gpio),
|
||||
snprintf(rp->export_, sizeof(rp->export_), "%s/export", root),
|
||||
snprintf(rp->direction, sizeof(rp->direction), "%s/gpio%d/direction", root, gpio),
|
||||
snprintf(rp->value, sizeof(rp->value), "%s/gpio%d/value", root, gpio),
|
||||
};
|
||||
for(size_t i = 0; i < sizeof(n) / sizeof(n[0]); i++) {
|
||||
/* The unsigned cast also maps an encoding error (n < 0) to "does not fit". */
|
||||
if((unsigned)n[i] >= PATH_MAX) {
|
||||
fprintf(stderr, "relays: WARDEN_GPIO_ROOT is too long (%zu bytes): sysfs paths "
|
||||
"under it exceed PATH_MAX (%d), refusing it\n", strlen(root), PATH_MAX);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool exported(const struct relay_paths * rp)
|
||||
{
|
||||
return s_io->exists(rp->gpio);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,28 +115,21 @@ static bool exported(int gpio)
|
||||
* relay the first time this page is opened; reading the current level first and
|
||||
* writing it straight back makes the export transparent.
|
||||
*/
|
||||
static bool ensure_ready(int gpio)
|
||||
static bool ensure_ready(uint32_t idx, const struct relay_paths * rp)
|
||||
{
|
||||
if(!exported(gpio)) {
|
||||
char ex[80], n[16];
|
||||
snprintf(ex, sizeof(ex), "%s/export", gpio_root());
|
||||
snprintf(n, sizeof(n), "%d", gpio);
|
||||
s_io->write(ex, n);
|
||||
if(!exported(gpio)) return false;
|
||||
if(!exported(rp)) {
|
||||
s_io->write(rp->export_, s_gpio_str[idx]);
|
||||
if(!exported(rp)) return false;
|
||||
}
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/direction", gpio_root(), gpio);
|
||||
char dir[16] = "";
|
||||
if(!s_io->read_line(p, dir, sizeof(dir))) return false;
|
||||
if(!s_io->read_line(rp->direction, dir, sizeof(dir))) return false;
|
||||
|
||||
if(strncmp(dir, "out", 3) != 0) {
|
||||
/* Preserve the level across the switch to output. */
|
||||
char vp[96];
|
||||
int cur;
|
||||
snprintf(vp, sizeof(vp), "%s/gpio%d/value", gpio_root(), gpio);
|
||||
if(!s_io->read_int(vp, &cur)) cur = 0;
|
||||
s_io->write(p, cur ? "high" : "low");
|
||||
if(!s_io->read_int(rp->value, &cur)) cur = 0;
|
||||
s_io->write(rp->direction, cur ? "high" : "low");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -106,27 +137,28 @@ static bool ensure_ready(int gpio)
|
||||
bool warden_relay_available(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
return ensure_ready(s_gpio[idx]);
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
return ensure_ready(idx, &rp);
|
||||
}
|
||||
|
||||
bool warden_relay_get(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
if(!exported(s_gpio[idx])) return false;
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
if(!exported(&rp)) return false;
|
||||
|
||||
char p[96];
|
||||
int v;
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
if(!s_io->read_int(p, &v)) v = 0;
|
||||
if(!s_io->read_int(rp.value, &v)) v = 0;
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
void warden_relay_set(uint32_t idx, bool on)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return;
|
||||
if(!ensure_ready(s_gpio[idx])) return;
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
s_io->write(p, on ? "1" : "0");
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return;
|
||||
if(!ensure_ready(idx, &rp)) return;
|
||||
s_io->write(rp.value, on ? "1" : "0");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
* the decision logic runs and is measured to 100% MC/DC on the host, and the
|
||||
* gpio root is `$WARDEN_GPIO_ROOT`-overridable so the real backend can run
|
||||
* against a scratch tree in an integration test.
|
||||
*
|
||||
* Paths are built in PATH_MAX buffers. A root too long for its longest path
|
||||
* ("<root>/gpioNN/direction" within PATH_MAX) is refused with a stderr line, and
|
||||
* every call then reports unavailable / off / no-op; it is never truncated.
|
||||
*/
|
||||
#ifndef WARDEN_RELAYS_H
|
||||
#define WARDEN_RELAYS_H
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../relays.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -30,11 +32,12 @@ static struct {
|
||||
const char *read_line_val;
|
||||
bool read_int_ok;
|
||||
int read_int_val;
|
||||
char last_write_path[160];
|
||||
char last_write_path[PATH_MAX];
|
||||
char last_write_val[32];
|
||||
int exists_calls;
|
||||
} fk;
|
||||
|
||||
static bool fk_exists(const char *p) { (void)p; return fk.exists_ret; }
|
||||
static bool fk_exists(const char *p) { (void)p; fk.exists_calls++; return fk.exists_ret; }
|
||||
static void fk_write(const char *p, const char *v) {
|
||||
snprintf(fk.last_write_path, sizeof fk.last_write_path, "%s", p);
|
||||
snprintf(fk.last_write_val, sizeof fk.last_write_val, "%s", v);
|
||||
@@ -56,6 +59,104 @@ static const struct relay_io FAKE = { fk_exists, fk_write, fk_read_line, fk_read
|
||||
|
||||
static void fk_reset(void) { memset(&fk, 0, sizeof fk); }
|
||||
|
||||
/* ---- stderr capture: proves a refusal is logged, not silent ---- */
|
||||
|
||||
static char g_err[1024];
|
||||
static int g_saved_stderr = -1;
|
||||
static char g_err_path[] = "/tmp/warden-relays-stderr-XXXXXX";
|
||||
|
||||
static void err_begin(void)
|
||||
{
|
||||
int fd = mkstemp(g_err_path);
|
||||
assert(fd >= 0);
|
||||
fflush(stderr);
|
||||
g_saved_stderr = dup(2);
|
||||
dup2(fd, 2);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void err_end(void)
|
||||
{
|
||||
fflush(stderr);
|
||||
dup2(g_saved_stderr, 2);
|
||||
close(g_saved_stderr);
|
||||
FILE *f = fopen(g_err_path, "r");
|
||||
size_t n = f ? fread(g_err, 1, sizeof g_err - 1, f) : 0;
|
||||
g_err[n] = '\0';
|
||||
if(f) fclose(f);
|
||||
unlink(g_err_path);
|
||||
memcpy(g_err_path + strlen(g_err_path) - 6, "XXXXXX", 6);
|
||||
}
|
||||
|
||||
/* A root of exactly @p len bytes ("/" then 'a's); it need not exist for fake io. */
|
||||
static char g_long[PATH_MAX + 64];
|
||||
static const char *long_root(size_t len)
|
||||
{
|
||||
assert(len >= 1 && len < sizeof g_long);
|
||||
g_long[0] = '/';
|
||||
memset(g_long + 1, 'a', len - 1);
|
||||
g_long[len] = '\0';
|
||||
return g_long;
|
||||
}
|
||||
|
||||
/* Root-length bounds (issue #10). The longest path is "<root>/gpio32/direction",
|
||||
* so a root of PATH_MAX - 1 - strlen("/gpio32/direction") bytes is the longest
|
||||
* that fits. One byte more must be refused loudly, never truncated. */
|
||||
static void long_root_unit_tests(void)
|
||||
{
|
||||
const size_t max_root = PATH_MAX - 1 - strlen("/gpio32/direction");
|
||||
|
||||
/* Well past the old 80/96-byte buffers but inside PATH_MAX: works, and the
|
||||
* io sees the full, untruncated path. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(200), 1);
|
||||
warden_relay_set(0, true);
|
||||
EXPECT(strcmp(fk.last_write_val, "1") == 0);
|
||||
EXPECT(strlen(fk.last_write_path) == 200 + strlen("/gpio32/value"));
|
||||
EXPECT(strncmp(fk.last_write_path, g_long, 200) == 0);
|
||||
EXPECT(strcmp(fk.last_write_path + 200, "/gpio32/value") == 0);
|
||||
|
||||
/* Exactly at the bound: still accepted. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root), 1);
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
|
||||
/* One byte over: "<root>/gpio32" still fits, the direction path does not.
|
||||
* Every entry point refuses, logs, and never touches the io. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root + 1), 1);
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
fk.read_int_ok = true; fk.read_int_val = 1;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
warden_relay_set(1, true);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.last_write_path[0] == '\0');
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
/* A root longer than PATH_MAX itself: refused the same way. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(PATH_MAX + 10), 1);
|
||||
fk_reset(); fk.exists_ret = true;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(1) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
unsetenv("WARDEN_GPIO_ROOT");
|
||||
}
|
||||
|
||||
static void unit_tests(void)
|
||||
{
|
||||
warden_relay__set_io(&FAKE);
|
||||
@@ -142,18 +243,20 @@ static void unit_tests(void)
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
warden_relay_set(0, false);
|
||||
EXPECT(strcmp(fk.last_write_val, "0") == 0);
|
||||
|
||||
long_root_unit_tests();
|
||||
}
|
||||
|
||||
/* ---------------- layer 2: real sysfs backend over a scratch tree ---------------- */
|
||||
|
||||
static char g_root[128];
|
||||
static char g_root[PATH_MAX];
|
||||
|
||||
static void wr(const char *rel, const char *content) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
FILE *f = fopen(p, "w"); if(f) { fputs(content, f); fclose(f); }
|
||||
}
|
||||
static void mkgpio(int n) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
}
|
||||
|
||||
static void integration_tests(void)
|
||||
@@ -207,6 +310,24 @@ static void integration_tests(void)
|
||||
wr("gpio33/direction", "in\n");
|
||||
wr("gpio33/value", "1\n");
|
||||
EXPECT(warden_relay_available(1) == true); /* reads value=1, writes direction "high" */
|
||||
|
||||
/* Issue #10: a real scratch tree under a root far longer than the old 80/96-byte
|
||||
* buffers (the simulator's case). Both relays must be available and switchable. */
|
||||
for(int i = 0; i < 5; i++) {
|
||||
size_t l = strlen(g_root);
|
||||
snprintf(g_root + l, sizeof g_root - l, "/%s", "long-scratch-directory-component-for-issue-10");
|
||||
EXPECT(mkdir(g_root, 0777) == 0);
|
||||
}
|
||||
EXPECT(strlen(g_root) > 200);
|
||||
setenv("WARDEN_GPIO_ROOT", g_root, 1);
|
||||
mkgpio(32); mkgpio(33);
|
||||
wr("gpio32/direction", "out\n"); wr("gpio32/value", "0\n");
|
||||
wr("gpio33/direction", "out\n"); wr("gpio33/value", "0\n");
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
EXPECT(warden_relay_available(1) == true);
|
||||
warden_relay_set(1, true);
|
||||
EXPECT(warden_relay_get(1) == true);
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
@@ -57,7 +57,9 @@ luckfox-sdk-patches/uboot/include/ new source files
|
||||
luckfox-sdk-patches/kernel/patches/ diffs against sysdrv/source/kernel/
|
||||
luckfox-sdk-patches/kernel/configs/ new kernel config fragments
|
||||
luckfox-sdk-patches/wifi/patches/ diffs against sysdrv/drv_ko/wifi/ (out-of-tree modules)
|
||||
luckfox-sdk-patches/board/patches/ diffs against project/ (board .mk + the build driver)
|
||||
luckfox-sdk-patches/board/patches/ diffs against project/ and sysdrv/ build files (board .mk,
|
||||
build drivers, Makefiles, init overlays); may delete files
|
||||
luckfox-sdk-patches/buildroot/ our delta on the Buildroot tree (see "Buildroot" below)
|
||||
```
|
||||
|
||||
Paths inside each patch are relative to the vendor SDK root, so apply with
|
||||
@@ -87,6 +89,29 @@ skipped; else if `git apply --check` succeeds it is applied; else it is a hand-
|
||||
patched SDK carrying an equivalent (or a genuine conflict) and the script warns
|
||||
and continues rather than aborting the build.
|
||||
|
||||
## Buildroot
|
||||
|
||||
The vendor checkout ships buildroot-2023.02.6; WardenOS builds against
|
||||
buildroot-2025.02.8, which is not in the vendor checkout.
|
||||
`board/patches/0006-buildroot-2025.patch` (project/build.sh) and
|
||||
`board/patches/0009-sysdrv-buildroot-2025.patch` (sysdrv/Makefile) select it,
|
||||
and `../build/unpack-buildroot.sh` puts the pristine tree at
|
||||
`sysdrv/source/buildroot/buildroot-2025.02.8`: it fetches the tarball with
|
||||
`../build/fetch-buildroot-tarball.sh` (sha256-pinned) and leaves an existing
|
||||
tree alone. flare-edge's `tools/build-firmware.sh` runs it right after
|
||||
applying the patches, then stages `buildroot/files/` and applies
|
||||
`buildroot/patches/` onto the tree (issue #4).
|
||||
|
||||
## Completeness check
|
||||
|
||||
flare-edge's `tools/verify-sdk-patches.sh` replays this series onto the vendor
|
||||
base and compares the result with an SDK checkout. It also fails when the SDK
|
||||
has a tracked change (edit or deletion) that no patch, no fragment and no
|
||||
entry in flare-edge's `tools/sdk-delta-allowlist.txt` accounts for, and when
|
||||
the 86Panel board config names a kernel or U-Boot config fragment that
|
||||
neither the vendor base nor this directory provides. Before that check, five
|
||||
real deltas lived only in copies of one SDK tree (issue #4).
|
||||
|
||||
## What each patch does
|
||||
|
||||
### `uboot/patches/0001-display-and-boot-timing.patch`
|
||||
@@ -269,6 +294,29 @@ had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close
|
||||
`sysdrv/source/uboot/u-boot/configs/` (it is a whole new file, not a diff);
|
||||
the board `.mk` patch is what references it by name.
|
||||
|
||||
### `board/patches/0009` to `0013` (issue #4)
|
||||
|
||||
Deltas that lived only in the workstation SDK until issue #4. Each patch
|
||||
header explains its change.
|
||||
|
||||
| patch | file | what it does |
|
||||
|---|---|---|
|
||||
| `0009-sysdrv-buildroot-2025.patch` | `sysdrv/Makefile` | `BUILDROOT_VER` to 2025.02.8 (the tree the `buildroot` target builds); relaxes the vendor unpack fallback's `cp` lines |
|
||||
| `0010-drop-2023-buildroot-package-patches.patch` | `sysdrv/tools/board/buildroot/{busybox,hcitool}_patch/` | deletes five 2023-era package patches the fallback would copy into Buildroot |
|
||||
| `0011-oem-flare-minimize.patch` | `project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh` | `flare_minimize`: strips camera/ISP files and modules from /oem |
|
||||
| `0012-drop-s50sshd.patch` | `overlay-luckfox-buildroot-init/etc/init.d/S50sshd` | deletes the generic sshd starter; dropbear provides SSH |
|
||||
| `0013-e2fsprogs-build-cflags.patch` | `sysdrv/tools/board/e2fsprogs/Makefile` | `BUILD_CFLAGS` so the host helpers build with gcc 14 |
|
||||
|
||||
### `board/patches/0014-s50usbdevice-unset-role-is-client.patch`
|
||||
|
||||
0004's S50usbdevice gate read an unset role as router, so a fresh `/userdata`
|
||||
never composed the USB gadget and the panel had no `usb0` until its second
|
||||
boot (flare-edge#278). 0014 makes unset mean client (0), like every other
|
||||
role reader; flare-edge's `tests/guards/run-role-default-tests.sh` pins the
|
||||
gate to them. It is a separate patch, not an edit to 0004, because
|
||||
`build-firmware.sh` would skip an edited 0004 as inconclusive on an SDK that
|
||||
already carries 0004 and 0008.
|
||||
|
||||
## Config fragments
|
||||
|
||||
| fragment | why |
|
||||
@@ -278,6 +326,8 @@ had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close
|
||||
| `uboot/flare-bootcount.config` | boot-failure fallback to `altbootcmd=download` -> MaskRom |
|
||||
| `uboot/flare-spl-brom.config` | builds `spl_bootrom.o`; does *not* set `SPL_ROCKCHIP_BACK_TO_BROM`, which would flip `SPL_MMC_SUPPORT` off |
|
||||
| `kernel/flare-backlight.config` | `CONFIG_BACKLIGHT_PWM=y`. As `=m` the backlight class device does not exist until userspace `insmod`s it at ~3.3-3.7 s, which is when the logo is being replaced anyway |
|
||||
| `kernel/flare-wireguard.config` | `CONFIG_WIREGUARD=y` for the vendor 5.10 kernel, which builds the recovery image. Named by the 86Panel board `.mk`; untracked in the workstation SDK until issue #4 |
|
||||
| `kernel/rv1106-usb-host-ethernet.config` | USB-Ethernet class drivers (with the `USB_NET_DRIVERS` menu gate) for the vendor 5.10 kernel. Same history as `flare-wireguard.config` |
|
||||
| `kernel/flare-fbcon.config` | `# CONFIG_LOGO is not set` (the SDK ships the LuckFox fox-head over our logo) plus `FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y` (fbcon seizing the fb destroyed the `drm_logo` image U-Boot handed over) |
|
||||
|
||||
## Measured boot timeline
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
Build buildroot-2025.02.8 from sysdrv/Makefile too.
|
||||
|
||||
0006-buildroot-2025.patch points project/build.sh at buildroot-2025.02.8, but
|
||||
sysdrv/Makefile has its own default, BUILDROOT_VER, and that is the one the
|
||||
`buildroot` target actually builds. Left at the vendor's 2023.02.6, a clean
|
||||
checkout configures and builds the old tree.
|
||||
|
||||
The same Makefile carries the vendor's fallback that unpacks
|
||||
tools/board/buildroot/$(BUILDROOT_VER).tar.gz when the tree is missing and
|
||||
copies the vendor defconfigs and package patches into it. Two relaxations
|
||||
keep that fallback usable with 2025.02.8:
|
||||
|
||||
- `*_defconfig` instead of only luckfox_pico_w_defconfig, so any defconfig
|
||||
staged beside the vendor ones is copied too.
|
||||
- `|| true` on the busybox and hcitool patch copies, because
|
||||
0010-drop-2023-buildroot-package-patches.patch empties those directories.
|
||||
|
||||
The WardenOS build does not use the fallback: flare-edge's
|
||||
tools/build-firmware.sh unpacks the pinned, sha256-verified tarball with
|
||||
build/unpack-buildroot.sh before the SDK build runs, so the Makefile's
|
||||
`test -d` finds the tree and skips its own unpack and copies.
|
||||
|
||||
diff --git a/sysdrv/Makefile b/sysdrv/Makefile
|
||||
index 5edb8f875..c173c219e 100644
|
||||
--- a/sysdrv/Makefile
|
||||
+++ b/sysdrv/Makefile
|
||||
@@ -281,7 +281,7 @@ BUSYBOX_DIR := $(SYSDRV_DIR)/source/busybox
|
||||
SYSDRV_BUSYBOX_OBJS_OUTPUT_DIR ?= $(BUSYBOX_DIR)/objs_$(BUSYBOX_CFG)
|
||||
|
||||
BUILDROOT_CFG ?= config_normal
|
||||
-BUILDROOT_VER ?= buildroot-2023.02.6
|
||||
+BUILDROOT_VER ?= buildroot-2025.02.8
|
||||
BUILDROOT_DIR := $(SYSDRV_DIR)/source/buildroot
|
||||
|
||||
CUSTOM_VER ?= custom
|
||||
@@ -599,11 +599,11 @@ buildroot_create:
|
||||
mkdir -p $(BUILDROOT_DIR)
|
||||
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR)
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
|
||||
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/
|
||||
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true
|
||||
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/
|
||||
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
|
||||
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true
|
||||
|
||||
buildroot: prepare
|
||||
@echo -e "$(C_GREEN) ==sysdrv== build buildroot $(C_NORMAL)"
|
||||
@@ -611,11 +611,11 @@ buildroot: prepare
|
||||
mkdir -p $(BUILDROOT_DIR) ;\
|
||||
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR) ;\
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
|
||||
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ ;\
|
||||
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true ;\
|
||||
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/ ;\
|
||||
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
|
||||
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true ;\
|
||||
);
|
||||
|
||||
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) $(BUILDROOT_DEFCONFIG) -C $(BUILDROOT_DIR)/$(BUILDROOT_VER)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
Strip camera and ISP payload from /oem.
|
||||
|
||||
luckfox-buildroot-oem-pre.sh runs over the OEM staging tree before it is
|
||||
packed. flare_minimize() removes what WardenOS never uses because no image
|
||||
sensor is fitted: the ISP tuning files (about 32 MB), the rkaiq 3A library
|
||||
and servers, the camera capture kernel modules, and the camera and MPI
|
||||
sample binaries.
|
||||
|
||||
NPU, video codec, RGA and rockit are kept on purpose. WiFi/BT, touch and the
|
||||
insmod scripts are not touched.
|
||||
|
||||
diff --git a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
index 4187457d4..de2bf74e6 100755
|
||||
--- a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
+++ b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
@@ -46,4 +46,37 @@ function remove_data()
|
||||
#=========================
|
||||
# run
|
||||
#=========================
|
||||
-remove_data
|
||||
\ No newline at end of file
|
||||
+remove_data
|
||||
+#=========================
|
||||
+# flare-edge: drop camera / ISP from /oem
|
||||
+#
|
||||
+# Camera is out of scope for the Warden gateway role (no sensor attached).
|
||||
+# NPU, video codec, RGA and rockit are KEPT deliberately - they are onboard
|
||||
+# hardware we chose to retain. WiFi/BT (aic8800*), touch (goodix) and the
|
||||
+# insmod scripts are never touched here.
|
||||
+#=========================
|
||||
+function flare_minimize()
|
||||
+{
|
||||
+ KO=$RK_PROJECT_PACKAGE_OEM_DIR/usr/ko
|
||||
+
|
||||
+ # ISP tuning data - by far the biggest item in /oem (~32MB)
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/share/iqfiles
|
||||
+
|
||||
+ # ISP 3A library and its servers
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/lib/librkaiq*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_3A_server
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_tool_server
|
||||
+
|
||||
+ # camera capture path: ISP, CIF, MIPI CSI-2 D-PHY, and the sensor drivers
|
||||
+ lf_rm $KO/video_rkisp.ko $KO/video_rkcif.ko
|
||||
+ lf_rm $KO/phy-rockchip-csi2-dphy.ko $KO/phy-rockchip-csi2-dphy-hw.ko
|
||||
+ lf_rm $KO/sc3336.ko $KO/mis5001.ko $KO/gspca_main.ko
|
||||
+
|
||||
+ # camera/ISP demo + sample binaries (keep luckfox_*_test and modetest:
|
||||
+ # those are the GPIO/UART/I2C/SPI/PWM/display bring-up tools we want)
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/sample_*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rk_mpi_*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/simple_*
|
||||
+}
|
||||
+
|
||||
+flare_minimize
|
||||
@@ -0,0 +1,65 @@
|
||||
Remove the generic S50sshd init script.
|
||||
|
||||
overlay-luckfox-buildroot-init is in the 86Panel board's RK_POST_OVERLAY.
|
||||
Its S50sshd runs `ssh-keygen -A` inline. With no hardware RNG and no saved
|
||||
seed on a freshly written rootfs, getrandom() blocks, and rcS is sequential,
|
||||
so every init script sorting after it (S50usbdevice among them) never ran
|
||||
and the board came up with no reachable interface.
|
||||
|
||||
WardenOS gets its SSH server from Buildroot's dropbear package, selected by
|
||||
flare_warden_defconfig, which installs its own init script.
|
||||
|
||||
diff --git a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd b/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
|
||||
deleted file mode 100755
|
||||
index e5b9c4451..000000000
|
||||
--- a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
|
||||
+++ /dev/null
|
||||
@@ -1,48 +0,0 @@
|
||||
-#!/bin/sh
|
||||
-#
|
||||
-# sshd Starts sshd.
|
||||
-#
|
||||
-
|
||||
-# Make sure the ssh-keygen progam exists
|
||||
-[ -f /usr/bin/ssh-keygen ] || exit 0
|
||||
-
|
||||
-umask 077
|
||||
-
|
||||
-start() {
|
||||
- chown root:root /var/empty/
|
||||
- # Create any missing keys
|
||||
- /usr/bin/ssh-keygen -A
|
||||
-
|
||||
- printf "Starting sshd: "
|
||||
- /usr/sbin/sshd
|
||||
- touch /var/lock/sshd
|
||||
- echo "OK"
|
||||
-}
|
||||
-stop() {
|
||||
- printf "Stopping sshd: "
|
||||
- killall sshd
|
||||
- rm -f /var/lock/sshd
|
||||
- echo "OK"
|
||||
-}
|
||||
-restart() {
|
||||
- stop
|
||||
- start
|
||||
-}
|
||||
-
|
||||
-case "$1" in
|
||||
- start)
|
||||
- start
|
||||
- ;;
|
||||
- stop)
|
||||
- stop
|
||||
- ;;
|
||||
- restart|reload)
|
||||
- restart
|
||||
- ;;
|
||||
- *)
|
||||
- echo "Usage: $0 {start|stop|restart}"
|
||||
- exit 1
|
||||
-esac
|
||||
-
|
||||
-exit $?
|
||||
-
|
||||
@@ -0,0 +1,21 @@
|
||||
Build e2fsprogs host helpers with gcc 14.
|
||||
|
||||
The vendor's e2fsprogs 1.43.9 compiles a few helper programs for the build
|
||||
host (BUILD_CC) while cross-building the target tools. That source relies on
|
||||
implicit function declarations and implicit int, which gcc 14 turns into
|
||||
errors, so the host helper build fails. BUILD_CFLAGS demotes those two back
|
||||
to warnings for the host helpers only; the target CFLAGS are unchanged.
|
||||
|
||||
diff --git a/sysdrv/tools/board/e2fsprogs/Makefile b/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
index 14ab9e503..baa541093 100644
|
||||
--- a/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
+++ b/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
@@ -20,7 +20,7 @@ all:
|
||||
mkdir -p $(CURRENT_DIR)/$(PKG_BIN)/usr/; \
|
||||
pushd $(CURRENT_DIR)/$(PKG_NAME)/; \
|
||||
./configure --host=$(SYSDRV_CROSS) --target=$(SYSDRV_CROSS) CFLAGS="$(SYSDRV_CROSS_CFLAGS)" \
|
||||
- LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
|
||||
+ LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" BUILD_CFLAGS="-Wno-implicit-function-declaration -Wno-implicit-int" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
|
||||
--disable-nls \
|
||||
--disable-debugfs --disable-imager --disable-defrag --enable-fsck --enable-resizer \
|
||||
--disable-testio-debug --disable-rpath --enable-symlink-install --disable-fuse2fs; \
|
||||
@@ -0,0 +1,45 @@
|
||||
Treat an unset USB role as client in S50usbdevice.
|
||||
|
||||
0004 gated the gadget build on `role || echo 1`, so a fresh /userdata (no
|
||||
role file) read as router and S50usbdevice exited before composing the
|
||||
gadget. Every other reader (flare-edge S26usbhost, S35iptables,
|
||||
usb-nic-hotplug.sh, wifi-link-watchdog.sh, flared's schema) defaults an
|
||||
unset role to client (0), so S26usbhost put the port in device role with no
|
||||
gadget to bind: a freshly provisioned or factory-reset panel had no usb0
|
||||
recovery link until its second boot (flare-edge#278).
|
||||
|
||||
A separate patch rather than an edit to 0004: tools/build-firmware.sh
|
||||
applies the series idempotently, and on an SDK that already carries 0004
|
||||
and 0008 an edited 0004 neither applies nor reverse-applies, so it would be
|
||||
skipped as inconclusive and the old gate would keep shipping. This one
|
||||
applies on top of either a pristine replay or an already-patched tree.
|
||||
|
||||
diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
index b521af4..fd8b693 100755
|
||||
--- a/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
@@ -6,12 +6,19 @@
|
||||
# Load default env variables from profiles
|
||||
. /etc/profile
|
||||
|
||||
-# flare-edge: the OTG port is a USB HOST in router (and the unset-role default),
|
||||
-# so building a gadget here is pointless AND harmful — the dwc3 "failed to add
|
||||
+# flare-edge: only build the gadget in client role. A router's OTG port is a
|
||||
+# USB HOST, where a gadget is pointless AND harmful: the dwc3 "failed to add
|
||||
# gadget" + the usb2-phy "illegal mode" it triggers race with the USB-Ethernet
|
||||
-# host enumeration and intermittently kill eth1 at boot. Only run in client role;
|
||||
-# S26usbhost re-invokes this explicitly when switching to client. (unset -> router)
|
||||
-[ "$(cat /userdata/warden/role 2>/dev/null || echo 1)" = "1" ] && exit 0
|
||||
+# host enumeration and intermittently kill eth1 at boot. S26usbhost re-invokes
|
||||
+# this explicitly when switching to client.
|
||||
+#
|
||||
+# An UNSET role is client (0), the fresh-install default every other reader
|
||||
+# uses (S26usbhost, S35iptables, usb-nic-hotplug.sh, wifi-link-watchdog.sh,
|
||||
+# flared's schema). This gate used to read unset as router, so a fresh store
|
||||
+# set the port to device role with no gadget to bind and came up with no usb0
|
||||
+# until a second boot (flare-edge#278). flare-edge's
|
||||
+# tests/guards/run-role-default-tests.sh pins this line to the other readers.
|
||||
+[ "$(cat /userdata/warden/role 2>/dev/null || echo 0)" = "1" ] && exit 0
|
||||
|
||||
UMS_EN=off
|
||||
ADB_EN=on
|
||||
@@ -0,0 +1,10 @@
|
||||
# WireGuard, built in rather than as a module.
|
||||
#
|
||||
# =y not =m deliberately: modules live on the oem partition and must be
|
||||
# reflashed in lockstep with the kernel, and this one is ~40KB. Paying that in
|
||||
# boot.img is cheaper than another matched-pair failure mode.
|
||||
#
|
||||
# Everything WireGuard needs it "select"s for itself (NET_UDP_TUNNEL,
|
||||
# DST_CACHE, CRYPTO_LIB_CURVE25519, CRYPTO_LIB_CHACHA20POLY1305), so unlike the
|
||||
# USB-Ethernet fragment there is no menu gate to open first. Verify anyway.
|
||||
CONFIG_WIREGUARD=y
|
||||
@@ -0,0 +1,20 @@
|
||||
# USB host + USB-Ethernet class drivers (flare-edge).
|
||||
#
|
||||
# The first symbol is the MENU GATE. Every driver below lives inside the
|
||||
# USB_NET_DRIVERS menuconfig, so without it kconfig discards the lot in
|
||||
# silence -- no warning, and not even the usual "not in final .config" from
|
||||
# merge_config.sh.
|
||||
#
|
||||
# Do not begin a comment line here with a hash followed by CONFIG_. That is
|
||||
# exactly the "is not set" syntax, so merge_config.sh parses the prose as a
|
||||
# directive and reports it as a redefinition of the symbol it names.
|
||||
CONFIG_USB_NET_DRIVERS=y
|
||||
CONFIG_USB_USBNET=y
|
||||
CONFIG_USB_NET_CDCETHER=y
|
||||
CONFIG_USB_NET_CDC_NCM=y
|
||||
CONFIG_USB_NET_CDC_EEM=y
|
||||
CONFIG_USB_RTL8152=y
|
||||
CONFIG_USB_NET_AX8817X=y
|
||||
CONFIG_USB_NET_AX88179_178A=y
|
||||
CONFIG_USB_NET_SMSC95XX=y
|
||||
CONFIG_USB_NET_MCS7830=y
|
||||
@@ -85,6 +85,11 @@ does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
|
||||
the executable bit, so the checked-out source file's own mode depends on the
|
||||
checking-out umask and cannot be trusted to arrive non-world-readable.
|
||||
|
||||
A flow seed may contain `qemu-flow-setup.sh`. Stage-2 init runs it inside the
|
||||
disposable guest after mounting userdata and before starting daemons or the
|
||||
UI. A nonzero exit stops the boot. Use it only for test devices and commands
|
||||
that the virt machine does not provide.
|
||||
|
||||
## Scenarios
|
||||
|
||||
All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
|
||||
+25
-2
@@ -106,8 +106,9 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
# on the first bad entry the same way --state fails closed above, rather
|
||||
# than copy it into the image and let it surface as a confusing read
|
||||
# later. Only a top-level plain file matches "one file per settings key"
|
||||
# (the Env note above) -- seed-fixtures.py never nests a subdirectory, and
|
||||
# neither should anything else pointed at this hook.
|
||||
# (the Env note above), with one exception, profiles/rs485/<slug>.w485p
|
||||
# (installed device profiles, checked below); seed-fixtures.py nests
|
||||
# nothing else, and neither should anything else pointed at this hook.
|
||||
#
|
||||
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
|
||||
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
|
||||
@@ -126,6 +127,28 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The one directory allowed: installed RS485 device profiles, as
|
||||
# warden-modbus keeps them (/userdata/warden/profiles/rs485/<slug>.w485p),
|
||||
# so a flow can boot with a profile already installed (flare-edge#387).
|
||||
# Nothing in it but plain <slug>.w485p files directly under rs485/.
|
||||
if [ "$base" = profiles ] && [ -d "$entry" ]; then
|
||||
while IFS= read -r -d '' p; do
|
||||
rel="${p#"$entry"/}"
|
||||
if [ "$rel" = rs485 ] && [ -d "$p" ] && [ ! -L "$p" ]; then continue; fi
|
||||
case "$rel" in
|
||||
rs485/*/*) ok=0 ;;
|
||||
rs485/*.w485p) ok=1 ;;
|
||||
*) ok=0 ;;
|
||||
esac
|
||||
name="${rel#rs485/}"
|
||||
case "${name%.w485p}" in ''|*[!a-z0-9-]*) ok=0 ;; esac
|
||||
if [ "$ok" -ne 1 ] || [ -L "$p" ] || [ ! -f "$p" ]; then
|
||||
echo "FATAL: SEED_DIR entry 'profiles/$rel' is not a plain profiles/rs485/<slug>.w485p file" >&2
|
||||
exit 1
|
||||
fi
|
||||
done < <(find "$entry" -mindepth 1 -print0)
|
||||
continue
|
||||
fi
|
||||
[ -f "$entry" ] || {
|
||||
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
|
||||
@@ -41,3 +41,24 @@ warden_slot() {
|
||||
esac
|
||||
echo "$slot"
|
||||
}
|
||||
|
||||
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
|
||||
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
|
||||
# handler for. A panel's busybox init handles them; without this the rig
|
||||
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
|
||||
# the kernel still prints its orderly "reboot: Restarting system" line.
|
||||
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
|
||||
warden_trap_power_signals() {
|
||||
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
|
||||
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
|
||||
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
|
||||
}
|
||||
|
||||
# Idle forever in a way a trapped signal interrupts at once: a foreground
|
||||
# `sleep` would hold the trap until it returned, up to an hour later.
|
||||
warden_idle_forever() {
|
||||
while :; do
|
||||
sleep 3600 &
|
||||
wait $!
|
||||
done
|
||||
}
|
||||
|
||||
+18
-6
@@ -57,6 +57,16 @@ mount_fatal userdata /userdata
|
||||
mount_fatal "oem${slot}" /oem
|
||||
mkdir -p /userdata/warden
|
||||
|
||||
# A flow may seed an opt-in guest fixture before the UI and payload daemons
|
||||
# start. The file lives only in this disposable QEMU disk image. Fail the
|
||||
# boot if setup fails so a flow cannot pass against an unprepared guest.
|
||||
if [ -f /userdata/warden/qemu-flow-setup.sh ]; then
|
||||
if ! /bin/busybox sh /userdata/warden/qemu-flow-setup.sh; then
|
||||
echo "FATAL: QEMU flow setup failed"
|
||||
poweroff -f
|
||||
fi
|
||||
fi
|
||||
|
||||
# RS485: warden-modbus hardcodes /dev/ttyS4 at compile time; alias it to the
|
||||
# VM's RS485 pci-serial UART (needs the virt.fragment kernel). run.sh lists
|
||||
# the control channel's port first when there is one (warden.ctl on the
|
||||
@@ -105,14 +115,14 @@ if grep -qw warden.fwapply /proc/cmdline; then
|
||||
echo "init: OTA APPLY ENABLED (warden.fwapply)"
|
||||
fi
|
||||
# The same daemons the panel's SysV scripts start, in their S-number order
|
||||
# (S92 ai, S93 automation, S94 modbus, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared), each with no arguments and no environment, exactly
|
||||
# as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (S21 modbus, S22 automation, S92 ai, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared; flare-edge#348), each with no arguments and no
|
||||
# environment, exactly as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (warden-ai wants the NPU) exits into its log and the UI shows the same
|
||||
# "not running" it would show on a panel whose daemon died; that is the
|
||||
# panel's behaviour, not a rig substitute for it. warden-watchdog stays out:
|
||||
# it and a payload flared do not mix (README).
|
||||
for d in /usr/bin/warden-ai /usr/bin/warden-automation /usr/bin/warden-modbus \
|
||||
for d in /usr/bin/warden-modbus /usr/bin/warden-automation /usr/bin/warden-ai \
|
||||
/usr/bin/warden-mikrotik /usr/bin/warden-asic /usr/bin/warden-starlink \
|
||||
/usr/bin/warden-stratum /usr/bin/warden-flared; do
|
||||
if [ -x "$d" ]; then
|
||||
@@ -239,5 +249,7 @@ if grep -qw warden.shell /proc/cmdline; then
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside.
|
||||
while :; do sleep 3600; done
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
|
||||
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
|
||||
warden_trap_power_signals
|
||||
warden_idle_forever
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# The rig's /sbin/init starts the Warden daemons in the panel's S-number
|
||||
# order (flare-edge#348): warden-modbus (S21modbus) before warden-automation
|
||||
# (S22automation), since an automation's device command goes through
|
||||
# warden-modbus, and both before the other app backends and flared. Reads
|
||||
# the daemon list from the init script's own start loop.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
FAIL=0
|
||||
|
||||
order=$(awk '
|
||||
/^for d in \/usr\/bin\/warden-/ { on = 1 }
|
||||
on {
|
||||
last = ($0 ~ /; do$/)
|
||||
for (i = 1; i <= NF; i++) if ($i ~ /^\/usr\/bin\/warden-/) { w = $i; sub(/;$/, "", w); print w }
|
||||
if (last) exit
|
||||
}' "$INIT")
|
||||
|
||||
want="/usr/bin/warden-modbus
|
||||
/usr/bin/warden-automation
|
||||
/usr/bin/warden-ai
|
||||
/usr/bin/warden-mikrotik
|
||||
/usr/bin/warden-asic
|
||||
/usr/bin/warden-starlink
|
||||
/usr/bin/warden-stratum
|
||||
/usr/bin/warden-flared"
|
||||
|
||||
if [ "$order" = "$want" ]; then
|
||||
echo "PASS: rig init starts the daemons in the panel's S-number order"
|
||||
else
|
||||
echo "FAIL: rig init daemon order differs from the panel's S-number order"
|
||||
diff <(printf '%s\n' "$want") <(printf '%s\n' "$order")
|
||||
FAIL=1
|
||||
fi
|
||||
exit "$FAIL"
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
|
||||
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
|
||||
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
|
||||
# commands, idles it the way /sbin/init does, sends each signal and requires
|
||||
# the matching action within two seconds.
|
||||
set -uo pipefail
|
||||
# Job control: each case's shell leads its own process group, so cleanup can
|
||||
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
|
||||
# script's output pipe open for an hour when a case fails.
|
||||
set -m
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
|
||||
run_case() { # run_case <signal> <expected marker> <label>
|
||||
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
|
||||
: > "$out"
|
||||
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
|
||||
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
|
||||
"$SH" -c ". '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
local pid=$!
|
||||
sleep 0.5
|
||||
kill -"$sig" "$pid"
|
||||
local n=0
|
||||
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
if grep -qx "$want" "$out"; then
|
||||
echo "[PASS] $label"
|
||||
else
|
||||
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
|
||||
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
|
||||
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
|
||||
|
||||
exit "$FAIL"
|
||||
+37
-7
@@ -244,6 +244,7 @@ def do_observed_tap(ctx, ax, ay):
|
||||
return True
|
||||
|
||||
send_events(ctx.s, ctx.f, [abs_ev("x", ax), abs_ev("y", ay), btn_ev(True)])
|
||||
ctx.tap_sent = True
|
||||
pressed = False
|
||||
try:
|
||||
pressed = wait_input_count(ctx, "presses", before.get("presses"))
|
||||
@@ -728,6 +729,10 @@ class Ctx:
|
||||
self.rs485_control = rs485_control
|
||||
self.outdir = outdir
|
||||
self.script_path = script_path
|
||||
# Set by drive() before each step: the command after this one, and the
|
||||
# console size when the step before this one began (flare-edge#233).
|
||||
self.next_cmd = None
|
||||
self.prev_step_console = 0
|
||||
|
||||
def need_ctl(self, lineno, cmd):
|
||||
if self.ctl is None:
|
||||
@@ -786,7 +791,19 @@ def verb_shot(ctx, lineno, cmd, args, line):
|
||||
|
||||
def verb_tap(ctx, lineno, cmd, args, line):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
ctx.tap_sent = False
|
||||
try:
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
except (RuntimeError, OSError):
|
||||
# A tap whose correct outcome is a reboot (the next step is
|
||||
# expect_reboot) can lose the control channel while its press/release
|
||||
# counts are still being polled: init tears warden-ui down first. Once
|
||||
# the press went out that is the tap working, not failing; the reboot
|
||||
# step judges the outcome (flare-edge#233). Anywhere else, or before
|
||||
# anything was sent, it stays a fatal step.
|
||||
if ctx.next_cmd == "expect_reboot" and ctx.tap_sent:
|
||||
return "ok", "tap sent; the control channel closed as the guest went down"
|
||||
raise
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
|
||||
@@ -829,10 +846,11 @@ def verb_expect_reboot(ctx, lineno, cmd, args, line):
|
||||
timeout = float(args[0])
|
||||
if not ctx.console_path:
|
||||
sys.exit(f"FATAL: {ctx.script_path}:{lineno}: '{cmd}' needs --console")
|
||||
try:
|
||||
start = os.path.getsize(ctx.console_path)
|
||||
except OSError:
|
||||
start = 0
|
||||
# From the start of the step BEFORE this one, not this one: the action
|
||||
# that reboots (a tap, usually) runs in that step, and a fast guest can
|
||||
# print its restart line before expect_reboot even begins (flare-edge#233).
|
||||
# A line from any earlier step still does not count.
|
||||
start = ctx.prev_step_console
|
||||
deadline = time.monotonic() + timeout
|
||||
|
||||
def console_since_start():
|
||||
@@ -1182,12 +1200,24 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
|
||||
console_path)
|
||||
console = ConsoleWatch(console_path)
|
||||
|
||||
def console_size():
|
||||
try:
|
||||
return os.path.getsize(console_path) if console_path else 0
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
steps = []
|
||||
for lineno, raw in enumerate(lines, 1):
|
||||
line = raw.split("#", 1)[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
if line:
|
||||
steps.append((lineno, line))
|
||||
step_console = console_size()
|
||||
|
||||
for i, (lineno, line) in enumerate(steps):
|
||||
parts = line.split()
|
||||
cmd, args = parts[0], parts[1:]
|
||||
ctx.next_cmd = steps[i + 1][1].split()[0] if i + 1 < len(steps) else None
|
||||
ctx.prev_step_console, step_console = step_console, console_size()
|
||||
|
||||
handler = VERBS.get(cmd)
|
||||
if handler is None:
|
||||
|
||||
@@ -186,5 +186,42 @@ else
|
||||
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 7: an installed RS485 profile, profiles/rs485/<slug>.w485p,
|
||||
# seeds into userdata/warden/profiles/rs485/ (flare-edge#387) ---
|
||||
SEED7="$SCRATCH/seed7"
|
||||
mkdir -p "$SEED7/profiles/rs485"
|
||||
printf '{"w485p_version":1}\n' > "$SEED7/profiles/rs485/acme-gen-ctl.w485p"
|
||||
OUT7="$SCRATCH/out7"
|
||||
if OUT="$OUT7" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED7" \
|
||||
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage7.log" 2>&1; then
|
||||
UIMG7="$SCRATCH/userdata7.img"
|
||||
extract_userdata "$OUT7/disk.img" "$UIMG7"
|
||||
prof="$(debugfs -R "cat /warden/profiles/rs485/acme-gen-ctl.w485p" "$UIMG7" 2>/dev/null)"
|
||||
if [ "$prof" = '{"w485p_version":1}' ]; then
|
||||
pass "SEED_DIR: an installed profile seeds into profiles/rs485/"
|
||||
else
|
||||
fail "SEED_DIR: profiles/rs485/acme-gen-ctl.w485p = '$prof'"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh rejected a profiles/rs485/<slug>.w485p seed (see $SCRATCH/mkimage7.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 8: anything else under profiles/ fails closed ---
|
||||
for bad in "rs485/x.json" "rs485/Bad.w485p" "other/x.w485p" "rs485/sub/x.w485p" "rs485/link.w485p"; do
|
||||
SEED8="$SCRATCH/seed8"
|
||||
rm -rf "$SEED8"
|
||||
mkdir -p "$SEED8/profiles/$(dirname "$bad")"
|
||||
if [ "$bad" = rs485/link.w485p ]; then ln -s /etc/passwd "$SEED8/profiles/$bad"; else printf 'x\n' > "$SEED8/profiles/$bad"; fi
|
||||
OUT8="$SCRATCH/out8"
|
||||
rm -rf "$OUT8"
|
||||
err8="$(OUT="$OUT8" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED8" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc8=$?
|
||||
if [ "$rc8" -ne 0 ] && printf '%s' "$err8" | grep -qF "is not a plain profiles/rs485/<slug>.w485p file"; then
|
||||
pass "SEED_DIR: profiles/$bad fails closed"
|
||||
else
|
||||
fail "SEED_DIR: profiles/$bad gave rc=$rc8, stderr='$err8'"
|
||||
fi
|
||||
done
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -924,6 +924,68 @@ class ExpectReboot(unittest.TestCase):
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class RebootTapRace(unittest.TestCase):
|
||||
"""flare-edge#233: a tap whose outcome is a reboot races init tearing
|
||||
warden-ui down. The control channel can close while the tap's press and
|
||||
release counts are still being polled, and the guest can print its restart
|
||||
line before expect_reboot starts. Both are the tap working."""
|
||||
|
||||
CONSOLE_LINE = b"init: reboot requested\n[ 17.8] reboot: Restarting system\n"
|
||||
|
||||
def run_race(self, script, console_before=b""):
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(console_before)
|
||||
line = self.CONSOLE_LINE
|
||||
|
||||
class RebootingCtl(FakeCtl):
|
||||
"""First stats answers (the tap's baseline); the next one, the
|
||||
press poll, finds the guest already going down: the restart line
|
||||
is on the console and the channel is closed."""
|
||||
def send(self, cmd):
|
||||
if cmd == "stats" and self.stats_calls >= 1:
|
||||
with open(console, "ab") as fh:
|
||||
fh.write(line)
|
||||
raise RuntimeError("control channel closed")
|
||||
return super().send(cmd)
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
return run_script(script, ctl_cls=RebootingCtl, rpc_fn=rpc, console_path=console)
|
||||
|
||||
def test_reboot_tap_losing_the_channel_then_expect_reboot_passes(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nexpect_reboot 2\n")
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"], rows)
|
||||
self.assertIn("control channel closed", rows[0]["detail"])
|
||||
|
||||
def test_the_same_channel_loss_before_any_other_step_is_still_fatal(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nsleep 0\n")
|
||||
self.assertEqual(rows[0]["status"], "fatal", rows)
|
||||
|
||||
def test_a_restart_line_from_two_steps_back_still_does_not_count(self):
|
||||
# The restart line is already on the console before the script; the
|
||||
# reboot step may look back one step, not to the start of the run.
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(b"reboot: Restarting system\n")
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
rc, by, rows = run_script("sleep 0\nexpect_reboot 1\n", rpc_fn=rpc,
|
||||
console_path=console)
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class FullscreenToggleTracksRealState(unittest.TestCase):
|
||||
"""qemu/tests/scripts/fullscreen-toggle-tracks-real-state.txt, offline:
|
||||
`home` clears the dashboard's real fullscreen state directly, and a
|
||||
|
||||
@@ -37,6 +37,7 @@ scripts=(
|
||||
"qemu/tests/stage-rootfs-perms.sh"
|
||||
"tests/fetch-vendor/run-fetch-vendor-tests.sh"
|
||||
"tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh"
|
||||
"tests/unpack-buildroot/run-unpack-buildroot-tests.sh"
|
||||
"tests/mk-bootimg/run-boot-img-validate-tests.sh"
|
||||
"tests/mk-bootimg/run-help-tests.sh"
|
||||
"tests/mk-bootimg/run-ci-wiring-tests.sh"
|
||||
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression tests for build/unpack-buildroot.sh (blueflare/bfe-core1106-sdk#4).
|
||||
#
|
||||
# A clean vendor checkout plus luckfox-sdk-patches/ could not build WardenOS
|
||||
# because nothing put buildroot-2025.02.8 where the SDK builds it. The unpack
|
||||
# script is now the thing that does, and the persistent CI SDK depends on it
|
||||
# leaving an existing tree alone. These cases pin both halves: a fresh SDK
|
||||
# gets a complete tree, an existing tree is never touched or re-fetched, and
|
||||
# every refusal (unpatched selectors, a bad tarball, a half-present tree, a
|
||||
# failed fetch) leaves no tree and no scratch directory behind.
|
||||
#
|
||||
# Runs the real script, copied beside a stub fetch-buildroot-tarball.sh that
|
||||
# copies a local fixture tarball instead of downloading. No network, no SDK.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/unpack-buildroot.sh"
|
||||
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
|
||||
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
TMP="$(mktemp -d)" || { echo "FAIL: mktemp -d failed"; exit 1; }
|
||||
[ -d "$TMP" ] || { echo "FAIL: mktemp -d failed"; exit 1; }
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
VER=2025.02.8
|
||||
|
||||
# Fixture tarballs: a minimal Buildroot-shaped tree, and one without Makefile.
|
||||
mk_tarball() { # mk_tarball <out.tar.xz> <with-makefile:0|1>
|
||||
local out="$1" mf="$2" src
|
||||
src="$(mktemp -d "$TMP/src.XXXXXX")"
|
||||
mkdir -p "$src/buildroot-$VER/configs" "$src/buildroot-$VER/package/busybox"
|
||||
printf 'CONFIG\n' > "$src/buildroot-$VER/package/busybox/busybox.config"
|
||||
[ "$mf" = 1 ] && printf 'all:\n' > "$src/buildroot-$VER/Makefile"
|
||||
tar -cJf "$out" -C "$src" "buildroot-$VER"
|
||||
}
|
||||
mk_tarball "$TMP/good.tar.xz" 1
|
||||
mk_tarball "$TMP/nomakefile.tar.xz" 0
|
||||
|
||||
# setup <case> <tarball-or-FAIL> -> fixture dir holding build/ and sdk/
|
||||
setup() {
|
||||
local dir="$TMP/$1" src="$2"
|
||||
mkdir -p "$dir/build" "$dir/sdk/project" "$dir/sdk/sysdrv/source/buildroot"
|
||||
cp "$SCRIPT" "$dir/build/unpack-buildroot.sh"
|
||||
{
|
||||
echo '#!/usr/bin/env bash'
|
||||
echo "BRVER=$VER"
|
||||
echo "echo fetch-called >> \"$dir/fetch-calls\""
|
||||
if [ "$src" = FAIL ]; then echo 'exit 1'; else echo "cp \"$src\" \"\$1\""; fi
|
||||
} > "$dir/build/fetch-buildroot-tarball.sh"
|
||||
# shellcheck disable=SC2016 # build.sh carries the literal text
|
||||
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-%s\n' "$VER" \
|
||||
> "$dir/sdk/project/build.sh"
|
||||
printf 'BUILDROOT_VER ?= buildroot-%s\n' "$VER" > "$dir/sdk/sysdrv/Makefile"
|
||||
printf '%s' "$dir"
|
||||
}
|
||||
|
||||
run() { # run <dir> -> $OUT, $RC
|
||||
OUT="$(bash "$1/build/unpack-buildroot.sh" "$1/sdk" 2>&1)"; RC=$?
|
||||
}
|
||||
tree() { printf '%s' "$1/sdk/sysdrv/source/buildroot/buildroot-$VER"; }
|
||||
fetches() { [ -f "$1/fetch-calls" ] && wc -l < "$1/fetch-calls" || echo 0; }
|
||||
no_scratch() { ! compgen -G "$1/sdk/sysdrv/source/buildroot/.unpack-buildroot.*" >/dev/null; }
|
||||
|
||||
# A. Fresh SDK: fetched once, unpacked to the selected path, no scratch left.
|
||||
d="$(setup fresh "$TMP/good.tar.xz")"; run "$d"
|
||||
if [ "$RC" -eq 0 ] && [ -f "$(tree "$d")/Makefile" ] && [ -f "$(tree "$d")/package/busybox/busybox.config" ] \
|
||||
&& [ "$(fetches "$d")" -eq 1 ] && no_scratch "$d"; then
|
||||
ok "fresh SDK: tree unpacked, one fetch, no scratch left"
|
||||
else
|
||||
bad "fresh SDK: tree unpacked, one fetch, no scratch left (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# B. Rerun on that SDK: already present, no second fetch, content untouched.
|
||||
printf 'LOCAL\n' > "$(tree "$d")/package/busybox/busybox.config"
|
||||
run "$d"
|
||||
if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q 'tree already present' \
|
||||
&& [ "$(fetches "$d")" -eq 1 ] && grep -qx LOCAL "$(tree "$d")/package/busybox/busybox.config"; then
|
||||
ok "existing tree: left alone, not re-fetched"
|
||||
else
|
||||
bad "existing tree: left alone, not re-fetched (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# C. project/build.sh still selects the vendor tree: refuse, fetch nothing.
|
||||
d="$(setup unpatched-build "$TMP/good.tar.xz")"
|
||||
# shellcheck disable=SC2016 # build.sh carries the literal text
|
||||
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6\n' > "$d/sdk/project/build.sh"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'project/build.sh selects' \
|
||||
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
|
||||
ok "unpatched project/build.sh: refused before fetching"
|
||||
else
|
||||
bad "unpatched project/build.sh: refused before fetching (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# D. sysdrv/Makefile still selects the vendor tree: refuse, fetch nothing.
|
||||
d="$(setup unpatched-make "$TMP/good.tar.xz")"
|
||||
printf 'BUILDROOT_VER ?= buildroot-2023.02.6\n' > "$d/sdk/sysdrv/Makefile"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'sysdrv/Makefile selects' \
|
||||
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
|
||||
ok "unpatched sysdrv/Makefile: refused before fetching"
|
||||
else
|
||||
bad "unpatched sysdrv/Makefile: refused before fetching (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# E. Tarball without a Buildroot Makefile: refuse, no tree, no scratch.
|
||||
d="$(setup bad-tarball "$TMP/nomakefile.tar.xz")"; run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'did not contain' \
|
||||
&& [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
|
||||
ok "tarball without Makefile: refused, nothing left behind"
|
||||
else
|
||||
bad "tarball without Makefile: refused, nothing left behind (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# F. A half-present tree (an interrupted hand unpack): refuse, keep it as is.
|
||||
d="$(setup half-tree "$TMP/good.tar.xz")"
|
||||
mkdir -p "$(tree "$d")/output"; printf 'keep\n' > "$(tree "$d")/output/marker"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'not a complete Buildroot tree' \
|
||||
&& [ -f "$(tree "$d")/output/marker" ] && [ "$(fetches "$d")" -eq 0 ]; then
|
||||
ok "half-present tree: refused and left untouched"
|
||||
else
|
||||
bad "half-present tree: refused and left untouched (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# G. Fetch fails (network down, sha256 mismatch): nonzero, no tree.
|
||||
d="$(setup fetch-fails FAIL)"; run "$d"
|
||||
if [ "$RC" -ne 0 ] && [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
|
||||
ok "failed fetch: nonzero, no tree"
|
||||
else
|
||||
bad "failed fetch: nonzero, no tree (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "ALL UNPACK-BUILDROOT TESTS PASSED"; else echo "UNPACK-BUILDROOT TESTS FAILED"; fi
|
||||
exit "$FAIL"
|
||||
Reference in New Issue
Block a user