Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61505ebadf |
@@ -17,7 +17,7 @@
|
||||
<text x="43.5" y="14">lines of code</text>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||
<text x="110.5" y="15" fill="#010101" fill-opacity=".3">10791</text>
|
||||
<text x="109.5" y="14">10791</text>
|
||||
<text x="110.5" y="15" fill="#010101" fill-opacity=".3">12562</text>
|
||||
<text x="109.5" y="14">12562</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -110,77 +110,7 @@ jobs:
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq shellcheck
|
||||
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
|
||||
- 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
|
||||
# push otherwise.
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: /var/cache/apt/archives
|
||||
key: apt-archives-python3-pil-${{ runner.os }}
|
||||
- name: ui-drive driver and image tools (offline)
|
||||
# qmp.py's drive() with QMP and the control channel faked, plus
|
||||
# imgtools' self-test: the per-step ok/fail/fatal contract and the
|
||||
# region reference math, no VM needed.
|
||||
run: |
|
||||
sudo apt-get install -y -qq python3-pil
|
||||
python3 qemu/tests/imgtools.py selftest
|
||||
python3 qemu/tests/test_qmp_drive.py
|
||||
- name: imgtools bench (smoke, printed for trend-watching)
|
||||
# Same pattern as the sim/rs485-bridge bench job above: no stored
|
||||
# baseline yet, just a number in the log so a phash/structural
|
||||
# regression (DCT size, downscale filter, occupancy thresholds)
|
||||
# is visible instead of only showing up as an unexplained slower
|
||||
# flow run later.
|
||||
run: python3 qemu/tests/imgtools.py bench
|
||||
- name: mk-bootimg probe regression tests
|
||||
# Guards issue #17 (mkimage's non-zero exit sinking the probe's grep
|
||||
# pipeline under set -o pipefail) on every push/PR, not only on the
|
||||
# next workflow_dispatch that happens to exercise mk-bootimg.sh for
|
||||
# real via kernel-build.
|
||||
run: bash tests/mk-bootimg/run-probe-tests.sh
|
||||
- name: run.sh argv ordering regression test
|
||||
# Pins the CTL-before-RS485 pci-serial argv order that
|
||||
# rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on: a swap here
|
||||
# reproduces run.sh:131-133's own incident, Modbus frames landing
|
||||
# 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: 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
|
||||
# reads it back with debugfs, no VM needed.
|
||||
run: bash qemu/tests/seed-dir.sh
|
||||
- name: qemu_stage_rootfs permission regression test
|
||||
# Git tracks only the executable bit, so a fresh checkout can land
|
||||
# the source etc/shadow world-readable under a permissive umask;
|
||||
# this pins the staged copy at 0600 regardless of the source mode.
|
||||
run: bash qemu/tests/stage-rootfs-perms.sh
|
||||
- name: fetch-vendor regression tests
|
||||
# --check state machine (MISSING/OK/DRIFTED), --help, and the
|
||||
# clone stall guard, against local throwaway repos: no network.
|
||||
run: bash tests/fetch-vendor/run-fetch-vendor-tests.sh
|
||||
- name: fetch-buildroot-tarball regression tests
|
||||
# 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: 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
|
||||
# data-position %512 checks and the embedded-data-FIT check.
|
||||
run: bash tests/mk-bootimg/run-boot-img-validate-tests.sh
|
||||
- name: mk-bootimg --help regression test
|
||||
# Pins --help against its own header comment so a hardcoded line
|
||||
# range can't silently start printing code again the next time the
|
||||
# header grows or shrinks (the bug fetch-vendor.sh's --help had).
|
||||
run: bash tests/mk-bootimg/run-help-tests.sh
|
||||
- name: qemu-tools CI wiring regression test
|
||||
# Catches a regression test shipping in this job without this job
|
||||
# ever calling it -- the exact gap run-probe-tests.sh sat in before
|
||||
# the step above wired it in.
|
||||
run: bash tests/mk-bootimg/run-ci-wiring-tests.sh
|
||||
qemu/rootfs/sbin/init qemu/rootfs/init
|
||||
- name: cache pinned busybox
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
|
||||
@@ -52,8 +52,7 @@ scenario tests (portal, OTA apply, display + touch, watchdog).
|
||||
| Directory | Contents |
|
||||
|---|---|
|
||||
| `patches/` | the RV1106 forward-port onto pristine linux-6.18.46, subsystem-split |
|
||||
| `luckfox-sdk-patches/` | the delta against the **legacy** vendor Luckfox SDK (U-Boot 2017.09, optionally the vendor 5.10.160 kernel, wifi driver, board build, buildroot) -- moved from `blueflare/flare-edge`'s `sdk-patches/` on 2026-09-15; unrelated to `patches/` above |
|
||||
| `build/` | hermetic kernel build: pinned fetch -> apply patches -> `zImage` + dtb; `vendor.manifest` pins the third-party trees this platform builds against (LVGL, the vendor RV1106 SDK) to exact commits, and `fetch-vendor.sh` obtains and verifies them |
|
||||
| `build/` | hermetic kernel build: pinned fetch -> apply patches -> `zImage` + dtb |
|
||||
| `qemu/` | device simulator: QEMU `-M virt` boots the real kernel and real userspace |
|
||||
| `sim/` | register-level hardware models (Rust): membus, HPMCU, CRU, Modbus, RGA, NPU |
|
||||
| `drivers/` | hardened hardware-facing drivers: HAL seams, test harnesses |
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
695360d10d038122f11c76c35f3bd10561d949af2bc90468659f4ec5ee6687cc buildroot-2025.02.8.tar.xz
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fetch (with retries) and sha256-verify the pristine Buildroot tarball into $1.
|
||||
#
|
||||
# WHY THIS EXISTS. The firmware builds against
|
||||
# sysdrv/source/buildroot/buildroot-2025.02.8 inside the vendor SDK. That tree
|
||||
# is NOT in the vendor checkout -- the SDK ships 2023.02.6 -- and nothing
|
||||
# recorded where it came from, so the build was reproducible only on the one
|
||||
# machine that happened to have the directory (flare-edge#135). Buildroot signs
|
||||
# its releases with GPG rather than publishing a .sha256, so the pin here was
|
||||
# computed from the downloaded tarball and is what this script verifies against.
|
||||
#
|
||||
# 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).
|
||||
#
|
||||
# Usage: fetch-buildroot-tarball.sh <destination-path>
|
||||
set -euo pipefail
|
||||
|
||||
BRVER=2025.02.8
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
|
||||
SHA_FILE="$HERE/buildroot-$BRVER.tar.xz.sha256"
|
||||
URL="https://buildroot.org/downloads/buildroot-$BRVER.tar.xz"
|
||||
|
||||
TB="${1:?usage: fetch-buildroot-tarball.sh <destination-path>}"
|
||||
|
||||
[ -f "$SHA_FILE" ] || {
|
||||
echo "FATAL: no pinned sha256 for buildroot-$BRVER (expected $SHA_FILE):" >&2
|
||||
echo " refusing an unverified tarball" >&2
|
||||
exit 1
|
||||
}
|
||||
WANT="$(awk '{print $1; exit}' "$SHA_FILE")"
|
||||
|
||||
verify() {
|
||||
[ -f "$TB" ] || return 1
|
||||
local got
|
||||
got="$(sha256sum "$TB" | awk '{print $1}')"
|
||||
[ "$got" = "$WANT" ]
|
||||
}
|
||||
|
||||
if verify; then
|
||||
echo "buildroot-$BRVER: already present and verified"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for attempt in 1 2 3; do
|
||||
echo "== fetching buildroot-$BRVER (attempt $attempt)"
|
||||
# --retry only re-fires once curl decides a transfer has failed; a connection
|
||||
# that opens and then stalls (blackholed route, hung proxy) never reaches
|
||||
# that decision and would otherwise block forever. --connect-timeout bounds
|
||||
# the handshake, --max-time bounds the whole request.
|
||||
if curl -fsSL --retry 2 --connect-timeout 20 --max-time 120 -o "$TB" "$URL" && verify; then
|
||||
echo "buildroot-$BRVER: sha256 verified"
|
||||
exit 0
|
||||
fi
|
||||
rm -f "$TB"
|
||||
done
|
||||
|
||||
echo "FATAL: could not fetch a buildroot-$BRVER tarball matching $WANT" >&2
|
||||
exit 1
|
||||
@@ -1,105 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Obtain (or verify) the third-party trees pinned in build/vendor.manifest.
|
||||
#
|
||||
# These trees are shared between worktrees and are far too large to live in git
|
||||
# (the vendor SDK alone is 21 GB, and its host tools bake in absolute paths, so
|
||||
# it must sit at ONE stable path anyway). What belongs in git is the answer to
|
||||
# "which commit" -- that is the manifest, and this is the only thing that reads
|
||||
# it.
|
||||
#
|
||||
# fetch-vendor.sh --check [DIR] report each tree's state; non-zero if any
|
||||
# is missing or off its pin (default: check)
|
||||
# fetch-vendor.sh --fetch [DIR] clone what is missing, then check
|
||||
#
|
||||
# DIR defaults to $WARDEN_VENDOR_DIR, else the conventional shared location
|
||||
# alongside a flare-edge checkout. Nothing is ever moved or reset: a tree that
|
||||
# has drifted is REPORTED, because a local change to a vendor tree is usually
|
||||
# someone's debugging session, not something to silently throw away.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
MANIFEST="$HERE/vendor.manifest"
|
||||
MODE="check"
|
||||
DIR=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--check) MODE="check"; shift ;;
|
||||
--fetch) MODE="fetch"; shift ;;
|
||||
# Print the header comment (line 1 is the shebang, so start at 2) and
|
||||
# stop at the first line of code rather than a hardcoded line count --
|
||||
# a fixed range silently starts printing code again the next time the
|
||||
# header comment grows or shrinks.
|
||||
-h|--help) awk '/^set /{exit} NR>1{print}' "$0"; exit 0 ;;
|
||||
*) DIR="$1"; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -r "$MANIFEST" ] || { echo "FATAL: no manifest at $MANIFEST" >&2; exit 1; }
|
||||
command -v git >/dev/null || { echo "FATAL: git not on PATH" >&2; exit 1; }
|
||||
|
||||
# A stalled clone (dead peer, wedged proxy) must not hang this script forever
|
||||
# with no way for a caller to tell "still working" from "wedged" -- the
|
||||
# luckfox-pico tree alone is ~21 GB, so a plain wall-clock timeout would also
|
||||
# abort a clone that is merely slow. Abort only on a stall instead: git's http
|
||||
# transport already aborts a transfer whose average speed drops below
|
||||
# LOW_SPEED_LIMIT bytes/sec for LOW_SPEED_TIME seconds straight, so a slow but
|
||||
# progressing clone is never penalized. Both are overridable for a link that
|
||||
# is legitimately slow.
|
||||
: "${WARDEN_VENDOR_LOW_SPEED_LIMIT:=1000}"
|
||||
: "${WARDEN_VENDOR_LOW_SPEED_TIME:=60}"
|
||||
export GIT_HTTP_LOW_SPEED_LIMIT="$WARDEN_VENDOR_LOW_SPEED_LIMIT"
|
||||
export GIT_HTTP_LOW_SPEED_TIME="$WARDEN_VENDOR_LOW_SPEED_TIME"
|
||||
|
||||
if [ -z "$DIR" ]; then
|
||||
DIR="${WARDEN_VENDOR_DIR:-$HOME/projects/scada/flare-edge}"
|
||||
fi
|
||||
|
||||
# Where each tree conventionally lives. lvgl sits under ui/ because that is the
|
||||
# shared tree flare-edge worktrees symlink into (ui-src/lvgl).
|
||||
tree_path() {
|
||||
case "$1" in
|
||||
lvgl) echo "$DIR/ui/lvgl" ;;
|
||||
luckfox-pico) echo "$DIR/sdk" ;;
|
||||
*) echo "$DIR/$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
rc=0
|
||||
while IFS=$'\t' read -r name url commit desc; do
|
||||
case "$name" in ''|\#*) continue ;; esac
|
||||
path="$(tree_path "$name")"
|
||||
|
||||
# -e, not -d: a git worktree or submodule has a .git FILE, and lvgl is
|
||||
# checked out as one here.
|
||||
if [ ! -e "$path/.git" ]; then
|
||||
if [ "$MODE" = "fetch" ]; then
|
||||
echo "== cloning $name -> $path"
|
||||
mkdir -p "$(dirname "$path")"
|
||||
git clone --quiet "$url" "$path" || { echo " FAILED to clone $name" >&2; rc=1; continue; }
|
||||
git -C "$path" checkout --quiet "$commit" || { echo " FAILED to check out $commit" >&2; rc=1; continue; }
|
||||
else
|
||||
echo "MISSING $name ($path)"
|
||||
rc=1
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
have="$(git -C "$path" rev-parse HEAD 2>/dev/null)"
|
||||
if [ "$have" = "$commit" ]; then
|
||||
# Local changes are reported but are NOT a failure. The vendor SDK is
|
||||
# expected to carry them: tools/build-firmware.sh applies our sdk-patches
|
||||
# series into that tree as part of every build, so a clean luckfox-pico
|
||||
# checkout is the unusual state, not the healthy one.
|
||||
dirty=""
|
||||
[ -n "$(git -C "$path" status --porcelain 2>/dev/null | head -1)" ] && dirty=" (locally modified)"
|
||||
echo "OK $name ${commit:0:12}$dirty"
|
||||
else
|
||||
echo "DRIFTED $name want ${commit:0:12} have ${have:0:12} ($path)"
|
||||
echo " not reset automatically: check whether that is deliberate, then"
|
||||
echo " either 'git -C $path checkout $commit' or update the manifest."
|
||||
rc=1
|
||||
fi
|
||||
done < "$MANIFEST"
|
||||
|
||||
exit "$rc"
|
||||
@@ -1,242 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Package a bootable boot.img from a kernel this SDK built.
|
||||
#
|
||||
# build-kernel.sh produces a zImage and a dtb; this turns them into the image
|
||||
# the board's U-Boot will actually boot, which was the last thing keeping the
|
||||
# device build tied to the vendor SDK. The format is not negotiable and was
|
||||
# established the hard way during M2 bring-up (kernel/docs/m2-boot-on-c8a3.md):
|
||||
#
|
||||
# - EXTERNAL-DATA FIT (`mkimage -E -p 0x800`). The FDT metadata stays tiny and
|
||||
# the kernel/fdt/resource payloads are appended after it. An ordinary
|
||||
# embedded-data FIT is rejected outright: "FIT: No fit blob".
|
||||
# - A `resource` MULTI SUB-IMAGE IS MANDATORY. Rockchip's U-Boot reads the DTB
|
||||
# over its RESC: path from a resource image holding `rk-kernel.dtb` (plus
|
||||
# any boot logos). Without one: "Failed to load DTB, ret=-19".
|
||||
# - SYSMEM SENTINEL LOAD ADDRESSES: fdt load 0xffffff00, kernel load/entry
|
||||
# 0xffffff01. These tell U-Boot's sysmem to place the images itself. Real
|
||||
# low addresses collide and come back as "No fit blob".
|
||||
#
|
||||
# The board's U-Boot has CONFIG_FIT_SIGNATURE off, so the image is not signed.
|
||||
#
|
||||
# Usage:
|
||||
# mk-bootimg.sh --kernel zImage --dtb rv1106-warden.dtb --out boot.img
|
||||
# [--logo FILE] [--logo-kernel FILE] [--logo-recovery FILE]
|
||||
# [--logo-verbose FILE]
|
||||
# [--resource-tool PATH]
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
KERNEL=""; DTB=""; OUT=""; RTOOL=""
|
||||
LOGO=""; LOGO_KERNEL=""; LOGO_RECOVERY=""; LOGO_VERBOSE=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--kernel) KERNEL="${2:?}"; shift 2 ;;
|
||||
--dtb) DTB="${2:?}"; shift 2 ;;
|
||||
--out) OUT="${2:?}"; shift 2 ;;
|
||||
--logo) LOGO="${2:?}"; shift 2 ;;
|
||||
--logo-kernel) LOGO_KERNEL="${2:?}"; shift 2 ;;
|
||||
--logo-recovery) LOGO_RECOVERY="${2:?}"; shift 2 ;;
|
||||
# The same image as --logo but with a VERBOSE mark. U-Boot draws it by
|
||||
# name when the splash is tapped, so it must be packed even though nothing
|
||||
# displays it on an ordinary boot.
|
||||
--logo-verbose) LOGO_VERBOSE="${2:?}"; shift 2 ;;
|
||||
--resource-tool) RTOOL="${2:?}"; shift 2 ;;
|
||||
# Print the header comment (line 1 is the shebang, so start at 2) and
|
||||
# stop at the first line of code rather than a hardcoded line count --
|
||||
# a fixed range silently starts printing code again the next time the
|
||||
# header comment grows or shrinks (see build/fetch-vendor.sh's own
|
||||
# --help, which had this exact bug).
|
||||
-h|--help) awk '/^set /{exit} NR>1{print}' "$0"; exit 0 ;;
|
||||
*) echo "FATAL: unknown argument '$1'" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$KERNEL" ] && [ -f "$KERNEL" ] || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
|
||||
[ -n "$DTB" ] && [ -f "$DTB" ] || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
|
||||
[ -n "$OUT" ] || { echo "FATAL: --out is required" >&2; exit 1; }
|
||||
command -v mkimage >/dev/null || {
|
||||
echo "FATAL: mkimage not on PATH (Debian/Ubuntu: u-boot-tools)" >&2; exit 1; }
|
||||
# fdtget backs the post-build alignment assertions below (the whole point of
|
||||
# which is that a misaligned image boots fine in CI and fails on a panel), so
|
||||
# its absence must fail the build rather than silently skip those checks.
|
||||
command -v fdtget >/dev/null || {
|
||||
echo "FATAL: fdtget not on PATH (Debian/Ubuntu: device-tree-compiler)" >&2; exit 1; }
|
||||
|
||||
# resource_tool is a Rockchip host tool. It has no free-standing source here, so
|
||||
# it is taken from the vendor SDK when one is present rather than vendored as a
|
||||
# binary; --resource-tool overrides. FAILS CLOSED, because a boot.img built
|
||||
# without a resource image looks fine and does not boot.
|
||||
if [ -z "$RTOOL" ]; then
|
||||
for c in \
|
||||
"$HERE/../tools/resource_tool" \
|
||||
"${WARDEN_VENDOR_SDK:-$HERE/../../../sdk}/sysdrv/tools/pc/toolkits/resource_tool" \
|
||||
"$HOME/projects/scada/flare-edge/sdk/sysdrv/tools/pc/toolkits/resource_tool"
|
||||
do
|
||||
[ -x "$c" ] && { RTOOL="$c"; break; }
|
||||
done
|
||||
fi
|
||||
[ -n "$RTOOL" ] && [ -x "$RTOOL" ] || {
|
||||
echo "FATAL: resource_tool not found; pass --resource-tool PATH" >&2; exit 1; }
|
||||
|
||||
WORKDIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORKDIR"' EXIT
|
||||
|
||||
# resource_tool packs files under a root dir by their names, and U-Boot looks
|
||||
# for the DTB under the fixed name rk-kernel.dtb.
|
||||
cp "$DTB" "$WORKDIR/rk-kernel.dtb"
|
||||
RES_FILES=(rk-kernel.dtb)
|
||||
for pair in "$LOGO:logo.bmp" "$LOGO_KERNEL:logo_kernel.bmp" \
|
||||
"$LOGO_RECOVERY:logo_recovery.bmp" "$LOGO_VERBOSE:logo_verbose.bmp"; do
|
||||
src="${pair%%:*}"; dst="${pair##*:}"
|
||||
[ -n "$src" ] || continue
|
||||
[ -f "$src" ] || { echo "FATAL: logo '$src' not found" >&2; exit 1; }
|
||||
cp "$src" "$WORKDIR/$dst"
|
||||
RES_FILES+=("$dst")
|
||||
done
|
||||
|
||||
echo "== resource.img (${RES_FILES[*]})"
|
||||
( cd "$WORKDIR" && "$RTOOL" --pack --root=. --image=resource.img "${RES_FILES[@]}" >/dev/null )
|
||||
[ -s "$WORKDIR/resource.img" ] || { echo "FATAL: resource_tool produced nothing" >&2; exit 1; }
|
||||
|
||||
cp "$KERNEL" "$WORKDIR/kernel"
|
||||
cp "$WORKDIR/resource.img" "$WORKDIR/resource"
|
||||
cp "$DTB" "$WORKDIR/fdt"
|
||||
|
||||
cat > "$WORKDIR/boot.its" <<'ITS'
|
||||
/dts-v1/;
|
||||
/ {
|
||||
description = "FIT image with Linux kernel, FDT blob and resource";
|
||||
images {
|
||||
fdt {
|
||||
data = /incbin/("fdt");
|
||||
type = "flat_dt";
|
||||
arch = "arm";
|
||||
compression = "none";
|
||||
load = <0xffffff00>;
|
||||
hash { algo = "sha256"; };
|
||||
};
|
||||
kernel {
|
||||
data = /incbin/("kernel");
|
||||
type = "kernel";
|
||||
arch = "arm";
|
||||
os = "linux";
|
||||
compression = "none";
|
||||
entry = <0xffffff01>;
|
||||
load = <0xffffff01>;
|
||||
hash { algo = "sha256"; };
|
||||
};
|
||||
resource {
|
||||
data = /incbin/("resource");
|
||||
type = "multi";
|
||||
arch = "arm";
|
||||
compression = "none";
|
||||
hash { algo = "sha256"; };
|
||||
};
|
||||
};
|
||||
configurations {
|
||||
default = "conf";
|
||||
conf {
|
||||
rollback-index = <0x0>;
|
||||
kernel = "kernel";
|
||||
fdt = "fdt";
|
||||
multi = "resource";
|
||||
};
|
||||
};
|
||||
};
|
||||
ITS
|
||||
|
||||
# - SUB-IMAGE ALIGNMENT (`-B 0x200`). `-p` places only the FIRST payload; the
|
||||
# rest are packed contiguously. U-Boot reads each with
|
||||
# `blk_off = (FIT_ALIGN(fdt_totalsize) + offset) / blksz` (fit.c:331), a
|
||||
# truncating divide by the 512-byte eMMC block, where FIT_ALIGN rounds to
|
||||
# IMAGE_ALIGN_SIZE = 512 (include/image.h:955-958). So TWO things must hold:
|
||||
# the metadata size must be a multiple of 512, or FIT_ALIGN(T) != T and
|
||||
# EVERY payload is read late by the difference; and each data-position must
|
||||
# be a multiple of 512, or the divide drops the remainder.
|
||||
#
|
||||
# Measured: without -B this script emitted the kernel at data-position
|
||||
# 0x9A94 (% 512 = 148) with metadata 1064 (% 512 = 40) -- both faults at
|
||||
# once. flare-edge 9387cff hit exactly this on hardware: "resource: sha256
|
||||
# Bad hash" then "No resource file: logo.bmp", fixed by -B 0x200 and
|
||||
# confirmed by a clean boot.
|
||||
#
|
||||
# 512, NOT 2048. An earlier revision of this comment claimed the vendor
|
||||
# aligns to 0x800 and gated on it. That was drawn from two payloads in one
|
||||
# build. Across the vendor's own release images on this machine, every
|
||||
# data-position is a multiple of 512 and only some are multiples of 2048
|
||||
# (four of eight RELEASE_TEST boot.img files sit at % 2048 = 1536), so a
|
||||
# 2048 gate rejects images the vendor shipped and U-Boot boots. 0x800 is the
|
||||
# vendor's -p value -- the absolute position of the first payload -- not an
|
||||
# alignment.
|
||||
#
|
||||
# A -B-capable mkimage is REQUIRED, not preferred. The SDK vendors 2017.09,
|
||||
# which has no -B, and project/build.sh:64 puts it first on PATH -- so the
|
||||
# wrong one is what a build inside the SDK environment picks up. Measured:
|
||||
# that binary produces metadata of 1064 bytes here, not a multiple of 512,
|
||||
# so FIT_ALIGN rounds it up and every payload is read late. It does NOT
|
||||
# 512-align this .its natively. Rather than silently emit an image that
|
||||
# fails on a panel, pick the first mkimage on PATH that supports -B and say
|
||||
# plainly when there is none.
|
||||
# >>> mkimage-probe (extracted verbatim by tests/mk-bootimg/run-probe-tests.sh)
|
||||
MKIMAGE=""
|
||||
_IFS_SAVE="$IFS"; IFS=:
|
||||
for _d in $PATH; do
|
||||
_c="$_d/mkimage"
|
||||
[ -x "$_c" ] || continue
|
||||
# mkimage with no args prints its usage and exits non-zero; under the
|
||||
# pipefail set at the top of this file that failure would sink the whole
|
||||
# pipeline, so the probe would reject every mkimage including good ones.
|
||||
if { "$_c" 2>&1 || true; } | grep -q -- '-B '; then MKIMAGE="$_c"; break; fi
|
||||
done
|
||||
IFS="$_IFS_SAVE"
|
||||
# <<< mkimage-probe
|
||||
if [ -z "$MKIMAGE" ]; then
|
||||
echo "FATAL: no mkimage on PATH supports -B (sub-image alignment)." >&2
|
||||
echo " The SDK vendors mkimage 2017.09, which does not, and its output" >&2
|
||||
echo " is not 512-aligned here. Install u-boot-tools (2025.01 works)" >&2
|
||||
echo " and make sure it precedes the SDK tools on PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "== FIT (external data, -E -p 0x800 -B 0x200) using $MKIMAGE"
|
||||
( cd "$WORKDIR" && "$MKIMAGE" -f boot.its -E -p 0x800 -B 0x200 boot.img >/dev/null )
|
||||
|
||||
# Assert what U-Boot actually requires, on every build: the failure is silent --
|
||||
# a misread offset does not fail the build, it fails on a panel, and sometimes
|
||||
# only as a missing logo. Computed once and reused below (the embedded-data-FIT
|
||||
# check further down needs the same value) so a future fix to how this is read
|
||||
# cannot land in one check and not the other.
|
||||
meta="$(od -An -tu4 -j4 -N4 --endian=big "$WORKDIR/boot.img" | tr -d ' ')"
|
||||
if [ $(( meta % 512 )) -ne 0 ]; then
|
||||
echo "FATAL: FIT metadata is $meta bytes, not a multiple of 512;" >&2
|
||||
echo " FIT_ALIGN would round it up and every payload reads late" >&2
|
||||
exit 1
|
||||
fi
|
||||
for _n in fdt kernel resource; do
|
||||
# fdtget's presence is checked up front; a failure here means the FIT this
|
||||
# script just built is malformed, not that the field is legitimately
|
||||
# absent (mkimage -E gives every one of these images a data-position). Fail
|
||||
# loud rather than treat an empty read as nothing to check.
|
||||
if ! _pos="$(fdtget -t u "$WORKDIR/boot.img" "/images/$_n" data-position 2>&1)"; then
|
||||
echo "FATAL: fdtget could not read /images/$_n data-position: $_pos" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $(( _pos % 512 )) -ne 0 ]; then
|
||||
echo "FATAL: /images/$_n data-position $_pos is not 512-aligned;" >&2
|
||||
echo " U-Boot's truncating block divide would read the wrong offset" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# A FIT whose metadata swelled to the size of the whole image is an
|
||||
# embedded-data build, which this U-Boot rejects. Catch it here rather than on
|
||||
# a panel that will not come back.
|
||||
total="$(stat -c %s "$WORKDIR/boot.img")"
|
||||
if [ "${meta:-0}" -ge 4096 ] || [ "${meta:-0}" -ge "$total" ]; then
|
||||
echo "FATAL: FIT metadata is ${meta} bytes of a ${total}-byte image: that is an" >&2
|
||||
echo " embedded-data FIT and U-Boot will report 'No fit blob'." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -m 0644 "$WORKDIR/boot.img" "$OUT"
|
||||
echo "boot.img: $OUT ($(stat -c %s "$OUT") bytes, FIT metadata ${meta} bytes)"
|
||||
@@ -1,35 +0,0 @@
|
||||
# Third-party trees this platform is built against, pinned to an exact commit.
|
||||
#
|
||||
# WHY A PIN AND NOT A COPY. Between them these are ~21 GB; the vendor SDK alone
|
||||
# is 21 GB of build tree with absolute paths baked into its host tools. Copying
|
||||
# that into git would make every clone of this repo unusable and would still not
|
||||
# make the result reproducible. What makes a build reproducible is knowing
|
||||
# EXACTLY which tree was used, and that is a commit id -- the same reasoning
|
||||
# build/fetch-kernel-tarball.sh already applies to the kernel, where a sha256
|
||||
# pin stands in for vendoring 150 MB of tarball.
|
||||
#
|
||||
# So this file is the single place that answers "which LVGL, which vendor SDK",
|
||||
# and fetch-vendor.sh is the only thing that acts on it. A checkout that has
|
||||
# drifted off its pin is reported, never silently used.
|
||||
#
|
||||
# NOT EVERYTHING HERE IS A GIT TREE. Two build inputs are pinned tarballs
|
||||
# instead, each with its own fetch-and-verify script beside this file, because a
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
# vendor SDK ships 2023.02.6 -- so that tree is not in the vendor checkout, was
|
||||
# not in this manifest, and had no recorded origin at all. A clean rebuild
|
||||
# silently used the vendor's older buildroot and produced a different userspace
|
||||
# (flare-edge#135). Our delta on top of it is captured in this repo at
|
||||
# luckfox-sdk-patches/buildroot/ (moved 2026-09-15 from the flare-edge repo's
|
||||
# sdk-patches/buildroot/).
|
||||
#
|
||||
# Format: name<TAB>url<TAB>commit<TAB>description
|
||||
# Blank lines and lines starting with '#' are ignored.
|
||||
|
||||
lvgl https://github.com/lvgl/lvgl.git 066d8db0b54819223357731f68961a90b3d785b4 LVGL v9.5.0-383-g066d8db0b: the UI toolkit warden-ui links against
|
||||
luckfox-pico https://github.com/LuckfoxTECH/luckfox-pico.git 824b817f889c2cbff1d48fcdb18ab494a68f69d1 Vendor RV1106 SDK: buildroot userspace, U-Boot and the host packaging tools. Being replaced by this repo; still the source of the rootfs and the FIT/resource host tools.
|
||||
@@ -138,8 +138,6 @@ CONFIG_NET=y
|
||||
CONFIG_PACKET=y
|
||||
CONFIG_UNIX=y
|
||||
CONFIG_INET=y
|
||||
CONFIG_IP_ADVANCED_ROUTER=y
|
||||
CONFIG_IP_MULTIPLE_TABLES=y
|
||||
CONFIG_IP_PNP=y
|
||||
CONFIG_IP_PNP_DHCP=y
|
||||
CONFIG_IP_PNP_BOOTP=y
|
||||
@@ -1310,65 +1308,3 @@ CONFIG_DEBUG_UART_PHYS=0xff4c0000
|
||||
CONFIG_DEBUG_UART_VIRT=0xff4c0000
|
||||
CONFIG_DEBUG_UART_8250_WORD=y
|
||||
CONFIG_EARLY_PRINTK=y
|
||||
|
||||
#
|
||||
# WardenOS platform networking.
|
||||
#
|
||||
# These were absent, and their absence is not visible until the panel is in
|
||||
# the field: the kernel boots, the UI runs, and then the mesh never comes up,
|
||||
# every iptables rule fails to load, and a tagged port carries nothing. The
|
||||
# shipping 5.10 kernel has all three, so a 6.18 image without them is a
|
||||
# REGRESSION against what is on the panel today -- caught by diffing the two
|
||||
# device configs, not by anything that fails at build time.
|
||||
#
|
||||
# WireGuard: flared's mesh to FLARE (wg0). Needs the UDP tunnel helper.
|
||||
CONFIG_WIREGUARD=y
|
||||
CONFIG_NET_UDP_TUNNEL=y
|
||||
# VLAN: the MikroTik app configures tagged ports and the panel terminates them.
|
||||
CONFIG_VLAN_8021Q=y
|
||||
# Bridging. Not in the vendor kernel, and its absence is why the panel's access
|
||||
# point has to be its own subnet with its own DHCP pool rather than joining the
|
||||
# LAN's broadcast domain (see the comment in ui-src/src/warden/router.c). With a
|
||||
# bridge the panel can run an AP the way a UniFi AP does: wlan0 and the LAN port
|
||||
# in one broadcast domain, addresses handed out by whatever router is already
|
||||
# upstream. That is a capability this kernel adds, not one it restores.
|
||||
CONFIG_BRIDGE=y
|
||||
CONFIG_BRIDGE_IGMP_SNOOPING=y
|
||||
CONFIG_LLC=y
|
||||
CONFIG_STP=y
|
||||
# Netfilter: S35iptables and router mode. Scoped to what the scripts actually
|
||||
# use -- filter + nat tables, MASQUERADE, and the state/limit matches -- rather
|
||||
# than the vendor kernel's full 124-symbol suite.
|
||||
CONFIG_NETFILTER=y
|
||||
CONFIG_NETFILTER_ADVANCED=y
|
||||
CONFIG_NF_CONNTRACK=y
|
||||
CONFIG_NF_NAT=y
|
||||
CONFIG_NF_NAT_MASQUERADE=y
|
||||
CONFIG_NETFILTER_XTABLES=y
|
||||
# ...which in turn gates on the legacy xtables core, another 6.18 split.
|
||||
CONFIG_NETFILTER_XTABLES_LEGACY=y
|
||||
CONFIG_NETFILTER_XT_MATCH_STATE=y
|
||||
CONFIG_NETFILTER_XT_MATCH_LIMIT=y
|
||||
CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
|
||||
CONFIG_NETFILTER_XT_NAT=y
|
||||
CONFIG_NETFILTER_XT_TARGET_MASQUERADE=y
|
||||
CONFIG_NF_DEFRAG_IPV4=y
|
||||
# No NF_CONNTRACK_IPV4 symbol here -- IPv4 conntrack has been unconditional in
|
||||
# NF_CONNTRACK's core since well before 6.18 (net/ipv4/netfilter/Kconfig has no
|
||||
# such config). Only stale arch defconfigs (e.g. keystone_defconfig) still set
|
||||
# it; Kconfig drops an unknown symbol with no warning, so it looked live but
|
||||
# did nothing. Left out on purpose so this file does not claim a gate that
|
||||
# does not exist. If a future kernel bump reintroduces a real symbol by this
|
||||
# name, catch it by diffing the expanded .config, not by functional test alone
|
||||
# -- see PORT-STATUS.md's own history of a silent-drop hiding a real gap.
|
||||
CONFIG_IP_NF_IPTABLES=y
|
||||
# 6.18 SPLIT THE LEGACY TABLES OUT. IP_NF_FILTER and IP_NF_NAT depend on
|
||||
# IP_NF_IPTABLES_LEGACY, which did not exist in 5.10 -- so copying the vendor
|
||||
# kernel's symbol list verbatim yields a kernel where `iptables` has no filter
|
||||
# or nat table and every rule in S35iptables fails. Our userspace drives legacy
|
||||
# iptables, not nft, so this is the table set to enable.
|
||||
CONFIG_IP_NF_IPTABLES_LEGACY=y
|
||||
CONFIG_IP_NF_FILTER=y
|
||||
CONFIG_IP_NF_TARGET_REJECT=y
|
||||
CONFIG_IP_NF_NAT=y
|
||||
CONFIG_IP_NF_MANGLE=y
|
||||
|
||||
@@ -17,7 +17,7 @@ tested (or not) differently. Today:
|
||||
| HPMCU / RISC-V coproc | `flared/src/hpmcu.rs` | via devmem + firmware blob load | `WARDEN_HPMCU_FW` redirects the blob path only | env gate disables it |
|
||||
| NPU load | `ui-src/.../sysmon.c` | read `/proc/rknpu/load` | **none**, literal path | file absent -> "NPU absent" |
|
||||
| RGA (2D blit) | `ui-src/.../warden_rga.c` | `librga improcess` + dma-heap ioctl | compile-time `#if WARDEN_USE_RGA` | `#if` off -> LVGL software path |
|
||||
| RS485 daemon | `apps/warden-modbus/modbus_engine.c` | `open("/dev/ttyS4")` | recompile `-DRS485_PORT=<pty>` | (recompiled for a pty) |
|
||||
| RS485 daemon | `warden-modbus/modbus_engine.c` | `open("/dev/ttyS4")` | recompile `-DRS485_PORT=<pty>` | (recompiled for a pty) |
|
||||
| RS485 panel client | `ui-src/.../modbus.c` | `AF_UNIX` socket | `WARDEN_MODBUS_SOCK` env override | socket absent -> "unavailable" |
|
||||
| Relays / GPIO | `ui-src/.../relays.c` | `/sys/class/gpio` sysfs | **none**, literal paths | path absent -> "unavailable" |
|
||||
| Slot metadata | `flared/src/slotctl.rs` | `misc` partition + `/proc/cmdline` | `WARDEN_MISC_DEV`, `WARDEN_CMDLINE_FILE` env overrides | (redirected to scratch files) |
|
||||
|
||||
+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`; 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. |
|
||||
|
||||
@@ -159,32 +159,3 @@ build-m2.sh reproducible M2 build (zImage + dtb)
|
||||
```
|
||||
The full ported tree lives in `flare-edge/research/linux-6.18.46/` (scratch); this dir is
|
||||
the durable, reviewable capture, to become a proper patch series as milestones land.
|
||||
|
||||
## Hardware verification (2026-09-03)
|
||||
|
||||
The current series in `../../patches/` was built with `build/build-kernel.sh` +
|
||||
`build/warden_defconfig` (rockchip gcc 8.3), packaged with the new
|
||||
`build/mk-bootimg.sh`, flashed to the bench panel's inactive slot armed for a
|
||||
single try, and booted. Working on real silicon: display (`/dev/fb0`,
|
||||
`/dev/dri/card0`), backlight, Goodix touch, RGA (`/dev/rga`), eth0, the usb0
|
||||
gadget, all userspace daemons, and zero kernel faults in dmesg.
|
||||
|
||||
M4 (display) and part of M6 (RGA) above are STALE: both are in the series and
|
||||
verified here. M5 (wifi) and the rest of M6 (watchdog, HPMCU, full USB-OTG
|
||||
dual role) are still open -- this run gives no evidence for them.
|
||||
|
||||
**What the same test found missing, and why it matters.** Diffing this
|
||||
defconfig's expansion against the kernel actually shipping on a panel showed
|
||||
three subsystems absent, none of which fail at build time:
|
||||
|
||||
ip link add type wireguard -> Operation not supported
|
||||
iptables -L -> FAIL (no filter or nat table)
|
||||
/proc/net/vlan -> absent
|
||||
|
||||
That is the FLARE mesh, every rule in S35iptables plus router-mode NAT, and the
|
||||
MikroTik tagged-port work. The netfilter half hid behind a 6.18 rename: the
|
||||
legacy tables moved under NETFILTER_XTABLES_LEGACY / IP_NF_IPTABLES_LEGACY, so
|
||||
copying the vendor kernel's symbol list verbatim leaves IP_NF_FILTER and
|
||||
IP_NF_NAT silently off. Fixed in warden_defconfig and re-verified on the same
|
||||
panel: wireguard device creates, filter and nat tables load, MASQUERADE and the
|
||||
state match apply, and a VLAN interface creates.
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
* RV1106 USB2 PHY: single OTG port at 0xff3e0000 (ported from the vendor driver;
|
||||
* fields map 1:1 to 6.18 except utmi_iddig -> utmi_id, and the 5.10-only
|
||||
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning
|
||||
* was originally left off here; it is now implemented (patches/27-usb-phy-tuning.patch)
|
||||
* because "functional without it" turned out not to mean reliable -- see #160.
|
||||
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning is
|
||||
* left off for now (guarded, so NULL is safe): the phy is functional without it.
|
||||
*/
|
||||
static const struct rockchip_usb2phy_cfg rv1106_phy_cfgs[] = {
|
||||
{
|
||||
.reg = 0xff3e0000,
|
||||
.num_ports = 1,
|
||||
.phy_tuning = rv1106_usb2phy_tuning,
|
||||
.clkout_ctl = { 0x0058, 4, 4, 1, 0 },
|
||||
.port_cfgs = {
|
||||
[USB2PHY_PORT_OTG] = {
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
# luckfox-sdk-patches
|
||||
|
||||
The Luckfox SDK (`LuckfoxTECH/luckfox-pico`, pinned in `../build/vendor.manifest`
|
||||
as `luckfox-pico`) is a ~2 GB vendor checkout and is deliberately **not** in
|
||||
this repo. Our changes to it were, until now, living only as uncommitted
|
||||
edits in one person's working copy -- which is how a stale second copy on
|
||||
another machine came within one command of silently reverting a day of work.
|
||||
This directory is the tracked form of those changes.
|
||||
|
||||
**Moved here 2026-09-15** from `sdk-patches/` in `blueflare/flare-edge`
|
||||
(source commit `flare-edge@86d4633`), so the SDK repo -- not the firmware
|
||||
repo that merely consumes it -- is the single canonical home for every
|
||||
kernel/U-Boot/driver delta. flare-edge's `tools/build-firmware.sh` and
|
||||
friends now read this directory through the `vendor/warden-sdk` submodule
|
||||
instead of a same-repo `sdk-patches/`.
|
||||
|
||||
**Vendor base: `824b817f8`** of <https://github.com/LuckfoxTECH/luckfox-pico>
|
||||
(`Pullrequest 260319 (#355)`) -- the same commit `../build/vendor.manifest`
|
||||
pins. Every patch here is `git diff` against that commit and has been
|
||||
verified with `git apply --check` against a pristine tree at that revision.
|
||||
If the vendor base moves, re-verify before trusting them.
|
||||
|
||||
**Not `patches/`, and not `sdk/`.** This repo's top-level `patches/` is a
|
||||
different, unrelated thing: the from-scratch Linux 6.18.46 forward-port
|
||||
series (see `../patches/README.md`). `luckfox-sdk-patches/` patches the
|
||||
**legacy** vendor tree instead (U-Boot 2017.09 and, optionally, the vendor
|
||||
5.10.160 kernel) -- naming it `luckfox-sdk-patches/` keeps the two
|
||||
unmistakable next to each other. It also isn't named plain `sdk/`, carrying
|
||||
forward the original naming rule from its flare-edge home: that repo's
|
||||
`ui-src/pkgconfig-stub/libdrm.pc` resolves `${pcfiledir}/../../sdk`, so a
|
||||
directory named `sdk/` anywhere it might be checked out alongside would
|
||||
shadow the real vendor SDK checkout. That specific collision cannot happen
|
||||
in this repo, but the name stayed to avoid a second rename and to keep the
|
||||
provenance trail (wiki, commit messages, flare-edge doc citations) legible
|
||||
across the move. Do not rename it.
|
||||
|
||||
## License
|
||||
|
||||
Everything here is a `git diff` against Rockchip/Luckfox's GPL-2.0 vendor
|
||||
U-Boot (2017.09) and Linux (5.10.160) forks, plus a handful of small
|
||||
standalone files we authored (`uboot/include/flare_touch.h`,
|
||||
`uboot/include/flare_trace.h`, the bluez5 `wordexp.h` compat shim, the mpv
|
||||
Bessel-function patch). The diffs are themselves GPL-2.0 derivative work,
|
||||
consistent with this repo's repo-wide GPL-2.0-only license (`../LICENSE`);
|
||||
the small standalone files carry no GPL restriction of their own but are
|
||||
distributed here under the same license for simplicity. Unlike `../patches/`
|
||||
(the 6.18 port), no per-driver provenance ledger exists for this directory
|
||||
yet -- everything here predates that convention. If one is wanted, it
|
||||
belongs beside `../kernel/rv1106-enablement/PROVENANCE.md`.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
luckfox-sdk-patches/uboot/patches/ diffs against sysdrv/source/uboot/u-boot/
|
||||
luckfox-sdk-patches/uboot/configs/ new config fragments (not patches -- whole new files)
|
||||
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)
|
||||
```
|
||||
|
||||
Paths inside each patch are relative to the vendor SDK root, so apply with
|
||||
`-p1` from there:
|
||||
|
||||
```sh
|
||||
cd /path/to/vendor/sdk
|
||||
for p in /path/to/warden-sdk/luckfox-sdk-patches/uboot/patches/*.patch \
|
||||
/path/to/warden-sdk/luckfox-sdk-patches/kernel/patches/*.patch \
|
||||
/path/to/warden-sdk/luckfox-sdk-patches/board/patches/*.patch; do
|
||||
git apply --check "$p" && git apply "$p"
|
||||
done
|
||||
cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/configs/*.config sysdrv/source/uboot/u-boot/configs/
|
||||
cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/include/*.h sysdrv/source/uboot/u-boot/include/
|
||||
cp /path/to/warden-sdk/luckfox-sdk-patches/kernel/configs/*.config sysdrv/source/kernel/arch/arm/configs/
|
||||
```
|
||||
|
||||
**You no longer have to run the above by hand.** flare-edge's
|
||||
`tools/build-firmware.sh` (in the `blueflare/flare-edge` repo, which carries
|
||||
this SDK as the `vendor/warden-sdk` submodule) applies everything in
|
||||
`luckfox-sdk-patches/` (patches idempotently, config fragments by copy)
|
||||
before it builds -- see its `apply_sdk_patches` step. The manual recipe is
|
||||
kept here as documentation of *what* that step does and for one-off use against
|
||||
a pristine tree. Idempotency rule the script uses per patch: if
|
||||
`git apply --reverse --check` succeeds the patch is already in the tree and is
|
||||
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.
|
||||
|
||||
## What each patch does
|
||||
|
||||
### `uboot/patches/0001-display-and-boot-timing.patch`
|
||||
|
||||
The U-Boot boot logo never appeared at all before this, and four separate bugs
|
||||
had to be fixed before it did. Each was measured on hardware, not inferred.
|
||||
|
||||
| file | fix |
|
||||
|---|---|
|
||||
| `rockchip_display.c` | `malloc` -> `calloc`. `enabled_at_spl` is only ever assigned under `#ifdef CONFIG_SPL_BUILD`, so in U-Boot proper it read uninitialised heap. Garbage read as truthy meant `display_enable()` skipped the connector pre-enable/enable path -- the only path that reaches `backlight_enable()`. |
|
||||
| `pwm_backlight.c` | `args.args[2] & 1`. The DT has `pwms = <&pwm1 0 100000 50000>`; assigning `50000` to a `bool` polarity field inverted the PWM. Measured `DUTY=0x26e8` (99.6%) with `CTRL=0x13`; after the fix `CTRL=0x0b`. The backlight was running at 0.4%. |
|
||||
| `clk_rv1106.c` | Two bugs. `rv1106_clk_set_rate()` returned a stale `ret` instead of the computed `rate`, so it always reported 0 Hz. And `DCLK_VOP_DIV_MASK` is 5 bits (max ÷32) while `DIV_ROUND_UP(1188 MHz, 30 MHz) = 40` wrote 39, truncated to 7 -- **the VOP was running at 125 MHz, not 30**. Now clamps to 32, picks the closest parent, and retunes CPLL 1000 -> 960 MHz when neither divides evenly, giving exactly 30.000 MHz. |
|
||||
| `rockchip_panel.c` | `FLARE_PANEL_SETTLE_MS`: wait after scanout starts before switching the backlight on. See the comment in the file -- it distinguishes two artefacts that look similar and have different causes. |
|
||||
| `board.c` | Release `RGB_RES` (GPIO0_A1) at the top of `board_init()` instead of `board_late_init()`, and `FLARE_TRACE` instrumentation. `setup_download_mode()` is deliberately kept **first** in `board_late_init()`: moving the logo ahead of it pushed BOOT-key sampling from 1.18 s to ~4-5 s and the key had to be held for eight seconds. |
|
||||
| `rv1106-u-boot.dtsi` | `u-boot,spl-boot-order = <&emmc>`. It was `<&sdmmc, &spi_nor, &spi_nand, &emmc>` -- the only fitted medium was last. Walking the dead entries cost **267 ms** every boot: ~212 ms failing to identify a non-existent SPI-NAND (`unknown raw ID 0 0 0`) and ~57 ms probing an SD slot this board does not have (`sdmmc` is wired to the AIC8800 WiFi as SDIO). **This file is shared by every rv1106 U-Boot build in the tree**; an SD- or SPI-NAND-booting variant would no longer boot. |
|
||||
| `console.c` | Timestamp every console line, including from SPL. Needed two fixes: the stock code formats with `%5lu.%06lu`, which `CONFIG_USE_TINY_PRINTF` cannot render (it supports only `%c %s %u %d %x`), and it hooked `puts()`, which SPL never calls -- tiny printf goes character-at-a-time through `putc()`. Costs 324 B of SPL. |
|
||||
| `rockchip_post_csc.c` | Add `#include <common.h>`. An upstream SDK bug, not a consequence of our config -- the vendor's own `rv1106_defconfig` also lacks `CONFIG_DM_I2C`. |
|
||||
|
||||
### `uboot/patches/0002-boot-robustness.patch`
|
||||
|
||||
Unattended recovery: `spl-boot-order.c` + `spl.c` register `BOOT_DEVICE_BOOTROM`
|
||||
as a last-resort SPL load method so a failed U-Boot load drops to MaskRom
|
||||
instead of hanging, and `bootcount/Kconfig` exposes `BOOTCOUNT_LIMIT` so
|
||||
repeated boot failures fall through to `altbootcmd`. The defconfig change adds
|
||||
the bootcount variables to `CONFIG_ENVF_LIST`.
|
||||
|
||||
**Provenance note:** this is boot-robustness rather than display work and may
|
||||
overlap with reliability work done in a parallel session. Review before merging.
|
||||
|
||||
### `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch`
|
||||
|
||||
Two hunks, both display:
|
||||
|
||||
- **`&panel`** -- removes `reset-gpios` and `reset-delay-ms`. GPIO0_A1 is *not*
|
||||
the panel's reset. Per the 86Panel schematic, net `RGB_RES` ties SoC GPIO0_A1,
|
||||
the panel RESET pin (FPC 6) and the `NRST` of a WCH **CH32V003** MCU (U6)
|
||||
together; that MCU's only wired pins are SPI to the same FPC, and its sole job
|
||||
is to clock the panel's initialisation sequence in. Handing the GPIO to
|
||||
`panel-simple` therefore made `drm_panel_prepare()` **reboot the panel
|
||||
initialiser while the VOP was already scanning out** -- which is the faint
|
||||
coloured vertical banding seen for ~1-3 s on every boot, and why adding a
|
||||
"reset" never cured it. Luckfox deleted these same two properties in
|
||||
`e2b0ffa22`. An earlier revision of our tree re-added them, having read that
|
||||
deletion as an accidental regression. **Confirmed fixed on hardware.**
|
||||
`backlight` stays, because U-Boot's `rockchip_panel.c` takes its backlight
|
||||
handle from this node.
|
||||
- **`&route_rgb`** -- `status = "okay"`. The rest of the RGB pipeline is already
|
||||
enabled in `rv1106-luckfox-pico-86panel-ipc.dtsi`; `route_rgb` was the only
|
||||
piece left off, and without it U-Boot's `rockchip_display` finds no route and
|
||||
skips drawing entirely.
|
||||
|
||||
Deliberately **excluded** from this patch, though present in the same file in
|
||||
the working tree: the `model` rename, and a `dr_mode = "peripheral"` revert that
|
||||
was a bench workaround to keep the USB network gadget stable for flashing. The
|
||||
latter is superseded by the live USB role-switching work on `main`.
|
||||
|
||||
### `kernel/patches/0005-pstore-ramoops.patch`
|
||||
|
||||
Adds a `ramoops@0f000000` node (1 MiB @ 240 MiB) to `reserved-memory` in
|
||||
`rv1106-luckfox-pico-86panel-ipc.dtsi` so pstore/ramoops has a DRAM region that
|
||||
survives a reset. Pairs with the `CONFIG_PSTORE*` lines in
|
||||
`kernel/configs/flare-edge.config`: the kernel console ring + oops/panic survive
|
||||
into the next boot (`/sys/fs/pstore`), which is the ONLY way to diagnose a
|
||||
pre-userspace hang (the c8a3 `0x40000` class) with no serial console. Placed
|
||||
HIGH, above the low kernel-image/DTB/initrd zone, so the carve-out can only
|
||||
remove kernel RAM -- it cannot recreate the c8a3 under-reservation collision.
|
||||
Needs a `boot.img` reflash.
|
||||
|
||||
### `kernel/patches/0006-reboot-mode-maskrom.patch`
|
||||
|
||||
Adds `&reboot_mode { mode-maskrom = <0xEF08A53C>; };` (`BOOT_BROM_DOWNLOAD`) to
|
||||
the 86Panel ipc.dtsi, so the OS helper `warden-maskrom maskrom`
|
||||
(`reboot(RESTART2,"maskrom")`) writes that magic to the boot-mode reg
|
||||
(`0xff020200`) and the next reset enters **true BootROM MaskRom** -- where
|
||||
`upgrade_tool db`+`wl` / `provision-ab.sh` flash reliably. The stock
|
||||
`mode-loader`/`-bootloader` only reach U-Boot rockusb "Loader" mode, whose
|
||||
multi-partition WL is unreliable (writes report 100% but may not persist).
|
||||
One-shot (PMU-domain reg, cleared by POR). Verified: the DTB compiles and
|
||||
carries `mode-maskrom=0xEF08A53C`. Needs a `boot.img` reflash -- and the FIRST
|
||||
deployment still needs one physical-MaskRom flash (chicken-and-egg), after which
|
||||
remote MaskRom flashing works. Independent hunk (end of ipc.dtsi) -- applies in
|
||||
any order vs 0005.
|
||||
|
||||
### `buildroot/files/package/mpv/0002-change-j1.patch`
|
||||
|
||||
Swaps mpv's `j1(x)` (video/out/filter_kernels.c, backing the EWA/jinc
|
||||
scalers) for a local `BesselJ1()`. Needed because this target's uClibc-ng
|
||||
does not provide `j1()`/`j0()`/`jn()` -- confirmed absent from
|
||||
`libuClibc-1.0.31.so` in the arm-rockchip830-linux-uclibcgnueabihf
|
||||
sysroot, the same kind of gap the bluez5_utils wordexp patch works around
|
||||
for a different function.
|
||||
|
||||
The first version of `BesselJ1()` summed a fixed 11-term power series.
|
||||
`jinc()` multiplies its argument by M_PI before calling it, and mpv's
|
||||
`--scale-radius` is user-settable, so any radius reaching roughly x=20
|
||||
already returns garbage: 11 terms had not converged there, so the value
|
||||
was 3.1e6 instead of the correct 0.0668, growing to 3.3e42 by x=1000.
|
||||
The current version sums a term-to-term-ratio series while each new term
|
||||
is still negligible (stable for the range where that converges) and
|
||||
falls back to the standard second-order asymptotic expansion for Bessel
|
||||
functions beyond that, checked against the host's real `j1()` across
|
||||
x in [0, 5000]: max absolute error 5e-8. `tools/bessel-j1-test.sh` pulls
|
||||
whatever `BesselJ1()` the patch currently carries out of the diff and
|
||||
checks it the same way, so a regression back to an unconverged series
|
||||
is caught there instead of showing up as scaler artifacts on a panel.
|
||||
|
||||
### `buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch`
|
||||
|
||||
Adds a `wordexp.h` at the BlueZ source root: a minimal wordexp(3)/wordfree(3)
|
||||
for uClibc-ng, which this toolchain does not provide. `bluetoothctl` and a few
|
||||
BlueZ tools include `<wordexp.h>` unconditionally and only ever pass
|
||||
`WRDE_NOCMD` ("no command substitution"), so a whitespace/quote tokenizer is a
|
||||
semantically complete substitute -- the same kind of gap the mpv `j1()` patch
|
||||
above works around for a different function.
|
||||
|
||||
`WRDE_APPEND` lets a caller accumulate words across more than one call onto
|
||||
the same `wordexp_t`. An allocation failure partway through such a call used
|
||||
to free the words the *earlier* call had already produced and leave
|
||||
`we_wordv` pointing at memory `realloc()` had already relocated or freed --
|
||||
reachable any time a second `WRDE_APPEND` call runs out of memory, not only
|
||||
under theoretical low-memory conditions. Fixed by capturing the pre-call word
|
||||
count and only ever freeing/relocating entries at or past it.
|
||||
|
||||
`tools/wordexp-test.sh` extracts `wordexp.h` from this patch's diff into a
|
||||
scratch dir (nothing else in the tree has a copy -- it is a full new-file
|
||||
patch, applied only during a firmware build) and runs `tools/wordexp_test.c`
|
||||
against it: plain and quoted tokenizing, an unterminated quote, growth past
|
||||
the initial capacity, `WRDE_APPEND` across two calls, and the allocation-
|
||||
failure case above. Wired into CI's `daemons` job.
|
||||
|
||||
### Seatbelt build changes (docs/firmware-update.md section 6.6)
|
||||
|
||||
The firmware-update **seatbelt** (auto-revert of a bad remote reflash) needs a
|
||||
handful of small U-Boot/OS build changes. Design section 6.6 lists six; items **1, 3,
|
||||
4** are the low-risk, independently-shippable wiring, and they were -- until now -- present only in one person's hand-patched SDK, which is the exact "stale
|
||||
second copy nearly reverted a day of work" trap that created this directory.
|
||||
They are tracked here and applied by `tools/build-firmware.sh`, so a clean SDK
|
||||
checkout plus that script reproduces them with no manual editing.
|
||||
|
||||
| section 6.6 | tracked as | what it does |
|
||||
|---|---|---|
|
||||
| **item 1** | `board/patches/0001-86panel-seatbelt-wiring.patch` (first hunk) + `uboot/configs/flare-bootcount.config` | Wires the bootcount fragment into the build: appends `flare-bootcount.config` to `RK_UBOOT_DEFCONFIG_FRAGMENT` in the 86Panel board `.mk`. The fragment itself (already tracked, see the Config-fragments table) turns on `CONFIG_BOOTCOUNT{,_LIMIT,_ENV}` and the extended `CONFIG_ENVF_LIST`. Without the wiring the fragment is inert and U-Boot never counts boots -- the seatbelt's U-Boot layer (section 6.1) is silently absent. |
|
||||
| **item 3** | `board/patches/0001-86panel-seatbelt-wiring.patch` (second hunk) + `board/patches/0002-build-honor-bootargs-extra.patch` | `panic=10` on the kernel cmdline (`sys_bootargs`) so a kernel panic **reboots** after 10 s instead of hanging (section 6.4). The board `.mk` sets `RK_BOOTARGS_EXTRA="panic=10"`; the second patch teaches `project/build.sh`'s `__GET_BOOTARGS_FROM_BOARD_CFG()` to append `RK_BOOTARGS_EXTRA` verbatim to `sys_bootargs` (the same place it already appends `rk_dma_heap_cma=`). That variable flows to `RK_KERNEL_CMDLINE_FRAGMENT` -> `sysdrv/Makefile`'s `KERNEL_CMDLINE_FRAGMENT` -> the actual boot args. The hook is generic and inert: a board that never sets `RK_BOOTARGS_EXTRA` is unaffected. |
|
||||
| **item 4** | `kernel/patches/0002-watchdog-enable.patch` | Enables the hardware watchdog DT node -- `&wdt { status = "okay"; };` on the 86Panel board dts. `CONFIG_DW_WATCHDOG` is already built, but `rv1106.dtsi` ships `wdt` `disabled`, so `/dev/watchdog` does not exist until this override. Once present, `warden-flared` pets it only while healthy; a post-boot hang then hard-resets and converges to `altbootcmd` -> recovery, the backstop to bootcount (section 6.7). Needs a `boot.img` reflash. |
|
||||
|
||||
Items **2** (provision recovery env at flash time), **5** (recovery partition +
|
||||
image) and **6** (`CONFIG_ENV_OFFSET_REDUND`) are *not* build-time source
|
||||
changes: item 2 is a provisioning-step env write (see `tools/envf.py` and the
|
||||
flash scripts), item 5 is a partition-table + recovery-FIT change scheduled with
|
||||
a hardware-validation pass, and item 6 is a hardening nice-to-have. They are
|
||||
tracked where they live, not here.
|
||||
|
||||
**Apply-order note.** `kernel/patches/0002-watchdog-enable.patch` and the
|
||||
existing `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch` both edit
|
||||
the same board dts, but at non-overlapping anchors (0002 inserts after the
|
||||
`&gmac` block near the top; 0001 appends `&panel`/`&route_rgb` at the tail), so
|
||||
they apply in either order. Verified with `git apply --check` against the
|
||||
pristine vendor base and by applying both in sequence.
|
||||
|
||||
**Precise apply targets** (relative to the SDK root -- the same `-p1` convention
|
||||
as every other patch here):
|
||||
|
||||
- `board/patches/0001-86panel-seatbelt-wiring.patch` -> `project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk`
|
||||
- `board/patches/0002-build-honor-bootargs-extra.patch` -> `project/build.sh` (function `__GET_BOOTARGS_FROM_BOARD_CFG`)
|
||||
- `board/patches/0003-build-fix-rkvar-grep-quote.patch` -> `project/build.sh` (functions `unset_env_config_rk`, `unset_board_config_all`)
|
||||
- `kernel/patches/0002-watchdog-enable.patch` -> `sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts`
|
||||
|
||||
**`board/patches/0003-build-fix-rkvar-grep-quote.patch`** -- required by item 3.
|
||||
`unset_board_config_all()` reset-sources every `RK_*` var out of the board `.mk`s
|
||||
with a greedy `grep -oh "^export.*RK_.*="`, whose `.*=` runs to the *last* `=` on
|
||||
the line. Once item 3 adds `export RK_BOOTARGS_EXTRA="panic=10"`, that grep yields
|
||||
`export RK_BOOTARGS_EXTRA="panic=` -- an unbalanced quote that makes the sourced
|
||||
temp file a syntax error and aborts **every** `build.sh` invocation on a clean SDK
|
||||
(`unexpected EOF while looking for matching '"'`). The fix narrows both greps
|
||||
(here and `unset_env_config_rk`) to the variable **name** only,
|
||||
`^export RK_[A-Za-z0-9_]*=`, dropping the value. Without this, a from-scratch
|
||||
checkout cannot build the 86Panel firmware at all; the runner's hand-patched SDK
|
||||
had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close).
|
||||
- `uboot/configs/flare-bootcount.config` is **copied** into
|
||||
`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.
|
||||
|
||||
## Config fragments
|
||||
|
||||
| fragment | why |
|
||||
|---|---|
|
||||
| `uboot/flare-display.config` | the DRM/panel/PWM symbols the logo path needs |
|
||||
| `uboot/flare-verbose.config` | `CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y` -- µs timestamps on every line. ~15 chars/line ~ 1.3 ms/line at 115200, so read instrumented timings as an upper bound |
|
||||
| `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-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
|
||||
|
||||
Instrumented boot, t=0 at the BootROM DDR banner:
|
||||
|
||||
| milestone | before this work | after |
|
||||
|---|---|---|
|
||||
| SPL total (self-reported) | 420.6 ms | 153.6 ms |
|
||||
| U-Boot logo drawn | 0.866 s | 0.604 s |
|
||||
| backlight on (logo visible) | 1.157 s | 0.695 s |
|
||||
| kernel handoff | 1.757 s | 1.292 s |
|
||||
| userspace colour splash | 4.335 s | 3.87 s |
|
||||
|
||||
`tools/boot-trace.py` produces this table from a UART capture. It splits U-Boot
|
||||
from kernel at the `Starting kernel` line rather than at the kernel banner,
|
||||
because with `ignore_loglevel` at 115200 the banner is regularly lost to
|
||||
`** N printk messages dropped **`.
|
||||
|
||||
## Still open
|
||||
|
||||
- The white logo starts **inverted and fades to correct** in its first instant.
|
||||
Believed to be the CH32V003's init still completing when the backlight lands,
|
||||
so we see the tail of the driver IC's internal rail ramp; `FLARE_PANEL_SETTLE_MS`
|
||||
is currently `250` as a test of that. The cost-free fix, if confirmed, is to
|
||||
release `RGB_RES` in SPL (~0.03 s) instead of `board_init()` (~0.21 s) and take
|
||||
the settle back toward zero -- that needs an `idblock` flash.
|
||||
- No display-driver-IC part number has been identified. The panel is a 4-inch
|
||||
720x720 RGB666 module, flex marked `BV-FPC39510A-N-V0`. Note the GT911 on this
|
||||
board is the **touch** controller on `i2c3@0x14` and has nothing to do with the
|
||||
display path.
|
||||
@@ -1,107 +0,0 @@
|
||||
diff --git a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
|
||||
index c8687187c..01e95378d 100755
|
||||
--- a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
|
||||
+++ b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk
|
||||
@@ -13,6 +13,13 @@ export RK_APP_TYPE=RK_WIFI_APP
|
||||
# Config CMA size in environment
|
||||
export RK_BOOTARGS_CMA_SIZE="1M"
|
||||
|
||||
+# flare-edge (docs/firmware-update.md §6.6 item 3): extra kernel cmdline
|
||||
+# args, appended verbatim to sys_bootargs by __GET_BOOTARGS_FROM_BOARD_CFG
|
||||
+# in project/build.sh. panic=10 makes a kernel panic REBOOT after 10 s
|
||||
+# instead of hanging, so a bad `major` update is counted by U-Boot's
|
||||
+# bootcount and falls through to altbootcmd -> recovery (§6.4).
|
||||
+export RK_BOOTARGS_EXTRA="panic=10"
|
||||
+
|
||||
# Kernel dts
|
||||
export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts
|
||||
|
||||
@@ -24,7 +31,7 @@ export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts
|
||||
export RK_BOOT_MEDIUM=emmc
|
||||
|
||||
# Uboot defconfig fragment
|
||||
-export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config"
|
||||
+export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config flare-spl-brom.config flare-bootcount.config flare-display.config flare-verbose.config flare-ab.config flare-usb-gadget.config flare-touch.config"
|
||||
|
||||
# specify post.sh for delete/overlay files
|
||||
# export RK_PRE_BUILD_OEM_SCRIPT=rv1103-spi_nor-post.sh
|
||||
@@ -35,7 +42,13 @@ export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.conf
|
||||
# <partdef> := <size>[@<offset>](part-name)
|
||||
# Note:
|
||||
# If the first partition offset is not 0x0, it must be added. Otherwise, it needn't adding.
|
||||
-export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot),512M(oem),256M(userdata),6G(rootfs)"
|
||||
+#
|
||||
+# flare-edge A/B layout (docs/decisions/0003-partition-layout.md in the repo):
|
||||
+# env/idblock/uboot offsets are fixed (BootROM scans LBA 0x40; SPL reads the
|
||||
+# FIT at byte 0x88000); uboot grows 256K->512K for headroom; misc carries the
|
||||
+# A/B slot metadata (byte 2048) and an INERT BCB (16K); boot/oem/rootfs are
|
||||
+# slotted; recovery holds the never-updated rescue FIT.
|
||||
+export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),512K(uboot),512K(misc),32M(boot_a),32M(boot_b),128M(oem_a),128M(oem_b),1G(rootfs_a),1G(rootfs_b),32M(recovery),1G(userdata)"
|
||||
|
||||
# config partition's filesystem type (squashfs is readonly)
|
||||
# emmc: squashfs/ext4
|
||||
@@ -46,7 +59,9 @@ export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot)
|
||||
# AAAA ----------> partition name
|
||||
# /BBBB/CCCC ----> partition mount point
|
||||
# ext4 ----------> partition filesystem type
|
||||
-export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/oem@ext4
|
||||
+# The _a names key image GENERATION (the build strips _[ab]); runtime mounting
|
||||
+# resolves the ACTIVE slot from warden.slot on the cmdline (mount_part patch).
|
||||
+export RK_PARTITION_FS_TYPE_CFG=rootfs_a@IGNORE@ext4,userdata@/userdata@ext4,oem_a@/oem@ext4
|
||||
|
||||
# config filesystem compress (Just for squashfs or ubifs)
|
||||
# squashfs: lz4/lzo/lzma/xz/gzip, default xz
|
||||
@@ -62,7 +77,7 @@ export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/
|
||||
export LF_TARGET_ROOTFS=buildroot
|
||||
|
||||
# Buildroot defconfig
|
||||
-export RK_BUILDROOT_DEFCONFIG=luckfox_pico_w_defconfig
|
||||
+export RK_BUILDROOT_DEFCONFIG=flare_warden_defconfig
|
||||
|
||||
#################################################
|
||||
# Defconfig
|
||||
@@ -75,7 +90,19 @@ export RK_ARCH=arm
|
||||
export RK_TOOLCHAIN_CROSS=arm-rockchip830-linux-uclibcgnueabihf
|
||||
|
||||
#misc image
|
||||
-export RK_MISC=wipe_all-misc.img
|
||||
+# NEVER the SDK default (recovery-misc.img: BCB says boot-recovery --wipe_all).
|
||||
+# warden-misc.img is generated by tools/mk-misc.py (flare-edge repo): inert
|
||||
+# BCB + A/B metadata with both slots successful, A preferred.
|
||||
+export RK_MISC=warden-misc.img
|
||||
+
|
||||
+# Rescue image: a never-updated kernel+initramfs FIT in the recovery
|
||||
+# partition, booted by U-Boot when both slots are exhausted (or on a BCB
|
||||
+# 'boot-recovery' command). Same kernel fragments as the main image (keep in
|
||||
+# sync with RK_KERNEL_DEFCONFIG_FRAGMENT below: referenced literally here
|
||||
+# because this line exports first): ethernet and WireGuard are built-in, so
|
||||
+# the rescue can get the device reachable.
|
||||
+export RK_ENABLE_RECOVERY=y
|
||||
+export RK_RECOVERY_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config"
|
||||
|
||||
# Uboot defconfig
|
||||
export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig
|
||||
@@ -84,7 +111,7 @@ export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig
|
||||
export RK_KERNEL_DEFCONFIG=luckfox_rv1106_linux_defconfig
|
||||
|
||||
# Kernel defconfig fragment
|
||||
-export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config"
|
||||
+export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config"
|
||||
|
||||
# Config sensor IQ files
|
||||
# RK_CAMERA_SENSOR_IQFILES format:
|
||||
@@ -104,7 +131,7 @@ export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config
|
||||
export RK_BUILD_APP_TO_OEM_PARTITION=y
|
||||
|
||||
# enable rockchip test
|
||||
-export RK_ENABLE_ROCKCHIP_TEST=y
|
||||
+export RK_ENABLE_ROCKCHIP_TEST=n
|
||||
|
||||
# enable rockchip wifi
|
||||
export RK_ENABLE_WIFI=y
|
||||
@@ -125,4 +152,4 @@ export RK_PRE_BUILD_OEM_SCRIPT=luckfox-buildroot-oem-pre.sh
|
||||
export RK_PRE_BUILD_USERDATA_SCRIPT=luckfox-userdata-pre.sh
|
||||
|
||||
# declare overlay directory
|
||||
-export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel"
|
||||
+export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel overlay-flare-warden-ui"
|
||||
@@ -1,21 +0,0 @@
|
||||
diff --git a/project/build.sh b/project/build.sh
|
||||
index 18552ca28..6fab50104 100755
|
||||
--- a/project/build.sh
|
||||
+++ b/project/build.sh
|
||||
@@ -2161,6 +2161,16 @@ __GET_BOOTARGS_FROM_BOARD_CFG() {
|
||||
if [ -n "$RK_BOOTARGS_CMA_SIZE" ]; then
|
||||
SYS_BOOTARGS="$SYS_BOOTARGS rk_dma_heap_cma=$RK_BOOTARGS_CMA_SIZE"
|
||||
fi
|
||||
+ # flare-edge (docs/firmware-update.md §6.6 item 3): append any extra
|
||||
+ # kernel bootargs the board .mk asks for, verbatim, to sys_bootargs.
|
||||
+ # The 86Panel board sets RK_BOOTARGS_EXTRA="panic=10" so a kernel
|
||||
+ # panic REBOOTS after 10 s instead of hanging -- which is what turns a
|
||||
+ # bad `major` update into a bootcount++ that U-Boot can count toward
|
||||
+ # ${bootlimit} -> ${altbootcmd} -> recovery. Generic + inert: a board
|
||||
+ # that never sets the var is completely unaffected.
|
||||
+ if [ -n "$RK_BOOTARGS_EXTRA" ]; then
|
||||
+ SYS_BOOTARGS="$SYS_BOOTARGS $RK_BOOTARGS_EXTRA"
|
||||
+ fi
|
||||
}
|
||||
|
||||
__LINK_DEFCONFIG_FROM_BOARD_CFG() {
|
||||
@@ -1,403 +0,0 @@
|
||||
Recovery partitions and the recovery ramdisk, in project/.
|
||||
|
||||
The BoardConfig hunks that used to head this patch were removed: patch 0001
|
||||
carries that file's whole delta, and both patches adding RK_BOOTARGS_EXTRA at
|
||||
the same line meant the two could never apply in sequence. What is left here is
|
||||
the part 0001 does not cover.
|
||||
|
||||
--- a/project/build.sh
|
||||
+++ b/project/build.sh
|
||||
@@ -1826,7 +1826,18 @@
|
||||
root_dev=\$(mountpoint -n /)
|
||||
root_dev=\${root_dev%% *}
|
||||
partname=\$1
|
||||
-part_dev=/dev/block/by-name/\$1
|
||||
+# flare-edge A/B: a slotted partition name resolves against the slot U-Boot
|
||||
+# actually booted (warden.slot on the cmdline), so /oem always matches the
|
||||
+# running kernel's slot. Falls through unchanged on a non-A/B image.
|
||||
+case "\$partname" in
|
||||
+ *_a|*_b)
|
||||
+ wslot=\$(sed -n 's/.*warden\.slot=\(_[ab]\).*/\1/p' /proc/cmdline)
|
||||
+ if [ -n "\$wslot" ]; then
|
||||
+ partname="\${partname%_[ab]}\$wslot"
|
||||
+ fi
|
||||
+ ;;
|
||||
+esac
|
||||
+part_dev=/dev/block/by-name/\$partname
|
||||
mountpt=\$2
|
||||
part_fstype=\$3
|
||||
part_realdev=\$(realpath \$part_dev)
|
||||
diff --git a/project/scripts/RkLunch-recovery.sh b/project/scripts/RkLunch-recovery.sh
|
||||
index 92c33ac29..9c5160b5f 100755
|
||||
--- a/project/scripts/RkLunch-recovery.sh
|
||||
+++ b/project/scripts/RkLunch-recovery.sh
|
||||
@@ -1,115 +1,270 @@
|
||||
#!/bin/sh
|
||||
+# WardenOS rescue image — runs as the recovery initramfs' RkLunch.sh.
|
||||
+#
|
||||
+# The rescue's ONE job (fota spec §8.2): become reachable and let a human
|
||||
+# recover the device. It is entered when both A/B slots are exhausted, or on
|
||||
+# a BCB 'boot-recovery' command. It restores nothing on its own initiative —
|
||||
+# a technician (or the ops team over the network) drives recovery with the
|
||||
+# helpers this script lays down in /usr/bin. Runbook:
|
||||
+# flare-edge docs/recovery-runbook.md.
|
||||
+#
|
||||
+# Two access paths, both authenticated (getty/telnetd via /bin/login against the
|
||||
+# pinned root credential), kept up together:
|
||||
+# 1. PRIMARY: a CDC-ACM serial console over USB (host opens /dev/ttyACM0). No
|
||||
+# IP — this is the reliable floor that survives the RNDIS usb0 flakiness (#26).
|
||||
+# 2. SECONDARY (network, for bulk image staging): usb0 RNDIS (172.32.0.93/16),
|
||||
+# plus eth0 DHCP -> /userdata/warden/rescue-net static -> link-local
|
||||
+# 169.254.86.86/16, with telnetd on top.
|
||||
+# The 'boot-recovery' BCB is cleared on entry so a failed rescue reboots to
|
||||
+# normal instead of looping.
|
||||
+#
|
||||
+# Source of truth: flare-edge sdk-patches/board/ — edit there, not in a
|
||||
+# built image.
|
||||
|
||||
-SD_DEVICES="mmcblk1 mmcblk2"
|
||||
-DEV_NAME=""
|
||||
-MOUNT_PATH=""
|
||||
-UPDATE_PACKAGE=""
|
||||
-UPDATE_OTA_DIR_PATH=""
|
||||
-delay_time=""
|
||||
-input_file="$1"
|
||||
-input_path="$2"
|
||||
+echo "==== WardenOS rescue image ===="
|
||||
+cat /proc/cmdline
|
||||
|
||||
-sleep 1
|
||||
-echo "Ready to update."
|
||||
+# S15linkmount_recovery already ran linkdev + mounted /userdata (if intact).
|
||||
+mkdir -p /userdata 2>/dev/null
|
||||
+mountpoint -q /userdata || mount /dev/block/by-name/userdata /userdata 2>/dev/null
|
||||
|
||||
-# Use the specified update package in preference.
|
||||
-if [ -f "$input_file" ]; then
|
||||
- UPDATE_PACKAGE=$(realpath $input_file)
|
||||
- UPDATE_OTA_DIR_PATH=$(dirname $UPDATE_PACKAGE)/update
|
||||
- [ -d "$input_path" ] && UPDATE_OTA_DIR_PATH="$input_path/update"
|
||||
+# ONE-SHOT recovery: clear the 'boot-recovery' BCB command (misc @16384) right
|
||||
+# now, so even if this rescue boot goes wrong (unreachable, wedged), a plain
|
||||
+# power-cycle returns to NORMAL boot instead of looping in recovery. The A/B
|
||||
+# slot metadata (misc @2048) is left untouched — this touches only the BCB
|
||||
+# command field. (If recovery was entered via exhausted slots rather than a BCB
|
||||
+# command there is nothing to clear; harmless.) This is the safety net that
|
||||
+# turns a failed rescue from a stranding into a reboot.
|
||||
+_MISC=$(realpath /dev/block/by-name/misc 2>/dev/null)
|
||||
+[ -n "$_MISC" ] && (
|
||||
+ # Backgrounded on purpose: a conv=fsync write to a degraded eMMC (a plausible
|
||||
+ # state on a device that needed recovery) can block in uninterruptible sleep
|
||||
+ # for the block layer's whole command-timeout/retry chain. Do NOT stall the
|
||||
+ # access paths below (ACM console / RNDIS / telnet) waiting on it — one-shot
|
||||
+ # only needs the BCB cleared before the NEXT reboot, and the rescue session
|
||||
+ # outlives a slow write. Report honestly if the write fails.
|
||||
+ if dd if=/dev/zero of="$_MISC" bs=1 seek=16384 count=32 \
|
||||
+ conv=notrunc,fsync 2>/dev/null && sync; then
|
||||
+ echo "rescue: boot-recovery BCB cleared (recovery is one-shot)"
|
||||
+ else
|
||||
+ echo "rescue: WARNING boot-recovery BCB clear FAILED — recovery may re-trigger next boot"
|
||||
+ fi
|
||||
+) &
|
||||
+
|
||||
+# ---- USB gadget: reachable over the same USB port as the main system, NO
|
||||
+# Ethernet cable / disassembly. A COMPOSITE gadget exposing TWO functions:
|
||||
+# - acm.gs0 (CDC-ACM serial): the RELIABLE console. The host just opens
|
||||
+# /dev/ttyACM0 — no netdev, no IP negotiation, none of the RNDIS
|
||||
+# usb0-netdev/IP race that left a rescue boot unreachable (#26). getty
|
||||
+# on /dev/ttyGS0 (below) gives an authenticated login over it.
|
||||
+# - rndis.gs0 (network at 172.32.0.93/16): the BULK path (staging images
|
||||
+# for rescue-restore). Best-effort — when it comes up, telnet works too.
|
||||
+# All built-in (USB_LIBCOMPOSITE / USB_F_ACM / USB_F_RNDIS / USB_CONFIGFS_* /
|
||||
+# USB_DWC3) on the built-in DWC3 UDC (ffb00000.usb).
|
||||
+setup_usb_gadget() {
|
||||
+ CFG=/sys/kernel/config
|
||||
+ mkdir -p $CFG 2>/dev/null
|
||||
+ mount -t configfs none $CFG 2>/dev/null
|
||||
+ G=$CFG/usb_gadget/rescue
|
||||
+ [ -d "$G" ] && return 0
|
||||
+ mkdir -p "$G" 2>/dev/null || return 1
|
||||
+ echo 0x2207 > "$G/idVendor" 2>/dev/null
|
||||
+ echo 0x0019 > "$G/idProduct" 2>/dev/null
|
||||
+ mkdir -p "$G/strings/0x409" 2>/dev/null
|
||||
+ echo "rescue" > "$G/strings/0x409/serialnumber" 2>/dev/null
|
||||
+ echo "BlueFlare" > "$G/strings/0x409/manufacturer" 2>/dev/null
|
||||
+ echo "Warden Rescue" > "$G/strings/0x409/product" 2>/dev/null
|
||||
+ # acm FIRST so the serial console is the primary interface; rndis second.
|
||||
+ mkdir -p "$G/functions/acm.gs0" 2>/dev/null
|
||||
+ mkdir -p "$G/functions/rndis.gs0" 2>/dev/null
|
||||
+ mkdir -p "$G/configs/b.1/strings/0x409" 2>/dev/null
|
||||
+ echo "rescue-acm+rndis" > "$G/configs/b.1/strings/0x409/configuration" 2>/dev/null
|
||||
+ ln -s "$G/functions/acm.gs0" "$G/configs/b.1/" 2>/dev/null
|
||||
+ ln -s "$G/functions/rndis.gs0" "$G/configs/b.1/" 2>/dev/null
|
||||
+ udc=$(ls /sys/class/udc/ 2>/dev/null | head -1)
|
||||
+ [ -n "$udc" ] && echo "$udc" > "$G/UDC" 2>/dev/null
|
||||
+ # ttyGS0 (the ACM console) appears the instant the gadget binds — no netdev,
|
||||
+ # so no race; the getty respawn below just waits for it. The RNDIS usb0
|
||||
+ # netdev is created ASYNCHRONOUSLY and is best-effort (its flakiness, #26, is
|
||||
+ # exactly why the ACM console exists). Poll for it and set the static IP.
|
||||
+ i=0
|
||||
+ while [ $i -lt 20 ]; do
|
||||
+ [ -e /sys/class/net/usb0 ] && break
|
||||
+ sleep 1; i=$((i + 1))
|
||||
+ done
|
||||
+ if [ -e /sys/class/net/usb0 ]; then
|
||||
+ ip link set usb0 up 2>/dev/null
|
||||
+ ip addr add 172.32.0.93/16 dev usb0 2>/dev/null
|
||||
+ echo "rescue: usb0 RNDIS up at 172.32.0.93 (UDC $udc, waited ${i}s)"
|
||||
+ else
|
||||
+ echo "rescue: usb0 netdev never appeared (UDC $udc) — use the /dev/ttyACM0 serial console"
|
||||
+ fi
|
||||
+}
|
||||
+setup_usb_gadget &
|
||||
|
||||
- echo "Update package: $UPDATE_PACKAGE"
|
||||
- mkdir -p $UPDATE_OTA_DIR_PATH
|
||||
- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH
|
||||
- if [ $? -ne 0 ]; then
|
||||
- echo "Error: Decompression failed, please check the update package(tar)."
|
||||
- exit 1
|
||||
- fi
|
||||
+# ---- network up ----
|
||||
+ip link set lo up 2>/dev/null
|
||||
+if ip link set eth0 up 2>/dev/null; then
|
||||
+ # DHCP in the background; static/link-local addresses coexist with it.
|
||||
+ udhcpc -i eth0 -b -t 10 -T 3 2>/dev/null &
|
||||
|
||||
- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh
|
||||
- if [ $? -eq 0 ]; then
|
||||
- echo "Upgrade successfully."
|
||||
- rm -rf $UPDATE_OTA_DIR_PATH
|
||||
- reboot
|
||||
- return
|
||||
- else
|
||||
- echo "Error: Upgrade failed, please check the partition."
|
||||
- rm -rf $UPDATE_OTA_DIR_PATH
|
||||
- exit 1
|
||||
- fi
|
||||
-else
|
||||
- echo "Warning: Update package ($1) was not found, checking SD card..."
|
||||
+ NETCFG=/userdata/warden/rescue-net
|
||||
+ if [ -r "$NETCFG" ]; then
|
||||
+ # PARSE strictly as ip=<cidr> / gw=<addr> — do NOT dot-source. `.`ing this
|
||||
+ # file would EXECUTE it as root: /userdata is writable, so a prior
|
||||
+ # compromise (or any file-write bug) could plant arbitrary shell that runs
|
||||
+ # on every rescue entry, before the telnet credential-pin below, defeating
|
||||
+ # it entirely. Restrict values to IP/CIDR characters.
|
||||
+ ip=$(sed -n 's/^ip=\([0-9./]\{1,32\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1)
|
||||
+ gw=$(sed -n 's/^gw=\([0-9.]\{1,15\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1)
|
||||
+ [ -n "$ip" ] && ip addr add "$ip" dev eth0 2>/dev/null
|
||||
+ [ -n "$gw" ] && ip route add default via "$gw" 2>/dev/null
|
||||
+ fi
|
||||
+
|
||||
+ # Link-local last resort — a technician with a laptop and a cable can
|
||||
+ # always reach 169.254.86.86.
|
||||
+ ip addr add 169.254.86.86/16 dev eth0 2>/dev/null
|
||||
fi
|
||||
|
||||
-# Check SD card when not input update package path.
|
||||
-for DEV_NAME in $SD_DEVICES
|
||||
-do
|
||||
- echo "************** DEV_NAME=$DEV_NAME **************"
|
||||
- delay_time=1
|
||||
- mount | grep -i "$DEV_NAME"
|
||||
- if [ $? -eq 0 ]; then
|
||||
- MOUNT_PATH=`mount | grep -i "$DEV_NAME" | awk '{printf $3}'`
|
||||
- echo "SDcard is already mounted in $MOUNT_PATH"
|
||||
- else
|
||||
- MOUNT_PATH=/mnt/sdcard
|
||||
- fi
|
||||
+# WireGuard phone-home if the identity and a rescue peer config survive on
|
||||
+# /userdata (WireGuard is built into this kernel; wg tool if present).
|
||||
+WGCONF=/userdata/warden/rescue-wg.conf
|
||||
+if [ -r "$WGCONF" ] && command -v wg >/dev/null 2>&1; then
|
||||
+ ip link add wg0 type wireguard 2>/dev/null &&
|
||||
+ wg setconf wg0 "$WGCONF" 2>/dev/null &&
|
||||
+ ip link set wg0 up 2>/dev/null &&
|
||||
+ echo "rescue: wg0 up from $WGCONF"
|
||||
+fi
|
||||
|
||||
- while [ $delay_time -le 5 ]
|
||||
- do
|
||||
- usleep 200000
|
||||
- dev=$(ls /dev/$DEV_NAME*)
|
||||
- if [ -n "$dev" ]; then
|
||||
- echo Find the device: $dev
|
||||
- break 2
|
||||
- fi
|
||||
- echo "Find $DEV_NAME failed $delay_time times"
|
||||
- delay_time=$(($delay_time+1))
|
||||
- done
|
||||
-done
|
||||
+# ---- remote access ----
|
||||
+# Authenticated telnet. The recovery ramdisk ships busybox's skeleton
|
||||
+# /etc/shadow (root == the SDK-wide public default "rockchip"), so pin root to a
|
||||
+# known device credential and run telnetd THROUGH /bin/login. Do NOT use
|
||||
+# `telnetd -l /bin/sh`: that execs a root shell on connect with no password
|
||||
+# prompt (reachable over eth0/link-local/usb0), defeating the credential the
|
||||
+# runbook documents.
|
||||
+#
|
||||
+# Credential source, in order: (1) a per-device override on /userdata
|
||||
+# (rescue-shadow, a single "root:<hash>:..." line — the same runtime-override
|
||||
+# pattern as rescue-net/rescue-wg.conf, so production password rotation reaches
|
||||
+# the rescue), else (2) the compiled-in default password 'root'
|
||||
+# (openssl passwd -1 -salt wardenrs root; matches the main firmware).
|
||||
+DEFAULT_ROOT_LINE='root:$1$wardenrs$F.aYwbBz69WjSvwa3RNRF1:19664::::::'
|
||||
+ROOT_LINE=""
|
||||
+RESCUE_SHADOW=/userdata/warden/rescue-shadow
|
||||
+[ -r "$RESCUE_SHADOW" ] && ROOT_LINE=$(grep '^root:' "$RESCUE_SHADOW" 2>/dev/null | head -1)
|
||||
+[ -n "$ROOT_LINE" ] || ROOT_LINE="$DEFAULT_ROOT_LINE"
|
||||
+WANT_HASH=$(printf '%s' "$ROOT_LINE" | cut -d: -f2)
|
||||
|
||||
-if [ -z "$dev" ]; then
|
||||
- echo "Error: Not found device, skipping upgrade."
|
||||
- sh /usr/bin/RK_OTA_erase_misc.sh
|
||||
- [ $? -eq 0 ] && reboot
|
||||
- exit 1
|
||||
+if [ -f /etc/shadow ]; then
|
||||
+ grep -v '^root:' /etc/shadow > /etc/shadow.new 2>/dev/null
|
||||
+ { printf '%s\n' "$ROOT_LINE"; cat /etc/shadow.new; } > /etc/shadow
|
||||
+ rm -f /etc/shadow.new
|
||||
+ chmod 600 /etc/shadow 2>/dev/null
|
||||
fi
|
||||
|
||||
-mkdir -p $MOUNT_PATH
|
||||
-UPDATE_OTA_DIR_PATH=$MOUNT_PATH/update
|
||||
-UPDATE_PACKAGE=$MOUNT_PATH/update_ota.tar
|
||||
+# Fail CLOSED: expose access only if the intended root hash actually landed.
|
||||
+# Exposing a shell over the ramdisk's public 'rockchip' default would be worse
|
||||
+# than no access at all (recover via USB/MaskRom instead). Both the serial
|
||||
+# console (getty->login) and telnet (telnetd -l /bin/login) authenticate against
|
||||
+# this same pinned credential.
|
||||
+GOT_HASH=$(grep '^root:' /etc/shadow 2>/dev/null | head -1 | cut -d: -f2)
|
||||
+if [ -n "$WANT_HASH" ] && [ "$GOT_HASH" = "$WANT_HASH" ]; then
|
||||
+ # PRIMARY, always-reachable path: an authenticated login on the CDC-ACM
|
||||
+ # serial console. The host opens /dev/ttyACM0 (no IP). getty runs /bin/login;
|
||||
+ # the respawn loop waits for ttyGS0 (created when the acm gadget binds) and
|
||||
+ # re-runs getty after each logout, so the console is durable.
|
||||
+ ( while true; do
|
||||
+ [ -e /dev/ttyGS0 ] && getty -L 115200 ttyGS0 vt100
|
||||
+ sleep 1
|
||||
+ done ) &
|
||||
+ echo "rescue: serial console up on /dev/ttyGS0 (host: /dev/ttyACM0), authenticated"
|
||||
+ # SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up.
|
||||
+ telnetd -l /bin/login
|
||||
+ echo "rescue: telnetd up (authenticated: root / device password)"
|
||||
+else
|
||||
+ echo "rescue: root-credential pin FAILED — NO shell exposed; recover via USB/MaskRom"
|
||||
+fi
|
||||
|
||||
-for SD_DEV in $dev
|
||||
-do
|
||||
- echo "************** SD_DEV=$SD_DEV **************"
|
||||
- if mount -t vfat $SD_DEV $MOUNT_PATH ; then
|
||||
- if [ -f $UPDATE_PACKAGE ]; then
|
||||
- echo "Update package: $UPDATE_PACKAGE"
|
||||
- mkdir -p $UPDATE_OTA_DIR_PATH
|
||||
- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH
|
||||
- if [ $? -ne 0 ]; then
|
||||
- echo "Error: Decompression failed, please check the update package(tar)."
|
||||
- exit 1
|
||||
- fi
|
||||
+# ---- recovery helpers ----
|
||||
+cat >/usr/bin/rescue-status <<'HLP'
|
||||
+#!/bin/sh
|
||||
+echo "== slots (misc AB metadata @2048) =="
|
||||
+MISC=$(realpath /dev/block/by-name/misc)
|
||||
+dd if=$MISC bs=1 skip=2048 count=32 2>/dev/null | hexdump -C
|
||||
+echo "== partitions =="
|
||||
+ls -l /dev/block/by-name/
|
||||
+echo "== staged images (if any) =="
|
||||
+ls -l /userdata/warden/rescue/ 2>/dev/null || echo none
|
||||
+HLP
|
||||
+chmod +x /usr/bin/rescue-status
|
||||
|
||||
- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh
|
||||
- if [ $? -eq 0 ]; then
|
||||
- echo "Upgrade successfully."
|
||||
- rm -rf $UPDATE_OTA_DIR_PATH
|
||||
- reboot
|
||||
- return
|
||||
- else
|
||||
- echo "Error: Upgrade failed, please check the partition."
|
||||
- rm -rf $UPDATE_OTA_DIR_PATH
|
||||
- exit 1
|
||||
- fi
|
||||
- else
|
||||
- echo "Warning: Not found update package: $UPDATE_PACKAGE"
|
||||
- fi
|
||||
- umount $MOUNT_PATH
|
||||
- fi
|
||||
+cat >/usr/bin/rescue-slot-reset <<'HLP'
|
||||
+#!/bin/sh
|
||||
+# Reset A/B metadata to provision defaults (A 15/0/1 preferred, B 14/0/1) —
|
||||
+# use after restoring slot images. Bytes generated by (and kept in sync
|
||||
+# with) flare-edge tools/mk-misc.py; CRC32-BE over the first 28 bytes.
|
||||
+set -e
|
||||
+MISC=$(realpath /dev/block/by-name/misc)
|
||||
+printf '\x00\x41\x42\x30\x01\x00\x00\x00\x0f\x00\x01\x00\x0e\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x93\x36\x79' >/tmp/absector
|
||||
+dd if=/tmp/absector of=$MISC bs=1 seek=2048 conv=notrunc,fsync 2>/dev/null
|
||||
+sync
|
||||
+echo "slot metadata reset to provision defaults"
|
||||
+HLP
|
||||
+chmod +x /usr/bin/rescue-slot-reset
|
||||
+
|
||||
+cat >/usr/bin/rescue-restore <<'HLP'
|
||||
+#!/bin/sh
|
||||
+# rescue-restore: write staged images from /userdata/warden/rescue/ onto BOTH
|
||||
+# slots, reset the A/B metadata to provision defaults, reboot.
|
||||
+# Stage boot.img / oem.img / rootfs.img there first (over the rescue
|
||||
+# network), then run this.
|
||||
+#
|
||||
+# `rescue-restore wipe-config` ALSO clears the /userdata rescue overrides
|
||||
+# (rescue-shadow / rescue-net / rescue-wg.conf). A plain restore preserves them
|
||||
+# (they survive reflash by design), but a planted rescue-shadow backdoor or a
|
||||
+# rogue rescue-wg peer would then outlive the reflash — so use wipe-config when
|
||||
+# recovering from a suspected COMPROMISE rather than a plain hardware fault.
|
||||
+set -e
|
||||
+if [ "$1" = "wipe-config" ]; then
|
||||
+ rm -f /userdata/warden/rescue-shadow /userdata/warden/rescue-net \
|
||||
+ /userdata/warden/rescue-wg.conf
|
||||
+ echo "rescue: cleared /userdata rescue overrides (compromise recovery)"
|
||||
+fi
|
||||
+D=/userdata/warden/rescue
|
||||
+for img in boot oem rootfs; do
|
||||
+ [ -r "$D/$img.img" ] || { echo "missing $D/$img.img"; exit 1; }
|
||||
+done
|
||||
+for slot in _a _b; do
|
||||
+ for img in boot oem rootfs; do
|
||||
+ dev=$(realpath /dev/block/by-name/$img$slot)
|
||||
+ sz=$(wc -c < "$D/$img.img")
|
||||
+ echo "writing $img.img -> $dev ($sz bytes)"
|
||||
+ dd if="$D/$img.img" of="$dev" bs=1M conv=fsync
|
||||
+ sync
|
||||
+ # Read-back verify BEFORE the slot-reset below commits both slots as
|
||||
+ # successful. dd alone reports only its own write, not what landed
|
||||
+ # (bad USB stick, dropped transfer, eMMC glitch); writing a truncated
|
||||
+ # image and then stamping the slot "successful" is precisely how a
|
||||
+ # Level-1-recoverable device becomes a Level-2 (MaskRom-only) brick.
|
||||
+ # head -c stops the read at the image length, so this is cheap even for
|
||||
+ # the 1G rootfs (no byte-at-a-time dd).
|
||||
+ src_sum=$(md5sum "$D/$img.img" | cut -d' ' -f1)
|
||||
+ dev_sum=$(dd if="$dev" bs=1M 2>/dev/null | head -c "$sz" | md5sum | cut -d' ' -f1)
|
||||
+ if [ "$src_sum" != "$dev_sum" ]; then
|
||||
+ echo "VERIFY FAILED for $img$slot ($src_sum != $dev_sum)"
|
||||
+ echo "ABORTING: slots NOT committed; re-stage a good $img.img and retry."
|
||||
+ exit 2
|
||||
+ fi
|
||||
+ echo " verified $img$slot ($src_sum)"
|
||||
+ done
|
||||
done
|
||||
+rescue-slot-reset
|
||||
+echo "restore complete; rebooting"
|
||||
+sync
|
||||
+devmem 0xff3b0c08 32 0xfdb9 2>/dev/null || true
|
||||
+reboot -f
|
||||
+HLP
|
||||
+chmod +x /usr/bin/rescue-restore
|
||||
|
||||
-echo "Recovery upgrade failed, skipping."
|
||||
-sh /usr/bin/RK_OTA_erase_misc.sh
|
||||
-[ $? -eq 0 ] && reboot
|
||||
-exit 1
|
||||
+echo "==== rescue ready: telnet in; rescue-status / rescue-restore ===="
|
||||
@@ -1,18 +0,0 @@
|
||||
diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
index d29c2334b..b175b77fb 100755
|
||||
--- a/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
@@ -6,6 +6,13 @@
|
||||
# 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
|
||||
+# 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
|
||||
+
|
||||
UMS_EN=off
|
||||
ADB_EN=on
|
||||
MTP_EN=off
|
||||
@@ -1,22 +0,0 @@
|
||||
diff --git a/project/build.sh b/project/build.sh
|
||||
index 6fab501..6adbe35 100755
|
||||
--- a/project/build.sh
|
||||
+++ b/project/build.sh
|
||||
@@ -7,7 +7,7 @@ RECORD_IFS="$IFS"
|
||||
|
||||
function unset_env_config_rk() {
|
||||
local tmp_file=$(mktemp)
|
||||
- env | grep -oh "^RK_.*=" >$tmp_file || true
|
||||
+ env | grep -oh "^RK_[A-Za-z0-9_]*=" >$tmp_file || true
|
||||
source $tmp_file
|
||||
rm -f $tmp_file
|
||||
}
|
||||
@@ -383,7 +383,7 @@ function save_board_config() {
|
||||
|
||||
function unset_board_config_all() {
|
||||
local tmp_file=$(mktemp)
|
||||
- grep -oh "^export.*RK_.*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file
|
||||
+ grep -oh "^export RK_[A-Za-z0-9_]*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file
|
||||
source $tmp_file
|
||||
rm -f $tmp_file
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
Point the build at buildroot-2025.02.8.
|
||||
|
||||
The vendor SDK ships buildroot-2023.02.6 and build.sh pointed at it. The tree we
|
||||
actually build against is 2025.02.8, and nothing recorded the switch: a rebuild
|
||||
from a pristine vendor checkout plus this patch series silently produced a
|
||||
different userspace.
|
||||
|
||||
The 2.6 GB tree itself cannot live in this repo and is NOT in the vendor
|
||||
checkout either; obtaining it is covered by the SDK's build/vendor.manifest.
|
||||
This patch records only the one line that selects it.
|
||||
|
||||
--- a/project/build.sh
|
||||
+++ b/project/build.sh
|
||||
@@ -34,7 +34,7 @@
|
||||
GLOBAL_SDK_VERSION=""
|
||||
WIFI_NEW_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant_new.conf
|
||||
WIFI_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant.conf
|
||||
-BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6
|
||||
+BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2025.02.8
|
||||
BUILDROOT_CONFIG_FILE=${BUILDROOT_PATH}/.config
|
||||
SDK_CONFIG_DIR=${SDK_ROOT_DIR}/config
|
||||
DTS_CONFIG=${SDK_CONFIG_DIR}/dts_config
|
||||
@@ -1,60 +0,0 @@
|
||||
Authenticate the recovery console (#27).
|
||||
|
||||
The busybox tiny_rootfs skeleton runs `::respawn:-/bin/sh` on /dev/console,
|
||||
which on this board is ttyFIQ0, the debug UART. That is a root prompt with no
|
||||
login for anyone who opens the case, and it bypasses the fail-closed credential
|
||||
pin RkLunch-recovery.sh enforces for every other rescue path. The skeleton's own
|
||||
ttyFIQ0 getty line is commented out directly below it, so the bare shell was the
|
||||
only console and the unauthenticated one.
|
||||
|
||||
build.sh now deletes that line when it stages the ramdisk, and the recovery
|
||||
script spawns an authenticated getty on the console inside its gated block, so
|
||||
a failed pin exposes nothing on the UART either.
|
||||
|
||||
--- a/project/build.sh
|
||||
+++ b/project/build.sh
|
||||
@@ -956,6 +956,24 @@
|
||||
cp -fa $PROJECT_TOP_DIR/scripts/RkLunch-recovery.sh $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/usr/bin/RkLunch.sh
|
||||
cp -fa $PROJECT_TOP_DIR/scripts/boot4recovery.its $RK_PROJECT_PATH_RAMDISK
|
||||
|
||||
+ # flare-edge (#27): the busybox tiny_rootfs skeleton runs an
|
||||
+ # UNAUTHENTICATED root shell on /dev/console -- which on this board is
|
||||
+ # ttyFIQ0, the debug UART:
|
||||
+ #
|
||||
+ # ::respawn:-/bin/sh
|
||||
+ #
|
||||
+ # That hands a root prompt with no login to anyone who opens the case,
|
||||
+ # bypassing the fail-closed credential pin RkLunch-recovery.sh enforces for
|
||||
+ # every other rescue path (ttyGS0 getty, telnetd -l /bin/login). Note the
|
||||
+ # skeleton's own ttyFIQ0 getty line is commented out right below it, so the
|
||||
+ # bare shell was the only console -- and the unauthenticated one.
|
||||
+ #
|
||||
+ # Removed here; RkLunch-recovery.sh spawns an authenticated getty on the
|
||||
+ # console INSIDE its gated block instead, so the debug UART now answers to
|
||||
+ # the same pinned credential as everything else.
|
||||
+ sed -i '/^::respawn:-\/bin\/sh$/d' \
|
||||
+ $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/etc/inittab
|
||||
+
|
||||
mkdir -p $(dirname $RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT)
|
||||
cat >$RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT <<EOF
|
||||
#!/bin/sh
|
||||
--- a/project/scripts/RkLunch-recovery.sh
|
||||
+++ b/project/scripts/RkLunch-recovery.sh
|
||||
@@ -179,6 +179,17 @@
|
||||
sleep 1
|
||||
done ) &
|
||||
echo "rescue: serial console up on /dev/ttyGS0 (host: /dev/ttyACM0), authenticated"
|
||||
+ # The DEBUG UART (/dev/console -> ttyFIQ0). The ramdisk skeleton used to run
|
||||
+ # `::respawn:-/bin/sh` from its inittab here: a root shell with no login,
|
||||
+ # reachable by anyone who opened the case, bypassing this entire gate (#27).
|
||||
+ # project/build.sh now deletes that line, so the console is owned HERE and
|
||||
+ # authenticates against the same pinned credential as every other path.
|
||||
+ # Inside the gate, so a failed pin exposes nothing on the UART either.
|
||||
+ ( while true; do
|
||||
+ getty -L console 0 vt100
|
||||
+ sleep 1
|
||||
+ done ) &
|
||||
+ echo "rescue: debug-UART console up on /dev/console, authenticated"
|
||||
# SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up.
|
||||
telnetd -l /bin/login
|
||||
echo "rescue: telnetd up (authenticated: root / device password)"
|
||||
@@ -1,77 +0,0 @@
|
||||
flare-edge: compose the USB gadget once, instead of rebinding twice.
|
||||
|
||||
Every unbind/rebind of a live gadget is a full controller teardown; the
|
||||
host loses usb0 and ttyACM0 and the halt times out (issue #145).
|
||||
|
||||
--- a/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
@@ -17,7 +17,13 @@
|
||||
ADB_EN=on
|
||||
MTP_EN=off
|
||||
NTB_EN=off
|
||||
-ACM_EN=off
|
||||
+# flare-edge: composed here rather than linked afterwards by S52usbacm. Every
|
||||
+# unbind/rebind of a live gadget is a full teardown -- the host loses usb0 and
|
||||
+# ttyACM0, and the controller logs "Host halt failed, -110" on the way down --
|
||||
+# so the panel's console function is built into the gadget before it is ever
|
||||
+# bound (issue #145). S52usbacm still runs; it now finds acm already linked,
|
||||
+# skips its rebind, and only starts the ttyGS0 getty.
|
||||
+ACM_EN=on
|
||||
UAC1_EN=off
|
||||
UAC2_EN=off
|
||||
UVC_EN=off
|
||||
@@ -73,6 +79,46 @@
|
||||
mkdir ${USB_FUNCTIONS_DIR}/hid.usb0
|
||||
}
|
||||
|
||||
+# flare-edge: the stable, serial-derived RNDIS MAC. MUST be applied before
|
||||
+# bind_functions links rndis.gs0 into the config, NOT merely before the UDC
|
||||
+# bind: rndis_alloc() runs at link time, takes opts->refcnt and immediately
|
||||
+# captures the MAC via gether_get_host_addr_u8(). After that the configfs
|
||||
+# store returns -EBUSY (u_ether_configfs.h guards on opts->refcnt), so a write
|
||||
+# here is silently discarded and the gadget enumerates with the kernel's
|
||||
+# random MAC (issue #157).
|
||||
+#
|
||||
+# S51usbmac used to repair that afterwards by tearing down a live gadget purely
|
||||
+# to change two strings (issue #145), which is the second enumeration a host
|
||||
+# sees on every boot. It still runs and is now a no-op that confirms the result.
|
||||
+#
|
||||
+# The writes are checked. Losing the stable MAC is not fatal, so this does not
|
||||
+# abort the boot, but it must never fail silently again: silence is exactly how
|
||||
+# #157 survived.
|
||||
+flare_stamp_rndis_mac()
|
||||
+{
|
||||
+ RN=${USB_FUNCTIONS_DIR}/rndis.gs0
|
||||
+ [ -d "$RN" ] || return 0
|
||||
+ SER=$(tr -d '\000' < /proc/device-tree/serial-number 2>/dev/null)
|
||||
+ [ -n "$SER" ] || return 0
|
||||
+ H=$(printf '%s' "$SER" | md5sum | cut -c1-10)
|
||||
+ A=$(echo "$H" | cut -c1-2); B=$(echo "$H" | cut -c3-4)
|
||||
+ C=$(echo "$H" | cut -c5-6); D=$(echo "$H" | cut -c7-8)
|
||||
+ E=$(echo "$H" | cut -c9-10)
|
||||
+ WANT="02:$A:$B:$C:$D:$E"
|
||||
+ # Already ours: S26usbhost re-runs this script on a role switch, and the
|
||||
+ # second run finds configfs present, so configfs_init is skipped and the
|
||||
+ # function is still linked from the first run. The MAC was set correctly
|
||||
+ # then, so writing it again would be refused with -EBUSY and warn about a
|
||||
+ # random MAC that is not in use. Nothing to do, and nothing to report.
|
||||
+ [ "$(cat "$RN/host_addr" 2>/dev/null)" = "$WANT" ] && return 0
|
||||
+ if ! echo "$WANT" > "$RN/host_addr" 2>/dev/null; then
|
||||
+ echo "S50usbdevice: rndis host_addr write refused and the MAC is NOT already correct; the function is linked, so the gadget will use a random MAC (#157)" > /dev/kmsg 2>/dev/null
|
||||
+ return 1
|
||||
+ fi
|
||||
+ echo "06:$A:$B:$C:$D:$E" > "$RN/dev_addr" 2>/dev/null ||
|
||||
+ echo "S50usbdevice: rndis dev_addr write refused (#157)" > /dev/kmsg 2>/dev/null
|
||||
+}
|
||||
+
|
||||
configfs_init()
|
||||
{
|
||||
echo "Debug: configfs_init"
|
||||
@@ -426,6 +450,7 @@
|
||||
use_os_desc
|
||||
echo $PID > ${USB_CONFIGFS_DIR}/idProduct
|
||||
+ flare_stamp_rndis_mac
|
||||
bind_functions
|
||||
pre_run_binary
|
||||
sleep 1
|
||||
UDC=`ls /sys/class/udc/| awk '{print $1}'`
|
||||
@@ -1,76 +0,0 @@
|
||||
BR2_arm=y
|
||||
BR2_cortex_a7=y
|
||||
BR2_TOOLCHAIN_EXTERNAL=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf"
|
||||
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf"
|
||||
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_WCHAR=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_CXX=y
|
||||
BR2_PRIMARY_SITE="http://sources.buildroot.net"
|
||||
BR2_OPTIMIZE_3=y
|
||||
BR2_TARGET_GENERIC_HOSTNAME="luckfox pico"
|
||||
BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico"
|
||||
BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox"
|
||||
BR2_SYSTEM_ENABLE_NLS=y
|
||||
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
|
||||
BR2_PACKAGE_GZIP=y
|
||||
BR2_PACKAGE_P7ZIP=y
|
||||
BR2_PACKAGE_UNZIP=y
|
||||
BR2_PACKAGE_XZ=y
|
||||
BR2_PACKAGE_ZIP=y
|
||||
BR2_PACKAGE_E2FSPROGS=y
|
||||
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
|
||||
BR2_PACKAGE_EVTEST=y
|
||||
BR2_PACKAGE_PYTHON3=y
|
||||
BR2_PACKAGE_PYTHON3_SSL=y
|
||||
BR2_PACKAGE_PYTHON_AIOHTTP=y
|
||||
BR2_PACKAGE_PYTHON_CLICK=y
|
||||
BR2_PACKAGE_PYTHON_ITSDANGEROUS=y
|
||||
BR2_PACKAGE_PYTHON_JINJA2=y
|
||||
BR2_PACKAGE_PYTHON_PERIPHERY=y
|
||||
BR2_PACKAGE_PYTHON_PILLOW=y
|
||||
BR2_PACKAGE_PYTHON_SERIAL=y
|
||||
BR2_PACKAGE_PYTHON_SETUPTOOLS=y
|
||||
BR2_PACKAGE_PYTHON_SMBUS_CFFI=y
|
||||
BR2_PACKAGE_PYTHON_SPIDEV=y
|
||||
BR2_PACKAGE_PYTHON_WERKZEUG=y
|
||||
BR2_PACKAGE_CA_CERTIFICATES=y
|
||||
BR2_PACKAGE_GNUTLS=y
|
||||
BR2_PACKAGE_LIBMD=y
|
||||
BR2_PACKAGE_FREETYPE=y
|
||||
BR2_PACKAGE_LIBDRM=y
|
||||
BR2_PACKAGE_DTC=y
|
||||
BR2_PACKAGE_DTC_PROGRAMS=y
|
||||
BR2_PACKAGE_LIBV4L=y
|
||||
BR2_PACKAGE_LIBV4L_UTILS=y
|
||||
BR2_PACKAGE_LIBCURL=y
|
||||
BR2_PACKAGE_LIBCURL_CURL=y
|
||||
BR2_PACKAGE_LIBCURL_VERBOSE=y
|
||||
BR2_PACKAGE_LIBRSYNC=y
|
||||
BR2_PACKAGE_PCRE2=y
|
||||
BR2_PACKAGE_PCRE2_16=y
|
||||
BR2_PACKAGE_PCRE2_32=y
|
||||
BR2_PACKAGE_BMON=y
|
||||
BR2_PACKAGE_DHCPCD=y
|
||||
BR2_PACKAGE_IPERF=y
|
||||
BR2_PACKAGE_IPERF3=y
|
||||
BR2_PACKAGE_IPTABLES=y
|
||||
BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
|
||||
BR2_PACKAGE_IPTABLES_NFTABLES=y
|
||||
BR2_PACKAGE_LRZSZ=y
|
||||
BR2_PACKAGE_NTP=y
|
||||
BR2_PACKAGE_OPENSSH=y
|
||||
BR2_PACKAGE_RSYNC=y
|
||||
BR2_PACKAGE_SOCAT=y
|
||||
BR2_PACKAGE_WGET=y
|
||||
BR2_PACKAGE_BASH=y
|
||||
BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y
|
||||
BR2_PACKAGE_DIALOG=y
|
||||
BR2_PACKAGE_TIME=y
|
||||
BR2_PACKAGE_HTOP=y
|
||||
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
|
||||
BR2_PACKAGE_NANO=y
|
||||
BR2_PACKAGE_HOST_DTC=y
|
||||
@@ -1,113 +0,0 @@
|
||||
BR2_arm=y
|
||||
BR2_cortex_a7=y
|
||||
BR2_TOOLCHAIN_EXTERNAL=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf"
|
||||
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf"
|
||||
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_WCHAR=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y
|
||||
BR2_TOOLCHAIN_EXTERNAL_CXX=y
|
||||
BR2_PRIMARY_SITE="http://sources.buildroot.net"
|
||||
BR2_OPTIMIZE_3=y
|
||||
BR2_TARGET_GENERIC_HOSTNAME="luckfox pico"
|
||||
BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico"
|
||||
BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox"
|
||||
BR2_SYSTEM_ENABLE_NLS=y
|
||||
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
|
||||
BR2_PACKAGE_ALSA_UTILS=y
|
||||
BR2_PACKAGE_ALSA_UTILS_ALSACONF=y
|
||||
BR2_PACKAGE_ALSA_UTILS_ACONNECT=y
|
||||
BR2_PACKAGE_ALSA_UTILS_AMIXER=y
|
||||
BR2_PACKAGE_ALSA_UTILS_APLAY=y
|
||||
BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y
|
||||
BR2_PACKAGE_BLUEZ_ALSA=y
|
||||
BR2_PACKAGE_BLUEZ_ALSA_HCITOP=y
|
||||
BR2_PACKAGE_BLUEZ_ALSA_RFCOMM=y
|
||||
BR2_PACKAGE_FFMPEG_FFPLAY=y
|
||||
BR2_PACKAGE_FFMPEG_FFPROBE=y
|
||||
BR2_PACKAGE_FFMPEG_AVRESAMPLE=y
|
||||
BR2_PACKAGE_JACK2=y
|
||||
BR2_PACKAGE_JACK2_LEGACY=y
|
||||
BR2_PACKAGE_JACK2_DBUS=y
|
||||
BR2_PACKAGE_MADPLAY=y
|
||||
BR2_PACKAGE_MPV=y
|
||||
BR2_PACKAGE_PULSEAUDIO=y
|
||||
BR2_PACKAGE_SOX=y
|
||||
BR2_PACKAGE_GZIP=y
|
||||
BR2_PACKAGE_P7ZIP=y
|
||||
BR2_PACKAGE_UNZIP=y
|
||||
BR2_PACKAGE_XZ=y
|
||||
BR2_PACKAGE_ZIP=y
|
||||
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
|
||||
BR2_PACKAGE_SDL2_GFX=y
|
||||
BR2_PACKAGE_SDL2_IMAGE=y
|
||||
BR2_PACKAGE_SDL2_MIXER=y
|
||||
BR2_PACKAGE_SDL2_NET=y
|
||||
BR2_PACKAGE_SDL2_TTF=y
|
||||
BR2_PACKAGE_VULKAN_HEADERS=y
|
||||
BR2_PACKAGE_DBUS_CPP=y
|
||||
BR2_PACKAGE_DBUS_TRIGGERD=y
|
||||
BR2_PACKAGE_EVTEST=y
|
||||
BR2_PACKAGE_PYTHON3_SSL=y
|
||||
BR2_PACKAGE_PYTHON_AIOHTTP=y
|
||||
BR2_PACKAGE_PYTHON_CLICK=y
|
||||
BR2_PACKAGE_PYTHON_ITSDANGEROUS=y
|
||||
BR2_PACKAGE_PYTHON_JINJA2=y
|
||||
BR2_PACKAGE_PYTHON_PERIPHERY=y
|
||||
BR2_PACKAGE_PYTHON_PILLOW=y
|
||||
BR2_PACKAGE_PYTHON_SERIAL=y
|
||||
BR2_PACKAGE_PYTHON_SETUPTOOLS=y
|
||||
BR2_PACKAGE_PYTHON_SMBUS_CFFI=y
|
||||
BR2_PACKAGE_PYTHON_SPIDEV=y
|
||||
BR2_PACKAGE_PYTHON_WERKZEUG=y
|
||||
BR2_PACKAGE_LIBAO=y
|
||||
BR2_PACKAGE_PORTAUDIO=y
|
||||
BR2_PACKAGE_CA_CERTIFICATES=y
|
||||
BR2_PACKAGE_LIBDRM=y
|
||||
BR2_PACKAGE_DTC=y
|
||||
BR2_PACKAGE_DTC_PROGRAMS=y
|
||||
BR2_PACKAGE_LIBV4L=y
|
||||
BR2_PACKAGE_LIBV4L_UTILS=y
|
||||
BR2_PACKAGE_CJSON=y
|
||||
BR2_PACKAGE_CJSON_UTILS=y
|
||||
BR2_PACKAGE_LIBCURL=y
|
||||
BR2_PACKAGE_LIBCURL_CURL=y
|
||||
BR2_PACKAGE_LIBCURL_VERBOSE=y
|
||||
BR2_PACKAGE_LIBRSYNC=y
|
||||
BR2_PACKAGE_PCRE2=y
|
||||
BR2_PACKAGE_PCRE2_16=y
|
||||
BR2_PACKAGE_PCRE2_32=y
|
||||
BR2_PACKAGE_BLUEZ_TOOLS=y
|
||||
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
|
||||
BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y
|
||||
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
|
||||
BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y
|
||||
BR2_PACKAGE_BMON=y
|
||||
BR2_PACKAGE_DHCPCD=y
|
||||
BR2_PACKAGE_IPERF=y
|
||||
BR2_PACKAGE_IPERF3=y
|
||||
BR2_PACKAGE_IPTABLES=y
|
||||
BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
|
||||
BR2_PACKAGE_IPTABLES_NFTABLES=y
|
||||
BR2_PACKAGE_IW=y
|
||||
BR2_PACKAGE_LRZSZ=y
|
||||
BR2_PACKAGE_NTP=y
|
||||
BR2_PACKAGE_OPENSSH=y
|
||||
BR2_PACKAGE_PPPD=y
|
||||
BR2_PACKAGE_PPPD_FILTER=y
|
||||
BR2_PACKAGE_PPPD_RADIUS=y
|
||||
BR2_PACKAGE_RSYNC=y
|
||||
BR2_PACKAGE_SAMBA4=y
|
||||
BR2_PACKAGE_SOCAT=y
|
||||
BR2_PACKAGE_WGET=y
|
||||
BR2_PACKAGE_BASH=y
|
||||
BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y
|
||||
BR2_PACKAGE_DIALOG=y
|
||||
BR2_PACKAGE_TIME=y
|
||||
BR2_PACKAGE_HTOP=y
|
||||
BR2_PACKAGE_PROCPS_NG=y
|
||||
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
|
||||
BR2_PACKAGE_NANO=y
|
||||
BR2_PACKAGE_HOST_DTC=y
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
Add a minimal wordexp(3) for uClibc-ng, which the Rockchip toolchain
|
||||
builds without. BlueZ (bluetoothctl via src/shared/shell.c, and a few
|
||||
tools) includes <wordexp.h> unconditionally; DEFAULT_INCLUDES=-I. makes
|
||||
this top-level header resolve. WRDE_NOCMD is always passed, so a
|
||||
whitespace/quote tokenizer is a semantically complete substitute.
|
||||
|
||||
Signed-off-by: BlueFlare Warden <noah@wildrosemining.com>
|
||||
|
||||
diff --git a/wordexp.h b/wordexp.h
|
||||
new file mode 100644
|
||||
index 0000000..1111111
|
||||
--- /dev/null
|
||||
+++ b/wordexp.h
|
||||
@@ -0,0 +1,171 @@
|
||||
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
+/*
|
||||
+ * Minimal wordexp(3) for uClibc-ng.
|
||||
+ *
|
||||
+ * The Rockchip external toolchain's uClibc-ng is built without wordexp, so it
|
||||
+ * ships no <wordexp.h>. Several BlueZ sources (src/shared/shell.c, which is
|
||||
+ * bluetoothctl's command reader, plus a few tools) include <wordexp.h>
|
||||
+ * unconditionally and call wordexp()/wordfree(). They always pass WRDE_NOCMD
|
||||
+ * -- "no command substitution" -- and use the result only to split a command
|
||||
+ * line into words, so a whitespace/quote tokenizer is a semantically complete
|
||||
+ * substitute. This is deliberately NOT a general shell expander: no globbing,
|
||||
+ * no variable or command substitution (WRDE_NOCMD is precisely the request to
|
||||
+ * omit those). Placed at the BlueZ source root, where DEFAULT_INCLUDES = -I.
|
||||
+ * makes <wordexp.h> resolve to it.
|
||||
+ */
|
||||
+#ifndef _WORDEXP_H_
|
||||
+#define _WORDEXP_H_
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <ctype.h>
|
||||
+
|
||||
+#define WRDE_DOOFFS 0x0001
|
||||
+#define WRDE_APPEND 0x0002
|
||||
+#define WRDE_NOCMD 0x0004
|
||||
+#define WRDE_REUSE 0x0008
|
||||
+#define WRDE_SHOWERR 0x0010
|
||||
+#define WRDE_UNDEF 0x0020
|
||||
+
|
||||
+enum {
|
||||
+ WRDE_SUCCESS = 0,
|
||||
+ WRDE_NOSPACE = 1,
|
||||
+ WRDE_BADCHAR = 2,
|
||||
+ WRDE_BADVAL = 3,
|
||||
+ WRDE_CMDSUB = 4,
|
||||
+ WRDE_SYNTAX = 5,
|
||||
+};
|
||||
+
|
||||
+typedef struct {
|
||||
+ size_t we_wordc; /* number of words */
|
||||
+ char **we_wordv; /* NULL-terminated vector of words */
|
||||
+ size_t we_offs; /* reserved-slot count; also used as a scratch flag
|
||||
+ by shell.c, which never passes WRDE_DOOFFS */
|
||||
+} wordexp_t;
|
||||
+
|
||||
+__attribute__((unused))
|
||||
+static int wordexp(const char *words, wordexp_t *we, int flags)
|
||||
+{
|
||||
+ size_t n, i;
|
||||
+ char **vec;
|
||||
+ const char *p;
|
||||
+ int appending;
|
||||
+ size_t orig_n; /* we->we_wordc as of function entry, so a failure
|
||||
+ partway through a WRDE_APPEND call can put the
|
||||
+ vector back to exactly its pre-call length rather
|
||||
+ than leaving it part-grown or short a
|
||||
+ terminator */
|
||||
+
|
||||
+ if (words == NULL || we == NULL)
|
||||
+ return WRDE_BADCHAR;
|
||||
+
|
||||
+ appending = (flags & WRDE_APPEND) && we->we_wordv != NULL;
|
||||
+ if (appending) {
|
||||
+ n = we->we_wordc; /* append to the existing vector */
|
||||
+ vec = we->we_wordv;
|
||||
+ } else {
|
||||
+ n = 0;
|
||||
+ vec = calloc(1, sizeof(char *));
|
||||
+ if (vec == NULL)
|
||||
+ return WRDE_NOSPACE;
|
||||
+ }
|
||||
+ orig_n = n;
|
||||
+
|
||||
+ for (p = words; *p != '\0'; ) {
|
||||
+ size_t cap = 16, len = 0;
|
||||
+ char *w, *tw, **t;
|
||||
+
|
||||
+ while (*p != '\0' && isspace((unsigned char)*p))
|
||||
+ p++;
|
||||
+ if (*p == '\0')
|
||||
+ break;
|
||||
+
|
||||
+ w = malloc(cap);
|
||||
+ if (w == NULL)
|
||||
+ goto nospace;
|
||||
+
|
||||
+ while (*p != '\0' && !isspace((unsigned char)*p)) {
|
||||
+ char c;
|
||||
+
|
||||
+ if (*p == '\'' || *p == '"') {
|
||||
+ char q = *p++;
|
||||
+ while (*p != '\0' && *p != q) {
|
||||
+ if (len + 1 >= cap) {
|
||||
+ cap *= 2;
|
||||
+ tw = realloc(w, cap);
|
||||
+ if (tw == NULL) { free(w); goto nospace; }
|
||||
+ w = tw;
|
||||
+ }
|
||||
+ w[len++] = *p++;
|
||||
+ }
|
||||
+ if (*p == q)
|
||||
+ p++;
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (*p == '\\' && p[1] != '\0')
|
||||
+ p++;
|
||||
+ c = *p++;
|
||||
+ if (len + 1 >= cap) {
|
||||
+ cap *= 2;
|
||||
+ tw = realloc(w, cap);
|
||||
+ if (tw == NULL) { free(w); goto nospace; }
|
||||
+ w = tw;
|
||||
+ }
|
||||
+ w[len++] = c;
|
||||
+ }
|
||||
+ w[len] = '\0';
|
||||
+
|
||||
+ t = (char **)realloc(vec, (n + 2) * sizeof(char *));
|
||||
+ if (t == NULL) { free(w); goto nospace; }
|
||||
+ vec = t;
|
||||
+ vec[n++] = w;
|
||||
+ vec[n] = NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (n == 0)
|
||||
+ vec[0] = NULL; /* keep the vector NULL-terminated */
|
||||
+
|
||||
+ we->we_wordv = vec;
|
||||
+ we->we_wordc = n;
|
||||
+ return WRDE_SUCCESS;
|
||||
+
|
||||
+nospace:
|
||||
+ if (appending) {
|
||||
+ /* vec already carries every word from before this call --
|
||||
+ realloc() preserves existing contents whether it
|
||||
+ relocates the block. Only entries at orig_n and above are
|
||||
+ this call's own; free those and put the vector back to
|
||||
+ exactly its pre-call length. vec, not we->we_wordv, is what
|
||||
+ still points at that data: realloc() may already have
|
||||
+ relocated or freed the pointer we->we_wordv held on entry,
|
||||
+ which is exactly why the old cleanup here could free the
|
||||
+ caller's pre-existing words and leave we->we_wordv
|
||||
+ dangling. */
|
||||
+ for (i = orig_n; i < n; i++)
|
||||
+ free(vec[i]);
|
||||
+ vec[orig_n] = NULL;
|
||||
+ we->we_wordv = vec;
|
||||
+ we->we_wordc = orig_n;
|
||||
+ } else {
|
||||
+ for (i = 0; i < n; i++)
|
||||
+ free(vec[i]);
|
||||
+ free(vec);
|
||||
+ }
|
||||
+ return WRDE_NOSPACE;
|
||||
+}
|
||||
+
|
||||
+__attribute__((unused))
|
||||
+static void wordfree(wordexp_t *we)
|
||||
+{
|
||||
+ size_t i;
|
||||
+
|
||||
+ if (we == NULL || we->we_wordv == NULL)
|
||||
+ return;
|
||||
+ for (i = 0; i < we->we_wordc; i++)
|
||||
+ free(we->we_wordv[i]);
|
||||
+ free(we->we_wordv);
|
||||
+ we->we_wordv = NULL;
|
||||
+ we->we_wordc = 0;
|
||||
+}
|
||||
+
|
||||
+#endif /* _WORDEXP_H_ */
|
||||
@@ -1,84 +0,0 @@
|
||||
Bessel J1 for mpv's EWA/jinc scaler. The Rockchip external toolchain's
|
||||
uClibc-ng does not provide j1()/j0()/jn() -- confirmed absent from
|
||||
libuClibc-1.0.31.so in the arm-rockchip830-linux-uclibcgnueabihf sysroot
|
||||
this SDK builds against, the same gap the bluez5_utils wordexp patch in
|
||||
this series works around for a different function. jinc() (video/out/
|
||||
filter_kernels.c) scales its argument by M_PI before calling this, and
|
||||
mpv's --scale-radius is user-settable, so BesselJ1 has to be accurate
|
||||
over the whole double range a real j1() would cover, not just small
|
||||
arguments -- the version this replaces summed a fixed 11-term power
|
||||
series whose terms have not converged by the time n runs out for any
|
||||
x much past 6 or 7, and are off by 7+ orders of magnitude by x=20.
|
||||
|
||||
--- a/video/out/filter_kernels.c 2024-04-26 11:14:00.377199103 +0800
|
||||
+++ b/video/out/filter_kernels.c 2024-04-26 11:13:50.217202856 +0800
|
||||
@@ -32,6 +32,60 @@
|
||||
|
||||
// NOTE: all filters are designed for discrete convolution
|
||||
|
||||
+/*
|
||||
+ * mpv's libm on this target is uClibc-ng, which does not provide
|
||||
+ * j1()/j0()/jn() -- confirmed absent from libuClibc-1.0.31.so in the
|
||||
+ * arm-rockchip830-linux-uclibcgnueabihf sysroot this SDK builds
|
||||
+ * against. jinc() (below) scales its argument by M_PI before calling
|
||||
+ * this, and --scale-radius is user-settable, so this has to hold up
|
||||
+ * over the whole double range, not just small arguments.
|
||||
+ *
|
||||
+ * A plain power series is only exact up to about x=20 in double
|
||||
+ * precision: past that, terms grow before they shrink, and summing
|
||||
+ * large alternating terms loses precision to cancellation. So this
|
||||
+ * sums the series -- by a term-to-term ratio rather than separate
|
||||
+ * factorial()/power() calls, which also keeps it from overflowing at
|
||||
+ * large n -- only while each new term is still negligible against the
|
||||
+ * running sum, and falls back to the standard second-order asymptotic
|
||||
+ * expansion for Bessel functions (Abramowitz & Stegun 9.2.5/9.2.6,
|
||||
+ * order 1) once x passes that point. Checked against libm's j1() on
|
||||
+ * the build host across x in [0, 5000]: max absolute error 5e-8, max
|
||||
+ * relative error 5e-5 away from J1's zero crossings, where any finite
|
||||
+ * error reads large against a reference near zero.
|
||||
+ */
|
||||
+static double warden_j1_series(double x)
|
||||
+{
|
||||
+ double half = x / 2.0;
|
||||
+ double term = half;
|
||||
+ double sum = term;
|
||||
+ double xsq = -(half * half);
|
||||
+ for (int n = 1; n < 80; n++) {
|
||||
+ term *= xsq / ((double)n * (double)(n + 1));
|
||||
+ sum += term;
|
||||
+ if (fabs(term) < 1e-18 * fabs(sum))
|
||||
+ break;
|
||||
+ }
|
||||
+ return sum;
|
||||
+}
|
||||
+
|
||||
+static double warden_j1_asymptotic(double x)
|
||||
+{
|
||||
+ double omega = x - 3.0 * M_PI / 4.0;
|
||||
+ double x2 = x * x;
|
||||
+ double p = 1.0 + 15.0 / (128.0 * x2) - 4725.0 / (32768.0 * x2 * x2);
|
||||
+ double q = 3.0 / (8.0 * x) - 105.0 / (1024.0 * x2 * x)
|
||||
+ + 363825.0 / (1310720.0 * x2 * x2 * x);
|
||||
+ return sqrt(2.0 / (M_PI * x)) * (p * cos(omega) - q * sin(omega));
|
||||
+}
|
||||
+
|
||||
+static double BesselJ1(double x)
|
||||
+{
|
||||
+ int neg = x < 0;
|
||||
+ double ax = fabs(x);
|
||||
+ double r = (ax < 12.0) ? warden_j1_series(ax) : warden_j1_asymptotic(ax);
|
||||
+ return neg ? -r : r;
|
||||
+}
|
||||
+
|
||||
const struct filter_window *mp_find_filter_window(const char *name)
|
||||
{
|
||||
if (!name)
|
||||
@@ -324,7 +378,7 @@
|
||||
if (fabs(x) < 1e-8)
|
||||
return 1.0;
|
||||
x *= M_PI;
|
||||
- return 2.0 * j1(x) / x;
|
||||
+ return 2.0 * BesselJ1(x) / x;
|
||||
}
|
||||
|
||||
static double sphinx(params *p, double x)
|
||||
@@ -1,74 +0,0 @@
|
||||
The busybox applet set this image ships.
|
||||
|
||||
Not a preference: two things in the firmware depend on it directly.
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y is why `sleep 0.1` works in the init scripts, and
|
||||
`# CONFIG_TIMEOUT is not set` is why S09splash's touch probe cannot use
|
||||
timeout(1) and backgrounds a reader instead. It also builds telnetd in.
|
||||
|
||||
This file lived only in the vendor SDK's unpacked buildroot tree, which is not
|
||||
in the vendor checkout and not in any manifest, so none of that was recorded
|
||||
anywhere (#135).
|
||||
|
||||
--- a/package/busybox/busybox.config
|
||||
+++ b/package/busybox/busybox.config
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.36.1
|
||||
-# Wed May 8 17:25:31 2024
|
||||
+# Sat Dec 9 10:36:18 2023
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -782,7 +782,7 @@
|
||||
# CONFIG_FEATURE_CROND_D is not set
|
||||
# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
|
||||
CONFIG_FEATURE_CROND_SPECIAL_TIMES=y
|
||||
-CONFIG_FEATURE_CROND_DIR="/etc/cron"
|
||||
+CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
# CONFIG_DEVFSD is not set
|
||||
# CONFIG_DEVFSD_MODLOAD is not set
|
||||
@@ -835,7 +835,7 @@
|
||||
CONFIG_PARTPROBE=y
|
||||
# CONFIG_RAIDAUTORUN is not set
|
||||
# CONFIG_READAHEAD is not set
|
||||
-# CONFIG_RFKILL is not set
|
||||
+CONFIG_RFKILL=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
# CONFIG_RX is not set
|
||||
CONFIG_SEEDRNG=y
|
||||
@@ -968,18 +968,18 @@
|
||||
CONFIG_ROUTE=y
|
||||
# CONFIG_SLATTACH is not set
|
||||
# CONFIG_SSL_CLIENT is not set
|
||||
-# CONFIG_TC is not set
|
||||
-# CONFIG_FEATURE_TC_INGRESS is not set
|
||||
+CONFIG_TC=y
|
||||
+CONFIG_FEATURE_TC_INGRESS=y
|
||||
# CONFIG_TCPSVD is not set
|
||||
# CONFIG_UDPSVD is not set
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
CONFIG_FEATURE_TELNET_WIDTH=y
|
||||
-# CONFIG_TELNETD is not set
|
||||
-# CONFIG_FEATURE_TELNETD_STANDALONE is not set
|
||||
-CONFIG_FEATURE_TELNETD_PORT_DEFAULT=0
|
||||
-# CONFIG_FEATURE_TELNETD_INETD_WAIT is not set
|
||||
+CONFIG_TELNETD=y
|
||||
+CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
+CONFIG_FEATURE_TELNETD_PORT_DEFAULT=23
|
||||
+CONFIG_FEATURE_TELNETD_INETD_WAIT=y
|
||||
CONFIG_TFTP=y
|
||||
# CONFIG_FEATURE_TFTP_PROGRESS_BAR is not set
|
||||
CONFIG_FEATURE_TFTP_HPA_COMPAT=y
|
||||
@@ -1016,7 +1016,7 @@
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
|
||||
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
-CONFIG_UDHCPC6_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
+CONFIG_UDHCPC6_DEFAULT_SCRIPT=""
|
||||
# CONFIG_UDHCPC6 is not set
|
||||
# CONFIG_FEATURE_UDHCPC6_RFC3646 is not set
|
||||
# CONFIG_FEATURE_UDHCPC6_RFC4704 is not set
|
||||
@@ -1,9 +0,0 @@
|
||||
# flare-edge: build the PWM backlight driver in, not as a module.
|
||||
#
|
||||
# Building the PWM backlight as a module means its class device does not exist
|
||||
# until userspace insmods pwm_bl.ko (~3.3-3.7s, via S25backlight). The
|
||||
# U-Boot -> kernel drm_logo boot-splash handoff replaces its framebuffer
|
||||
# at almost exactly that same time, so there is effectively no window
|
||||
# where a backlight device exists AND the logo is still on screen.
|
||||
# Built-in makes the device exist from early kernel boot instead.
|
||||
CONFIG_BACKLIGHT_PWM=y
|
||||
@@ -1,104 +0,0 @@
|
||||
# flare-edge kernel config fragment
|
||||
#
|
||||
# Merged by the RK build: BoardConfig-...-86Panel-IPC.mk names this file in
|
||||
# the kernel fragment list (".mk:88"), and tools/build-firmware.sh's
|
||||
# copy_fragments step installs it into arch/arm/configs/ before the kernel
|
||||
# build. (It had, until now, existed ONLY as an untracked hand-edit in the SDK
|
||||
# working copy at arch/arm/configs/flare-edge.config -- the exact stale-copy
|
||||
# trap sdk-patches/ exists to close. This tracked form is authoritative.)
|
||||
|
||||
# --- kexec (SSH-side kernel swap, no flash writes) -------------------------
|
||||
# Enable kexec so a new kernel can be booted from a running SSH session
|
||||
# with zero writes to flash. The stock image has this stubbed out: all of
|
||||
# sys_kexec_load / sys_kexec_file_load / compat_sys_kexec_load resolve to
|
||||
# the same sys_ni_syscall address, so the syscall is absent.
|
||||
#
|
||||
# KEXEC depends on (!SMP || PM_SLEEP_SMP) && MMU. RV1106 is a single-core
|
||||
# Cortex-A7 and symmetric multiprocessing is disabled in the base defconfig,
|
||||
# so the dependency is satisfied.
|
||||
CONFIG_KEXEC=y
|
||||
|
||||
# --- RGA2 2D engine + CMA dma-buf heaps (graph-scroll offload) --------------
|
||||
# warden: enable the RV1106 RGA2 2D engine (/dev/rga) for graph-scroll offload.
|
||||
# Builtin (not =m) so devtmpfs auto-creates the node at boot; the rga2 DT node is
|
||||
# already status="okay" via rv1106-evb.dtsi, so no device-tree change is needed.
|
||||
CONFIG_ROCKCHIP_MULTI_RGA=y
|
||||
# Portable CMA dma-buf allocator (/dev/dma_heap/cma) for contiguous, RGA-safe
|
||||
# (no-IOMMU) graph canvas buffers; reuses the existing 10MB linux,cma pool.
|
||||
CONFIG_DMABUF_HEAPS=y
|
||||
CONFIG_DMABUF_HEAPS_CMA=y
|
||||
|
||||
# --- host-side USB-Ethernet class drivers (router mode adds a LAN port) ------
|
||||
# In router mode S26usbhost flips the OTG port to USB HOST so a USB-Ethernet
|
||||
# adapter enumerates as an extra network port. The stock defconfig ships
|
||||
# the USB network driver menu disabled, so even once the DTS dr_mode="otg" host
|
||||
# switch (sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch) brings xHCI
|
||||
# up, no ethN netdev would be created. Build these in (=y, not =m) so a NIC works
|
||||
# with zero userspace insmod, from early boot. Covers the common adapter silicon:
|
||||
# CDC-ECM/NCM (generic), ASIX AX88xxx (2.0 + gigabit), Realtek RTL8152/8153.
|
||||
# Trim to the adapters actually deployed if image size matters.
|
||||
CONFIG_USB_NET_DRIVERS=y
|
||||
CONFIG_USB_USBNET=y
|
||||
CONFIG_USB_NET_CDCETHER=y
|
||||
CONFIG_USB_NET_CDC_NCM=y
|
||||
CONFIG_USB_NET_AX8817X=y
|
||||
CONFIG_USB_NET_AX88179_178A=y
|
||||
CONFIG_USB_RTL8152=y
|
||||
|
||||
# --- WireGuard (FLARE management mesh) --------------------------------------
|
||||
# Kernel WireGuard is the chosen mesh transport (module + userspace `wg`, not
|
||||
# boringtun). The base luckfox_rv1106_linux_defconfig ALREADY builds it in
|
||||
# (built in at line ~212), and =y Kconfig-selects its crypto/UDP-tunnel
|
||||
# deps (CHACHA20POLY1305, CURVE25519, NET_UDP_TUNNEL), so nothing is missing and
|
||||
# no dep lines are needed here. We PIN =y (rather than the =m the task named, or
|
||||
# omitting it) so a future defconfig drift cannot silently drop the mesh
|
||||
# transport -- and so this fragment documents that WireGuard is a hard build
|
||||
# requirement. =y > =m here: no insmod, present from boot. Do NOT set =m: that
|
||||
# would DOWNGRADE the built-in to a module and merge_config would flag the
|
||||
# conflict.
|
||||
CONFIG_WIREGUARD=y
|
||||
|
||||
# --- 802.1Q VLAN (per-port router subnets, MikroTik switch termination) --------
|
||||
# router.c terminates each per-port subnet as an eth1.<vid> 802.1Q subinterface
|
||||
# (`ip link add link eth1 name eth1.<vid> type vlan id <vid>`), which needs 8021q
|
||||
# in the kernel; without it that call returns EOPNOTSUPP, so the VLAN config
|
||||
# screen + MikroTik app could program a switch the warden itself cannot route.
|
||||
#
|
||||
# ABI NOTE (root-caused on hardware 2026-08-13): enabling this inserts a
|
||||
# `struct vlan_info *vlan_info;` into `struct net_device`
|
||||
# (include/linux/netdevice.h, under the VLAN feature guard), which
|
||||
# shifts the offset of every field after it. The out-of-tree aic8800 wifi driver
|
||||
# and the modular cfg80211.ko MUST be rebuilt against this config or they read
|
||||
# net_device at stale offsets and NULL-deref at boot (crash in rwnx_interface_add
|
||||
# -> the "white logo" hang). A clean image build does this correctly:
|
||||
# build.sh kernel (mrproper -> clean VLAN kernel)
|
||||
# build.sh rootfs (rebuilds drv_ko/aic8800 + cfg80211.ko against that kernel)
|
||||
# build.sh firmware
|
||||
# so boot.img and the /oem modules always ship as a consistent set. NEVER flash a
|
||||
# VLAN boot.img over non-VLAN modules (that is what produced the hang during
|
||||
# incremental testing). =y (not =m): =m also flips IS_ENABLED, so it changes the
|
||||
# ABI identically while adding an insmod step for no benefit here.
|
||||
CONFIG_VLAN_8021Q=y
|
||||
|
||||
# --- pstore/ramoops: persistent crash/boot log across a reset -----------------
|
||||
# The debug UART is unwirable (under the daughterboard) and the USB CDC-ACM
|
||||
# console (S52usbacm) only comes up in userspace, so NEITHER can capture a
|
||||
# pre-userspace kernel hang -- which is exactly the class that bricked c8a3
|
||||
# (a load address in unreserved kernel RAM, hung before eth0). pstore/ramoops
|
||||
# keeps the kernel console ring + any oops/panic in a reserved DRAM region that
|
||||
# survives the reset (warm reset preserves DRAM), so the NEXT boot can read
|
||||
# /sys/fs/pstore and see the last words before the hang. Pairs with the already-
|
||||
# shipped `panic=10` cmdline + enabled watchdog (a hang -> reset -> log persists)
|
||||
# and the warden-flight recorder (which drains /sys/fs/pstore to /userdata, so
|
||||
# the log is also MaskRom-`dd`-recoverable off a brick).
|
||||
#
|
||||
# The DRAM region is carved by a `ramoops@0f000000` reserved-memory node
|
||||
# (sdk-patches/kernel/patches/0005-pstore-ramoops.patch): 1 MiB at 240 MiB, HIGH
|
||||
# above the low kernel/DTB/initrd load zone, so reserving it can only remove RAM
|
||||
# from the kernel -- it CANNOT recreate the c8a3 under-reservation collision.
|
||||
# console-size captures dmesg (the boot log); record-size captures oops/panic.
|
||||
CONFIG_PSTORE=y
|
||||
CONFIG_PSTORE_DEFLATE_COMPRESS=y
|
||||
CONFIG_PSTORE_CONSOLE=y
|
||||
CONFIG_PSTORE_PMSG=y
|
||||
CONFIG_PSTORE_RAM=y
|
||||
@@ -1,24 +0,0 @@
|
||||
# flare-edge: fbcon display policy -- keep OUR splash on screen, uninterrupted.
|
||||
#
|
||||
# Two separate problems, both fbcon, both fixed here.
|
||||
#
|
||||
# 1) The generic Linux logo option draws
|
||||
# drivers/video/logo/logo_linux_clut224.ppm whenever fbcon takes over a
|
||||
# framebuffer. This is NOT Rockchip's drm_logo handoff -- it is the
|
||||
# kernel's generic boot-logo feature, and the LuckFox SDK ships that file
|
||||
# replaced with their own fox-head + "LUCKFOX" wordmark. It painted over
|
||||
# our white BlueFlare logo on every boot.
|
||||
#
|
||||
# 2) The takeover itself. Even with no logo to draw, fbcon seizing the
|
||||
# framebuffer destroys the drm_logo image U-Boot handed us -- measured at
|
||||
# 1.895s, only 0.83s after the backlight came on at 1.068s, so the white
|
||||
# logo appeared as a brief flash and then the panel went blank until the
|
||||
# userspace colour splash. DEFERRED_TAKEOVER makes fbcon wait until
|
||||
# something actually writes text to the console before claiming the fb.
|
||||
# Our console is ttyFIQ0 (serial), so in practice nothing ever does, and
|
||||
# the U-Boot logo survives until S09splash draws over it deliberately.
|
||||
#
|
||||
# Deps for DEFERRED_TAKEOVER (FB=y, FRAMEBUFFER_CONSOLE, DUMMY_CONSOLE) are
|
||||
# all already satisfied in this defconfig -- verified before enabling.
|
||||
# CONFIG_LOGO is not set
|
||||
CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y
|
||||
@@ -1,82 +0,0 @@
|
||||
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
index 8c07a90d3..ece8d149f 100755
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
@@ -147,3 +158,77 @@ &uart4 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&uart4m0_xfer>;
|
||||
};
|
||||
+
|
||||
+/**********PANEL RESET + BACKLIGHT LINK**********/
|
||||
+/*
|
||||
+ * Restored from the FACTORY device tree (extracted from the stock boot.img of
|
||||
+ * this unit and diffed against current SDK HEAD, which had silently dropped
|
||||
+ * both properties). Without them the panel is never taken out of reset: DRM
|
||||
+ * sets 720x720@48.87Hz, the connector reports "connected", the VOP streams
|
||||
+ * pixels and the PWM backlight lights — but the panel controller is
|
||||
+ * unconfigured, so the screen stays black. Even a `modetest` test pattern is
|
||||
+ * invisible, which is what proved the fault sits BELOW DRM rather than in
|
||||
+ * fbdev or the app.
|
||||
+ *
|
||||
+ * gpio0 RK_PA1 is the same line U-Boot drives via `gpio set 1 1` when
|
||||
+ * CONFIG_LUCKFOX_EXECUTE_CMD is set (rv1106-luckfox-rgb-reset.config) — that
|
||||
+ * "Luckfox Pico RGB MCU reset" is the RGB panel's reset, not an LED.
|
||||
+ *
|
||||
+ * Factory values: reset-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>, reset-delay-ms = 200
|
||||
+ */
|
||||
+&panel {
|
||||
+ /*
|
||||
+ * flare-edge: backlight ONLY. reset-gpios and reset-delay-ms are
|
||||
+ * deliberately absent -- do not "restore" them.
|
||||
+ *
|
||||
+ * GPIO0_A1 is not the panel's reset. The schematic (U6 on
|
||||
+ * Luckfox-Pico-86-Panel.pdf) shows a WCH CH32V003 RISC-V MCU whose sole
|
||||
+ * job is to clock this panel's SPI init sequence into it, and the net
|
||||
+ * RGB_RES ties SoC GPIO0_A1, the panel RESET pin (FPC 6) and the MCU's
|
||||
+ * NRST (pin 1) together. Luckfox's own U-Boot comment says as much:
|
||||
+ * "Luckfox Pico RGB MCU reset gpio".
|
||||
+ *
|
||||
+ * So giving panel-simple this GPIO makes drm_panel_prepare() assert it
|
||||
+ * for reset-delay-ms and release it -- REBOOTING THE INIT MCU while the
|
||||
+ * VOP is already scanning pixels. The panel is then clocked with RGB
|
||||
+ * data before its power/gamma/VCOM registers are written, which is
|
||||
+ * exactly the faint coloured vertical banding seen for ~1-3 s on every
|
||||
+ * boot, and why a GPIO "reset" never cleared it (it re-ran the race).
|
||||
+ *
|
||||
+ * Luckfox removed these two properties in commit e2b0ffa22 for this
|
||||
+ * reason. An earlier revision of this file re-added them, having read
|
||||
+ * the deletion as an accidental regression -- see 40-kernel-stack.md,
|
||||
+ * which recorded them as "silently dropped" by SDK HEAD. They were not
|
||||
+ * dropped; they were the fix.
|
||||
+ *
|
||||
+ * The MCU is released exactly once, early, by U-Boot: board_init()
|
||||
+ * drives GPIO0_A1 high, and luckfox_execute_cmd() does the same again
|
||||
+ * harmlessly. At power-on the pin is input-with-pulldown, so the MCU is
|
||||
+ * held in reset until then, which is the intended sequencing.
|
||||
+ *
|
||||
+ * backlight is kept because U-Boot's rockchip_panel.c takes its
|
||||
+ * backlight handle from this node, and our boot logo needs it.
|
||||
+ */
|
||||
+ backlight = <&backlight>;
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * flare-edge: enable the U-Boot/kernel boot logo route.
|
||||
+ *
|
||||
+ * The whole RGB pipeline (display_subsystem, rgb, rgb_in_vop, vop) is already
|
||||
+ * "okay" in rv1106-luckfox-pico-86panel-ipc.dtsi, and that file also wires
|
||||
+ * logo-memory-region = <&drm_logo>. route_rgb was the only piece left
|
||||
+ * disabled, and without it U-Boot's rockchip_display finds no route and skips
|
||||
+ * drawing entirely.
|
||||
+ *
|
||||
+ * The node itself (rv1106.dtsi) already carries logo,uboot = "logo.bmp",
|
||||
+ * logo,kernel = "logo_kernel.bmp" and logo,mode = "center". Those files come
|
||||
+ * from resource.img, which scripts/mkmultidtb.py builds with
|
||||
+ * `resource_tool logo.bmp logo_kernel.bmp <dtbs>` out of the kernel source
|
||||
+ * directory -- so replacing sysdrv/source/kernel/logo.bmp is what changes the
|
||||
+ * splash. Setting logo,kernel to the same image keeps it on screen from
|
||||
+ * U-Boot through kernel handover until LVGL takes over.
|
||||
+ */
|
||||
+&route_rgb {
|
||||
+ status = "okay";
|
||||
+};
|
||||
@@ -1,28 +0,0 @@
|
||||
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
index 8c07a90d3..a9eb6c9d0 100755
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
@@ -114,6 +114,23 @@ &gmac {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
+/**********WATCHDOG (flare-edge: docs/firmware-update.md §6.6 item 4, §6.7)**********/
|
||||
+/*
|
||||
+ * flare-edge: enable the RV1106 designware watchdog.
|
||||
+ *
|
||||
+ * The kernel already builds CONFIG_DW_WATCHDOG, but rv1106.dtsi ships this
|
||||
+ * `wdt` node status = "disabled", so /dev/watchdog never appears. Once it is
|
||||
+ * "okay", warden-flared opens /dev/watchdog, sets a timeout (<= ~89 s on this
|
||||
+ * core) and pets it ONLY while the UI is proven live (ui_alive_fresh), after a
|
||||
+ * short unconditional boot grace. A post-boot hang then stops the pets, the SoC hard-resets,
|
||||
+ * and that reset is another boot U-Boot's bootcount sees -- so a wedged new
|
||||
+ * image converges to bootlimit -> altbootcmd -> recovery, exactly like a kernel
|
||||
+ * panic (docs §6.7). One line; needs a boot.img reflash.
|
||||
+ */
|
||||
+&wdt {
|
||||
+ status = "okay";
|
||||
+};
|
||||
+
|
||||
/**********USB**********/
|
||||
&usbdrd_dwc3 {
|
||||
status = "okay";
|
||||
@@ -1,28 +0,0 @@
|
||||
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
index 8c07a90d3..efc27c0b8 100755
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
@@ -117,8 +117,21 @@ &gmac {
|
||||
/**********USB**********/
|
||||
&usbdrd_dwc3 {
|
||||
status = "okay";
|
||||
- dr_mode = "peripheral";
|
||||
- //dr_mode = "host";
|
||||
+ /*
|
||||
+ * flare-edge: dual-role (OTG), not peripheral-only.
|
||||
+ *
|
||||
+ * router mode switches the port to USB HOST at runtime (S26usbhost writes
|
||||
+ * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates
|
||||
+ * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the
|
||||
+ * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the
|
||||
+ * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles
|
||||
+ * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime
|
||||
+ * host switch actually hosts. It still boots peripheral-by-default (ID floats
|
||||
+ * device until `host` asserts it), so the usb0 RNDIS recovery gadget that
|
||||
+ * client mode + net-flash rely on continues to bind. "host" alone would break
|
||||
+ * that recovery gadget, so "otg" is the correct value.
|
||||
+ */
|
||||
+ dr_mode = "otg";
|
||||
};
|
||||
|
||||
/**********RTC**********/
|
||||
@@ -1,26 +0,0 @@
|
||||
--- a/sysdrv/source/kernel/scripts/mkimg
|
||||
+++ b/sysdrv/source/kernel/scripts/mkimg
|
||||
@@ -51,6 +51,11 @@
|
||||
LOGO_KERNEL_PATH=${srctree}/logo_kernel.bmp
|
||||
[ -f ${LOGO_KERNEL_PATH} ] && LOGO_KERNEL=logo_kernel.bmp
|
||||
|
||||
+# flare-edge: USB-recovery splash, drawn by U-Boot's download path
|
||||
+# (cmd/download.c rockchip_show_bmp("logo_recovery.bmp"))
|
||||
+LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp
|
||||
+[ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp
|
||||
+
|
||||
KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image
|
||||
KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}"
|
||||
if [ "${ARCH}" == "arm" ]; then
|
||||
@@ -243,8 +248,9 @@
|
||||
cp -a ${LOGO_KERNEL_PATH} ${objtree}/;
|
||||
fi
|
||||
fi
|
||||
-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} >/dev/null
|
||||
-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL}) is ready"
|
||||
+[ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}"
|
||||
+scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null
|
||||
+echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready"
|
||||
|
||||
if [ -f "${BOOT_IMG}" ]; then
|
||||
if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then
|
||||
@@ -1,25 +0,0 @@
|
||||
--- a/sysdrv/source/kernel/scripts/mkimg
|
||||
+++ b/sysdrv/source/kernel/scripts/mkimg
|
||||
@@ -55,7 +55,10 @@
|
||||
# (cmd/download.c rockchip_show_bmp("logo_recovery.bmp"))
|
||||
LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp
|
||||
[ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp
|
||||
+# flare-edge: tapped verbose-boot acknowledgement, selected by U-Boot
|
||||
+LOGO_VERBOSE_PATH=${srctree}/logo_verbose.bmp
|
||||
+[ -f ${LOGO_VERBOSE_PATH} ] && LOGO_VERBOSE=logo_verbose.bmp
|
||||
|
||||
KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image
|
||||
KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}"
|
||||
if [ "${ARCH}" == "arm" ]; then
|
||||
@@ -248,8 +251,9 @@
|
||||
fi
|
||||
fi
|
||||
[ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}"
|
||||
-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null
|
||||
-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready"
|
||||
+[ -n "${LOGO_VERBOSE}" ] && cp -f "${LOGO_VERBOSE_PATH}" "${LOGO_VERBOSE}"
|
||||
+scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE} >/dev/null
|
||||
+echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE}) is ready"
|
||||
|
||||
if [ -f "${BOOT_IMG}" ]; then
|
||||
if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then
|
||||
@@ -1,32 +0,0 @@
|
||||
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
index f4e6fb77e..202710496 100755
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
@@ -108,6 +108,27 @@ linux,cma {
|
||||
mmc_ecsd: mmc@3f000 {
|
||||
reg = <0x3f000 0x00001000>;
|
||||
};
|
||||
+
|
||||
+ /*
|
||||
+ * flare-edge: pstore/ramoops persistent crash region. 1 MiB at
|
||||
+ * 240 MiB (of 256 MiB DRAM: reg = <0x0 0x10000000>). Placed HIGH,
|
||||
+ * far above the low kernel-image/DTB/initrd load zone, so this
|
||||
+ * carve-out can only REMOVE RAM from the kernel -- it cannot cause
|
||||
+ * the c8a3-class collision (which was an UN-reserved 0x40000 used
|
||||
+ * by both the boot MCU and the kernel). Kept below the very top of
|
||||
+ * DRAM (U-Boot self-relocates there) so the log is more likely to
|
||||
+ * survive into the recovery boot. console-size captures the kernel
|
||||
+ * console ring (the boot log before a hang); record-size captures
|
||||
+ * oops/panic. No ECC (no reed-solomon dep); no no-map (ramoops
|
||||
+ * memremaps the region itself). See kernel cfg flare-edge.config.
|
||||
+ */
|
||||
+ ramoops@0f000000 {
|
||||
+ compatible = "ramoops";
|
||||
+ reg = <0x0f000000 0x00100000>;
|
||||
+ console-size = <0x00040000>;
|
||||
+ record-size = <0x00020000>;
|
||||
+ pmsg-size = <0x00020000>;
|
||||
+ };
|
||||
};
|
||||
|
||||
acodec_sound: acodec-sound {
|
||||
@@ -1,23 +0,0 @@
|
||||
diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
index f4e6fb77e..dc08f6256 100755
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi
|
||||
@@ -302,3 +302,18 @@ tp_irq: tp-irq {
|
||||
};
|
||||
};
|
||||
};
|
||||
+
|
||||
+/*********************** on-demand MaskRom ************************/
|
||||
+/*
|
||||
+ * flare-edge: let the OS reach TRUE BootROM MaskRom (USB 2207:110c, reliably
|
||||
+ * flashable) via `warden-maskrom maskrom` -> reboot(RESTART2,"maskrom") ->
|
||||
+ * syscon-reboot-mode writes BOOT_BROM_DOWNLOAD to the boot-mode reg 0xff020200.
|
||||
+ * One-shot: a power-on-reset clears the PMU-domain reg. The stock
|
||||
+ * mode-loader/-bootloader only reach U-Boot rockusb "Loader" mode, whose WL is
|
||||
+ * unreliable for multi-partition flashing (writes report 100% but do not
|
||||
+ * persist); this reaches the BootROM proper, where db+wl are reliable.
|
||||
+ * 0xEF08A53C == U-Boot BOOT_BROM_DOWNLOAD (arch-rockchip/boot_mode.h).
|
||||
+ */
|
||||
+&reboot_mode {
|
||||
+ mode-maskrom = <0xEF08A53C>;
|
||||
+};
|
||||
@@ -1,55 +0,0 @@
|
||||
The panel DTS as the SDK actually has it.
|
||||
|
||||
Replaying patches 0001-0006 onto a pristine vendor tree did not reproduce this
|
||||
file: the board model string is "Luckfox Pico 86Panel W" in the SDK, and the
|
||||
watchdog block 0002 adds sits in a different place. Both were hand-edits made
|
||||
directly in the SDK checkout and never captured here, so a rebuild from a clean
|
||||
vendor tree plus this series produced a DTS that differed from the one every
|
||||
shipped image was built with.
|
||||
|
||||
This patch is the remainder, generated by diffing the replayed result against
|
||||
the live SDK. It has no intent of its own beyond making the series faithful.
|
||||
|
||||
--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
+++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <dt-bindings/display/media-bus-format.h>
|
||||
|
||||
/ {
|
||||
- model = "Luckfox Pico 86Panel";
|
||||
+ model = "Luckfox Pico 86Panel W";
|
||||
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106g3";
|
||||
|
||||
restart-poweroff {
|
||||
@@ -134,21 +134,17 @@
|
||||
/**********USB**********/
|
||||
&usbdrd_dwc3 {
|
||||
status = "okay";
|
||||
- /*
|
||||
- * flare-edge: dual-role (OTG), not peripheral-only.
|
||||
- *
|
||||
- * router mode switches the port to USB HOST at runtime (S26usbhost writes
|
||||
- * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates
|
||||
- * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the
|
||||
- * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the
|
||||
- * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles
|
||||
- * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime
|
||||
- * host switch actually hosts. It still boots peripheral-by-default (ID floats
|
||||
- * device until `host` asserts it), so the usb0 RNDIS recovery gadget that
|
||||
- * client mode + net-flash rely on continues to bind. "host" alone would break
|
||||
- * that recovery gadget, so "otg" is the correct value.
|
||||
- */
|
||||
+ /* otg, not host: CONFIG_USB_DWC3_DUAL_ROLE is built in, so the port can
|
||||
+ * still come up as a gadget (usb0) when cabled to a PC while also being
|
||||
+ * able to host a USB Ethernet adapter. host would work for the adapter
|
||||
+ * but would remove the gadget link permanently. */
|
||||
dr_mode = "otg";
|
||||
+ //dr_mode = "peripheral";
|
||||
+ //dr_mode = "host";
|
||||
+ /* flare-edge: set to otg for the host/client live-switch test — a stable
|
||||
+ * network path (onboard eth0) is now in hand, so the usb0-gadget-inconsistency
|
||||
+ * that motivated the earlier peripheral revert no longer blocks us. This
|
||||
+ * matches sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch. */
|
||||
};
|
||||
|
||||
/**********RTC**********/
|
||||
@@ -1,10 +0,0 @@
|
||||
# flare-edge: A/B slot boot in U-Boot proper.
|
||||
#
|
||||
# Lean port of the vendor SPL A/B engine (common/flare_ab.c): AOSP
|
||||
# AvbABData metadata in one CRC32-protected sector at misc+2048, slot
|
||||
# suffixing hooked into part_get_info_by_name() (covers boot_fit AND the
|
||||
# board_init()-time kernel-DTB/resource load), one tries decrement per
|
||||
# boot attempt while a slot is unconfirmed, recovery-FIT fallback when
|
||||
# both slots are exhausted, MaskRom when even that fails.
|
||||
# Design: docs/decisions/0001-slot-machine.md (flare-edge repo).
|
||||
CONFIG_FLARE_AB=y
|
||||
@@ -1,35 +0,0 @@
|
||||
# flare-edge: the env bootcount escalation layer is RETIRED.
|
||||
#
|
||||
# History: this fragment used to enable U-Boot's env bootcount
|
||||
# options: autoboot.c incremented a counter in the 32 KiB env on
|
||||
# every boot and, once it passed ${bootlimit}, ran ${altbootcmd}=download to
|
||||
# drop into USB download/MaskRom. Two properties made it dangerous:
|
||||
# 1. The counter lived in the env, so it PERSISTED across power cycles.
|
||||
# 2. It escalated to USB download, not to the recovery FIT.
|
||||
# A panel that lost power mid-boot several times therefore walked the counter
|
||||
# past the limit and then booted straight into the USB-download screen on EVERY
|
||||
# power-on, with no way to clear it from the device (issue #123, seen on a real
|
||||
# panel at the warehouse 2026-09-02).
|
||||
#
|
||||
# Replacement: the A/B engine (common/flare_ab.c) now drives boot-failure
|
||||
# escalation from a PMU register (OS_REG4), gated on the CRU reset-status
|
||||
# register. It survives a warm reset (so in-session retries accumulate) but is
|
||||
# cleared by a power-on reset, so escalation is: selected slot for a couple of
|
||||
# attempts, then the other committed slot, then the recovery FIT, then USB
|
||||
# download -- and a POWER CYCLE always restarts at the selected slot. flared
|
||||
# clears OS_REG4 once a boot proves healthy and before a deliberate reboot. No
|
||||
# per-boot flash writes, and no state that can strand a device across a power
|
||||
# cycle. See docs/boot-flow.md and docs/decisions/0001-slot-machine.md.
|
||||
#
|
||||
# The filename is kept so the board makefile fragment-list reference
|
||||
# (sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch) still resolves.
|
||||
# This fragment is merged last, so it disables bootcount and sets the env
|
||||
# whitelist authoritatively.
|
||||
# CONFIG_BOOTCOUNT is not set
|
||||
# CONFIG_BOOTCOUNT_LIMIT is not set
|
||||
# CONFIG_BOOTCOUNT_ENV is not set
|
||||
# Env whitelist WITHOUT the retired escalation keys (bootcount, bootlimit,
|
||||
# altbootcmd, upgrade_available) -- a stale env carrying them can no longer feed
|
||||
# the retired layer. bootcmd/bootdelay/preboot stay so a provisioned env can
|
||||
# still override the compiled-in boot command.
|
||||
CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr bootcmd bootdelay preboot"
|
||||
@@ -1,78 +0,0 @@
|
||||
# CONFIG_ATMEL_HLCD is not set
|
||||
# CONFIG_BACKLIGHT_GPIO is not set
|
||||
CONFIG_BACKLIGHT_PWM=y
|
||||
# CONFIG_CMD_BMP is not set
|
||||
# CONFIG_CMD_REGULATOR is not set
|
||||
CONFIG_CONSOLE_NORMAL=y
|
||||
# CONFIG_CONSOLE_ROTATION is not set
|
||||
CONFIG_CONSOLE_SCROLL_LINES=1
|
||||
# CONFIG_CONSOLE_TRUETYPE is not set
|
||||
CONFIG_DISPLAY=y
|
||||
CONFIG_DM_PWM=y
|
||||
# CONFIG_DM_REGULATOR_FIXED is not set
|
||||
# CONFIG_DM_REGULATOR_GPIO is not set
|
||||
CONFIG_DM_REGULATOR=y
|
||||
CONFIG_DM_VIDEO=y
|
||||
# CONFIG_DRM_MAXIM_MAX96745 is not set
|
||||
# CONFIG_DRM_MAXIM_MAX96752F is not set
|
||||
# CONFIG_DRM_MAXIM_MAX96755F is not set
|
||||
CONFIG_DRM_MEM_RESERVED_SIZE_MBYTES=32
|
||||
CONFIG_DRM_MIPI_DSI=y
|
||||
# CONFIG_DRM_PANEL_MAXIM_DESERIALIZER is not set
|
||||
# CONFIG_DRM_ROCKCHIP_ANALOGIX_DP is not set
|
||||
# CONFIG_DRM_ROCKCHIP_DW_DP is not set
|
||||
# CONFIG_DRM_ROCKCHIP_DW_HDMI is not set
|
||||
# CONFIG_DRM_ROCKCHIP_DW_HDMI_QP is not set
|
||||
# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI2 is not set
|
||||
# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI is not set
|
||||
# CONFIG_DRM_ROCKCHIP_INNO_HDMI is not set
|
||||
# CONFIG_DRM_ROCKCHIP_INNO_MIPI_PHY is not set
|
||||
# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_COMBO_PHY is not set
|
||||
# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_PHY is not set
|
||||
# CONFIG_DRM_ROCKCHIP_LVDS is not set
|
||||
CONFIG_DRM_ROCKCHIP_PANEL=y
|
||||
CONFIG_DRM_ROCKCHIP_RGB=y
|
||||
# CONFIG_DRM_ROCKCHIP_RK1000 is not set
|
||||
# CONFIG_DRM_ROCKCHIP_RK618 is not set
|
||||
# CONFIG_DRM_ROCKCHIP_SAMSUNG_MIPI_DCPHY is not set
|
||||
CONFIG_DRM_ROCKCHIP=y
|
||||
CONFIG_I2C_EDID=y
|
||||
# CONFIG_NOP_PHY is not set
|
||||
# CONFIG_PHY_ROCKCHIP_SAMSUNG_HDPTX_HDMI is not set
|
||||
CONFIG_PHY=y
|
||||
# CONFIG_PWM_EXYNOS is not set
|
||||
CONFIG_PWM_ROCKCHIP=y
|
||||
# CONFIG_PWM_TEGRA is not set
|
||||
# CONFIG_REGULATOR_FAN53555 is not set
|
||||
# CONFIG_REGULATOR_PWM is not set
|
||||
# CONFIG_REGULATOR_RK860X is not set
|
||||
CONFIG_ROCKCHIP_CUBIC_LUT_SIZE=0
|
||||
# CONFIG_DRM_ROCKCHIP_TVE is not set
|
||||
# CONFIG_ROCKCHIP_INNO_HDMI_PHY is not set
|
||||
# CONFIG_SPL_DM_REGULATOR is not set
|
||||
# CONFIG_VIDCONSOLE_AS_LCD is not set
|
||||
CONFIG_VIDEO_BPP16=y
|
||||
CONFIG_VIDEO_BPP32=y
|
||||
CONFIG_VIDEO_BPP8=y
|
||||
# CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345 is not set
|
||||
# CONFIG_VIDEO_BRIDGE_NXP_PTN3460 is not set
|
||||
# CONFIG_VIDEO_BRIDGE_PARADE_PS862X is not set
|
||||
CONFIG_VIDEO_BRIDGE=y
|
||||
# CONFIG_VIDEO_ROCKCHIP is not set
|
||||
# CONFIG_VIDEO_TEGRA124 is not set
|
||||
# flare-edge: BMP logo support for the boot splash. The rockchip_display logo
|
||||
# path accepts 16/24/32bpp (display_logo() in drivers/video/drm/rockchip_display.c);
|
||||
# our logo.bmp is 720x720 24bpp uncompressed, which matches the panel exactly.
|
||||
# flare-edge: keep USING_KERNEL_DTB=y (the proven flow: envf import, fixups),
|
||||
# but adopt an EMBEDDED kernel-style DTB instead of the booted slot's one. The
|
||||
# 6.18 slot's mainline-style DTB has no vendor display nodes, which silenced
|
||||
# the boot logo there; embedding the proven 5.10 board DTB (extracted from the
|
||||
# vendor-built boot.img resource) makes U-Boot's own device world -- display
|
||||
# included -- identical on every slot. Each slot's FIT still hands the real
|
||||
# kernel its own fdt; fdt_addr_r stays reserved for it (see kernel_dtb.c).
|
||||
# A DISABLED USING_KERNEL_DTB was tried first and broke the envf whitelist
|
||||
# import (no blkdevparts on the cmdline -> no eMMC partitions -> rootwait
|
||||
# hang on both slots); do not retry that route without fixing envf.
|
||||
CONFIG_EMBED_KERNEL_DTB=y
|
||||
CONFIG_EMBED_KERNEL_DTB_ALWAYS=y
|
||||
CONFIG_EMBED_KERNEL_DTB_PATH="dts/rv1106-warden-kernel.dtb"
|
||||
@@ -1,7 +0,0 @@
|
||||
# flare-edge: build spl_bootrom.o so BOOT_DEVICE_BOOTROM is a registered SPL
|
||||
# load method. Paired with the board_boot_order() change in
|
||||
# arch/arm/mach-rockchip/spl-boot-order.c, this makes a failed U-Boot load drop
|
||||
# to MaskRom instead of hanging. Does NOT set SPL_ROCKCHIP_BACK_TO_BROM: that
|
||||
# would flip SPL_MMC_SUPPORT off (see mach-rockchip/Kconfig) and hand the whole
|
||||
# load path to the BROM, which is a behaviour change we do not want.
|
||||
CONFIG_SPL_BOOTROM_SUPPORT=y
|
||||
@@ -1,12 +0,0 @@
|
||||
# flare-edge: let U-Boot read the panel's touchscreen.
|
||||
#
|
||||
# The verbose-boot choice is made in the bootloader (see
|
||||
# arch/arm/mach-rockchip/flare_touch.c), so it is on the kernel command line
|
||||
# before the kernel prints its first line. That needs I2C, which this board's
|
||||
# U-Boot did not have: only the EDID I2C helper was set, and that is the display
|
||||
# path's EDID parser, not a controller driver.
|
||||
#
|
||||
# The GT911 sits on i2c3 (i2c@ff460000). Both symbols are required: the
|
||||
# Rockchip controller driver depends on the DM I2C uclass.
|
||||
CONFIG_DM_I2C=y
|
||||
CONFIG_SYS_I2C_ROCKCHIP=y
|
||||
@@ -1,54 +0,0 @@
|
||||
# flare-edge: USB device-mode recovery from U-Boot (rockusb gadget).
|
||||
#
|
||||
# WHY: the BootROM only self-enters MaskRom when it cannot LOAD idblock/uboot.
|
||||
# A U-Boot that loads but then fails to boot (a bug in our display/FLARE_AB
|
||||
# code, an exhausted A/B set, a corrupt recovery FIT) never reaches Linux, so
|
||||
# the software MaskRom trigger and the rescue-image RNDIS gadget are both
|
||||
# unavailable, leaving only the daughterboard-blocked BOOT button. Enabling
|
||||
# the DWC3 USB gadget + rockusb closes that gap: `download` (which FLARE_AB and
|
||||
# altbootcmd already invoke on failure) runs `rockusb` FROM U-BOOT
|
||||
# (cmd/download.c), exposing the Rockchip flashing protocol on the existing USB
|
||||
# port (2207:110c, same as MaskRom to upgrade_tool). Recover or reflash without
|
||||
# opening the case. Falls through to `rbrom` (BootROM MaskRom) only if the
|
||||
# gadget can't start.
|
||||
#
|
||||
# RV1106 USB = DWC3 (rv1106.dtsi usb@ffb00000 snps,dwc3) + Innosilicon USB2
|
||||
# PHY, dr_mode=otg. Symbols below mirror the vendor rv1106-usb.config /
|
||||
# rv1106-dfu.config references. Fits the 512K uboot partition (A/B layout).
|
||||
CONFIG_USB=y
|
||||
CONFIG_DM_USB=y
|
||||
CONFIG_USB_DWC3=y
|
||||
CONFIG_USB_DWC3_GENERIC=y
|
||||
CONFIG_USB_DWC3_GADGET=y
|
||||
# dwc3-generic unconditionally compiles its host (xHCI) probe in non-SPL
|
||||
# builds (it calls xhci_register), so the xHCI host core must link even though
|
||||
# we only use gadget mode; the vendor rv1106-usb.config pairs them the same
|
||||
# way. Harmless in peripheral/otg mode; the host driver is simply never probed.
|
||||
CONFIG_USB_HOST=y
|
||||
CONFIG_USB_XHCI_HCD=y
|
||||
CONFIG_PHY_ROCKCHIP_INNO_USB2=y
|
||||
CONFIG_DM_REGULATOR=y
|
||||
CONFIG_DM_REGULATOR_FIXED=y
|
||||
CONFIG_USB_GADGET=y
|
||||
CONFIG_USB_GADGET_DUALSPEED=y
|
||||
CONFIG_USB_GADGET_DOWNLOAD=y
|
||||
# Fastboot is a separate download function whose FASTBOOT_BUF_ADDR symbol has
|
||||
# no default and would make `yes "" | make oldconfig` loop forever (it produced
|
||||
# a 16 GB log). We only want rockusb, so disable fastboot explicitly, exactly
|
||||
# as the vendor rv1106-dfu.config does. rockusb coexists fine without it.
|
||||
# CONFIG_FASTBOOT is not set
|
||||
CONFIG_USB_GADGET_MANUFACTURER="Rockchip"
|
||||
CONFIG_USB_GADGET_PRODUCT_NUM=0x110c
|
||||
CONFIG_USB_GADGET_VENDOR_NUM=0x2207
|
||||
CONFIG_USB_GADGET_VBUS_DRAW=2
|
||||
# rockusb has no dedicated Kconfig symbol. f_rockusb.c is #include'd by
|
||||
# f_mass_storage.c and gated purely by CMD_ROCKUSB + the UMS/gadget framework
|
||||
# (the mass-storage function, already defined in rv1106_common.h).
|
||||
CONFIG_CMD_ROCKUSB=y
|
||||
# The display stack + this USB gadget push uboot.itb past the old 256K limit
|
||||
# (287K). scripts/fit-core.sh uses SPL_FIT_IMAGE_KB as BOTH the pack ceiling
|
||||
# and how many KB SPL reads for the FIT. Raise it to 512 to match the A/B
|
||||
# layout's 512K `uboot` partition (docs/decisions/0003-partition-layout.md).
|
||||
# This is an SPL/idblock change (self-recovering to MaskRom if wrong), taken in
|
||||
# the same MaskRom re-provision as the repartition.
|
||||
CONFIG_SPL_FIT_IMAGE_KB=512
|
||||
@@ -1,12 +0,0 @@
|
||||
# flare-edge: boot instrumentation.
|
||||
#
|
||||
# Prefixes EVERY U-Boot console line with [ssss.uuuuuu] microseconds since
|
||||
# power-on, using the timestamping puts() that already exists in this Rockchip
|
||||
# fork (common/console.c, guarded by this symbol). Same time base as the
|
||||
# FLARE_TRACE macro and as Rockchip's own "Total: x/y ms" line, so U-Boot,
|
||||
# SPL and the kernel can all be put on one axis.
|
||||
#
|
||||
# Cost is ~15 characters per line. At 115200 baud that is ~1.3 ms per line, so
|
||||
# a verbose boot IS measurably slower than a production one -- read timings
|
||||
# from an instrumented boot as an upper bound, not as production numbers.
|
||||
CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y
|
||||
@@ -1,49 +0,0 @@
|
||||
# rv1106-warden-kernel.dtb -- provenance and regeneration
|
||||
|
||||
This binary is U-Boot's embedded control DTB (`CONFIG_EMBED_KERNEL_DTB_PATH`,
|
||||
set in `../configs/flare-display.config`). With `CONFIG_EMBED_KERNEL_DTB_ALWAYS`
|
||||
U-Boot adopts it in `board_init()` instead of reading the booted slot's DTB out
|
||||
of `resource`, so the display bring-up (boot logo included) is identical on
|
||||
every slot regardless of the slot kernel's own device tree.
|
||||
|
||||
## Where this exact blob came from
|
||||
|
||||
Extracted 2026-09-01 from the vendor-built 5.10 firmware image
|
||||
`sdk/output/image/boot.img` (build of 2026-08-24, WardenOS 0.3.x line): the
|
||||
`rk-kernel.dtb` entry of its `resource` sub-image, 73379 bytes, dtb magic
|
||||
`d00dfeed`. That is byte-for-byte the DTB U-Boot's display stack was proven
|
||||
against when it adopted the slot DTB directly.
|
||||
|
||||
## Regenerating after a kernel DTS change
|
||||
|
||||
Run this from a `blueflare/flare-edge` worktree with this SDK checked out at
|
||||
`vendor/warden-sdk` (the normal layout). The 5.10 board DTS is the source of
|
||||
truth (`sdk/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts`
|
||||
plus its ipc dtsi, where `sdk/` is flare-edge's own vendor-SDK checkout, not
|
||||
this repo). After any display-relevant change there, rebuild the firmware
|
||||
once and re-extract:
|
||||
|
||||
```python
|
||||
import struct, subprocess, re
|
||||
fit = open('sdk/output/image/boot.img','rb').read()
|
||||
open('/tmp/fitmeta.dtb','wb').write(fit[:4096])
|
||||
def fdtget(node, prop):
|
||||
r = subprocess.run(['fdtget','-ti','/tmp/fitmeta.dtb',node,prop],
|
||||
capture_output=True, text=True)
|
||||
return int(r.stdout.split()[0])
|
||||
pos, size = fdtget('/images/resource','data-position'), fdtget('/images/resource','data-size')
|
||||
res = fit[pos:pos+size]
|
||||
for m in re.finditer(b'ENTR', res):
|
||||
e = res[m.start():m.start()+272]
|
||||
name = e[4:260].split(b'\0')[0].decode()
|
||||
blk_off, sz = struct.unpack('<II', e[260:268])
|
||||
if name == 'rk-kernel.dtb':
|
||||
open('vendor/warden-sdk/luckfox-sdk-patches/uboot/dts/rv1106-warden-kernel.dtb','wb').write(
|
||||
res[blk_off*512: blk_off*512+sz])
|
||||
```
|
||||
|
||||
Then rebuild U-Boot and confirm the boot log prints
|
||||
`DTB: dts/rv1106-warden-kernel.dtb`. A stale blob here silently diverges from
|
||||
the kernel-side display timings; this file must be regenerated in the same
|
||||
change that edits them. flare-edge's `tools/build-firmware.sh` hard-fails if
|
||||
the file is missing while `EMBED_KERNEL_DTB_ALWAYS` is configured.
|
||||
Binary file not shown.
@@ -1,68 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* flare-edge: bootloader-side touch probe for the verbose-boot choice.
|
||||
* See arch/arm/mach-rockchip/flare_touch.c for why the decision is made here
|
||||
* rather than in userspace, and why it costs no boot time.
|
||||
*/
|
||||
#ifndef __FLARE_TOUCH_H
|
||||
#define __FLARE_TOUCH_H
|
||||
|
||||
/**
|
||||
* struct flare_touch_state - what the controller said, for the boot report
|
||||
*
|
||||
* @addr: I2C address that answered, or 0 if the controller was never
|
||||
* reached
|
||||
* @status: raw value of the coordinate/status register, sampled at the
|
||||
* read this struct reports (i.e. after the splash appeared)
|
||||
* @arm_status: raw value of the same register, sampled by flare_touch_arm()
|
||||
* before it cleared any power-on report -- lets the two reads be
|
||||
* told apart, one from before the splash and one from after
|
||||
* @armed: whether flare_touch_arm() ran and reached the controller
|
||||
* before this read, so @arm_status can be trusted
|
||||
* @id: product id string the controller reports ("911" on this
|
||||
* panel), NUL-terminated, empty if it could not be read
|
||||
*
|
||||
* A panel in the field has no serial console, so every one of these ends up on
|
||||
* the kernel command line. "No touchscreen", "touchscreen present but silent"
|
||||
* and "not touched" are three different faults that look identical without it.
|
||||
*/
|
||||
struct flare_touch_state {
|
||||
int addr;
|
||||
unsigned char status;
|
||||
unsigned char arm_status;
|
||||
bool armed;
|
||||
char id[8];
|
||||
};
|
||||
|
||||
/**
|
||||
* flare_touch_arm() - discard whatever the controller is holding right now
|
||||
*
|
||||
* Call once, early, as soon as the splash is up. The GT911 publishes a report
|
||||
* when it powers up, so on a COLD boot there is already one waiting before
|
||||
* anybody has touched anything -- and a later read cannot tell that apart from
|
||||
* a tap that has since been released, because both read as "ready, zero
|
||||
* fingers". Clearing here makes the later read mean something precise: a
|
||||
* report that arrived AFTER the splash appeared.
|
||||
*
|
||||
* Costs one I2C transaction and no delay. Safe if the controller is absent.
|
||||
*/
|
||||
void flare_touch_arm(void);
|
||||
|
||||
/**
|
||||
* flare_touch_tapped() - is a touch report waiting?
|
||||
*
|
||||
* ONE I2C read, no polling and no delay. The controller latches a report and
|
||||
* holds it until the host acknowledges it, so a single late read catches a
|
||||
* touch that happened any time earlier in the boot. Watching for a window
|
||||
* would add that window to every boot, touched or not, which is not a price
|
||||
* worth paying for a diagnostic escape hatch.
|
||||
*
|
||||
* Safe on a board with no reachable controller: reports "not touched" rather
|
||||
* than failing, so no boot path depends on the hardware answering.
|
||||
*
|
||||
* @st: filled in with what was observed; may be NULL
|
||||
* @return 1 if a touch was waiting, 0 otherwise
|
||||
*/
|
||||
int flare_touch_tapped(struct flare_touch_state *st);
|
||||
|
||||
#endif /* __FLARE_TOUCH_H */
|
||||
@@ -1,30 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* flare-edge boot instrumentation.
|
||||
*
|
||||
* Emits "FLARE-T <microseconds-since-power-on> <label>" on the console at
|
||||
* interesting points in the boot, so tools/boot-trace.py can build a single
|
||||
* timeline spanning BootROM -> SPL -> U-Boot -> kernel -> userspace.
|
||||
*
|
||||
* The time expression is deliberately the same one Rockchip's own
|
||||
* "Total: x/y ms" line uses (arch/arm/lib/bootm.c, common/spl/spl.c): the
|
||||
* secure timer is started in TPL/SPL and free-runs from power-on, so
|
||||
* get_ticks() is ticks-since-power-on and COUNTER_FREQUENCY is 24 MHz.
|
||||
* That makes these values directly comparable to that existing line, and
|
||||
* immune to UART transmit latency (unlike host-side timestamps, which lag
|
||||
* by ~5 ms per line at 115200 and much more when the port is flooded).
|
||||
*
|
||||
* Cost is a handful of printf calls. Note the uboot partition has only
|
||||
* ~12.8 KB spare (see wiki 30-uboot.md), so do not add these liberally.
|
||||
*/
|
||||
#ifndef _FLARE_TRACE_H_
|
||||
#define _FLARE_TRACE_H_
|
||||
|
||||
#define FLARE_USEC() \
|
||||
((ulong)(get_ticks() / (COUNTER_FREQUENCY / 1000000)))
|
||||
|
||||
#define FLARE_TRACE(label) \
|
||||
printf("FLARE-T %lu %s\n", \
|
||||
FLARE_USEC(), label)
|
||||
|
||||
#endif /* _FLARE_TRACE_H_ */
|
||||
@@ -1,647 +0,0 @@
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
index 8821862db..ab2c45239 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
@@ -12,7 +12,34 @@
|
||||
|
||||
chosen {
|
||||
stdout-path = &uart2;
|
||||
- u-boot,spl-boot-order = &sdmmc, &spi_nor, &spi_nand, &emmc;
|
||||
+ /*
|
||||
+ * flare-edge: eMMC first -- it is the only boot medium fitted.
|
||||
+ *
|
||||
+ * Stock order was <&sdmmc, &spi_nor, &spi_nand, &emmc>, i.e. the
|
||||
+ * one device that actually works came last. MEASURED cost of
|
||||
+ * walking the three dead entries first, from the timestamped SPL
|
||||
+ * log: ~212 ms resolving spi_nand (it fails with "unknown raw ID
|
||||
+ * 0 0 0" from drivers/mtd/nand/spi/core.c) plus ~57 ms probing
|
||||
+ * sdmmc twice ("Card did not respond to voltage select",
|
||||
+ * mmc_init: -95). That is ~270 ms of a ~450 ms SPL, spent on
|
||||
+ * hardware this board does not have: sdmmc is wired to the
|
||||
+ * AIC8800 WiFi as SDIO (non-removable, supports-sdio), there is
|
||||
+ * no SD slot, and nothing is fitted on the SFC.
|
||||
+ *
|
||||
+ * Recovery is unaffected. VERIFIED on hardware: BOOT-key recovery
|
||||
+ * runs in U-Boot proper via SARADC at ~1.18 s ("download key
|
||||
+ * pressed... entering download mode"), so it only needs SPL to
|
||||
+ * reach U-Boot -- which is exactly what booting eMMC first does,
|
||||
+ * sooner. If eMMC itself fails, board_boot_order() still appends
|
||||
+ * BOOT_DEVICE_BOOTROM, and a corrupt idblock drops to MaskRom via
|
||||
+ * the BootROM regardless. See 80-open-questions.md §8.
|
||||
+ *
|
||||
+ * NOTE: this dtsi is shared by every rv1106 U-Boot build in this
|
||||
+ * tree. Only the eMMC 86Panel is built here; if an SD- or
|
||||
+ * SPI-NAND-booting variant is ever built, restore the stock order
|
||||
+ * from rv1106-u-boot.dtsi.flare-orig.
|
||||
+ */
|
||||
+ u-boot,spl-boot-order = &emmc;
|
||||
};
|
||||
|
||||
secure-otp@ff3fd8000 {
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
index 067176a9b..25972c645 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <cli.h>
|
||||
#include <clk.h>
|
||||
#include <console.h>
|
||||
+#include <flare_trace.h>
|
||||
#include <debug_uart.h>
|
||||
#include <dm.h>
|
||||
#include <dvfs.h>
|
||||
@@ -461,10 +462,67 @@ static void scan_run_cmd(void)
|
||||
}
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * flare-edge: the VOP frame/underrun watcher lived here and has been removed.
|
||||
+ *
|
||||
+ * It enabled the VOP's own interrupt sources and polled them, which is the only
|
||||
+ * way to learn what the display hardware is actually doing rather than when our
|
||||
+ * code ran. Its verdict, MEASURED on hardware: 150 frames in 3.08 s (48.7 Hz,
|
||||
+ * exactly the designed rate) with ZERO bus_error, ZERO win1_empty and ZERO
|
||||
+ * post_buf_empty. So the SoC emits a perfect, never-starved raster from ~0.9 s,
|
||||
+ * and the ~3 s before the panel shows a stable image is the glass failing to
|
||||
+ * lock onto a signal that is already valid -- not anything on our side.
|
||||
+ *
|
||||
+ * It cost exactly its own duration (3 s) in added boot time, because U-Boot is
|
||||
+ * single-threaded and the counters have to be polled. Removed now that it has
|
||||
+ * answered the question.
|
||||
+ *
|
||||
+ * To bring it back, the expensive part is the register map, so it is recorded
|
||||
+ * here. VOP base 0xff990000: INTR_EN 0x34, INTR_CLEAR 0x38, INTR_STATUS 0x3c,
|
||||
+ * all write-masked (value in the low half word, write-enable mask in the high).
|
||||
+ * Bit order is rk3366-lite (= rv1106), and array index IS the hardware bit, per
|
||||
+ * rk3366_vop_lit_intrs[] in the kernel's rockchip_vop_reg.c:
|
||||
+ * bit0 FS (frame start) bit5 BUS_ERROR
|
||||
+ * bit7 WIN1_EMPTY bit11 POST_BUF_EMPTY
|
||||
+ * Poll INTR_STATUS & 0xffff, count set bits, write them back to INTR_CLEAR.
|
||||
+ * See 80-open-questions.md 1f.
|
||||
+ */
|
||||
+
|
||||
int board_late_init(void)
|
||||
{
|
||||
+ FLARE_TRACE("board_late_init entry");
|
||||
#ifdef CONFIG_LUCKFOX_EXECUTE_CMD
|
||||
luckfox_execute_cmd();
|
||||
+ FLARE_TRACE("panel MCU reset released (gpio set 1 1)");
|
||||
+#endif
|
||||
+ /*
|
||||
+ * flare-edge: sample the BOOT key BEFORE the display work.
|
||||
+ *
|
||||
+ * setup_download_mode() is this board's primary recovery path -- it is
|
||||
+ * how a held BOOT key reaches run_command("download") -> rbrom ->
|
||||
+ * MaskRom (VERIFIED on hardware, 80-open-questions.md 8). It is a cheap
|
||||
+ * SARADC read when the key is not pressed.
|
||||
+ *
|
||||
+ * An earlier revision of this reorder put rockchip_show_logo() first and
|
||||
+ * left this call after it, which pushed the key sample from ~1.18 s to
|
||||
+ * ~1.5 s -- and when a 3 s diagnostic briefly sat between them, out past
|
||||
+ * 4 s. A recovery mechanism that silently requires an 8 second hold is a
|
||||
+ * trap, so the safety check goes first and the logo follows it. The logo
|
||||
+ * still runs well before ethaddr/serialno/scan_run_cmd, which is what
|
||||
+ * the reorder was for.
|
||||
+ */
|
||||
+ setup_download_mode();
|
||||
+
|
||||
+ /* Logo as early as possible, but never ahead of the recovery path. */
|
||||
+#ifdef CONFIG_DRM_ROCKCHIP
|
||||
+ if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) {
|
||||
+ FLARE_TRACE("rockchip_show_logo start");
|
||||
+ rockchip_show_logo();
|
||||
+ FLARE_TRACE("rockchip_show_logo done");
|
||||
+ }
|
||||
+#endif
|
||||
+#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
|
||||
+ rockchip_eink_show_uboot_logo();
|
||||
#endif
|
||||
#ifdef CONFIG_ROCKCHIP_SET_ETHADDR
|
||||
rockchip_set_ethaddr();
|
||||
@@ -472,7 +530,6 @@ int board_late_init(void)
|
||||
#ifdef CONFIG_ROCKCHIP_SET_SN
|
||||
rockchip_set_serialno();
|
||||
#endif
|
||||
- setup_download_mode();
|
||||
scan_run_cmd();
|
||||
#ifdef CONFIG_ROCKCHIP_USB_BOOT
|
||||
boot_from_udisk();
|
||||
@@ -485,13 +542,6 @@ int board_late_init(void)
|
||||
rk_minidump_init();
|
||||
#endif
|
||||
|
||||
-#ifdef CONFIG_DRM_ROCKCHIP
|
||||
- if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT)
|
||||
- rockchip_show_logo();
|
||||
-#endif
|
||||
-#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
|
||||
- rockchip_eink_show_uboot_logo();
|
||||
-#endif
|
||||
#if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
|
||||
setup_boot_mode();
|
||||
#endif
|
||||
@@ -539,9 +589,52 @@ static void board_debug_init(void)
|
||||
printf("Cmd interface: disabled\n");
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * flare-edge: set once we have released the panel reset ourselves, read by
|
||||
+ * drivers/video/drm/rockchip_panel.c so it does not reset the panel a second
|
||||
+ * time and restart its initialisation.
|
||||
+ */
|
||||
+int flare_panel_reset_early;
|
||||
+
|
||||
+/*
|
||||
+ * flare-edge: release GPIO0_A1 (net RGB_RES) as early as possible.
|
||||
+ *
|
||||
+ * This is NOT simply "the panel reset". Per the 86Panel schematic, RGB_RES
|
||||
+ * ties three things together: SoC GPIO0_A1, the panel's RESET pin (FPC 6),
|
||||
+ * and the NRST of a WCH CH32V003 MCU (U6) whose only wired pins are SPI
|
||||
+ * (CS/SCK/SDI) to that same FPC. That MCU exists to clock the panel's
|
||||
+ * initialisation sequence in; Luckfox's own comment calls it the "RGB MCU".
|
||||
+ *
|
||||
+ * So holding this line low holds the *initialiser* in reset, and the panel
|
||||
+ * cannot come up until it is released and the MCU has run. At power-on the
|
||||
+ * pin is input-with-pulldown, i.e. asserted, so the sooner we drive it high
|
||||
+ * the sooner the panel becomes usable. MEASURED: the glass takes ~2-3 s from
|
||||
+ * release before it displays a stable image, so this is the long pole in the
|
||||
+ * whole boot -- every millisecond of head start counts.
|
||||
+ *
|
||||
+ * A previous revision of this function ASSERTED the line here and held it
|
||||
+ * ~540 ms across init_kernel_dtb(), on the theory that the panel needed a
|
||||
+ * longer reset pulse. That was backwards: it delayed the initialiser by half
|
||||
+ * a second. Do not reintroduce it.
|
||||
+ *
|
||||
+ * Register-level rather than DM/pinctrl because this runs before the kernel
|
||||
+ * DTB is adopted and before most of the driver model exists. RV1106 GPIO v2
|
||||
+ * at 0xff380000: swport_dr_l 0x00, swport_ddr_l 0x08, both write-masked with
|
||||
+ * the enable bits in the upper half word, so only bit 1 is touched.
|
||||
+ */
|
||||
+static void flare_release_panel_reset(void)
|
||||
+{
|
||||
+ writel(0x00020002, (void *)0xff380008); /* bit 1 -> output */
|
||||
+ writel(0x00020002, (void *)0xff380000); /* bit 1 -> high: MCU + panel
|
||||
+ * out of reset */
|
||||
+ flare_panel_reset_early = 1;
|
||||
+}
|
||||
+
|
||||
+
|
||||
int board_init(void)
|
||||
{
|
||||
board_debug_init();
|
||||
+ flare_release_panel_reset();
|
||||
#ifdef DEBUG
|
||||
soc_clk_dump();
|
||||
#endif
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/console.c b/sysdrv/source/uboot/u-boot/common/console.c
|
||||
index 629c2a645..bce3e51b6 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/common/console.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/console.c
|
||||
@@ -515,11 +515,72 @@ static inline void pre_console_putc(const char c) {}
|
||||
static inline void print_pre_console_buffer(int flushpoint) {}
|
||||
#endif
|
||||
|
||||
+#ifdef CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP
|
||||
+/*
|
||||
+ * flare-edge: prefix every console line with "[ s.uuuuuu] ", microseconds
|
||||
+ * since power-on.
|
||||
+ *
|
||||
+ * Hooked into putc() rather than puts() on purpose. With
|
||||
+ * CONFIG_USE_TINY_PRINTF (required for SPL size) printf() emits one character
|
||||
+ * at a time through putc_normal() -> putc() and never calls puts(), so a
|
||||
+ * puts()-level hook is invisible to SPL -- which is precisely the ~0.42 s of
|
||||
+ * boot we most wanted to see. putc() catches both paths.
|
||||
+ *
|
||||
+ * Formatted by hand because tiny printf supports only %c %s %u %d %x: no
|
||||
+ * field width, no zero padding, so "%5lu.%06lu" would not render. get_ticks()
|
||||
+ * is the free-running secure timer started in TPL at 24 MHz, so this shares a
|
||||
+ * clock with Rockchip's own "Total: x/y ms" lines and with FLARE_TRACE.
|
||||
+ */
|
||||
+static int flare_in_ts;
|
||||
+
|
||||
+static void flare_putc_ts(void)
|
||||
+{
|
||||
+ unsigned long ticks = (unsigned long)(get_ticks() / 24ULL);
|
||||
+ unsigned long sec = ticks / 1000000UL;
|
||||
+ unsigned long us = ticks % 1000000UL;
|
||||
+ unsigned long div;
|
||||
+ char d[12];
|
||||
+ int n = 0;
|
||||
+
|
||||
+ putc('[');
|
||||
+ if (!sec) {
|
||||
+ d[n++] = '0';
|
||||
+ } else {
|
||||
+ while (sec) {
|
||||
+ d[n++] = '0' + (char)(sec % 10);
|
||||
+ sec /= 10;
|
||||
+ }
|
||||
+ }
|
||||
+ for (div = n; div < 5; div++)
|
||||
+ putc(' ');
|
||||
+ while (n--)
|
||||
+ putc(d[n]);
|
||||
+ putc('.');
|
||||
+ for (div = 100000UL; div; div /= 10)
|
||||
+ putc('0' + (char)((us / div) % 10));
|
||||
+ putc(']');
|
||||
+ putc(' ');
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
void putc(const char c)
|
||||
{
|
||||
if (!gd || gd->flags & GD_FLG_DISABLE_CONSOLE)
|
||||
return;
|
||||
|
||||
+#ifdef CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP
|
||||
+ if (!flare_in_ts) {
|
||||
+ if (c == '\n') {
|
||||
+ gd->new_line = 1;
|
||||
+ } else if (gd->new_line) {
|
||||
+ gd->new_line = 0;
|
||||
+ flare_in_ts = 1;
|
||||
+ flare_putc_ts();
|
||||
+ flare_in_ts = 0;
|
||||
+ }
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
#ifdef CONFIG_PSTORE
|
||||
putc_to_ram(c);
|
||||
#endif
|
||||
@@ -553,51 +614,11 @@ void putc(const char c)
|
||||
}
|
||||
}
|
||||
|
||||
-#if ((!defined(CONFIG_SPL_BUILD) || !defined(CONFIG_USE_TINY_PRINTF)) && \
|
||||
- defined(CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP))
|
||||
-static void vspfunc(char *buf, size_t size, char *format, ...)
|
||||
-{
|
||||
- va_list ap;
|
||||
-
|
||||
- va_start(ap, format);
|
||||
- vsnprintf(buf, size, format, ap);
|
||||
- va_end(ap);
|
||||
-}
|
||||
-
|
||||
-void puts(const char *s)
|
||||
-{
|
||||
- unsigned long ts_sec, ts_msec, ticks;
|
||||
- char pr_timestamp[32], *p;
|
||||
-
|
||||
- while (*s) {
|
||||
- if (*s == '\n') {
|
||||
- gd->new_line = 1;
|
||||
- putc(*s++);
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- if (gd->new_line) {
|
||||
- gd->new_line = 0;
|
||||
- ticks = (get_ticks() / 24ULL);
|
||||
- ts_sec = ticks / 1000000;
|
||||
- ts_msec = ticks % 1000000;
|
||||
- vspfunc(pr_timestamp, sizeof(pr_timestamp),
|
||||
- "[%5lu.%06lu] ", ts_sec, ts_msec);
|
||||
- p = pr_timestamp;
|
||||
- while (*p)
|
||||
- putc(*p++);
|
||||
- }
|
||||
-
|
||||
- putc(*s++);
|
||||
- }
|
||||
-}
|
||||
-#else
|
||||
void puts(const char *s)
|
||||
{
|
||||
while (*s)
|
||||
putc(*s++);
|
||||
}
|
||||
-#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_CONSOLE_RECORD
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c b/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
|
||||
index a99846f4e..4fc64f33d 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/clk/rockchip/clk_rv1106.c
|
||||
@@ -976,20 +976,93 @@ static ulong rv1106_vop_set_clk(struct rv1106_clk_priv *priv,
|
||||
sel << ACLK_VOP_SEL_SHIFT);
|
||||
break;
|
||||
case DCLK_VOP_SRC:
|
||||
- case DCLK_VOP:
|
||||
- if ((priv->cpll_hz % rate) == 0) {
|
||||
+ case DCLK_VOP: {
|
||||
+ /*
|
||||
+ * flare-edge: the divider field is 5 bits (DCLK_VOP_DIV_MASK
|
||||
+ * = 0x1f << 3), so the largest divisor the hardware can encode
|
||||
+ * is 32. The original code took DIV_ROUND_UP() of the parent
|
||||
+ * rate and wrote (div - 1) straight into that field with no
|
||||
+ * range check. For this panel -- 30 MHz pixel clock from a
|
||||
+ * 1188 MHz GPLL -- that is a divisor of 40, i.e. 39 = 0b100111
|
||||
+ * written into 5 bits, which truncates to 7. MEASURED result:
|
||||
+ * the VOP ran at 125 MHz instead of 30 MHz, so the panel was
|
||||
+ * fed a signal it cannot lock to and showed coloured vertical
|
||||
+ * lines / black while U-Boot happily turned the backlight on.
|
||||
+ *
|
||||
+ * Neither PLL can actually reach 30 MHz through a /32 divider
|
||||
+ * (1188/32 = 37.125, 1000/32 = 31.25), so clamp to the field
|
||||
+ * maximum and choose whichever parent lands closest to the
|
||||
+ * request rather than silently corrupting the register.
|
||||
+ */
|
||||
+ ulong c_div, g_div, c_rate, g_rate, c_err, g_err;
|
||||
+
|
||||
+ /*
|
||||
+ * flare-edge: if neither PLL can divide down to the requested
|
||||
+ * pixel clock exactly, retune CPLL so that it can.
|
||||
+ *
|
||||
+ * Stock rates give 1188/32 = 37.125 MHz and 1000/32 = 31.25 MHz
|
||||
+ * against the 30 MHz this panel wants, so the best achievable
|
||||
+ * was 4.2% fast. An already-locked panel copes with that --
|
||||
+ * Linux never notices, because it inherits a display U-Boot has
|
||||
+ * already started -- but U-Boot is the ONLY stage that locks the
|
||||
+ * panel from cold, and at 31.25 MHz that took 1-2 seconds of
|
||||
+ * visible coloured banding before the image settled.
|
||||
+ *
|
||||
+ * CPLL is safe to move here: within this driver only the VOP and
|
||||
+ * UART (as a secondary parent) derive from it. The eMMC, peri and
|
||||
+ * bus roots do not, and the debug UART runs from the 24 MHz
|
||||
+ * oscillator, so neither the boot media nor the console is
|
||||
+ * affected. rkclk_init() pins CPLL to CPLL_HZ and has already run
|
||||
+ * by this point, so nothing puts it back underneath us.
|
||||
+ */
|
||||
+ if ((priv->cpll_hz % rate) && (priv->gpll_hz % rate)) {
|
||||
+ ulong want = rate * 32;
|
||||
+
|
||||
+ if (want >= 300 * MHz && want <= 1200 * MHz &&
|
||||
+ !rockchip_pll_set_rate(&rv1106_pll_clks[CPLL],
|
||||
+ priv->cru, CPLL, want)) {
|
||||
+ printf("dclk_vop: cpll %luHz -> %luHz for an exact /32\n",
|
||||
+ priv->cpll_hz, want);
|
||||
+ priv->cpll_hz = want;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ c_div = DIV_ROUND_UP(priv->cpll_hz, rate);
|
||||
+ g_div = DIV_ROUND_UP(priv->gpll_hz, rate);
|
||||
+ if (c_div > 32)
|
||||
+ c_div = 32;
|
||||
+ if (g_div > 32)
|
||||
+ g_div = 32;
|
||||
+ if (c_div < 1)
|
||||
+ c_div = 1;
|
||||
+ if (g_div < 1)
|
||||
+ g_div = 1;
|
||||
+
|
||||
+ c_rate = priv->cpll_hz / c_div;
|
||||
+ g_rate = priv->gpll_hz / g_div;
|
||||
+ c_err = (c_rate > rate) ? (c_rate - rate) : (rate - c_rate);
|
||||
+ g_err = (g_rate > rate) ? (g_rate - rate) : (rate - g_rate);
|
||||
+
|
||||
+ if (c_err <= g_err) {
|
||||
sel = DCLK_VOP_SEL_CPLL;
|
||||
- div = DIV_ROUND_UP(priv->cpll_hz, rate);
|
||||
+ div = c_div;
|
||||
} else {
|
||||
sel = DCLK_VOP_SEL_GPLL;
|
||||
- div = DIV_ROUND_UP(priv->gpll_hz, rate);
|
||||
+ div = g_div;
|
||||
}
|
||||
+
|
||||
+ printf("dclk_vop: want %luHz, cpll=%luHz/%lu=%luHz gpll=%luHz/%lu=%luHz -> %s/%d\n",
|
||||
+ rate, priv->cpll_hz, c_div, c_rate,
|
||||
+ priv->gpll_hz, g_div, g_rate,
|
||||
+ sel == DCLK_VOP_SEL_CPLL ? "cpll" : "gpll", div);
|
||||
+
|
||||
rk_clrsetreg(&cru->clksel_con[23],
|
||||
DCLK_VOP_SEL_MASK |
|
||||
DCLK_VOP_DIV_MASK,
|
||||
sel << DCLK_VOP_SEL_SHIFT |
|
||||
(div - 1) << DCLK_VOP_DIV_SHIFT);
|
||||
break;
|
||||
+ }
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -1226,10 +1299,17 @@ static ulong rv1106_clk_set_rate(struct clk *clk, ulong rate)
|
||||
case DCLK_VOP:
|
||||
case ACLK_VOP_ROOT:
|
||||
case ACLK_VOP:
|
||||
- rate = rv1106_vop_set_clk(priv, clk->id, rate);
|
||||
+ /* flare-edge: was "rate = ...", but this function returns `ret`,
|
||||
+ * so the actual rate was discarded and clk_set_rate() always
|
||||
+ * reported 0. The hardware was still programmed, which is why
|
||||
+ * this stayed hidden -- but it made the VOP's own
|
||||
+ * "set crtc_clock to 30000KHz, get 0Hz" line useless as a
|
||||
+ * diagnostic, and 0 is indistinguishable from a dead clock when
|
||||
+ * you are trying to work out why a panel shows nothing. */
|
||||
+ ret = rv1106_vop_set_clk(priv, clk->id, rate);
|
||||
break;
|
||||
case DCLK_DECOM:
|
||||
- rate = rv1106_decom_set_clk(priv, rate);
|
||||
+ ret = rv1106_decom_set_clk(priv, rate);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
|
||||
index 69e9a1dfa..fe09efe09 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
|
||||
@@ -2106,7 +2106,12 @@ static int rockchip_display_probe(struct udevice *dev)
|
||||
}
|
||||
split_conn = rockchip_get_split_connector(conn);
|
||||
|
||||
- s = malloc(sizeof(*s));
|
||||
+ /* flare-edge: calloc, not malloc -- enabled_at_spl and other fields
|
||||
+ * are only explicitly initialised under CONFIG_SPL_BUILD, which does
|
||||
+ * not apply here (this file runs in U-Boot proper). Uninitialised
|
||||
+ * heap garbage in enabled_at_spl silently skips panel prepare/enable
|
||||
+ * (and therefore backlight_enable) in display_enable() below. */
|
||||
+ s = calloc(1, sizeof(*s));
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
|
||||
index 9ddb4d819..44c31945c 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_panel.c
|
||||
@@ -12,6 +12,31 @@
|
||||
#include <malloc.h>
|
||||
#include <video.h>
|
||||
#include <backlight.h>
|
||||
+
|
||||
+/*
|
||||
+ * Milliseconds to wait after the CRTC starts scanning out, before switching
|
||||
+ * the backlight on, when the devicetree gives no enable-delay-ms.
|
||||
+ *
|
||||
+ * This hides the panel's own wake, which is driven by the CH32V003 (U6)
|
||||
+ * clocking the init sequence in over SPI once RGB_RES is released at the top
|
||||
+ * of board_init(). Two artefacts have been seen here with DIFFERENT causes --
|
||||
+ * do not conflate them:
|
||||
+ *
|
||||
+ * coloured vertical banding -- NOT a settle problem. That was Linux
|
||||
+ * rebooting the CH32V003 mid-scanout via reset-gpios on &panel; fixed in
|
||||
+ * the kernel DTS. Raising this constant only ever masked it.
|
||||
+ * inverted image that fades to correct -- the driver IC is still coming up
|
||||
+ * when the backlight lands, so we see the tail of its internal rail ramp.
|
||||
+ * This constant is the right tool for that one.
|
||||
+ *
|
||||
+ * Trade-off is explicit: first light moves later, but what you see first is
|
||||
+ * the logo rather than garbage. The better fix is to release RGB_RES earlier
|
||||
+ * (SPL/TPL) so the initialiser is done before we get here -- same margin,
|
||||
+ * without delaying the logo. That needs an idblock flash, hence not done yet.
|
||||
+ */
|
||||
+#define FLARE_PANEL_SETTLE_MS 250
|
||||
+
|
||||
+extern int flare_panel_reset_early;
|
||||
#include <spi.h>
|
||||
#include <asm/gpio.h>
|
||||
#include <dm/device.h>
|
||||
@@ -302,6 +327,24 @@ static void panel_simple_prepare(struct rockchip_panel *panel)
|
||||
if (priv->prepared)
|
||||
return;
|
||||
|
||||
+ /*
|
||||
+ * flare-edge: force the backlight OFF before touching the panel.
|
||||
+ *
|
||||
+ * The PWM block is not reset by a warm reboot, so after `reboot` from
|
||||
+ * Linux the backlight is still lit from the previous session for the
|
||||
+ * whole of U-Boot. Delaying our own backlight_enable() therefore did
|
||||
+ * nothing -- the lamp was already on, and the panel's 1-2 s cold-lock
|
||||
+ * banding was plainly visible through it. Only a cold power-cycle hid
|
||||
+ * the problem, which is exactly why it looked inconsistent.
|
||||
+ *
|
||||
+ * Explicitly blanking here means the settle happens in the dark on
|
||||
+ * both warm and cold boots, and the first thing the user sees is the
|
||||
+ * finished logo. panel_simple_enable() switches it back on once the
|
||||
+ * panel has locked.
|
||||
+ */
|
||||
+ if (priv->backlight)
|
||||
+ backlight_disable(priv->backlight);
|
||||
+
|
||||
if (priv->power_supply)
|
||||
regulator_set_enable(priv->power_supply, !plat->power_invert);
|
||||
|
||||
@@ -311,6 +354,15 @@ static void panel_simple_prepare(struct rockchip_panel *panel)
|
||||
if (plat->delay.prepare)
|
||||
mdelay(plat->delay.prepare);
|
||||
|
||||
+ /*
|
||||
+ * flare-edge: board_init() asserted this reset back at ~0.47 s and has
|
||||
+ * been holding it ever since, so by the time we get here the panel has
|
||||
+ * already had a ~540 ms low pulse -- far longer than the 200 ms
|
||||
+ * reset-delay-ms below, and the closest we can get to the full
|
||||
+ * power-down that this panel demonstrably needs. Run the normal cycle
|
||||
+ * anyway: it is harmless (the line is already low) and it is what
|
||||
+ * actually releases the reset.
|
||||
+ */
|
||||
if (dm_gpio_is_valid(&priv->reset_gpio))
|
||||
dm_gpio_set_value(&priv->reset_gpio, 1);
|
||||
|
||||
@@ -388,6 +440,26 @@ static void panel_simple_enable(struct rockchip_panel *panel)
|
||||
if (plat->delay.enable)
|
||||
mdelay(plat->delay.enable);
|
||||
|
||||
+ /*
|
||||
+ * flare-edge: this panel needs 1-2 s to lock onto the RGB signal from
|
||||
+ * cold, and until it does it shows faint coloured vertical banding.
|
||||
+ * U-Boot is the only stage that ever starts it from cold -- Linux
|
||||
+ * inherits an already-running display -- so this is the only place the
|
||||
+ * problem appears. Lighting the backlight before the panel has locked
|
||||
+ * just makes the garbage visible.
|
||||
+ *
|
||||
+ * Ruled out as causes, each MEASURED rather than assumed: memory
|
||||
+ * bandwidth contention (the image is rock steady through sustained
|
||||
+ * 8 MB eMMC reads at the U-Boot prompt), and pixel-clock accuracy
|
||||
+ * (retuning CPLL to 960 MHz for an exact 30.000 MHz changed nothing).
|
||||
+ * It is simply the panel's own lock time.
|
||||
+ *
|
||||
+ * Prefer the devicetree's enable-delay-ms above if a value is set;
|
||||
+ * this is the fallback for a DT that specifies none.
|
||||
+ */
|
||||
+ if (!plat->delay.enable)
|
||||
+ mdelay(FLARE_PANEL_SETTLE_MS);
|
||||
+
|
||||
if (priv->backlight)
|
||||
backlight_enable(priv->backlight);
|
||||
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
|
||||
index 240910395..675ac1580 100755
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_post_csc.c
|
||||
@@ -4,6 +4,20 @@
|
||||
* Author: Zhang yubing <yubing.zhang@rock-chips.com>
|
||||
*/
|
||||
|
||||
+/*
|
||||
+ * flare-edge: <common.h> must come first.
|
||||
+ *
|
||||
+ * rockchip_post_csc.h pulls in <edid.h>, which includes <i2c.h>
|
||||
+ * unconditionally (edid.h:20). With CONFIG_DM_I2C unset -- which is the case
|
||||
+ * in rv1106_defconfig and ours -- i2c.h takes its legacy branch (i2c.h:554),
|
||||
+ * and those prototypes use `uchar`. That typedef lives in <common.h>, which
|
||||
+ * this file never included, so the prototypes failed to parse and the later
|
||||
+ * inline users of i2c_read()/i2c_write() then became implicit-declaration
|
||||
+ * errors. Including common.h first resolves the whole cascade, and is far
|
||||
+ * cheaper than enabling the DM I2C stack purely to dodge a header ordering
|
||||
+ * bug (the uboot partition is 256K with ~64K spare).
|
||||
+ */
|
||||
+#include <common.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/errno.h>
|
||||
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c b/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
|
||||
index 718b2fd04..83dbd7e56 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/video/pwm_backlight.c
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <pwm.h>
|
||||
#include <asm/gpio.h>
|
||||
#include <power/regulator.h>
|
||||
+#include <flare_trace.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
@@ -66,6 +67,19 @@ static int pwm_backlight_enable(struct udevice *dev)
|
||||
if (dm_gpio_is_valid(&priv->enable))
|
||||
dm_gpio_set_value(&priv->enable, 1);
|
||||
|
||||
+ /*
|
||||
+ * Report the values that actually determine whether the panel lights
|
||||
+ * up, not just "we got here". The previous message claimed "panel now
|
||||
+ * visible", which was untrue for a long time: the PWM was enabled at
|
||||
+ * 99.6%% duty but INVERTED, so the real brightness was ~0.4%% and the
|
||||
+ * screen looked dead. A trace marker that asserts an outcome it cannot
|
||||
+ * observe is worse than no marker at all.
|
||||
+ */
|
||||
+ printf("FLARE-T %lu backlight pwm enabled: duty=%u/%u ns (%lu%%), polarity=%s\n",
|
||||
+ (ulong)(get_ticks() / (COUNTER_FREQUENCY / 1000000)),
|
||||
+ duty_cycle, priv->period_ns,
|
||||
+ priv->period_ns ? (ulong)duty_cycle * 100 / priv->period_ns : 0,
|
||||
+ priv->polarity ? "inverted" : "normal");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -143,7 +157,20 @@ static int pwm_backlight_ofdata_to_platdata(struct udevice *dev)
|
||||
}
|
||||
priv->channel = args.args[0];
|
||||
priv->period_ns = args.args[1];
|
||||
- priv->polarity = args.args[2];
|
||||
+ /*
|
||||
+ * flare-edge: the third pwm cell is a FLAGS word, not a boolean.
|
||||
+ * Only bit 0 (PWM_POLARITY_INVERTED) selects polarity; the kernel
|
||||
+ * masks it and ignores everything else.
|
||||
+ *
|
||||
+ * This board's DTS carries pwms = <&pwm1 0 100000 50000>. Assigning
|
||||
+ * 50000 straight into a bool made U-Boot invert the PWM while Linux
|
||||
+ * did not, so a 99.6% duty cycle (PERIOD=10000, DUTY=9960) came out
|
||||
+ * as ~0.4% on. MEASURED: PWM_CTRL read back 0x13, i.e. DUTY_NEGATIVE
|
||||
+ * + INACTIVE_POSITIVE. The backlight reported itself enabled and was
|
||||
+ * to the eye completely dark -- while the logo was rendering into the
|
||||
+ * framebuffer perfectly the whole time.
|
||||
+ */
|
||||
+ priv->polarity = args.args[2] & 1;
|
||||
|
||||
index = dev_read_u32_default(dev, "default-brightness-level", 255);
|
||||
cell = dev_read_prop(dev, "brightness-levels", &len);
|
||||
@@ -1,108 +0,0 @@
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
|
||||
index 3b943079d..bdc6876e0 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl-boot-order.c
|
||||
@@ -197,7 +197,28 @@ void board_boot_order(u32 *spl_boot_list)
|
||||
|
||||
/* If we had no matches, fall back to spl_boot_device */
|
||||
if (idx == 0)
|
||||
- spl_boot_list[0] = spl_boot_device();
|
||||
+ spl_boot_list[idx++] = spl_boot_device();
|
||||
+
|
||||
+#ifdef CONFIG_SPL_BOOTROM_SUPPORT
|
||||
+ /*
|
||||
+ * flare-edge: last-resort recovery entry.
|
||||
+ *
|
||||
+ * boot_from_devices() walks this list in order and, if every entry
|
||||
+ * fails, common/spl/spl.c does puts("SPL: failed to boot from all
|
||||
+ * boot devices") followed by hang(). A hung SPL presents nothing on
|
||||
+ * USB, and the BOOT key is sampled by U-Boot proper (SARADC, in
|
||||
+ * board_late_init) -- so it cannot rescue a failure that happens
|
||||
+ * before U-Boot runs. The board would then need hardware recovery.
|
||||
+ *
|
||||
+ * Appending the BROM here costs nothing on a healthy boot (MMC is
|
||||
+ * tried first and succeeds), but turns "unbootable uboot.img" from a
|
||||
+ * hang into an automatic drop to MaskRom, which upgrade_tool can talk
|
||||
+ * to. See board_return_to_bootrom() in mach-rockchip/spl.c: with
|
||||
+ * SPL_ROCKCHIP_BACK_TO_BROM off this issues BROM_BOOT_ENTER_DNL.
|
||||
+ */
|
||||
+ if (idx < 5)
|
||||
+ spl_boot_list[idx++] = BOOT_DEVICE_BOOTROM;
|
||||
+#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
|
||||
index 9f882ca14..430302c38 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
|
||||
@@ -31,7 +31,23 @@ DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
void board_return_to_bootrom(void)
|
||||
{
|
||||
+#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
|
||||
+ /* Normal flow: the BROM is expected to load the next stage for us. */
|
||||
back_to_bootrom(BROM_BOOT_NEXTSTAGE);
|
||||
+#else
|
||||
+ /*
|
||||
+ * flare-edge: SPL loads U-Boot from MMC itself, so this is only
|
||||
+ * reached as the final entry of board_boot_order() -- i.e. every real
|
||||
+ * boot device already failed. Asking the BROM to continue the boot
|
||||
+ * sequence would just fail again, so request download mode instead
|
||||
+ * and let MaskRom recovery take over.
|
||||
+ *
|
||||
+ * This file is obj-spl-y only (TPL uses tpl.o), so TPL's own
|
||||
+ * back-to-BROM path, which must stay BROM_BOOT_NEXTSTAGE, is
|
||||
+ * unaffected.
|
||||
+ */
|
||||
+ back_to_bootrom(BROM_BOOT_ENTER_DNL);
|
||||
+#endif
|
||||
}
|
||||
|
||||
__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
|
||||
diff --git a/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig b/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
|
||||
index 0fe5c20b3..ac74ec7f1 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
|
||||
+++ b/sysdrv/source/uboot/u-boot/configs/luckfox_rv1106_uboot_defconfig
|
||||
@@ -78,7 +78,7 @@ CONFIG_OF_LIVE=y
|
||||
CONFIG_OF_SPL_REMOVE_PROPS="interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
|
||||
CONFIG_OF_U_BOOT_REMOVE_PROPS="interrupt-parent"
|
||||
CONFIG_ENVF=y
|
||||
-CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr"
|
||||
+CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr bootcmd bootdelay preboot altbootcmd bootlimit bootcount"
|
||||
CONFIG_REGMAP=y
|
||||
CONFIG_SPL_REGMAP=y
|
||||
CONFIG_SYSCON=y
|
||||
diff --git a/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig b/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
|
||||
index c9d627cce..a71a7e421 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/bootcount/Kconfig
|
||||
@@ -13,6 +13,28 @@ config BOOTCOUNT
|
||||
|
||||
if BOOTCOUNT
|
||||
|
||||
+config BOOTCOUNT_LIMIT
|
||||
+ bool "Enable boot count limit (altbootcmd fallback)"
|
||||
+ help
|
||||
+ Used by common/autoboot.c: each boot increments the counter and, once
|
||||
+ it exceeds ${bootlimit}, U-Boot runs ${altbootcmd} instead of
|
||||
+ ${bootcmd}. The code has always referenced CONFIG_BOOTCOUNT_LIMIT but
|
||||
+ this tree never declared it in Kconfig, so it could only be set via a
|
||||
+ board config header. Declared here so it can come from a defconfig
|
||||
+ fragment. (flare-edge)
|
||||
+
|
||||
+config BOOTCOUNT_ENV
|
||||
+ bool "Store boot counter in the environment"
|
||||
+ help
|
||||
+ Keeps the counter in the environment (drivers/bootcount/bootcount_env.c).
|
||||
+ Note both load and store are gated on ${upgrade_available}, so the
|
||||
+ counter only runs during an upgrade window -- which is the behaviour we
|
||||
+ want: arm it when flashing, clear it once userspace confirms a good
|
||||
+ boot. Requires an environment backend that implements save(); ENVF does
|
||||
+ (env/envf.c: .save = env_save_ptr(envf_save)). The Makefile already
|
||||
+ builds bootcount_env.o for this symbol; only the Kconfig entry was
|
||||
+ missing. (flare-edge)
|
||||
+
|
||||
config BOOTCOUNT_EXT
|
||||
bool "Boot counter on EXT filesystem"
|
||||
help
|
||||
@@ -1,953 +0,0 @@
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
|
||||
index 7c5681a02..b8787dda1 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/fit.c
|
||||
@@ -10,6 +10,9 @@
|
||||
#include <sysmem.h>
|
||||
#include <asm/arch/fit.h>
|
||||
#include <asm/arch/resource_img.h>
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+#include <flare_ab.h>
|
||||
+#endif
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
@@ -145,10 +148,28 @@ static void *fit_get_blob(struct blk_desc *dev_desc,
|
||||
char *part_name = PART_BOOT;
|
||||
void *fit, *fdt;
|
||||
int blk_num;
|
||||
+ __maybe_unused int recovery = 0;
|
||||
|
||||
#ifndef CONFIG_ANDROID_AB
|
||||
- if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY)
|
||||
+ if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY) {
|
||||
+ part_name = PART_RECOVERY;
|
||||
+ recovery = 1;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+ /*
|
||||
+ * BCB-commanded recovery (above) and no-bootable-slot fallback
|
||||
+ * both boot the shared recovery FIT; either way the A/B layer
|
||||
+ * must know, so it stops decrementing slot tries and escalates
|
||||
+ * to MaskRom if the recovery FIT itself will not boot.
|
||||
+ */
|
||||
+ if (!recovery && flare_ab_enabled() && !flare_ab_have_bootable()) {
|
||||
part_name = PART_RECOVERY;
|
||||
+ recovery = 1;
|
||||
+ }
|
||||
+ if (recovery)
|
||||
+ flare_ab_set_recovery_mode();
|
||||
#endif
|
||||
|
||||
if (part_get_info_by_name(dev_desc, part_name, &part) < 0) {
|
||||
diff --git a/sysdrv/source/uboot/u-boot/cmd/bootfit.c b/sysdrv/source/uboot/u-boot/cmd/bootfit.c
|
||||
index 3a8b75bf7..6335cbf39 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/cmd/bootfit.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/cmd/bootfit.c
|
||||
@@ -12,6 +12,9 @@
|
||||
#include <malloc.h>
|
||||
#include <sysmem.h>
|
||||
#include <asm/arch/fit.h>
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+#include <flare_ab.h>
|
||||
+#endif
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
@@ -69,6 +72,20 @@ static int do_boot_fit(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
||||
|
||||
printf("## Booting FIT Image ");
|
||||
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+ /*
|
||||
+ * Count this boot attempt against the selected slot BEFORE trying
|
||||
+ * to load its FIT (the SPL engine's "decrease before load" rule):
|
||||
+ * a slot whose FIT is corrupt must still burn tries on every failed
|
||||
+ * attempt, or the failure path below would reset forever without
|
||||
+ * ever falling back to the other slot. Writes one sector, and only
|
||||
+ * while the slot is not yet marked successful; no-op in recovery
|
||||
+ * fallback mode (the earlier kernel-DTB load already resolved it).
|
||||
+ */
|
||||
+ if (argc == 1)
|
||||
+ flare_ab_boot_attempt();
|
||||
+#endif
|
||||
+
|
||||
if (argc == 1)
|
||||
fit = do_boot_fit_storage(&size);
|
||||
else
|
||||
@@ -120,8 +137,24 @@ static int do_boot_fit(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
||||
goto out;
|
||||
}
|
||||
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+ if (ret && argc == 1)
|
||||
+ goto out;
|
||||
+#endif
|
||||
+
|
||||
return CMD_RET_SUCCESS;
|
||||
out:
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+ /*
|
||||
+ * A storage boot that reached this point failed to load or boot
|
||||
+ * the selected slot's FIT. On an A/B layout this resets so the
|
||||
+ * next boot makes progress (retries burn down, then the other
|
||||
+ * slot, then recovery, then MaskRom); on a legacy layout it
|
||||
+ * returns and stock behavior continues.
|
||||
+ */
|
||||
+ if (argc == 1)
|
||||
+ flare_ab_boot_failed();
|
||||
+#endif
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/Kconfig b/sysdrv/source/uboot/u-boot/common/Kconfig
|
||||
index c276f701a..31b5c712d 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/common/Kconfig
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/Kconfig
|
||||
@@ -620,6 +620,21 @@ config ANDROID_AB
|
||||
allows a bootloader to try a new version of the system but roll back
|
||||
to previous version if the new one didn't boot all the way.
|
||||
|
||||
+config FLARE_AB
|
||||
+ bool "flare-edge A/B slot boot (lean, misc-based, no libavb)"
|
||||
+ depends on !ANDROID_AB
|
||||
+ default n
|
||||
+ help
|
||||
+ A/B slot selection for U-Boot proper using the same AOSP
|
||||
+ AvbABData metadata (single CRC32-protected sector at
|
||||
+ misc + 2048 bytes) as the vendor SPL A/B engine, without the
|
||||
+ libavb stack CONFIG_ANDROID_AB pulls in. Slot suffixing hooks
|
||||
+ part_get_info_by_name(), so boot_a/boot_b (and the early
|
||||
+ kernel-DTB/resource load) resolve transparently; tries are
|
||||
+ decremented once per boot attempt only while a slot is not yet
|
||||
+ marked successful; with no bootable slot the recovery FIT is
|
||||
+ booted, and failing that the board drops to MaskRom.
|
||||
+
|
||||
config ANDROID_WRITE_KEYBOX
|
||||
bool "Support Write Keybox"
|
||||
default y
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/Makefile b/sysdrv/source/uboot/u-boot/common/Makefile
|
||||
index 52cd612d1..a81071566 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/common/Makefile
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/Makefile
|
||||
@@ -12,6 +12,7 @@ obj-$(CONFIG_SUPPORT_USBPLUG) += usbplug/
|
||||
|
||||
obj-y += main.o
|
||||
obj-y += exports.o
|
||||
+obj-$(CONFIG_FLARE_AB) += flare_ab.o
|
||||
obj-$(CONFIG_HASH) += hash.o
|
||||
obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
|
||||
obj-$(CONFIG_AUTOBOOT) += autoboot.o
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/flare_ab.c b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
new file mode 100644
|
||||
index 000000000..6a5a07e37
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
@@ -0,0 +1,642 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0+
|
||||
+/*
|
||||
+ * flare-edge A/B slot boot for U-Boot proper.
|
||||
+ *
|
||||
+ * Core metadata engine adapted from the vendor's common/spl/spl_ab.c
|
||||
+ * (Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd) so U-Boot
|
||||
+ * proper and SPL agree byte-for-byte on the AvbABData struct at
|
||||
+ * `misc` + AB_METADATA_OFFSET blocks, without pulling in libavb.
|
||||
+ *
|
||||
+ * Semantics (AOSP A/B, unchanged from the SPL engine):
|
||||
+ * - a slot is bootable iff priority>0 && (successful_boot || tries>0)
|
||||
+ * - selection prefers the higher-priority bootable slot
|
||||
+ * - one tries_remaining decrement per boot attempt, ONLY while the
|
||||
+ * slot is not yet successful; metadata is written only if changed,
|
||||
+ * so a confirmed steady-state device never writes flash at boot
|
||||
+ * - corrupt metadata self-reinitializes (both slots bootable, A first)
|
||||
+ * - when no slot is bootable, selection falls back to last_boot and
|
||||
+ * fit_get_blob() redirects to the recovery FIT instead
|
||||
+ */
|
||||
+
|
||||
+#include <common.h>
|
||||
+#include <asm/io.h>
|
||||
+#include <blk.h>
|
||||
+#include <boot_rkimg.h>
|
||||
+#include <command.h>
|
||||
+#include <malloc.h>
|
||||
+#include <part.h>
|
||||
+#include <flare_ab.h>
|
||||
+#include <android_avb/avb_ab_flow.h>
|
||||
+
|
||||
+/*
|
||||
+ * Per-power-session boot-attempt escalation (warehouse deployment).
|
||||
+ *
|
||||
+ * The AvbABData tries above are PERSISTENT (in the misc sector) and exist for
|
||||
+ * the UPDATE case: a freshly written slot gets a tries budget, and a bad update
|
||||
+ * burns it down and reverts to the other slot even across power cycles (a bad
|
||||
+ * image must not come back after a brownout). That is correct for updates and
|
||||
+ * is left unchanged.
|
||||
+ *
|
||||
+ * The STEADY-STATE case (both slots already committed, no update in flight) has
|
||||
+ * a different requirement: retry the selected slot a couple of times, then the
|
||||
+ * other slot, then recovery -- and RESET on every power cycle, so a device that
|
||||
+ * merely lost power mid-boot always comes back up on its selected slot instead
|
||||
+ * of walking itself into recovery. A persistent counter cannot express "reset
|
||||
+ * on power cycle"; this needs a store that survives a WARM reset (so in-session
|
||||
+ * escalation accumulates) but is cleared by a power-on reset.
|
||||
+ *
|
||||
+ * Two PMU-domain registers give exactly that, both hardware-validated on a real
|
||||
+ * 86-panel 2026-09-02:
|
||||
+ * - CRU glb_rst_st (0xff3b0c04): reads 0 after a power-on reset, nonzero
|
||||
+ * (bit0 set) after a warm/software reset. It survives the boot chain into
|
||||
+ * Linux and no vendor code clears it, so U-Boot can read it as the
|
||||
+ * cold-vs-warm discriminator.
|
||||
+ * - PMU GRF OS_REG4 (0xff020210): a free scratch register (OS_REG2/3 hold DDR
|
||||
+ * info, OS_REG8+ are used by the PM code, OS_REG0/1 are boot-mode/chip-ver).
|
||||
+ * It survives a warm reset (the attempt count accumulates) and, being in the
|
||||
+ * always-on PMU domain like the boot-mode register, is cleared by a power-on
|
||||
+ * reset. We additionally gate on glb_rst_st, so a power cycle restarts the
|
||||
+ * count even if the register somehow retained a value.
|
||||
+ *
|
||||
+ * flared clears OS_REG4 once a boot proves healthy (UI live for a sustained
|
||||
+ * hold) and before any deliberate reboot -- the same discipline the retired env
|
||||
+ * bootcount used, moved to a register that costs no flash wear and resets for
|
||||
+ * free on power loss. So only CONSECUTIVE unhealthy boots within one power
|
||||
+ * session escalate; a healthy boot, or a power cycle, restarts at the selected
|
||||
+ * slot.
|
||||
+ */
|
||||
+#define FLARE_AB_GLB_RST_ST 0xff3b0c04u /* CRU reset-status: 0 on POR */
|
||||
+#define FLARE_AB_SESSION_REG 0xff020210u /* PMU GRF OS_REG4: attempt count */
|
||||
+/*
|
||||
+ * Attempts on the selected committed slot before failing over to the other
|
||||
+ * committed slot; the other slot then gets the same budget before recovery.
|
||||
+ * Keep in sync with the runbook and flared's docs.
|
||||
+ */
|
||||
+#define FLARE_AB_SLOT_TRIES 2
|
||||
+/* Clamp against a garbage register value (validated free, so belt-only). */
|
||||
+#define FLARE_AB_MAX_SESSION 250
|
||||
+
|
||||
+static u32 flare_ab_reg_read(u32 addr)
|
||||
+{
|
||||
+ return readl((void __iomem *)(uintptr_t)addr);
|
||||
+}
|
||||
+
|
||||
+static void flare_ab_reg_write(u32 addr, u32 val)
|
||||
+{
|
||||
+ writel(val, (void __iomem *)(uintptr_t)addr);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Slot selection is resolved once per boot and memoized: the first
|
||||
+ * caller is init_kernel_dtb() at board_init() time (via the part-name
|
||||
+ * hook), and the per-attempt decrement must never flip the selection
|
||||
+ * mid-boot (the "boundary problem" the SPL engine documents).
|
||||
+ *
|
||||
+ * cached state: -1 unknown, -2 no A/B layout, 0 slot A, 1 slot B
|
||||
+ */
|
||||
+static int flare_ab_cached_slot = -1;
|
||||
+static int flare_ab_recovery;
|
||||
+
|
||||
+/*
|
||||
+ * Set during slot selection when the per-power-session escalation has burned
|
||||
+ * through both committed slots and the boot must fall to the recovery FIT.
|
||||
+ * Resolved once (inside ab_select_slot, via the flare_ab_cached_slot memo) and
|
||||
+ * read by flare_ab_have_bootable()/boot_attempt()/update_root_partition(), so
|
||||
+ * every consumer agrees for the whole boot. Distinct from flare_ab_recovery,
|
||||
+ * which fit_get_blob sets once it has actually redirected to the recovery FIT.
|
||||
+ */
|
||||
+static int flare_ab_force_recovery;
|
||||
+
|
||||
+/*
|
||||
+ * The serialized metadata must fit in the single 512-byte sector we read and
|
||||
+ * write. This is a build invariant, not a runtime condition (the struct is a
|
||||
+ * fixed 32 bytes), so assert it at compile time instead of branching on it.
|
||||
+ */
|
||||
+_Static_assert(sizeof(AvbABData) <= 512, "AvbABData must fit in one sector");
|
||||
+
|
||||
+/*
|
||||
+ * Whether any slot is bootable is resolved once per boot and memoized, exactly
|
||||
+ * like the slot selection above: fit_get_blob() reads it BOTH at the early
|
||||
+ * kernel-DTB load and again at the FIT load, and flare_ab_boot_attempt()'s
|
||||
+ * tries decrement runs between those two reads. An uncached re-read could flip
|
||||
+ * on the last-try boot (tries 1->0) and source U-Boot's own control FDT from a
|
||||
+ * slot we then abandon for the recovery FIT. -1 unknown, 0 none, 1 bootable.
|
||||
+ */
|
||||
+static int flare_ab_cached_bootable = -1;
|
||||
+
|
||||
+static uint32_t flare_htobe32(uint32_t in)
|
||||
+{
|
||||
+ union {
|
||||
+ uint32_t word;
|
||||
+ uint8_t bytes[4];
|
||||
+ } ret;
|
||||
+
|
||||
+ ret.bytes[0] = (in >> 24) & 0xff;
|
||||
+ ret.bytes[1] = (in >> 16) & 0xff;
|
||||
+ ret.bytes[2] = (in >> 8) & 0xff;
|
||||
+ ret.bytes[3] = in & 0xff;
|
||||
+
|
||||
+ return ret.word;
|
||||
+}
|
||||
+
|
||||
+static uint32_t flare_be32toh(uint32_t in)
|
||||
+{
|
||||
+ uint8_t *d = (uint8_t *)∈
|
||||
+ uint32_t ret;
|
||||
+
|
||||
+ ret = ((uint32_t)d[0]) << 24;
|
||||
+ ret |= ((uint32_t)d[1]) << 16;
|
||||
+ ret |= ((uint32_t)d[2]) << 8;
|
||||
+ ret |= ((uint32_t)d[3]);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static bool ab_data_verify_and_byteswap(const AvbABData *src, AvbABData *dest)
|
||||
+{
|
||||
+ if (memcmp(src->magic, AVB_AB_MAGIC, AVB_AB_MAGIC_LEN) != 0) {
|
||||
+ printf("FLARE-AB: magic is incorrect\n");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ memcpy(dest, src, sizeof(AvbABData));
|
||||
+ dest->crc32 = flare_be32toh(dest->crc32);
|
||||
+
|
||||
+ if (dest->version_major > AVB_AB_MAJOR_VERSION) {
|
||||
+ printf("FLARE-AB: no support for given major version\n");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ if (dest->crc32 != crc32(0, (const uint8_t *)dest,
|
||||
+ sizeof(AvbABData) - sizeof(uint32_t))) {
|
||||
+ printf("FLARE-AB: CRC32 does not match\n");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+static void ab_data_update_crc_and_byteswap(const AvbABData *src,
|
||||
+ AvbABData *dest)
|
||||
+{
|
||||
+ memcpy(dest, src, sizeof(AvbABData));
|
||||
+ dest->crc32 = flare_htobe32(crc32(0, (const uint8_t *)dest,
|
||||
+ sizeof(AvbABData) - sizeof(uint32_t)));
|
||||
+}
|
||||
+
|
||||
+static void ab_data_init(AvbABData *data)
|
||||
+{
|
||||
+ memset(data, '\0', sizeof(AvbABData));
|
||||
+ memcpy(data->magic, AVB_AB_MAGIC, AVB_AB_MAGIC_LEN);
|
||||
+ data->version_major = AVB_AB_MAJOR_VERSION;
|
||||
+ data->version_minor = AVB_AB_MINOR_VERSION;
|
||||
+ data->last_boot = 0;
|
||||
+ data->slots[0].priority = AVB_AB_MAX_PRIORITY;
|
||||
+ data->slots[0].tries_remaining = AVB_AB_MAX_TRIES_REMAINING;
|
||||
+ data->slots[0].successful_boot = 0;
|
||||
+ data->slots[1].priority = AVB_AB_MAX_PRIORITY - 1;
|
||||
+ data->slots[1].tries_remaining = AVB_AB_MAX_TRIES_REMAINING;
|
||||
+ data->slots[1].successful_boot = 0;
|
||||
+}
|
||||
+
|
||||
+static int ab_read_metadata(struct blk_desc *dev_desc, AvbABData *ab_data)
|
||||
+{
|
||||
+ disk_partition_t part_info;
|
||||
+ char temp[512];
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!dev_desc || !ab_data)
|
||||
+ return -EFAULT;
|
||||
+
|
||||
+ /*
|
||||
+ * Strict lookup: "misc" must never itself be slot-suffixed, and
|
||||
+ * this path is re-entered from the part-name hook.
|
||||
+ */
|
||||
+ if (part_get_info_by_name_strict(dev_desc, PART_MISC, &part_info) < 0)
|
||||
+ return -ENOENT;
|
||||
+
|
||||
+ ret = blk_dread(dev_desc, part_info.start + AB_METADATA_OFFSET, 1,
|
||||
+ temp);
|
||||
+ if (ret != 1)
|
||||
+ return -ENODEV;
|
||||
+
|
||||
+ memcpy(ab_data, temp, sizeof(AvbABData));
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int ab_write_metadata(struct blk_desc *dev_desc, AvbABData *ab_data)
|
||||
+{
|
||||
+ disk_partition_t part_info;
|
||||
+ char temp[512];
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!dev_desc || !ab_data)
|
||||
+ return -EFAULT;
|
||||
+
|
||||
+ memset(temp, 0, sizeof(temp));
|
||||
+ memcpy(temp, ab_data, sizeof(AvbABData));
|
||||
+ if (part_get_info_by_name_strict(dev_desc, PART_MISC, &part_info) < 0)
|
||||
+ return -ENOENT;
|
||||
+
|
||||
+ ret = blk_dwrite(dev_desc, part_info.start + AB_METADATA_OFFSET, 1,
|
||||
+ temp);
|
||||
+ if (ret != 1)
|
||||
+ return -ENODEV;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int ab_data_write(struct blk_desc *dev_desc, AvbABData *ab_data)
|
||||
+{
|
||||
+ AvbABData serialized;
|
||||
+
|
||||
+ ab_data_update_crc_and_byteswap(ab_data, &serialized);
|
||||
+
|
||||
+ return ab_write_metadata(dev_desc, &serialized);
|
||||
+}
|
||||
+
|
||||
+static int ab_data_read(struct blk_desc *dev_desc, AvbABData *ab_data)
|
||||
+{
|
||||
+ AvbABData serialized;
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = ab_read_metadata(dev_desc, &serialized);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ if (!ab_data_verify_and_byteswap(&serialized, ab_data)) {
|
||||
+ printf("FLARE-AB: invalid metadata, resetting to defaults\n");
|
||||
+ ab_data_init(ab_data);
|
||||
+ ab_data_write(dev_desc, ab_data);
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static bool slot_is_bootable(AvbABSlotData *slot)
|
||||
+{
|
||||
+ return slot->priority > 0 &&
|
||||
+ (slot->successful_boot || (slot->tries_remaining > 0));
|
||||
+}
|
||||
+
|
||||
+static void slot_set_unbootable(AvbABSlotData *slot)
|
||||
+{
|
||||
+ slot->priority = 0;
|
||||
+ slot->tries_remaining = 0;
|
||||
+ slot->successful_boot = 0;
|
||||
+}
|
||||
+
|
||||
+static void slot_normalize(AvbABSlotData *slot)
|
||||
+{
|
||||
+ if (slot->priority > 0) {
|
||||
+ if (slot->tries_remaining == 0 && !slot->successful_boot)
|
||||
+ slot_set_unbootable(slot);
|
||||
+ if (slot->tries_remaining > 0 && slot->successful_boot)
|
||||
+ slot_set_unbootable(slot);
|
||||
+ } else {
|
||||
+ slot_set_unbootable(slot);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * This power session's boot-attempt number against the selected slot (>=1).
|
||||
+ * glb_rst_st==0 (a power-on reset) restarts the count; a warm reset carries the
|
||||
+ * prior value forward. Writes the incremented value back to OS_REG4 so the next
|
||||
+ * warm reset escalates. Called exactly once per boot (from ab_select_slot, which
|
||||
+ * itself runs once behind the flare_ab_cached_slot memo).
|
||||
+ */
|
||||
+static int flare_ab_bump_session(void)
|
||||
+{
|
||||
+ u32 prior;
|
||||
+
|
||||
+ if (flare_ab_reg_read(FLARE_AB_GLB_RST_ST) == 0)
|
||||
+ prior = 0;
|
||||
+ else
|
||||
+ prior = flare_ab_reg_read(FLARE_AB_SESSION_REG);
|
||||
+
|
||||
+ if (prior > FLARE_AB_MAX_SESSION)
|
||||
+ prior = FLARE_AB_MAX_SESSION;
|
||||
+
|
||||
+ prior += 1;
|
||||
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, prior);
|
||||
+
|
||||
+ return (int)prior;
|
||||
+}
|
||||
+
|
||||
+static int ab_select_slot(void)
|
||||
+{
|
||||
+ struct blk_desc *dev_desc;
|
||||
+ AvbABData ab_data;
|
||||
+ int pref, other, session;
|
||||
+
|
||||
+ dev_desc = rockchip_get_bootdev();
|
||||
+ if (!dev_desc)
|
||||
+ return -2;
|
||||
+
|
||||
+ if (ab_data_read(dev_desc, &ab_data))
|
||||
+ return -2; /* no misc partition: legacy single-slot layout */
|
||||
+
|
||||
+ if (slot_is_bootable(&ab_data.slots[0]) &&
|
||||
+ slot_is_bootable(&ab_data.slots[1])) {
|
||||
+ if (ab_data.slots[1].priority > ab_data.slots[0].priority)
|
||||
+ pref = 1;
|
||||
+ else
|
||||
+ pref = 0;
|
||||
+ } else if (slot_is_bootable(&ab_data.slots[0])) {
|
||||
+ pref = 0;
|
||||
+ } else if (slot_is_bootable(&ab_data.slots[1])) {
|
||||
+ pref = 1;
|
||||
+ } else {
|
||||
+ /*
|
||||
+ * No bootable slot at all (an exhausted update). Keep a
|
||||
+ * deterministic answer (last_boot) so partition lookups still
|
||||
+ * resolve; the boot path falls back to the recovery FIT instead
|
||||
+ * (fit_get_blob checks flare_ab_have_bootable). Session
|
||||
+ * escalation does not apply here -- persistent tries already
|
||||
+ * decided this -- so leave OS_REG4 alone.
|
||||
+ */
|
||||
+ printf("FLARE-AB: no bootable slot, lastboot=%d\n",
|
||||
+ ab_data.last_boot);
|
||||
+ return ab_data.last_boot ? 1 : 0;
|
||||
+ }
|
||||
+
|
||||
+ other = 1 - pref;
|
||||
+
|
||||
+ if (!ab_data.slots[pref].successful_boot) {
|
||||
+ /*
|
||||
+ * UPDATE regime: the preferred bootable slot is an unconfirmed
|
||||
+ * update. The persistent per-attempt tries decrement (in
|
||||
+ * flare_ab_boot_attempt) drives the revert, and it must survive
|
||||
+ * power cycles so a bad update cannot return after a brownout.
|
||||
+ * The session counter plays no part here; clear it so that once
|
||||
+ * the update resolves to a committed steady state the escalation
|
||||
+ * starts fresh at the selected slot.
|
||||
+ */
|
||||
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, 0);
|
||||
+ printf("FLARE-AB: slot %s (update in flight), tries-remain=%d\n",
|
||||
+ pref ? "_b" : "_a",
|
||||
+ ab_data.slots[pref].tries_remaining);
|
||||
+ return pref;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * STEADY-STATE regime: the selected slot is committed. Escalate per
|
||||
+ * power session -- selected slot for FLARE_AB_SLOT_TRIES attempts, then
|
||||
+ * the other slot if it too is committed, then the recovery FIT. A power
|
||||
+ * cycle (glb_rst_st==0) restarts at the selected slot.
|
||||
+ */
|
||||
+ session = flare_ab_bump_session();
|
||||
+
|
||||
+ if (session <= FLARE_AB_SLOT_TRIES) {
|
||||
+ printf("FLARE-AB: slot %s (attempt %d/%d this power session)\n",
|
||||
+ pref ? "_b" : "_a", session, FLARE_AB_SLOT_TRIES);
|
||||
+ return pref;
|
||||
+ }
|
||||
+
|
||||
+ if (session <= 2 * FLARE_AB_SLOT_TRIES &&
|
||||
+ slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ ab_data.slots[other].successful_boot) {
|
||||
+ printf("FLARE-AB: slot %s failed %d attempts this session, trying %s\n",
|
||||
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES,
|
||||
+ other ? "_b" : "_a");
|
||||
+ return other;
|
||||
+ }
|
||||
+
|
||||
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
|
||||
+ flare_ab_force_recovery = 1;
|
||||
+ return pref;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_enabled(void)
|
||||
+{
|
||||
+ if (flare_ab_cached_slot == -1)
|
||||
+ flare_ab_cached_slot = ab_select_slot();
|
||||
+
|
||||
+ return flare_ab_cached_slot >= 0;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_get_current_slot(char *slot)
|
||||
+{
|
||||
+ if (!flare_ab_enabled())
|
||||
+ return -ENOENT;
|
||||
+
|
||||
+ memcpy(slot, flare_ab_cached_slot ? "_b" : "_a", 2);
|
||||
+ slot[2] = '\0';
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_append_part_slot(struct blk_desc *dev_desc,
|
||||
+ const char *part_name, char *new_name)
|
||||
+{
|
||||
+ char slot_suffix[3] = {0};
|
||||
+
|
||||
+ /*
|
||||
+ * Never suffix the slot-metadata carrier itself (also breaks
|
||||
+ * the re-entrancy from ab_read_metadata), nor the shared
|
||||
+ * recovery FIT.
|
||||
+ */
|
||||
+ if (!strcmp(part_name, PART_MISC) ||
|
||||
+ !strcmp(part_name, PART_RECOVERY)) {
|
||||
+ strcat(new_name, part_name);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (flare_ab_get_current_slot(slot_suffix)) {
|
||||
+ /* No A/B layout: behave exactly like stock. */
|
||||
+ strcat(new_name, part_name);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ strcpy(new_name, part_name);
|
||||
+ strcat(new_name, slot_suffix);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_have_bootable(void)
|
||||
+{
|
||||
+ struct blk_desc *dev_desc;
|
||||
+ AvbABData ab_data;
|
||||
+
|
||||
+ /*
|
||||
+ * Resolve selection first: the per-power-session escalation can decide
|
||||
+ * both committed slots are exhausted and force the recovery FIT even
|
||||
+ * though the persistent metadata still marks a slot bootable. In that
|
||||
+ * case there is no bootable NORMAL slot for this boot.
|
||||
+ */
|
||||
+ flare_ab_enabled();
|
||||
+ if (flare_ab_force_recovery)
|
||||
+ return 0;
|
||||
+
|
||||
+ /*
|
||||
+ * Memoized for the whole boot (see flare_ab_cached_bootable): the two
|
||||
+ * fit_get_blob() reads straddle the per-attempt tries decrement, so an
|
||||
+ * uncached answer could disagree with itself on the last-try boot.
|
||||
+ */
|
||||
+ if (flare_ab_cached_bootable != -1)
|
||||
+ return flare_ab_cached_bootable;
|
||||
+
|
||||
+ flare_ab_cached_bootable = 0;
|
||||
+
|
||||
+ dev_desc = rockchip_get_bootdev();
|
||||
+ if (!dev_desc)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (ab_data_read(dev_desc, &ab_data))
|
||||
+ return 0;
|
||||
+
|
||||
+ flare_ab_cached_bootable = slot_is_bootable(&ab_data.slots[0]) ||
|
||||
+ slot_is_bootable(&ab_data.slots[1]);
|
||||
+ return flare_ab_cached_bootable;
|
||||
+}
|
||||
+
|
||||
+void flare_ab_set_recovery_mode(void)
|
||||
+{
|
||||
+ if (!flare_ab_recovery) {
|
||||
+ printf("FLARE-AB: recovery FIT selected\n");
|
||||
+ /*
|
||||
+ * One-shot, like the BCB clear RkLunch-recovery.sh does on
|
||||
+ * entry to the rescue ramdisk: the per-power-session
|
||||
+ * escalation has done its job (or was bypassed by a BCB
|
||||
+ * command) once we are here, so reset it. Without this,
|
||||
+ * OS_REG4 keeps carrying the count that forced recovery, and
|
||||
+ * this SoC's `reboot` only works via the CRU global-reset
|
||||
+ * poke (docs/boot-flow.md) -- itself a WARM reset -- so any
|
||||
+ * reboot issued from inside recovery would re-escalate
|
||||
+ * straight back into recovery on the next boot, stranding
|
||||
+ * the operator until someone cycles power at the unit. This
|
||||
+ * one hook covers every path that reaches PART_RECOVERY (BCB
|
||||
+ * command, no-bootable-slot fallback, and this session
|
||||
+ * escalation alike).
|
||||
+ */
|
||||
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, 0);
|
||||
+ }
|
||||
+ flare_ab_recovery = 1;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_in_recovery(void)
|
||||
+{
|
||||
+ return flare_ab_recovery;
|
||||
+}
|
||||
+
|
||||
+void flare_ab_boot_attempt(void)
|
||||
+{
|
||||
+ struct blk_desc *dev_desc;
|
||||
+ AvbABData ab_data, ab_data_orig;
|
||||
+ int slot_index;
|
||||
+
|
||||
+ if (!flare_ab_enabled() || flare_ab_recovery || flare_ab_force_recovery)
|
||||
+ return;
|
||||
+
|
||||
+ slot_index = flare_ab_cached_slot;
|
||||
+
|
||||
+ dev_desc = rockchip_get_bootdev();
|
||||
+ if (!dev_desc)
|
||||
+ return;
|
||||
+
|
||||
+ if (ab_data_read(dev_desc, &ab_data))
|
||||
+ return;
|
||||
+
|
||||
+ memcpy(&ab_data_orig, &ab_data, sizeof(AvbABData));
|
||||
+
|
||||
+ slot_normalize(&ab_data.slots[0]);
|
||||
+ slot_normalize(&ab_data.slots[1]);
|
||||
+
|
||||
+ if (!ab_data.slots[slot_index].successful_boot &&
|
||||
+ ab_data.slots[slot_index].tries_remaining > 0)
|
||||
+ ab_data.slots[slot_index].tries_remaining -= 1;
|
||||
+
|
||||
+ ab_data.last_boot = slot_index;
|
||||
+
|
||||
+ /*
|
||||
+ * Single-sector write, and only while an update window is open
|
||||
+ * (an unsuccessful slot): a confirmed device's ordinary boots
|
||||
+ * and power cycles never write flash here.
|
||||
+ */
|
||||
+ if (memcmp(&ab_data, &ab_data_orig, sizeof(AvbABData)))
|
||||
+ ab_data_write(dev_desc, &ab_data);
|
||||
+}
|
||||
+
|
||||
+void flare_ab_boot_failed(void)
|
||||
+{
|
||||
+ if (!flare_ab_enabled())
|
||||
+ return;
|
||||
+
|
||||
+ if (flare_ab_recovery) {
|
||||
+ /*
|
||||
+ * Both slots AND the recovery FIT are gone. Escalate to USB
|
||||
+ * download: `download` runs `rockusb` FROM U-BOOT when
|
||||
+ * CONFIG_CMD_ROCKUSB is built (flare-usb-gadget.config), so a
|
||||
+ * bad-boot device is reflashable over USB with no MaskRom
|
||||
+ * button / disassembly; if rockusb is absent it falls through
|
||||
+ * to `rbrom` (BootROM MaskRom). Either way the host can recover
|
||||
+ * it over the existing USB port.
|
||||
+ */
|
||||
+ printf("FLARE-AB: recovery FIT unbootable, entering USB download\n");
|
||||
+ run_command("download", 0);
|
||||
+ hang();
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * A storage-slot boot failed to load its FIT. Reset so the next boot
|
||||
+ * makes forward progress. This is a WARM reset, so glb_rst_st stays
|
||||
+ * nonzero and OS_REG4 carries the attempt count: the next boot
|
||||
+ * escalates -- retry the same committed slot up to FLARE_AB_SLOT_TRIES,
|
||||
+ * then the other committed slot, then the recovery FIT, then USB
|
||||
+ * download. In the update regime the per-attempt persistent-tries
|
||||
+ * decrement (flare_ab_boot_attempt) has already run, so the same reset
|
||||
+ * drives the persistent revert to the other slot. A power cycle
|
||||
+ * (glb_rst_st==0) restarts at the selected slot -- no failure state is
|
||||
+ * written to flash for a committed slot.
|
||||
+ */
|
||||
+ printf("FLARE-AB: slot boot failed, resetting\n");
|
||||
+ do_reset(NULL, 0, 0, NULL);
|
||||
+ hang();
|
||||
+}
|
||||
+
|
||||
+void flare_ab_update_root_partition(void)
|
||||
+{
|
||||
+ disk_partition_t part_info;
|
||||
+ struct blk_desc *dev_desc;
|
||||
+ char arg[64];
|
||||
+ char slot_suffix[3] = {0};
|
||||
+ int part_num;
|
||||
+
|
||||
+ if (!flare_ab_enabled())
|
||||
+ return;
|
||||
+
|
||||
+ if (flare_ab_recovery || flare_ab_force_recovery) {
|
||||
+ /*
|
||||
+ * Recovery boots from its own initramfs; publish the
|
||||
+ * marker and leave root= alone (unused under rdinit).
|
||||
+ * flare_ab_force_recovery is set by the session escalation at
|
||||
+ * selection time, before fit_get_blob has set flare_ab_recovery,
|
||||
+ * so it must be honored here too.
|
||||
+ */
|
||||
+ env_update("bootargs", "warden.recovery=1");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ dev_desc = rockchip_get_bootdev();
|
||||
+ if (!dev_desc)
|
||||
+ return;
|
||||
+
|
||||
+ /* Auto-suffixed by the part-name hook: resolves rootfs_a/_b. */
|
||||
+ part_num = part_get_info_by_name(dev_desc, "rootfs", &part_info);
|
||||
+ if (part_num < 0) {
|
||||
+ printf("FLARE-AB: no rootfs slot partition\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if (dev_desc->if_type != IF_TYPE_MMC)
|
||||
+ return;
|
||||
+
|
||||
+ snprintf(arg, sizeof(arg), "root=/dev/mmcblk0p%d", part_num);
|
||||
+ env_update("bootargs", arg);
|
||||
+
|
||||
+ flare_ab_get_current_slot(slot_suffix);
|
||||
+ snprintf(arg, sizeof(arg), "warden.slot=%s", slot_suffix);
|
||||
+ env_update("bootargs", arg);
|
||||
+}
|
||||
diff --git a/sysdrv/source/uboot/u-boot/configs/flare-ab.config b/sysdrv/source/uboot/u-boot/configs/flare-ab.config
|
||||
new file mode 100644
|
||||
index 000000000..1404655c0
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/configs/flare-ab.config
|
||||
@@ -0,0 +1,10 @@
|
||||
+# flare-edge: A/B slot boot in U-Boot proper.
|
||||
+#
|
||||
+# Lean port of the vendor SPL A/B engine (common/flare_ab.c): AOSP
|
||||
+# AvbABData metadata in one CRC32-protected sector at misc+2048, slot
|
||||
+# suffixing hooked into part_get_info_by_name() (covers boot_fit AND the
|
||||
+# board_init()-time kernel-DTB/resource load), one tries decrement per
|
||||
+# boot attempt while a slot is unconfirmed, recovery-FIT fallback when
|
||||
+# both slots are exhausted, MaskRom when even that fails.
|
||||
+# Design: docs/decisions/0001-slot-machine.md (flare-edge repo).
|
||||
+CONFIG_FLARE_AB=y
|
||||
diff --git a/sysdrv/source/uboot/u-boot/disk/part.c b/sysdrv/source/uboot/u-boot/disk/part.c
|
||||
index 182c03771..ad73662eb 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/disk/part.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/disk/part.c
|
||||
@@ -14,6 +14,9 @@
|
||||
#ifdef CONFIG_SPL_AB
|
||||
#include <spl_ab.h>
|
||||
#endif
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+#include <flare_ab.h>
|
||||
+#endif
|
||||
#include <ubifs_uboot.h>
|
||||
#ifdef CONFIG_ANDROID_AB
|
||||
#include <android_avb/avb_ops_user.h>
|
||||
@@ -700,7 +703,8 @@ static int part_get_info_by_name_option(struct blk_desc *dev_desc,
|
||||
}
|
||||
|
||||
/* 1. Query partition with A/B slot suffix */
|
||||
-#if defined(CONFIG_ANDROID_AB) || defined(CONFIG_SPL_AB)
|
||||
+#if defined(CONFIG_ANDROID_AB) || defined(CONFIG_SPL_AB) || \
|
||||
+ defined(CONFIG_FLARE_AB)
|
||||
char *slot = (char *)name + strlen(name) - 2;
|
||||
|
||||
if (!strcmp(slot, "_a") || !strcmp(slot, "_b"))
|
||||
@@ -710,6 +714,10 @@ static int part_get_info_by_name_option(struct blk_desc *dev_desc,
|
||||
if (rk_avb_append_part_slot(name, name_slot))
|
||||
return -1;
|
||||
full_name = name_slot;
|
||||
+#elif defined(CONFIG_FLARE_AB) && !defined(CONFIG_SPL_BUILD)
|
||||
+ if (flare_ab_append_part_slot(dev_desc, name, name_slot))
|
||||
+ return -1;
|
||||
+ full_name = name_slot;
|
||||
#elif defined(CONFIG_SPL_AB) && defined(CONFIG_SPL_BUILD)
|
||||
if (spl_ab_append_part_slot(dev_desc, name, name_slot))
|
||||
return -1;
|
||||
diff --git a/sysdrv/source/uboot/u-boot/include/flare_ab.h b/sysdrv/source/uboot/u-boot/include/flare_ab.h
|
||||
new file mode 100644
|
||||
index 000000000..d009525e0
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/include/flare_ab.h
|
||||
@@ -0,0 +1,73 @@
|
||||
+/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
+/*
|
||||
+ * flare-edge A/B slot boot for U-Boot proper.
|
||||
+ *
|
||||
+ * A lean, libavb-free port of the vendor SPL A/B engine
|
||||
+ * (common/spl/spl_ab.c) so the same AOSP AvbABData metadata (one
|
||||
+ * CRC32-protected 32-byte struct in a single 512-byte sector at
|
||||
+ * `misc` + AB_METADATA_OFFSET blocks) drives slot selection in U-Boot
|
||||
+ * proper: boot_a/boot_b via the part_get_info_by_name() suffix hook,
|
||||
+ * per-attempt tries decrement, and fallback to the recovery FIT when
|
||||
+ * both slots are exhausted.
|
||||
+ *
|
||||
+ * Linux-side counterpart: flared's slotctl module — the ONLY writer of
|
||||
+ * this metadata from userspace (CI-enforced).
|
||||
+ */
|
||||
+
|
||||
+#ifndef _FLARE_AB_H_
|
||||
+#define _FLARE_AB_H_
|
||||
+
|
||||
+#include <blk.h>
|
||||
+
|
||||
+/* Same on-disk location as the vendor SPL engine (spl_ab.h). */
|
||||
+#ifndef AB_METADATA_OFFSET
|
||||
+#define AB_METADATA_OFFSET 4
|
||||
+#endif
|
||||
+
|
||||
+/*
|
||||
+ * True when an A/B layout is present (a `misc` partition with valid or
|
||||
+ * initializable metadata). On a legacy single-slot layout every hook
|
||||
+ * below degrades to stock behavior.
|
||||
+ */
|
||||
+int flare_ab_enabled(void);
|
||||
+
|
||||
+/* Memoized for the whole boot: "_a"/"_b" into slot[3]. 0 on success. */
|
||||
+int flare_ab_get_current_slot(char *slot);
|
||||
+
|
||||
+/* part_get_info_by_name() hook: append the active slot suffix. */
|
||||
+int flare_ab_append_part_slot(struct blk_desc *dev_desc,
|
||||
+ const char *part_name, char *new_name);
|
||||
+
|
||||
+/* Any slot with priority>0 and (successful || tries>0)? */
|
||||
+int flare_ab_have_bootable(void);
|
||||
+
|
||||
+/*
|
||||
+ * One boot attempt against the selected slot: decrement tries_remaining
|
||||
+ * iff the slot is not yet successful (single-sector write, and no write
|
||||
+ * at all in the successful steady state — spec fault 14 by construction).
|
||||
+ * No-op in recovery fallback mode or on a non-A/B layout.
|
||||
+ */
|
||||
+void flare_ab_boot_attempt(void);
|
||||
+
|
||||
+/*
|
||||
+ * Storage boot failed (FIT unreadable/unbootable). On an A/B layout:
|
||||
+ * reset so the next boot re-selects (per-attempt decrement guarantees
|
||||
+ * progress); once no slot is bootable the next boot falls back to the
|
||||
+ * recovery FIT; if that also failed, drop to MaskRom (`download`).
|
||||
+ * Returns (doing nothing) on a non-A/B layout.
|
||||
+ */
|
||||
+void flare_ab_boot_failed(void);
|
||||
+
|
||||
+/* fit_get_blob() fell back to (or was commanded into) the recovery FIT. */
|
||||
+void flare_ab_set_recovery_mode(void);
|
||||
+int flare_ab_in_recovery(void);
|
||||
+
|
||||
+/*
|
||||
+ * bootargs fixup, mirrors ab_update_root_partition(): key-replace
|
||||
+ * root= with the active slot's rootfs partition and publish
|
||||
+ * warden.slot=_x (and warden.recovery=1 in recovery fallback) for
|
||||
+ * userspace (oem mount, slotctl).
|
||||
+ */
|
||||
+void flare_ab_update_root_partition(void);
|
||||
+
|
||||
+#endif /* _FLARE_AB_H_ */
|
||||
diff --git a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
@@ -16,6 +16,9 @@
|
||||
#include <cli.h>
|
||||
#include <clk.h>
|
||||
#include <console.h>
|
||||
#include <flare_trace.h>
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+#include <flare_ab.h>
|
||||
+#endif
|
||||
#include <debug_uart.h>
|
||||
#include <dm.h>
|
||||
@@ -1340,9 +1343,19 @@
|
||||
static void bootargs_add_android(bool verbose)
|
||||
{
|
||||
#ifdef CONFIG_ANDROID_AB
|
||||
ab_update_root_partition();
|
||||
#endif
|
||||
|
||||
+#ifdef CONFIG_FLARE_AB
|
||||
+ /*
|
||||
+ * Runs after bootargs_add_partition() merged sys_bootargs, so
|
||||
+ * the env_update() here key-replaces any build-time root= with
|
||||
+ * the active slot's rootfs partition (and publishes warden.slot
|
||||
+ * for userspace).
|
||||
+ */
|
||||
+ flare_ab_update_root_partition();
|
||||
+#endif
|
||||
+
|
||||
/* Android header v4+ need this handle */
|
||||
#ifdef CONFIG_ANDROID_BOOT_IMAGE
|
||||
struct andr_img_hdr *hdr;
|
||||
@@ -1,35 +0,0 @@
|
||||
diff --git a/sysdrv/source/uboot/u-boot/cmd/download.c b/sysdrv/source/uboot/u-boot/cmd/download.c
|
||||
index 528501305..77f56ea12 100644
|
||||
--- a/sysdrv/source/uboot/u-boot/cmd/download.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/cmd/download.c
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <console.h>
|
||||
+#if defined(CONFIG_DRM_ROCKCHIP) && defined(CONFIG_FLARE_AB)
|
||||
+#include <video_rockchip.h>
|
||||
+#endif
|
||||
|
||||
__weak void do_board_download(void)
|
||||
{
|
||||
@@ -17,6 +20,20 @@ static int do_download(cmd_tbl_t *cmdtp, int flag,
|
||||
{
|
||||
disable_ctrlc(1);
|
||||
|
||||
+#if defined(CONFIG_DRM_ROCKCHIP) && defined(CONFIG_FLARE_AB)
|
||||
+ /*
|
||||
+ * flare-edge: paint the "connect USB to recover" splash before entering
|
||||
+ * download mode. Reached on every download trigger — FLARE_AB slot/
|
||||
+ * recovery exhaustion, altbootcmd=download, the BOOT key, Ctrl+D. The
|
||||
+ * VOP keeps scanning out this framebuffer while rockusb (below) serves
|
||||
+ * from U-Boot WITHOUT a reset, so the image PERSISTS on screen the whole
|
||||
+ * time the device is USB-flashable. (On the rbrom fallback a CRU reset
|
||||
+ * clears it — BootROM has no display — but rockusb is the primary path.)
|
||||
+ * logo_recovery.bmp is packed into resource.img (kernel scripts/mkimg).
|
||||
+ */
|
||||
+ rockchip_show_bmp("logo_recovery.bmp");
|
||||
+#endif
|
||||
+
|
||||
/* Allow board specific download, maybe noreturn */
|
||||
do_board_download();
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
diff -ruN a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi 2026-09-01 15:32:39.100121610 -0600
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi 2026-09-01 15:32:39.056121549 -0600
|
||||
@@ -93,7 +93,14 @@
|
||||
|
||||
&sdmmc {
|
||||
u-boot,dm-spl;
|
||||
- pwr-en-gpios = <&gpio0 RK_PA1 GPIO_ACTIVE_LOW>;
|
||||
+ /* flare-edge: the EVB's SD-slot power enable was <&gpio0 RK_PA1
|
||||
+ * GPIO_ACTIVE_LOW> -- on the 86-Panel that pin is RGB_RES, the
|
||||
+ * CH32V003 panel-init MCU's reset (schematic-confirmed net). The
|
||||
+ * sdmmc probe was driving it low in SPL on every boot, holding the
|
||||
+ * panel initialiser in reset until board_init re-released it at
|
||||
+ * ~0.55 s and restarting its measured, fixed 4.89 s init -- the
|
||||
+ * single longest pole in time-to-first-image. The 86-Panel's SD slot
|
||||
+ * has no switched rail on this line; drop the property. */
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
diff -ruN a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c 2026-09-01 15:32:39.100121610 -0600
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/spl.c 2026-09-01 15:32:39.040121527 -0600
|
||||
@@ -216,6 +216,23 @@
|
||||
#endif
|
||||
gd->flags = dummy;
|
||||
rockchip_stimer_init();
|
||||
+#if defined(CONFIG_ROCKCHIP_RV1106)
|
||||
+ /*
|
||||
+ * flare-edge: release GPIO0_A1 (net RGB_RES) at the earliest possible
|
||||
+ * moment. The net holds the 86-Panel's CH32V003 init MCU (and the
|
||||
+ * panel's own reset pin) in reset via the pin's power-on pulldown, and
|
||||
+ * the MCU takes a MEASURED, fixed 4.89 s from release to first photons
|
||||
+ * (its SPI init of the NV3052 controller) regardless of anything the
|
||||
+ * SoC does. Every millisecond the release moves earlier is a
|
||||
+ * millisecond off time-to-first-image, so it happens here in SPL
|
||||
+ * (~0.03 s) rather than U-Boot proper's board_init() (~0.45 s), which
|
||||
+ * keeps its own idempotent release as a fallback. Raw writels because
|
||||
+ * no driver model exists yet: RV1106 GPIO0 v2 @0xff380000,
|
||||
+ * swport_dr_l 0x00 / swport_ddr_l 0x08, write-masked upper half word.
|
||||
+ */
|
||||
+ writel(0x00020002, (void *)0xff380008); /* GPIO0_A1 -> output */
|
||||
+ writel(0x00020002, (void *)0xff380000); /* GPIO0_A1 -> high */
|
||||
+#endif
|
||||
#define EARLY_UART
|
||||
#if defined(EARLY_UART) && defined(CONFIG_DEBUG_UART)
|
||||
/*
|
||||
@@ -230,6 +247,14 @@
|
||||
!(gd->flags & GD_FLG_DISABLE_CONSOLE))
|
||||
debug_uart_init();
|
||||
printascii("U-Boot SPL board init");
|
||||
+#if defined(CONFIG_ROCKCHIP_RV1106)
|
||||
+ /* flare-edge: diagnose the early GPIO0_A1 release -- print DR+DDR. */
|
||||
+ printascii(" [RGB_RES dr=");
|
||||
+ printhex8(readl((void *)0xff380000));
|
||||
+ printascii(" ddr=");
|
||||
+ printhex8(readl((void *)0xff380008));
|
||||
+ printascii("] ");
|
||||
+#endif
|
||||
#endif
|
||||
gd->sys_start_tick = get_ticks();
|
||||
#ifdef CONFIG_SPL_PCIE_EP_SUPPORT
|
||||
@@ -1,109 +0,0 @@
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/dts/rv1106-u-boot.dtsi
|
||||
@@ -246,3 +246,106 @@
|
||||
u-boot,dm-pre-reloc;
|
||||
status = "okay";
|
||||
};
|
||||
+
|
||||
+/*
|
||||
+ * flare-edge: the 86-Panel display graph, kept in U-Boot's OWN device tree.
|
||||
+ *
|
||||
+ * DORMANT in the shipped configuration: flare-display.config keeps
|
||||
+ * CONFIG_USING_KERNEL_DTB=y and embeds a kernel-style control DTB
|
||||
+ * (CONFIG_EMBED_KERNEL_DTB_ALWAYS, dts/rv1106-warden-kernel.dtb), which
|
||||
+ * board_init() adopts BEFORE any display bring-up -- so these nodes are not
|
||||
+ * consulted at runtime today. They are kept as the complete, board-correct
|
||||
+ * display graph for a future own-control-DTB configuration, copied verbatim
|
||||
+ * from the proven 5.10 kernel DTS (rv1106-luckfox-pico-86panel-ipc.dtsi).
|
||||
+ *
|
||||
+ * Do NOT enable such a configuration by setting
|
||||
+ * "CONFIG_USING_KERNEL_DTB is not set": that path was tried 2026-09-01 and
|
||||
+ * silently breaks the ENVF whitelist import -- blkdevparts= disappears from
|
||||
+ * the kernel cmdline and, with no partition table outside the cmdline, BOTH
|
||||
+ * slots hang in rootwait (see flare-display.config for the full account).
|
||||
+ * The logo BMPs always come from the booted slot's resource.img.
|
||||
+ */
|
||||
+/ {
|
||||
+ backlight: backlight {
|
||||
+ compatible = "pwm-backlight";
|
||||
+ pwms = <&pwm1 0 100000 50000>;
|
||||
+ };
|
||||
+
|
||||
+ panel: panel {
|
||||
+ compatible = "simple-panel";
|
||||
+ backlight = <&backlight>;
|
||||
+ bus-format = <0x1009>; /* MEDIA_BUS_FMT_RGB666_1X18 */
|
||||
+ width-mm = <85>;
|
||||
+ height-mm = <85>;
|
||||
+
|
||||
+ display-timings {
|
||||
+ native-mode = <&timing0>;
|
||||
+
|
||||
+ timing0: timing0 {
|
||||
+ clock-frequency = <30000000>;
|
||||
+ hactive = <720>;
|
||||
+ vactive = <720>;
|
||||
+ hback-porch = <44>;
|
||||
+ hfront-porch = <46>;
|
||||
+ vback-porch = <18>;
|
||||
+ vfront-porch = <16>;
|
||||
+ hsync-len = <2>;
|
||||
+ vsync-len = <2>;
|
||||
+ hsync-active = <0>;
|
||||
+ vsync-active = <0>;
|
||||
+ de-active = <0>;
|
||||
+ pixelclk-active = <0>;
|
||||
+ };
|
||||
+ };
|
||||
+
|
||||
+ port {
|
||||
+ panel_in_rgb: endpoint {
|
||||
+ remote-endpoint = <&rgb_out_panel>;
|
||||
+ };
|
||||
+ };
|
||||
+ };
|
||||
+};
|
||||
+
|
||||
+&display_subsystem {
|
||||
+ status = "okay";
|
||||
+
|
||||
+ route {
|
||||
+ route_rgb: route-rgb {
|
||||
+ status = "okay";
|
||||
+ logo,uboot = "logo.bmp";
|
||||
+ logo,kernel = "logo_kernel.bmp";
|
||||
+ logo,mode = "center";
|
||||
+ charge_logo,mode = "center";
|
||||
+ connect = <&vop_out_rgb>;
|
||||
+ };
|
||||
+ };
|
||||
+};
|
||||
+
|
||||
+&pwm1 {
|
||||
+ status = "okay";
|
||||
+ pinctrl-names = "default";
|
||||
+ pinctrl-0 = <&pwm1m2_pins>;
|
||||
+};
|
||||
+
|
||||
+&rgb {
|
||||
+ status = "okay";
|
||||
+ pinctrl-names = "default";
|
||||
+ pinctrl-0 = <&lcd_pins>;
|
||||
+
|
||||
+ ports {
|
||||
+ rgb_out: port@1 {
|
||||
+ reg = <1>;
|
||||
+ #address-cells = <1>;
|
||||
+ #size-cells = <0>;
|
||||
+
|
||||
+ rgb_out_panel: endpoint@0 {
|
||||
+ reg = <0>;
|
||||
+ remote-endpoint = <&panel_in_rgb>;
|
||||
+ };
|
||||
+ };
|
||||
+ };
|
||||
+};
|
||||
+
|
||||
+&vop {
|
||||
+ status = "okay";
|
||||
+};
|
||||
@@ -1,36 +0,0 @@
|
||||
diff -ruN a/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h b/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h
|
||||
--- a/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h 2026-09-01 16:48:53.948824814 -0600
|
||||
+++ b/sysdrv/source/uboot/u-boot/include/configs/rv1106_common.h 2026-09-01 16:48:53.936824778 -0600
|
||||
@@ -68,18 +68,26 @@
|
||||
#define ENV_MEM_LAYOUT_SETTINGS CONFIG_ENV_MEM_LAYOUT_SETTINGS
|
||||
#else
|
||||
/*
|
||||
+ * flare-edge layout (2026-09-01): the vendor put fdt at 12M and ramdisk at
|
||||
+ * 14M, which capped the zImage (loaded at 0x8000) at ~11.95MB -- sysmem
|
||||
+ * rejects the boot with "slot boot failed" the moment the kernel grows past
|
||||
+ * the fdt region, which our gzip-compressed 6.18 (12.25MB) did. Move fdt to
|
||||
+ * 128M (matching the load address our external-data FITs already carry) and
|
||||
+ * ramdisk above it; a 256MB board has the room, and the kernel can now grow
|
||||
+ * to ~120MB before this bites again.
|
||||
+ *
|
||||
* Image: 0 - 8M
|
||||
- * zImage: 8 - 12M
|
||||
- * fdt: 12 - 13M
|
||||
- * ramdisk: 14 ...
|
||||
+ * zImage: 8 - ...
|
||||
+ * fdt: 128M
|
||||
+ * ramdisk: 132M ...
|
||||
*/
|
||||
#define ENV_MEM_LAYOUT_SETTINGS \
|
||||
"scriptaddr=0x00b00000\0" \
|
||||
- "pxefile_addr_r=0x00c00000\0" \
|
||||
- "fdt_addr_r=0x00c00000\0" \
|
||||
+ "pxefile_addr_r=0x08000000\0" \
|
||||
+ "fdt_addr_r=0x08000000\0" \
|
||||
"kernel_addr_c=0x00808000\0" \
|
||||
"kernel_addr_r=0x00008000\0" \
|
||||
- "ramdisk_addr_r=0x000e00000\0"
|
||||
+ "ramdisk_addr_r=0x008400000\0"
|
||||
#endif
|
||||
|
||||
#define CONFIG_EXTRA_ENV_SETTINGS \
|
||||
@@ -1,503 +0,0 @@
|
||||
flare-edge: decide the verbose boot in U-Boot, from a press on the splash.
|
||||
|
||||
See arch/arm/mach-rockchip/flare_touch.c for the measurements behind the
|
||||
sampling design (issues #140, #143).
|
||||
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/board.c
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <clk.h>
|
||||
#include <console.h>
|
||||
#include <flare_trace.h>
|
||||
+#include <flare_touch.h>
|
||||
#ifdef CONFIG_FLARE_AB
|
||||
#include <flare_ab.h>
|
||||
#endif
|
||||
@@ -519,9 +520,28 @@
|
||||
/* Logo as early as possible, but never ahead of the recovery path. */
|
||||
#ifdef CONFIG_DRM_ROCKCHIP
|
||||
if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) {
|
||||
+ char ubt[64];
|
||||
+ ulong t0, t1;
|
||||
+
|
||||
FLARE_TRACE("rockchip_show_logo start");
|
||||
+ t0 = FLARE_USEC();
|
||||
rockchip_show_logo();
|
||||
+ t1 = FLARE_USEC();
|
||||
FLARE_TRACE("rockchip_show_logo done");
|
||||
+ /* Milliseconds since power-on, entering and leaving the logo
|
||||
+ * call. Reported on the kernel command line because that is the
|
||||
+ * only place a panel with no serial console can be asked
|
||||
+ * afterwards how long its splash really took. */
|
||||
+ snprintf(ubt, sizeof(ubt), "warden.ubt=%lu,%lu",
|
||||
+ t0 / 1000, t1 / 1000);
|
||||
+ env_set("flare_ubt", ubt);
|
||||
+
|
||||
+ /*
|
||||
+ * From here on, anything the touch controller reports is
|
||||
+ * something that happened while the splash was on screen.
|
||||
+ */
|
||||
+ flare_touch_arm();
|
||||
+
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
|
||||
@@ -676,6 +696,49 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * flare-edge: swap the splash mark and ask for a verbose boot, if the panel
|
||||
+ * was tapped.
|
||||
+ *
|
||||
+ * The splash's bottom-right mark reads GRAPHIC. A tap swaps it for the
|
||||
+ * otherwise identical VERBOSE image and puts warden.verbose=1 on the kernel
|
||||
+ * command line, so what the operator is shown matches the boot they get.
|
||||
+ *
|
||||
+ * BOTH image calls are needed. rockchip_show_bmp() repaints what U-Boot is
|
||||
+ * showing now; rockchip_set_kernel_logo() changes the separate image handed to
|
||||
+ * the kernel at the display handoff. Without the second, the kernel logo
|
||||
+ * paints GRAPHIC back over the first a few milliseconds later and the tap
|
||||
+ * looks ignored.
|
||||
+ *
|
||||
+ * warden.touch is reported on EVERY boot, tapped or not. Without it, "no
|
||||
+ * controller", "controller present but silent" and "not touched" are the same
|
||||
+ * silence on a panel with no serial console.
|
||||
+ */
|
||||
+static void flare_verbose_check(void)
|
||||
+{
|
||||
+ struct flare_touch_state st;
|
||||
+ char buf[80];
|
||||
+ int tapped, shown, kset;
|
||||
+
|
||||
+ tapped = flare_touch_tapped(&st);
|
||||
+
|
||||
+ snprintf(buf, sizeof(buf), "warden.touch=0x%x,%d,%s,arm%d:0x%02x,rd0x%02x",
|
||||
+ st.addr, tapped, st.id[0] ? st.id : "none",
|
||||
+ st.armed, st.arm_status, st.status);
|
||||
+ env_set("flare_touch", buf);
|
||||
+ FLARE_TRACE(buf);
|
||||
+
|
||||
+ if (!tapped)
|
||||
+ return;
|
||||
+
|
||||
+ shown = rockchip_show_bmp("logo_verbose.bmp");
|
||||
+ kset = rockchip_set_kernel_logo("logo_verbose.bmp");
|
||||
+ snprintf(buf, sizeof(buf), "warden.vmark=%d,%d", shown, kset);
|
||||
+ env_set("flare_vmark", buf);
|
||||
+ env_set("flare_verbose", "1");
|
||||
+ FLARE_TRACE("verbose boot selected by touch");
|
||||
+}
|
||||
+
|
||||
int board_fdt_fixup(void *blob)
|
||||
{
|
||||
/*
|
||||
@@ -684,6 +747,23 @@
|
||||
*/
|
||||
rk_board_dm_fdt_fixup(blob);
|
||||
|
||||
+ /*
|
||||
+ * flare-edge: the verbose-boot tap.
|
||||
+ *
|
||||
+ * Sampled HERE, and deliberately not earlier. The controller latches a
|
||||
+ * touch report and holds it until acknowledged, so one read at this
|
||||
+ * point catches a tap made at any time during the splash -- without
|
||||
+ * watching for a window, which would add that window to every boot
|
||||
+ * whether or not anyone touched the panel. An escape hatch is not worth
|
||||
+ * paying for on boots that never use it.
|
||||
+ *
|
||||
+ * This is the last moment both halves can still be changed: it runs
|
||||
+ * before rockchip_display_fixup() below loads the kernel logo, and
|
||||
+ * arch_fixup_fdt() runs before fdt_chosen(), so the command line built
|
||||
+ * by board_fdt_chosen_bootargs() still picks up what is set here.
|
||||
+ */
|
||||
+ flare_verbose_check();
|
||||
+
|
||||
/* Common fixup for DRM */
|
||||
#ifdef CONFIG_DRM_ROCKCHIP
|
||||
rockchip_display_fixup(blob);
|
||||
@@ -1475,6 +1555,29 @@
|
||||
bootargs_add_fwver(verbose);
|
||||
bootargs_add_android(verbose);
|
||||
|
||||
+ /* flare-edge: the splash tap, carried to the kernel. Added here rather
|
||||
+ * than where it is sampled because sys_bootargs is merged into bootargs
|
||||
+ * after board_late_init, and an earlier append does not survive it. */
|
||||
+ {
|
||||
+ const char *ub = env_get("flare_ubt");
|
||||
+ const char *ft = env_get("flare_touch");
|
||||
+
|
||||
+ if (ub)
|
||||
+ env_update("bootargs", ub);
|
||||
+ const char *fv = env_get("flare_verbose");
|
||||
+
|
||||
+ if (ft)
|
||||
+ env_update("bootargs", ft);
|
||||
+
|
||||
+ if (fv && !strcmp(fv, "1")) {
|
||||
+ const char *vm = env_get("flare_vmark");
|
||||
+
|
||||
+ env_update("bootargs", "warden.verbose=1");
|
||||
+ if (vm)
|
||||
+ env_update("bootargs", vm);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/*
|
||||
* Initrd fixup: remove unused "initrd=0x...,0x...",
|
||||
* this for compatible with legacy parameter.txt
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/Makefile
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/Makefile
|
||||
@@ -37,6 +37,7 @@
|
||||
obj-y += boot_mode.o
|
||||
obj-y += boot_rkimg.o
|
||||
obj-y += board.o
|
||||
+obj-y += flare_touch.o
|
||||
obj-y += iomem.o
|
||||
obj-y += memblk.o
|
||||
obj-$(CONFIG_ROCKCHIP_HOTKEY) += hotkey.o
|
||||
--- a/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/drivers/video/drm/rockchip_display.c
|
||||
@@ -52,7 +52,22 @@
|
||||
#define RK_BLK_SIZE 512
|
||||
#define BMP_PROCESSED_FLAG 8399
|
||||
#define BYTES_PER_PIXEL sizeof(uint32_t)
|
||||
-#define MAX_IMAGE_BYTES (8 * 1024 * 1024)
|
||||
+/*
|
||||
+ * flare-edge: 8 MB was too large to ask for twice.
|
||||
+ *
|
||||
+ * This is the transient scratch buffer a single image load takes, and it is
|
||||
+ * held while the decoded bitmap (~2 MB for this panel) is also live. Against
|
||||
+ * CONFIG_SYS_MALLOC_LEN of 16 MB the first load fits, but by the second the
|
||||
+ * heap can no longer satisfy another 8 MB contiguous request and the load
|
||||
+ * fails with -ENOMEM. That is invisible on a panel: rockchip_show_bmp() went
|
||||
+ * on to report success, so a second image simply never appeared.
|
||||
+ *
|
||||
+ * The panel's own logos are 720x720x3 plus header = 1,555,254 bytes, so 4 MB
|
||||
+ * is still 2.6x the largest image this board can display while being small
|
||||
+ * enough to allocate repeatedly. An image larger than this reads short and is
|
||||
+ * then rejected by the decoder rather than shown corrupt.
|
||||
+ */
|
||||
+#define MAX_IMAGE_BYTES (4 * 1024 * 1024)
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
static LIST_HEAD(rockchip_display_list);
|
||||
@@ -1549,7 +1564,15 @@
|
||||
|
||||
list_for_each_entry(s, &rockchip_display_list, head) {
|
||||
s->logo.mode = s->charge_logo_mode;
|
||||
- if (load_bmp_logo(&s->logo, bmp))
|
||||
+ /*
|
||||
+ * flare-edge: report the load failure instead of swallowing it.
|
||||
+ * `ret` starts at 0 and this loop used to `continue` past a
|
||||
+ * failed load, so a call that displayed nothing at all still
|
||||
+ * returned success -- which sent a whole debugging round after
|
||||
+ * a display that had never been given an image.
|
||||
+ */
|
||||
+ ret = load_bmp_logo(&s->logo, bmp);
|
||||
+ if (ret)
|
||||
continue;
|
||||
ret = display_logo(s);
|
||||
}
|
||||
@@ -1557,6 +1580,36 @@
|
||||
return ret;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * flare-edge: change which image the KERNEL is handed at the display handoff.
|
||||
+ *
|
||||
+ * rockchip_show_bmp() only repaints what U-Boot itself is showing. The image
|
||||
+ * the kernel keeps on screen is a separate one, loaded from klogo_name into
|
||||
+ * the rockchip,drm-logo reserved memory during rockchip_display_fixup(), and
|
||||
+ * it is painted over whatever U-Boot drew moments earlier. So swapping the
|
||||
+ * splash for a tap without also swapping this one shows the new image for a
|
||||
+ * few milliseconds and then reverts, which reads on the panel as the tap
|
||||
+ * having done nothing at all.
|
||||
+ */
|
||||
+int rockchip_set_kernel_logo(const char *bmp)
|
||||
+{
|
||||
+ struct display_state *s;
|
||||
+ int found = 0;
|
||||
+
|
||||
+ if (!bmp)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ list_for_each_entry(s, &rockchip_display_list, head) {
|
||||
+ if (strlen(bmp) >= sizeof(s->klogo_name))
|
||||
+ return -ENAMETOOLONG;
|
||||
+ memset(s->klogo_name, 0, sizeof(s->klogo_name));
|
||||
+ memcpy(s->klogo_name, bmp, strlen(bmp));
|
||||
+ found++;
|
||||
+ }
|
||||
+
|
||||
+ return found ? 0 : -ENODEV;
|
||||
+}
|
||||
+
|
||||
int rockchip_show_logo(void)
|
||||
{
|
||||
struct display_state *s;
|
||||
--- a/sysdrv/source/uboot/u-boot/include/video_rockchip.h
|
||||
+++ b/sysdrv/source/uboot/u-boot/include/video_rockchip.h
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
int rockchip_show_bmp(const char *bmp);
|
||||
int rockchip_show_logo(void);
|
||||
+int rockchip_set_kernel_logo(const char *bmp);
|
||||
void rockchip_display_fixup(void *blob);
|
||||
|
||||
#endif
|
||||
--- a/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/flare_touch.c
|
||||
+++ b/sysdrv/source/uboot/u-boot/arch/arm/mach-rockchip/flare_touch.c
|
||||
@@ -0,0 +1,252 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0+
|
||||
+/*
|
||||
+ * flare-edge: read the panel's touchscreen from U-Boot, so the choice between
|
||||
+ * the graphic splash and a verbose boot is made BEFORE the kernel starts.
|
||||
+ *
|
||||
+ * WHY THIS LIVES IN THE BOOTLOADER. The same decision used to be made in
|
||||
+ * userspace, by S09splash watching the evdev node. That could only ever cover
|
||||
+ * the part of the boot that had already happened by the time an init script
|
||||
+ * ran, and it was fragile for a second reason: the window was expressed as an
|
||||
+ * absolute uptime, and once the splash started later than that deadline the
|
||||
+ * probe ended on its first iteration and the feature was silently dead
|
||||
+ * (issue #143). Deciding here removes both problems -- the flag is on the
|
||||
+ * kernel command line before the kernel prints its first line, and there is no
|
||||
+ * race with when an init script happens to run.
|
||||
+ *
|
||||
+ * THE PANEL'S CONTROLLER. A Goodix GT911 on i2c3 (i2c@ff460000). Its I2C
|
||||
+ * address is selected by the INT pin level while RESET is released: high
|
||||
+ * selects 0x14, low selects 0x5d. U-Boot drives RESET (it is in the DT as
|
||||
+ * reset-gpios) but NOT INT (the DT describes INT as an interrupt, not a gpio),
|
||||
+ * so the address after our reset is whatever INT floats to. Rather than fight
|
||||
+ * that, both addresses are probed and the one that answers is used. The kernel
|
||||
+ * driver re-runs its own reset sequence later regardless, so leaving the
|
||||
+ * controller in either state is safe.
|
||||
+ *
|
||||
+ * COST. Everything here is bounded and skipped entirely when the controller
|
||||
+ * does not answer, so a panel with no touchscreen, or one whose controller is
|
||||
+ * held in reset, adds only the probe attempt to boot -- not the poll window.
|
||||
+ */
|
||||
+#include <common.h>
|
||||
+#include <dm.h>
|
||||
+#include <i2c.h>
|
||||
+#include <asm/gpio.h>
|
||||
+#include <dm/ofnode.h>
|
||||
+#include <linux/libfdt.h>
|
||||
+#include <asm/global_data.h>
|
||||
+#include <flare_trace.h>
|
||||
+#include <flare_touch.h>
|
||||
+
|
||||
+DECLARE_GLOBAL_DATA_PTR;
|
||||
+
|
||||
+#define GT911_I2C_BUS 3
|
||||
+#define GT911_ADDR_INT_HIGH 0x14
|
||||
+#define GT911_ADDR_INT_LOW 0x5d
|
||||
+
|
||||
+/*
|
||||
+ * Coordinate/status register. Bit 7 is "a fresh report is ready"; the low
|
||||
+ * nibble counts the touch points in it. The controller does not clear this
|
||||
+ * itself -- the reader must write 0 back, or the same report is returned for
|
||||
+ * ever and a single stale touch would look like a finger held down.
|
||||
+ */
|
||||
+#define GT911_REG_STATUS 0x814e
|
||||
+#define GT911_STATUS_READY 0x80
|
||||
+#define GT911_STATUS_NTOUCH 0x0f
|
||||
+
|
||||
+/* Datasheet: >=10 ms asserted, and the controller needs ~50 ms after release
|
||||
+ * before it answers on I2C. The margins here are deliberately generous: this
|
||||
+ * runs once per boot and a retry costs more than the wait it saves. */
|
||||
+#define GT911_RESET_HOLD_MS 20
|
||||
+#define GT911_RESET_SETTLE_MS 60
|
||||
+
|
||||
+/* Product id lives here: four ASCII bytes, "911" on this panel. Reading it is
|
||||
+ * how we tell a real controller from an address that merely ACKs. */
|
||||
+#define GT911_REG_ID 0x8140
|
||||
+
|
||||
+/*
|
||||
+ * Release the controller from reset, if the DT tells us which pin that is.
|
||||
+ * Only used when nothing answered on either address: the reset latches the
|
||||
+ * I2C address from the INT level, which U-Boot does not drive, so it is a last
|
||||
+ * resort rather than routine initialisation.
|
||||
+ *
|
||||
+ * Returns 0 when the line was driven, or a negative errno when the node or the
|
||||
+ * property is missing.
|
||||
+ */
|
||||
+static int gt911_release_reset(void)
|
||||
+{
|
||||
+ struct gpio_desc reset;
|
||||
+ int node, ret;
|
||||
+
|
||||
+ node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "goodix,gt911");
|
||||
+ if (node < 0)
|
||||
+ return -ENODEV;
|
||||
+
|
||||
+ ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpios",
|
||||
+ 0, &reset, GPIOD_IS_OUT);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ /* Asserted, then released. dm_gpio_set_value() takes the LOGICAL level,
|
||||
+ * so the DT's active-low flag is already accounted for here. */
|
||||
+ dm_gpio_set_value(&reset, 1);
|
||||
+ mdelay(GT911_RESET_HOLD_MS);
|
||||
+ dm_gpio_set_value(&reset, 0);
|
||||
+ mdelay(GT911_RESET_SETTLE_MS);
|
||||
+
|
||||
+ dm_gpio_free(NULL, &reset);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+/* The address the controller answered on, for the boot report. */
|
||||
+static int gt911_addr;
|
||||
+
|
||||
+/* Find the controller at whichever address it is currently on. */
|
||||
+static struct udevice *gt911_probe(void)
|
||||
+{
|
||||
+ static const int addrs[] = { GT911_ADDR_INT_HIGH, GT911_ADDR_INT_LOW };
|
||||
+ struct udevice *dev;
|
||||
+ u8 status;
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < ARRAY_SIZE(addrs); i++) {
|
||||
+ if (i2c_get_chip_for_busnum(GT911_I2C_BUS, addrs[i], 2, &dev))
|
||||
+ continue;
|
||||
+ /* A successful read is the only proof the chip is really there:
|
||||
+ * i2c_get_chip_for_busnum() will hand back a device for an
|
||||
+ * address nothing answers on. */
|
||||
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
|
||||
+ continue;
|
||||
+ gt911_addr = addrs[i];
|
||||
+ return dev;
|
||||
+ }
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+/* Probe, resetting only if nothing answers on either address. */
|
||||
+static struct udevice *gt911_get(bool *did_reset)
|
||||
+{
|
||||
+ struct udevice *dev = gt911_probe();
|
||||
+
|
||||
+ if (!dev) {
|
||||
+ gt911_release_reset();
|
||||
+ if (did_reset)
|
||||
+ *did_reset = true;
|
||||
+ dev = gt911_probe();
|
||||
+ }
|
||||
+
|
||||
+ return dev;
|
||||
+}
|
||||
+
|
||||
+/* What arm() found and cleared, for the boot report. */
|
||||
+static u8 gt911_arm_status;
|
||||
+static bool gt911_armed;
|
||||
+
|
||||
+void flare_touch_arm(void)
|
||||
+{
|
||||
+ struct udevice *dev = gt911_get(NULL);
|
||||
+ u8 status = 0;
|
||||
+ u8 clear = 0;
|
||||
+
|
||||
+ if (!dev)
|
||||
+ return;
|
||||
+
|
||||
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
|
||||
+ return;
|
||||
+
|
||||
+ gt911_arm_status = status;
|
||||
+ gt911_armed = true;
|
||||
+
|
||||
+ if (status & GT911_STATUS_READY) {
|
||||
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
|
||||
+ FLARE_TRACE("touch: cleared the power-on report");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+int flare_touch_tapped(struct flare_touch_state *st)
|
||||
+{
|
||||
+ struct udevice *dev;
|
||||
+ bool did_reset = false;
|
||||
+ u8 status = 0;
|
||||
+ u8 clear = 0;
|
||||
+
|
||||
+ if (st) {
|
||||
+ st->addr = 0;
|
||||
+ st->status = 0;
|
||||
+ st->armed = false;
|
||||
+ st->arm_status = 0;
|
||||
+ st->id[0] = '\0';
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Probe BEFORE resetting. The controller is normally already running by
|
||||
+ * the time U-Boot gets here, and resetting a working one is not free:
|
||||
+ * its I2C address is latched from the INT level while RESET is released,
|
||||
+ * and U-Boot does not drive INT, so a reset can move the chip to the
|
||||
+ * other address or leave it mid-init. Only reset when nothing answers.
|
||||
+ */
|
||||
+ dev = gt911_get(&did_reset);
|
||||
+ if (!dev) {
|
||||
+ FLARE_TRACE("touch: no GT911 on i2c3");
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (st) {
|
||||
+ st->armed = gt911_armed;
|
||||
+ st->arm_status = gt911_arm_status;
|
||||
+ st->addr = gt911_addr;
|
||||
+ if (dm_i2c_read(dev, GT911_REG_ID, (u8 *)st->id, 4) == 0)
|
||||
+ st->id[4] = '\0';
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * A single read. The report is latched: bit 7 stays set until the host
|
||||
+ * writes the register back to 0, so this sees a touch that happened at
|
||||
+ * any point since the controller came up, without watching for one.
|
||||
+ */
|
||||
+ if (dm_i2c_read(dev, GT911_REG_STATUS, &status, 1))
|
||||
+ return 0;
|
||||
+ if (st)
|
||||
+ st->status = status;
|
||||
+
|
||||
+ if (!(status & GT911_STATUS_READY))
|
||||
+ return 0;
|
||||
+
|
||||
+ /*
|
||||
+ * A report we produced ourselves is not a tap.
|
||||
+ *
|
||||
+ * Bringing the controller out of reset makes it publish a report, so on
|
||||
+ * a panel whose GT911 does not answer until we reset it, EVERY boot
|
||||
+ * latches one and every boot would come up verbose. MEASURED on the
|
||||
+ * bench panel: it answers only at 0x5d after a reset, and reported
|
||||
+ * status 0x80 on a boot nobody touched.
|
||||
+ *
|
||||
+ * Acknowledge it and report untouched. A panel in this state cannot
|
||||
+ * report a tap made before we woke its controller either -- there was
|
||||
+ * nothing listening to record it.
|
||||
+ */
|
||||
+ if (did_reset) {
|
||||
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
|
||||
+ FLARE_TRACE("touch: report discarded, we caused it");
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ /* Acknowledge, so the same report cannot be read again next boot. */
|
||||
+ dm_i2c_write(dev, GT911_REG_STATUS, &clear, 1);
|
||||
+
|
||||
+ /*
|
||||
+ * A finger must be ON THE GLASS right now. The ready bit is not enough.
|
||||
+ *
|
||||
+ * MEASURED on the bench panel across cold boots nobody touched: the
|
||||
+ * controller had a report waiting when the splash appeared (arm 0x80,
|
||||
+ * cleared), and had published ANOTHER by the time this read ran
|
||||
+ * (rd 0x80). It re-arms on its own, so "a report exists" is true on
|
||||
+ * every boot and cannot mean "someone touched it". Only the point count
|
||||
+ * distinguishes a finger from the controller talking to itself.
|
||||
+ *
|
||||
+ * The cost is that the touch has to be HELD across this sample rather
|
||||
+ * than tapped and released, because catching a release would mean
|
||||
+ * watching for one, and watching means adding that time to every boot.
|
||||
+ * A press held through the splash is the reliable, free signal.
|
||||
+ */
|
||||
+ return (status & GT911_STATUS_NTOUCH) ? 1 : 0;
|
||||
+}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
diff --git a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
|
||||
index 276fc6017..b9a66c416 100755
|
||||
--- a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
|
||||
+++ b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/rwnx_cmds.c
|
||||
@@ -76,7 +76,7 @@ int cmd_mgr_queue_force_defer(struct rwnx_cmd_mgr *cmd_mgr,
|
||||
spin_lock_bh(&cmd_mgr->lock);
|
||||
|
||||
if (cmd_mgr->state == RWNX_CMD_MGR_STATE_CRASHED) {
|
||||
- printk(KERN_CRIT "cmd queue crashed\n");
|
||||
+ printk_ratelimited(KERN_CRIT "cmd queue crashed\n");
|
||||
cmd->result = -EPIPE;
|
||||
spin_unlock_bh(&cmd_mgr->lock);
|
||||
return -EPIPE;
|
||||
@@ -168,7 +168,7 @@ static int cmd_mgr_queue(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd)
|
||||
}
|
||||
|
||||
if (cmd_mgr->state == RWNX_CMD_MGR_STATE_CRASHED) {
|
||||
- printk(KERN_CRIT "cmd queue crashed\n");
|
||||
+ printk_ratelimited(KERN_CRIT "cmd queue crashed\n");
|
||||
cmd->result = -EPIPE;
|
||||
spin_unlock_bh(&cmd_mgr->lock);
|
||||
return -EPIPE;
|
||||
@@ -260,10 +260,17 @@ static int cmd_mgr_queue(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd)
|
||||
/* TODO: kill the cmd at fw level */
|
||||
}
|
||||
#else
|
||||
+ /* flare-edge: queue_sz must never scale this to zero. A zero
|
||||
+ * timeout makes wait_for_completion_timeout() return
|
||||
+ * immediately, so the "timeout" path runs without ever
|
||||
+ * waiting -- measured as ~2000 "cmd timed-out" per second
|
||||
+ * (668349 in 319s), which saturates the console and takes the
|
||||
+ * whole system down with it. Clamp to at least one. */
|
||||
unsigned long tout = msecs_to_jiffies(
|
||||
- RWNX_80211_CMD_TIMEOUT_MS * cmd_mgr->queue_sz);
|
||||
+ RWNX_80211_CMD_TIMEOUT_MS *
|
||||
+ max_t(u32, cmd_mgr->queue_sz, 1));
|
||||
if (!wait_for_completion_timeout(&cmd->complete, tout)) {
|
||||
- printk(KERN_CRIT "cmd timed-out\n");
|
||||
+ printk_ratelimited(KERN_CRIT "cmd timed-out\n");
|
||||
#ifdef AICWF_SDIO_SUPPORT
|
||||
ret = aicwf_sdio_writeb(
|
||||
sdiodev, sdiodev->sdio_reg.wakeup_reg, 2);
|
||||
@@ -395,11 +402,12 @@ void cmd_mgr_task_process(struct work_struct *work)
|
||||
#endif
|
||||
kfree(next->a2e_msg);
|
||||
|
||||
+ /* flare-edge: see above -- never a zero timeout */
|
||||
tout = msecs_to_jiffies(RWNX_80211_CMD_TIMEOUT_MS *
|
||||
- cmd_mgr->queue_sz);
|
||||
+ max_t(u32, cmd_mgr->queue_sz, 1));
|
||||
if (!wait_for_completion_timeout(&next->complete,
|
||||
tout)) {
|
||||
- printk(KERN_CRIT "cmd timed-out\n");
|
||||
+ printk_ratelimited(KERN_CRIT "cmd timed-out\n");
|
||||
#ifdef AICWF_SDIO_SUPPORT
|
||||
if (aicwf_sdio_writeb(
|
||||
sdiodev,
|
||||
@@ -1,73 +0,0 @@
|
||||
diff --git a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
|
||||
index 13005ac68..d28b7127a 100755
|
||||
--- a/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
|
||||
+++ b/sysdrv/drv_ko/wifi/aic8800dc/aic8800_fdrv/aicwf_sdio.c
|
||||
@@ -1356,6 +1356,8 @@ int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
|
||||
}
|
||||
|
||||
if (sdiodev->state == SDIO_SLEEP_ST) {
|
||||
+ int woke = 0;
|
||||
+
|
||||
AICWFDBG(LOGSDPWRC, "%s w\n", __func__);
|
||||
|
||||
//rwnx_pm_stay_awake(sdiodev);
|
||||
@@ -1379,21 +1381,53 @@ int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
|
||||
txrx_err(
|
||||
"sdio wakeup read fail\n");
|
||||
else if ((val & 0x1) == 0) {
|
||||
+ woke = 1;
|
||||
break;
|
||||
}
|
||||
read_retry--;
|
||||
- udelay(200);
|
||||
+ /*
|
||||
+ * flare-edge: sleep, do NOT udelay()
|
||||
+ * here. This is a sleepable context
|
||||
+ * (reached only under pwrctl_wakeup_sema
|
||||
+ * from the bustx kthread), and that
|
||||
+ * thread re-enters this path on every
|
||||
+ * TX. A busy-wait therefore pins the
|
||||
+ * single Cortex-A7 core whenever the
|
||||
+ * SDIO link wedges, starving the UI
|
||||
+ * render loop -- the "extremely laggy"
|
||||
+ * failure. Sleeping frees the core.
|
||||
+ */
|
||||
+ usleep_range(200, 400);
|
||||
}
|
||||
- if (read_retry != 0)
|
||||
+ if (woke)
|
||||
break;
|
||||
}
|
||||
sdio_dbg("write retry: %d \n", write_retry);
|
||||
write_retry--;
|
||||
- udelay(100);
|
||||
+ if (write_retry)
|
||||
+ usleep_range(100, 200);
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * flare-edge: never fake SDIO_ACTIVE_ST on a failed wake. The
|
||||
+ * stock driver advanced state unconditionally, so a wedged link
|
||||
+ * looked "awake" and every later TX hammered a dead chip forever
|
||||
+ * with no recovery. Advance state only when the chip actually
|
||||
+ * acknowledged; otherwise stay SLEEP and report the error so the
|
||||
+ * caller (and the reset-recovery path added in a later patch)
|
||||
+ * can act on it.
|
||||
+ */
|
||||
+ if (woke) {
|
||||
+ sdiodev->state = SDIO_ACTIVE_ST;
|
||||
+ aicwf_sdio_pwrctl_timer(sdiodev,
|
||||
+ sdiodev->active_duration);
|
||||
+ ret = 0;
|
||||
+ } else {
|
||||
+ printk_ratelimited(
|
||||
+ KERN_WARNING
|
||||
+ "aic8800: SDIO wakeup failed; chip may be wedged\n");
|
||||
+ ret = -1;
|
||||
}
|
||||
-
|
||||
- sdiodev->state = SDIO_ACTIVE_ST;
|
||||
- aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
diff --git a/sysdrv/drv_ko/wifi/insmod_wifi.sh b/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
index f34ae1581..c70664564 100755
|
||||
--- a/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
+++ b/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
@@ -124,8 +124,23 @@ if [ -n "$(cat /proc/device-tree/model | grep "W")" ] || \
|
||||
fi
|
||||
|
||||
#start wifi app
|
||||
+#
|
||||
+# flare-edge: rkwifi_server is deliberately NOT started. WardenOS owns wlan0
|
||||
+# through warden-ui, which runs its own wpa_supplicant against
|
||||
+# /userdata/warden/wpa_supplicant.conf.
|
||||
+#
|
||||
+# rkwifi_server starts "wpa_supplicant -B -i wlan0 -c /data/wpa_supplicant.conf"
|
||||
+# using the stock config, whose network block is the vendor placeholder
|
||||
+# ssid="Your wifi ssid". The radio then scans forever for a network that does
|
||||
+# not exist while the real one sits at -50 dBm.
|
||||
+#
|
||||
+# warden-ui already does "killall rkwifi_server" before taking over, but that
|
||||
+# does not kill the wpa_supplicant rkwifi_server spawned, and the UI guards its
|
||||
+# own launch with `if ! pidof wpa_supplicant`. So the orphan survives, the
|
||||
+# guard sees it, the UI never starts its own, and the saved credentials are
|
||||
+# never used. Not starting the daemon removes the race entirely.
|
||||
+#
|
||||
+# Re-enable only if something other than warden-ui needs to own wlan0.
|
||||
if ifconfig wlan0 2>&1 | grep -q "not found"; then
|
||||
- echo "wlan0 not found. Stop run rkwifi_server."
|
||||
-else
|
||||
- rkwifi_server start >/dev/null 2>&1 &
|
||||
+ echo "wlan0 not found."
|
||||
fi
|
||||
@@ -1,59 +0,0 @@
|
||||
diff --git a/sysdrv/drv_ko/wifi/insmod_wifi.sh b/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
--- a/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
+++ b/sysdrv/drv_ko/wifi/insmod_wifi.sh
|
||||
@@ -33,7 +33,26 @@
|
||||
if [ $? -eq 0 ]; then
|
||||
insmod cfg80211.ko
|
||||
insmod aic_load_fw.ko aic_fw_path=/oem/usr/ko/
|
||||
- insmod aic8800_fdrv.ko
|
||||
+ # flare-edge: he_on=0 -- do NOT let this radio negotiate 802.11ax (HE).
|
||||
+ #
|
||||
+ # The AIC8800DC associates fine in HE and negotiates high HE-MCS rates, then
|
||||
+ # silently loses the unicast path while every local indicator still reads
|
||||
+ # healthy (wpa_state=COMPLETED, carrier 1, lease BOUND, strong signal). Only
|
||||
+ # beacons and broadcast keep arriving. See flare-edge issue #156.
|
||||
+ #
|
||||
+ # Measured on warden-c8a3 against an 802.11ax AP: with HE on, the driver
|
||||
+ # deinit/reconnect cycle fired every ~965 s indefinitely
|
||||
+ # ("deinit:macaddr" -> "rwnx_send_sm_connect_req", 154 times in 2.8 days).
|
||||
+ # he_on=0 makes the chip advertise HT/VHT only (phy reports "HE supp 0") and
|
||||
+ # the cycle stops.
|
||||
+ #
|
||||
+ # This costs Wi-Fi 6 rates, which the radio was never actually delivering
|
||||
+ # usable throughput at anyway, and costs no compatibility: 802.11ax APs serve
|
||||
+ # n/ac clients normally, so the panel still joins modern networks.
|
||||
+ #
|
||||
+ # Remove only when the HE path is actually fixed in the driver or the AIC
|
||||
+ # firmware blob, and re-verify with a multi-hour soak against an ax AP.
|
||||
+ insmod aic8800_fdrv.ko he_on=0
|
||||
insmod bcmdhd.ko
|
||||
fi
|
||||
|
||||
@@ -117,7 +136,26 @@
|
||||
insmod aes_generic.ko
|
||||
insmod aic8800_bsp.ko
|
||||
sleep 0.2
|
||||
- insmod aic8800_fdrv.ko
|
||||
+ # flare-edge: he_on=0 -- do NOT let this radio negotiate 802.11ax (HE).
|
||||
+ #
|
||||
+ # The AIC8800DC associates fine in HE and negotiates high HE-MCS rates, then
|
||||
+ # silently loses the unicast path while every local indicator still reads
|
||||
+ # healthy (wpa_state=COMPLETED, carrier 1, lease BOUND, strong signal). Only
|
||||
+ # beacons and broadcast keep arriving. See flare-edge issue #156.
|
||||
+ #
|
||||
+ # Measured on warden-c8a3 against an 802.11ax AP: with HE on, the driver
|
||||
+ # deinit/reconnect cycle fired every ~965 s indefinitely
|
||||
+ # ("deinit:macaddr" -> "rwnx_send_sm_connect_req", 154 times in 2.8 days).
|
||||
+ # he_on=0 makes the chip advertise HT/VHT only (phy reports "HE supp 0") and
|
||||
+ # the cycle stops.
|
||||
+ #
|
||||
+ # This costs Wi-Fi 6 rates, which the radio was never actually delivering
|
||||
+ # usable throughput at anyway, and costs no compatibility: 802.11ax APs serve
|
||||
+ # n/ac clients normally, so the panel still joins modern networks.
|
||||
+ #
|
||||
+ # Remove only when the HE path is actually fixed in the driver or the AIC
|
||||
+ # firmware blob, and re-verify with a multi-hour soak against an ax AP.
|
||||
+ insmod aic8800_fdrv.ko he_on=0
|
||||
sleep 2
|
||||
insmod aic8800_btlpm.ko
|
||||
sleep 0.1
|
||||
@@ -1,128 +0,0 @@
|
||||
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
@@ -247,6 +247,7 @@
|
||||
struct device *dev;
|
||||
struct regmap *grf;
|
||||
struct regmap *usbgrf;
|
||||
+ void __iomem *phy_base;
|
||||
struct clk_bulk_data *clks;
|
||||
struct clk *clk480m;
|
||||
struct clk_hw clk480m_hw;
|
||||
@@ -1417,6 +1418,19 @@
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
+ /*
|
||||
+ * RV1106 tunes signal quality through the PHY's own register block, which
|
||||
+ * is this node's "reg" resource and is distinct from the GRF regmap above.
|
||||
+ * Map it only where a tuning callback needs it; every other SoC here tunes
|
||||
+ * through the GRF and must keep working with phy_base left NULL.
|
||||
+ */
|
||||
+ if (of_device_is_compatible(np, "rockchip,rv1106-usb2phy")) {
|
||||
+ rphy->phy_base = devm_platform_ioremap_resource(pdev, 0);
|
||||
+ if (IS_ERR(rphy->phy_base))
|
||||
+ return dev_err_probe(dev, PTR_ERR(rphy->phy_base),
|
||||
+ "failed to map phy registers\n");
|
||||
+ }
|
||||
+
|
||||
rphy->phy_reset = devm_reset_control_get_optional(dev, "phy");
|
||||
if (IS_ERR(rphy->phy_reset))
|
||||
return PTR_ERR(rphy->phy_reset);
|
||||
@@ -1506,6 +1520,30 @@
|
||||
return ret;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * Direct PHY-register accessors. Most SoCs here tune through the GRF regmap,
|
||||
+ * but the RV1106's signal-quality registers live in the PHY's own block, which
|
||||
+ * is mapped separately into rphy->phy_base.
|
||||
+ */
|
||||
+static inline void phy_update_bits(void __iomem *reg, u32 mask, u32 val)
|
||||
+{
|
||||
+ u32 tmp = readl(reg);
|
||||
+
|
||||
+ tmp &= ~mask;
|
||||
+ tmp |= val & mask;
|
||||
+ writel(tmp, reg);
|
||||
+}
|
||||
+
|
||||
+static inline void phy_set_bits(void __iomem *reg, u32 bits)
|
||||
+{
|
||||
+ writel(readl(reg) | bits, reg);
|
||||
+}
|
||||
+
|
||||
+static inline void phy_clear_bits(void __iomem *reg, u32 bits)
|
||||
+{
|
||||
+ writel(readl(reg) & ~bits, reg);
|
||||
+}
|
||||
+
|
||||
static int rk3128_usb2phy_tuning(struct rockchip_usb2phy *rphy)
|
||||
{
|
||||
/* Turn off differential receiver in suspend mode */
|
||||
@@ -2291,10 +2329,65 @@
|
||||
* iddig_output/iddig_en/bvalid_grf_sel are dropped). Signal-quality phy_tuning is
|
||||
* left off for now (guarded, so NULL is safe) — the phy is functional without it.
|
||||
*/
|
||||
+/*
|
||||
+ * RV1106 USB2 PHY signal-quality tuning, ported from the vendor 5.10 driver
|
||||
+ * (drivers/phy/rockchip/phy-rockchip-inno-usb2.c, rv1106_usb2phy_tuning).
|
||||
+ *
|
||||
+ * The 6.18 forward-port originally omitted this ("the phy is functional without
|
||||
+ * it"). It is functional, but not reliable: with these registers left at reset
|
||||
+ * defaults the HS link is electrically marginal under sustained traffic. On a
|
||||
+ * bench panel a USB-Ethernet dongle would stall a bulk transfer after a few
|
||||
+ * minutes; the r8152 Tx-timeout recovery then issues an xHCI Stop Endpoint
|
||||
+ * command which the controller never answers, and xhci-hcd declares the
|
||||
+ * controller dead and tears the bus down (flare-edge issue #160). Measured
|
||||
+ * carrier-on to death across four runs: 14s, 519s, 521s, 584s -- a stochastic
|
||||
+ * spread, not a timer, which is what marginal signalling looks like.
|
||||
+ *
|
||||
+ * Pre-emphasis strength is silicon-revision dependent. The vendor driver picks
|
||||
+ * it from rockchip_get_cpu_version(), which does not exist in mainline; it
|
||||
+ * derives from RV1106_OS_REG1 (0xff020204) & 0x7. Our panels read 1, i.e. the
|
||||
+ * non-zero branch, so 3'b001 is pinned here. If a board ever reports version 0
|
||||
+ * it wants 3'b011 instead -- see the vendor driver.
|
||||
+ */
|
||||
+static int rv1106_usb2phy_tuning(struct rockchip_usb2phy *rphy)
|
||||
+{
|
||||
+ /* Mapped only for this compatible; refuse to poke a NULL base. */
|
||||
+ if (!rphy->phy_base)
|
||||
+ return -ENODEV;
|
||||
+
|
||||
+ /* Always enable pre-emphasis in SOF & EOP & chirp & non-chirp state */
|
||||
+ phy_update_bits(rphy->phy_base + 0x30, GENMASK(2, 0), 0x07);
|
||||
+
|
||||
+ /* Set Tx HS pre_emphasize strength to 3'b001 (cpu_version != 0) */
|
||||
+ phy_update_bits(rphy->phy_base + 0x40, GENMASK(5, 3), (0x01 << 3));
|
||||
+
|
||||
+ /* Set RX Squelch trigger point configure to 4'b0000(112.5 mV) */
|
||||
+ phy_update_bits(rphy->phy_base + 0x64, GENMASK(6, 3), (0x00 << 3));
|
||||
+
|
||||
+ /* Turn off differential receiver by default to save power */
|
||||
+ phy_clear_bits(rphy->phy_base + 0x100, BIT(6));
|
||||
+
|
||||
+ /* Set 45ohm HS ODT value to 5'b10111 to increase driver strength */
|
||||
+ phy_update_bits(rphy->phy_base + 0x11c, GENMASK(4, 0), 0x17);
|
||||
+
|
||||
+ /* Set Tx HS eye height tuning to 3'b011(462 mV) */
|
||||
+ phy_update_bits(rphy->phy_base + 0x124, GENMASK(4, 2), (0x03 << 2));
|
||||
+
|
||||
+ /* Bypass Squelch detector calibration */
|
||||
+ phy_update_bits(rphy->phy_base + 0x1a4, GENMASK(7, 4), (0x01 << 4));
|
||||
+ phy_update_bits(rphy->phy_base + 0x1b4, GENMASK(7, 4), (0x01 << 4));
|
||||
+
|
||||
+ /* Set HS disconnect detect mode to single ended detect mode */
|
||||
+ phy_set_bits(rphy->phy_base + 0x70, BIT(2));
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static const struct rockchip_usb2phy_cfg rv1106_phy_cfgs[] = {
|
||||
{
|
||||
.reg = 0xff3e0000,
|
||||
.num_ports = 1,
|
||||
+ .phy_tuning = rv1106_usb2phy_tuning,
|
||||
.clkout_ctl = { 0x0058, 4, 4, 1, 0 },
|
||||
.port_cfgs = {
|
||||
[USB2PHY_PORT_OTG] = {
|
||||
@@ -1,136 +0,0 @@
|
||||
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
|
||||
@@ -203,6 +203,7 @@
|
||||
* @event_nb: hold event notification callback.
|
||||
* @state: define OTG enumeration states before device reset.
|
||||
* @mode: the dr_mode of the controller.
|
||||
+ * @host_mode: the port is currently acting as a USB host.
|
||||
*/
|
||||
struct rockchip_usb2phy_port {
|
||||
struct phy *phy;
|
||||
@@ -222,6 +223,7 @@
|
||||
struct notifier_block event_nb;
|
||||
enum usb_otg_state state;
|
||||
enum usb_dr_mode mode;
|
||||
+ bool host_mode;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -239,6 +241,8 @@
|
||||
* @dcd_retries: The retry count used to track Data contact
|
||||
* detection process.
|
||||
* @edev: extcon device for notification registration
|
||||
+ * @edev_self_allocated: no extcon phandle in DT, so the OTG state machine
|
||||
+ * has no external role signal at all
|
||||
* @irq: muxed interrupt for single irq configuration
|
||||
* @phy_cfg: phy register configuration, assigned by driver data.
|
||||
* @ports: phy port instance.
|
||||
@@ -257,6 +261,7 @@
|
||||
enum power_supply_type chg_type;
|
||||
u8 dcd_retries;
|
||||
struct extcon_dev *edev;
|
||||
+ bool edev_self_allocated;
|
||||
int irq;
|
||||
const struct rockchip_usb2phy_cfg *phy_cfg;
|
||||
struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS];
|
||||
@@ -459,6 +464,14 @@
|
||||
if (ret)
|
||||
return dev_err_probe(rphy->dev, ret,
|
||||
"failed to register extcon device\n");
|
||||
+
|
||||
+ /*
|
||||
+ * Nothing external drives the role on this board. The extcon
|
||||
+ * below is ours, and no code ever sets a cable state on it, so
|
||||
+ * the OTG state machine's view of the world is permanently
|
||||
+ * blank rather than merely stale.
|
||||
+ */
|
||||
+ rphy->edev_self_allocated = true;
|
||||
}
|
||||
|
||||
rphy->edev = edev;
|
||||
@@ -649,11 +662,52 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * The OTG port's state machines only make sense while the port is a
|
||||
+ * peripheral. In host role their inputs are meaningless on a board with no
|
||||
+ * ID source: charger detection drives the analog front end of a port that is
|
||||
+ * already enumerating a device, and its DCP verdict ends in
|
||||
+ * rockchip_usb2phy_power_off(), which suspends the phy and drops the 480M
|
||||
+ * clkout that the host controller's core runs on. The controller then stops
|
||||
+ * clocking with its registers still readable, so it reports itself healthy
|
||||
+ * while no transfer ever completes.
|
||||
+ *
|
||||
+ * dwc3 already calls phy_set_mode() on every role change, but this driver
|
||||
+ * implemented no .set_mode, so the phy never learned the role. Track it and
|
||||
+ * keep both state machines out of host role.
|
||||
+ */
|
||||
+static int rockchip_usb2phy_set_mode(struct phy *phy, enum phy_mode mode,
|
||||
+ int submode)
|
||||
+{
|
||||
+ struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
|
||||
+
|
||||
+ if (rport->port_id != USB2PHY_PORT_OTG)
|
||||
+ return 0;
|
||||
+
|
||||
+ switch (mode) {
|
||||
+ case PHY_MODE_USB_HOST:
|
||||
+ if (!rport->host_mode) {
|
||||
+ rport->host_mode = true;
|
||||
+ cancel_delayed_work_sync(&rport->otg_sm_work);
|
||||
+ cancel_delayed_work_sync(&rport->chg_work);
|
||||
+ }
|
||||
+ break;
|
||||
+ case PHY_MODE_USB_DEVICE:
|
||||
+ rport->host_mode = false;
|
||||
+ break;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static const struct phy_ops rockchip_usb2phy_ops = {
|
||||
.init = rockchip_usb2phy_init,
|
||||
.exit = rockchip_usb2phy_exit,
|
||||
.power_on = rockchip_usb2phy_power_on,
|
||||
.power_off = rockchip_usb2phy_power_off,
|
||||
+ .set_mode = rockchip_usb2phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@@ -667,6 +721,15 @@
|
||||
unsigned long delay;
|
||||
bool vbus_attach, sch_work, notify_charger;
|
||||
|
||||
+ /*
|
||||
+ * This machine can only get the answer wrong here. In host role its
|
||||
+ * verdict suspends a phy that is enumerating a device (#160); with a
|
||||
+ * self-allocated extcon it has no role signal in EITHER direction, and
|
||||
+ * in device role it strands the gadget the same way (#168).
|
||||
+ */
|
||||
+ if (rport->host_mode || rphy->edev_self_allocated)
|
||||
+ return;
|
||||
+
|
||||
vbus_attach = property_enabled(rphy->grf,
|
||||
&rport->port_cfg->utmi_bvalid);
|
||||
|
||||
@@ -825,6 +888,15 @@
|
||||
bool is_dcd, tmout, vout, vbus_attach;
|
||||
unsigned long delay;
|
||||
|
||||
+ /*
|
||||
+ * Never probe the front end of a port that is hosting a device, and
|
||||
+ * never at all on a board whose bvalid is pinned high by the VBUS
|
||||
+ * bypass: charger detection cannot be meaningful there, and its DCP
|
||||
+ * verdict powers the phy off underneath a working link (#160, #168).
|
||||
+ */
|
||||
+ if (rport->host_mode || rphy->edev_self_allocated)
|
||||
+ return;
|
||||
+
|
||||
vbus_attach = property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid);
|
||||
|
||||
dev_dbg(&rport->phy->dev, "chg detection work state = %d\n",
|
||||
@@ -18,8 +18,6 @@ with `../build/warden_defconfig` -> `zImage` + `rv1106-warden.dtb`).
|
||||
| `15-pinctrl.patch` | `pinctrl-rockchip` RV1106 iomux |
|
||||
| `20-arch-dts-bindings.patch` | `arch/arm` DTs (`rv1106.dtsi`, `rv1106-warden.dts`, pinctrl), mach, configs, `include/dt-bindings` |
|
||||
| `25-usb-phy.patch` | inno-usb2 phy |
|
||||
| `27-usb-phy-tuning.patch` | inno-usb2 phy: RV1106 signal-quality register tuning |
|
||||
| `29-usb2phy-no-blind-otg-sm.patch` | inno-usb2 phy: stop the OTG/charger state machines running blind |
|
||||
| `30-drm-vop-panel-rgb.patch` | VOP (`rgb_dclk_pol`=0 + WIN1 scanout), panel-simple bus-format, rockchip_rgb |
|
||||
| `35-mailbox-hpmcu.patch` | rockchip-mailbox (rv1106 num_chans=1) |
|
||||
| `40-pvtm-soc.patch` | PVTM (core+pmu) + `include/soc/rockchip/pvtm.h` |
|
||||
|
||||
+7
-41
@@ -37,15 +37,6 @@ Documented guest deviations from production, set by stage-2 init:
|
||||
`WARDEN_HPMCU=0` (no mailbox SRAM on virt; flared >= flare-edge#106 fix
|
||||
required, or the daemon dies of SIGBUS).
|
||||
|
||||
**The VM's kernel is ahead of the panels' in one way that shows in the UI.**
|
||||
It is built from `build/warden_defconfig` plus `configs/virt.fragment`, so it
|
||||
has `CONFIG_BRIDGE`; the vendor 5.10 kernel most panels still run does not.
|
||||
A Client-mode access point is bridged to the wired uplink and needs that, so
|
||||
the Wi-Fi page offers it in the VM and says "Needs Router mode: this kernel
|
||||
cannot bridge" on a 5.10 panel. Both are correct for the kernel underneath.
|
||||
The difference disappears as panels move to the 6.18 build, but until then a
|
||||
screenshot from here is not evidence about a 5.10 panel's Wi-Fi page.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```sh
|
||||
@@ -63,27 +54,9 @@ bash qemu/run.sh --kernel $HOME/kbuild-out/linux-6.18.46/arch/arm/boot/zImage --
|
||||
```
|
||||
|
||||
Payload: drop static musl armv7 binaries into `qemu/payload/` (see its
|
||||
README). Stage-2 init starts every panel daemon it finds, in the panel's own
|
||||
S-number order (`warden-ai`, `warden-automation`, `warden-modbus`,
|
||||
`warden-mikrotik`, `warden-asic`, `warden-starlink`, `warden-stratum`,
|
||||
`warden-flared`), then `warden-ui` (the LVGL fbdev+evdev build from
|
||||
flare-edge `tools/build-ui-vm.sh`). The quickest faithful payload is the
|
||||
daemons a bench panel already runs: flare-edge `tools/rig-pull-daemons.sh
|
||||
--host <panel>` copies them in. The RS485 UART is always present (a null
|
||||
chardev without `--rs485`), so `warden-modbus` polls a port with nothing on
|
||||
it, as on a panel with an empty header, and never the control channel.
|
||||
|
||||
The VT cursor is kept off (`vt.global_cursor_default=0`): fbcon shares the
|
||||
virtio-gpu framebuffer with warden-ui and its blinking cursor would otherwise
|
||||
show up in screendumps at random (issue #18).
|
||||
|
||||
The guest carries the panel's own `/etc/passwd`, `/etc/shadow` and
|
||||
`/etc/group` (root's md5-crypt of the documented default password), so a
|
||||
screen that verifies the root password against `/etc/shadow` behaves as it
|
||||
does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
|
||||
(`lib.sh`) forces `etc/shadow` to mode 0600 on every stage: git tracks only
|
||||
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.
|
||||
README); `warden-flared`, `warden-modbus`, and `warden-ui` (the LVGL
|
||||
fbdev+evdev build from flare-edge `tools/build-ui-vm.sh`) are started by
|
||||
stage-2 init when present.
|
||||
|
||||
## Scenarios
|
||||
|
||||
@@ -91,16 +64,11 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
|
||||
| Scenario | Needs | Proves |
|
||||
|---|---|---|
|
||||
| `stage-rootfs-perms.sh` | - | offline, no VM: `qemu_stage_rootfs()` always lands `etc/shadow` at 0600, even staged from a source copy deliberately left 0644 |
|
||||
| `seed-dir.sh` | - | offline, no VM: `mkimage.sh`'s `SEED_DIR` hook lands every seeded file under userdata/warden with its original mode (a 0600 secret included), a seeded file beats a same-named `--state` value, a `SEED_DIR` that isn't a directory fails closed, and so does an individual entry that is a symlink, a subdirectory, or named outside `[A-Za-z0-9_.-]+` -- a hyphenated key such as `gas-plant.devices` still seeds cleanly |
|
||||
| `boot-smoke.sh` | - | sentinel-asserting boot; runs in CI inside kernel-build |
|
||||
| `portal-scenario.sh` | `FLARE_EDGE` | real flared against the desk mock portal: authenticated check-in, desired-state pull, signed tier-1 `.wfw` download; verify/stage/APPLYING as a dry run (no `WARDEN_FW_ALLOW_APPLY`) |
|
||||
| `ota-apply.sh` | `FLARE_EDGE` | the FULL apply: the `.wfw`'s bootable rootfs payload is written to rootfs_b (`run.sh --allow-apply` gates it per boot), the AvbABData in `misc` flips, and slot `_b` boots the applied version |
|
||||
| `ui-shot.sh` | - | display+touch, headless: QMP-screendumps the 720x720 UI, taps the Metrics tab via `input-send-event`, asserts the frame changed (`qmp.py` is the QMP client) |
|
||||
| `ui-drive.sh <script>` | - | the same rig for a SEQUENCE: boots once, runs a `qmp.py drive` script of taps/swipes/screenshots in panel pixels, and FAILS if warden-ui died on the way (stage-2 init announces the exit on the console). `tests/scripts/nav-stress.txt` is the navigation regression: it reproduces the s_row_left overflow that segfaulted the UI on returning to Settings > Apps; `tests/scripts/home-leaves-fullscreen.txt` proves the `home` verb clears dashboard fullscreen, the state a hardware wake tap leaves behind (flare-edge #176); `tests/scripts/fullscreen-toggle-tracks-real-state.txt` proves a `fullscreen toggle` right after `home` (or a real tap) reads the dashboard's actual state rather than a belief `home` bypassed -- `test_qmp_drive.py`'s `FullscreenToggleTracksRealState` pins the same contract offline |
|
||||
| `real-image-boot.sh` | matched `rootfs.img` + `oem.img` | an ACTUAL flare-edge build (placed by `mkimage.sh --rootfs-image/--oem-image`) boots its own init chain to getty; binaries predating known fixes reproduce their bugs faithfully, a time machine for field issues |
|
||||
| `test-ui-drive-rs485.sh` | - | offline, no VM: a fake `run.sh` and (for one case) a fake `socat` stand in so `ui-drive.sh --rs485-devices`'s startup fails closed instead of printing a false "== rs485 simulator: ..." over a bus nothing is serving, for each of a qemu rs.sock that never appears, a socat that never links rs.pty, and an mbsim.py that dies before opening rs.ctl; also proves `cleanup()` escalates to SIGKILL for a sim process that ignores SIGTERM |
|
||||
| `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts |
|
||||
| watchdog (`run.sh --watchdog`) | - | arm `/dev/watchdog`, don't pet: the VM resets ~30 s later (verified) |
|
||||
|
||||
Scenario fine print:
|
||||
@@ -127,9 +95,7 @@ Scenario fine print:
|
||||
## Requirements
|
||||
|
||||
`qemu-system-arm` (Debian 13 ships QEMU 10), `curl`, `cpio`, `mkfs.ext4`,
|
||||
`debugfs` (both ship in `e2fsprogs`; `seed-dir.sh` reads a built partition
|
||||
back with it), `gcc-arm-linux-gnueabihf` (kernel build), `python3`
|
||||
(+`cryptography` for the portal scenario's `.wfw` signing). CI: the hosted
|
||||
`qemu-tools` job builds the tooling; the boot smoke runs inside the (also
|
||||
hosted, dispatch-only) `kernel-build` job, which apt-installs its own
|
||||
toolchain and qemu (ADR-0007).
|
||||
`gcc-arm-linux-gnueabihf` (kernel build), `python3` (+`cryptography` for the
|
||||
portal scenario's `.wfw` signing). CI: the hosted `qemu-tools` job builds the
|
||||
tooling; the boot smoke runs inside the (also hosted, dispatch-only)
|
||||
`kernel-build` job, which apt-installs its own toolchain and qemu (ADR-0007).
|
||||
|
||||
+7
-32
@@ -22,34 +22,15 @@ qemu_get_busybox() {
|
||||
echo "FATAL: no pinned sha256 for busybox (expected $sha_file): refusing to build from an unverified binary" >&2
|
||||
exit 1
|
||||
}
|
||||
if [ ! -f "$BB" ]; then
|
||||
qemu_log "downloading $BB_URL"
|
||||
curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$BB_URL" -o "$BB"
|
||||
fi
|
||||
local want got
|
||||
want="$(cat "$sha_file")"
|
||||
if [ -f "$BB" ]; then
|
||||
got="$(sha256sum "$BB" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
qemu_log "busybox sha256 verified"
|
||||
return
|
||||
fi
|
||||
qemu_log "cached busybox failed verification; fetching a clean copy"
|
||||
fi
|
||||
|
||||
local attempt tmp="${BB}.download.$$"
|
||||
rm -f "$tmp"
|
||||
for attempt in 1 2 3; do
|
||||
qemu_log "downloading $BB_URL (attempt $attempt/3)"
|
||||
if curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$BB_URL" -o "$tmp"; then
|
||||
got="$(sha256sum "$tmp" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
mv -f "$tmp" "$BB"
|
||||
qemu_log "busybox sha256 verified"
|
||||
return
|
||||
fi
|
||||
echo "busybox sha256 mismatch on attempt $attempt: want $want got $got" >&2
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
done
|
||||
echo "FATAL: could not fetch pinned busybox after 3 verified attempts" >&2
|
||||
exit 1
|
||||
got="$(sha256sum "$BB" | awk '{print $1}')"
|
||||
[ "$want" = "$got" ] || { echo "busybox sha256 mismatch: want $want got $got" >&2; exit 1; }
|
||||
qemu_log "busybox sha256 verified"
|
||||
}
|
||||
|
||||
# Stage the shared rootfs skeleton (qemu/rootfs/ + busybox) into $1.
|
||||
@@ -63,12 +44,6 @@ qemu_stage_rootfs() {
|
||||
cp -a "$QEMU_DIR/rootfs/." "$root/"
|
||||
chmod 0755 "$root/init" "$root/sbin/init" "$root/etc/rc" \
|
||||
"$root/usr/share/udhcpc/default.script"
|
||||
# git only tracks the executable bit, so a checkout lands etc/shadow at
|
||||
# whatever the umask gives a non-executable file (644 under the common
|
||||
# 022) -- root's crypt hash world-readable. Force the normal shadow mode
|
||||
# here, once, for every caller (mkimage.sh and mkinitramfs.sh both stage
|
||||
# through this function).
|
||||
chmod 0600 "$root/etc/shadow"
|
||||
}
|
||||
|
||||
# Parse a "SIZE[@OFFSET](NAME)" blkdevparts entry list (without the "vda:"
|
||||
|
||||
+2
-51
@@ -15,14 +15,8 @@
|
||||
# flare-edge build's rootfs.img/oem.img matched pair) into slot A instead of
|
||||
# the busybox skeleton; slot B keeps the skeleton as a known-good fallback.
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# OUT output dir (default: qemu/out); image at $OUT/disk.img
|
||||
# SEED_DIR a directory of pre-built userdata/warden files (one file per
|
||||
# settings key, e.g. flare-edge tools/seed-fixtures.py's output)
|
||||
# copied in VERBATIM, after --portal-url/--state. Lets a caller
|
||||
# seed an arbitrary key set -- a flow spec's setup.seed can name
|
||||
# anything settings.c reads -- without growing --state into a
|
||||
# multi-value flag; last one written wins, same as --state.
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# OUT output dir (default: qemu/out); image at $OUT/disk.img
|
||||
set -euo pipefail
|
||||
|
||||
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@@ -91,49 +85,6 @@ for kv in ${STATE_KV[@]+"${STATE_KV[@]}"}; do
|
||||
printf '%s\n' "${kv#*=}" > "$UDATA/warden/${kv%%=*}"
|
||||
done
|
||||
|
||||
# SEED_DIR: a pre-built set of settings files (see the Env note above), copied
|
||||
# in whole rather than re-parsed here -- seed-fixtures.py already wrote them
|
||||
# in the exact format settings.c reads (filename = key, mode 0600 for a
|
||||
# secret), so re-deriving that here would be a second place to keep in sync
|
||||
# with settings.c. Applied after --state so a seeded file can override a
|
||||
# same-named --state value; `cp -a` preserves the 0600 on a secret entry.
|
||||
if [ -n "${SEED_DIR:-}" ]; then
|
||||
[ -d "$SEED_DIR" ] || { echo "FATAL: SEED_DIR '$SEED_DIR' is not a directory" >&2; exit 1; }
|
||||
# Validate every entry before cp -a touches any of them: `cp -a` preserves
|
||||
# a symlink rather than following it, so one placed in SEED_DIR would land
|
||||
# as a live symlink under /userdata/warden that a later read (flared's
|
||||
# settings loader, running inside the guest) resolves through. Fail closed
|
||||
# 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.
|
||||
#
|
||||
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
|
||||
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
|
||||
# keys like "gas-plant.devices" (flare-edge#151), and committed flow
|
||||
# specs (gas_compression, gas_plant, liquid_pumping, power_generation)
|
||||
# already seed hyphenated keys through this exact path -- --state's
|
||||
# charset would reject every one of them.
|
||||
while IFS= read -r -d '' entry; do
|
||||
base="$(basename "$entry")"
|
||||
case "$base" in
|
||||
*[!A-Za-z0-9_.-]*)
|
||||
echo "FATAL: SEED_DIR entry '$base' must match [A-Za-z0-9_.-]+ (it becomes a filename)" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
if [ -L "$entry" ]; then
|
||||
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ -f "$entry" ] || {
|
||||
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
}
|
||||
done < <(find "$SEED_DIR" -mindepth 1 -maxdepth 1 -print0)
|
||||
cp -a "$SEED_DIR"/. "$UDATA/warden/"
|
||||
fi
|
||||
|
||||
mkdir -p "$SCRATCH/empty"
|
||||
|
||||
# mkfs an ext4 partition image of exactly $2 bytes from staged dir $1.
|
||||
|
||||
+4
-13
@@ -20,16 +20,7 @@ Then:
|
||||
cp <flare-edge>/target/armv7-unknown-linux-musleabihf/release/warden-flared qemu/payload/
|
||||
```
|
||||
|
||||
Or take them from a panel that already runs them: every daemon is a static
|
||||
musl binary, so flare-edge `tools/rig-pull-daemons.sh --host <panel>` copies
|
||||
`/usr/bin/warden-*` straight into this directory (recording the panel's
|
||||
release and each md5 in `PULLED.txt`), minus `warden-ui`, which the rig
|
||||
needs as the fbdev+evdev build.
|
||||
|
||||
Stage-2 init starts every `warden-*` daemon it finds here, in the panel's
|
||||
own S-number order (ai, automation, modbus, mikrotik, asic, starlink,
|
||||
stratum, flared), then `warden-ui` (the UI also needs `--display
|
||||
on|headless` + the virt.fragment kernel for /dev/fb0). Logs land in
|
||||
`/tmp/<name>.log` inside the guest, readable over the control bridge with
|
||||
`ctl @cat /tmp/<name>.log`. An empty payload is valid: the image boots
|
||||
busybox-only.
|
||||
Stage-2 init starts `warden-flared`, `warden-modbus`, and `warden-ui` (the
|
||||
UI also needs `--display on|headless` + the virt.fragment kernel for
|
||||
/dev/fb0) automatically when present (logs land in `/tmp/<name>.log` inside
|
||||
the guest). An empty payload is valid: the image boots busybox-only.
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
root:x:0:
|
||||
daemon:x:1:
|
||||
bin:x:2:
|
||||
sys:x:3:
|
||||
mail:x:8:
|
||||
www-data:x:33:
|
||||
operator:x:37:
|
||||
nogroup:x:65534:
|
||||
@@ -1,9 +0,0 @@
|
||||
root:x:0:0:root:/root:/bin/sh
|
||||
daemon:x:1:1:daemon:/usr/sbin:/bin/false
|
||||
bin:x:2:2:bin:/bin:/bin/false
|
||||
sys:x:3:3:sys:/dev:/bin/false
|
||||
sync:x:4:100:sync:/bin:/bin/sync
|
||||
mail:x:8:8:mail:/var/spool/mail:/bin/false
|
||||
www-data:x:33:33:www-data:/var/www:/bin/false
|
||||
operator:x:37:37:Operator:/var:/bin/false
|
||||
nobody:x:65534:65534:nobody:/home:/bin/false
|
||||
@@ -1,9 +0,0 @@
|
||||
root:$1$wardenrs$F.aYwbBz69WjSvwa3RNRF1:19664::::::
|
||||
daemon:*:::::::
|
||||
bin:*:::::::
|
||||
sys:*:::::::
|
||||
sync:*:::::::
|
||||
mail:*:::::::
|
||||
www-data:*:::::::
|
||||
operator:*:::::::
|
||||
nobody:*:::::::
|
||||
+4
-141
@@ -10,26 +10,9 @@
|
||||
exec </dev/console >/dev/console 2>&1
|
||||
/bin/busybox --install -s /bin
|
||||
|
||||
# mkfs.ext4 -d preserves the checkout owner's uid. Production owns shadow as
|
||||
# root, and the UI intentionally rejects any other owner before verifying it.
|
||||
chown 0:0 /etc/shadow
|
||||
chmod 0600 /etc/shadow
|
||||
root_hash="$(awk -F: '$1 == "root" { print $2 }' /etc/shadow)"
|
||||
test_hash="$(printf '%s' root | /usr/bin/mkpasswd -m md5 -S wardenrs 2>/dev/null)"
|
||||
if [ -z "$root_hash" ] || [ "$test_hash" != "$root_hash" ]; then
|
||||
echo "FATAL: QEMU root credential verifier is unavailable"
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
mount -t tmpfs tmpfs /tmp
|
||||
# The UI's Terminal page opens a PTY (posix_openpt), which needs devpts mounted
|
||||
# and /dev/ptmx pointing into it. Without this the page can only ever report
|
||||
# "no PTY available" -- it renders, so a screenshot scenario looks fine, while
|
||||
# the one thing the page does is untestable in the VM.
|
||||
mkdir -p /dev/pts
|
||||
mount -t devpts devpts /dev/pts 2>/dev/null
|
||||
|
||||
# shellcheck source=qemu/rootfs/etc/warden-lib.sh disable=SC1091
|
||||
. /etc/warden-lib.sh
|
||||
@@ -58,12 +41,8 @@ mount_fatal "oem${slot}" /oem
|
||||
mkdir -p /userdata/warden
|
||||
|
||||
# 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
|
||||
# cmdline), so the RS485 UART is ttyS1 then and ttyS0 otherwise. Aliasing
|
||||
# ttyS0 blindly put Modbus polls on the control channel.
|
||||
if grep -qw warden.ctl /proc/cmdline; then rs485="/dev/ttyS1"; else rs485="/dev/ttyS0"; fi
|
||||
[ -c "$rs485" ] && ln -sf "$rs485" /dev/ttyS4
|
||||
# VM's pci-serial UART when one is present (needs the virt.fragment kernel).
|
||||
[ -c /dev/ttyS0 ] && ln -sf /dev/ttyS0 /dev/ttyS4
|
||||
|
||||
# Network: slirp user-mode net on eth0 (DHCP, fallback to QEMU's static map).
|
||||
# The fallback keys off the interface actually having an address: udhcpc
|
||||
@@ -95,26 +74,13 @@ export WARDEN_HPMCU=0
|
||||
# post-apply "reboot" surfaces as a clean flared error; the scenario harness
|
||||
# performs the actual reboot into the applied slot.
|
||||
export WARDEN_HARD_RESET=0
|
||||
# Production init scripts create this volatile socket directory before their
|
||||
# daemons start. The compact QEMU rootfs must provide the same contract.
|
||||
mkdir -p /run/warden
|
||||
# OTA apply is opt-in per boot (run.sh --allow-apply): writing rootfs_b is
|
||||
# safe inside disk.img but must never be the default posture.
|
||||
if grep -qw warden.fwapply /proc/cmdline; then
|
||||
export WARDEN_FW_ALLOW_APPLY=1
|
||||
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
|
||||
# (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 \
|
||||
/usr/bin/warden-mikrotik /usr/bin/warden-asic /usr/bin/warden-starlink \
|
||||
/usr/bin/warden-stratum /usr/bin/warden-flared; do
|
||||
for d in /usr/bin/warden-flared /usr/bin/warden-modbus; do
|
||||
if [ -x "$d" ]; then
|
||||
name="$(basename "$d")"
|
||||
echo "init: starting $name"
|
||||
@@ -127,110 +93,7 @@ done
|
||||
# virt.fragment kernel.
|
||||
if [ -x /usr/bin/warden-ui ] && [ -c /dev/fb0 ]; then
|
||||
echo "init: starting warden-ui (fbdev)"
|
||||
# Announce the exit on the CONSOLE, not just in the log. A UI that dies
|
||||
# mid-scenario otherwise looks exactly like a UI that stopped repainting:
|
||||
# the framebuffer holds its last frame, screendumps keep working, and the
|
||||
# scenario reports a stale picture as the current state. With this, a crash
|
||||
# is one grep away for any scenario driving the VM from outside, and the
|
||||
# signal or status that caused it is on the line.
|
||||
(
|
||||
# tee, not a plain redirect: the UI's own log (LV_LOG_USER and friends)
|
||||
# is the most useful thing there is when a scenario does not do what it
|
||||
# should, and a scenario driving the VM from outside can only see the
|
||||
# CONSOLE. The file is kept as well so the exit dump below still works.
|
||||
/usr/bin/warden-ui 2>&1 | tee /tmp/warden-ui.log
|
||||
rc=$?
|
||||
echo "init: warden-ui EXITED rc=$rc"
|
||||
# 128+n is a signal death (139 = SIGSEGV); dump the tail so the
|
||||
# scenario's console log carries the UI's own last words.
|
||||
echo "init: warden-ui log tail:"
|
||||
tail -n 20 /tmp/warden-ui.log 2>/dev/null
|
||||
) &
|
||||
fi
|
||||
|
||||
# Control bridge: the UI's debug FIFO, reachable from OUTSIDE the VM.
|
||||
#
|
||||
# warden-ui answers nav/page/stats/hit on /tmp/warden-ui.ctl (warden_debug.c),
|
||||
# but that FIFO lives in here and a scenario drives the VM from the host. On
|
||||
# real hardware the same channel is reached over SSH (flare-edge
|
||||
# tools/warden-ctl); this initramfs is busybox-only and has no sshd, so the
|
||||
# equivalent seam is a second 16550 that run.sh --ctl exposes as a unix socket
|
||||
# (pci-serial, the same device the RS485 bridge already rides). One command
|
||||
# per line in, the FIFO's reply out, and a sentinel line so the reader knows
|
||||
# the reply is complete without a timeout. The FIFO vocabulary itself is
|
||||
# identical on both sides of that seam, which is what lets one flow script
|
||||
# run against the sim and against a panel.
|
||||
#
|
||||
# One exception, answered by the bridge itself and never forwarded to the
|
||||
# FIFO: `@cat PATH` replies with PATH's contents (or one "bridge: no such
|
||||
# file: PATH" line if it is missing), then the same sentinel. This is how the
|
||||
# json flow channel reads webstatus.c's /tmp/warden-web-status.json snapshot
|
||||
# from OUTSIDE the VM -- on a panel that file is just as reachable over the
|
||||
# SSH session tools/warden-ctl already has, so hardware needs no equivalent.
|
||||
#
|
||||
# run.sh lists the ctl port before any other pci-serial, so it is always the
|
||||
# first 8250, and it says so with warden.ctl on the command line. The marker,
|
||||
# not the mere presence of a ttyS0, is what arms the bridge: a VM launched
|
||||
# with --rs485 alone also has a ttyS0, and that one is the Modbus wire.
|
||||
if grep -qw warden.ctl /proc/cmdline && [ -c /dev/ttyS0 ]; then
|
||||
ctl=/dev/ttyS0
|
||||
echo "init: control bridge on $ctl"
|
||||
(
|
||||
# Opened ONCE, read-write, on fd 3. Reopening a serial port per line
|
||||
# can block on carrier detect; one open at bridge start either works
|
||||
# or fails visibly on the console. The tty stays in its default cooked
|
||||
# mode: the host discards echoed input, and a whole line arrives per
|
||||
# read.
|
||||
exec 3<> "$ctl"
|
||||
while IFS= read -r cmd <&3; do
|
||||
[ -n "$cmd" ] || continue
|
||||
case "$cmd" in
|
||||
"@cat "*)
|
||||
# A bridge-local command, never forwarded to warden-ui's
|
||||
# FIFO: `@cat PATH` reads PATH directly off the GUEST's
|
||||
# own filesystem and answers with it, which is how the
|
||||
# json flow channel gets webstatus.c's snapshot out to
|
||||
# the host driving the VM from outside. `-f` so a
|
||||
# directory or device node reports as missing rather than
|
||||
# cat hanging or erroring oddly.
|
||||
path="${cmd#@cat }"
|
||||
if [ -f "$path" ]; then
|
||||
cat "$path" >&3
|
||||
# Force a newline after the file's own bytes: the
|
||||
# status json (webstatus.c) is written with NO
|
||||
# trailing newline, and without this the sentinel
|
||||
# below would land on the SAME line as the content
|
||||
# and the reader (qmp.py Ctl.send, line-based) would
|
||||
# block forever waiting for a line that never comes.
|
||||
echo >&3
|
||||
else
|
||||
echo "bridge: no such file: $path" >&3
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [ -p /tmp/warden-ui.ctl ]; then
|
||||
# Remove the previous reply BEFORE sending, then wait
|
||||
# for the new one to appear (the UI renames it into
|
||||
# place whole). A fixed settle used to hand back the
|
||||
# previous command's reply whenever a page took longer
|
||||
# than 0.3 s to build (flare-edge #152); this is the
|
||||
# same recipe tools/warden-ctl uses over SSH.
|
||||
rm -f /tmp/warden-ui.dbg
|
||||
printf '%s\n' "$cmd" > /tmp/warden-ui.ctl
|
||||
n=0
|
||||
while [ ! -s /tmp/warden-ui.dbg ] && [ "$n" -lt 100 ]; do
|
||||
sleep 0.05
|
||||
n=$((n + 1))
|
||||
done
|
||||
cat /tmp/warden-ui.dbg 2>/dev/null >&3
|
||||
else
|
||||
echo "bridge: warden-ui control FIFO not present" >&3
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo "<<END>>" >&3
|
||||
done
|
||||
) &
|
||||
/usr/bin/warden-ui > /tmp/warden-ui.log 2>&1 &
|
||||
fi
|
||||
|
||||
if grep -qw warden.shell /proc/cmdline; then
|
||||
|
||||
+4
-34
@@ -14,9 +14,6 @@
|
||||
# "device boots believing 2021" incident class
|
||||
# --rs485 SOCK unix socket chardev for the RS485/Modbus bridge
|
||||
# (pci-serial: needs the virt.fragment kernel)
|
||||
# --ctl SOCK unix socket to warden-ui's debug channel (nav/page/hit),
|
||||
# bridged by init from a pci-serial port; the rig-side
|
||||
# twin of tools/warden-ctl over SSH on a real panel
|
||||
# --watchdog add i6300esb watchdog, reset on expiry (fragment kernel)
|
||||
# --qmp SOCK QMP unix socket (screendump, input-send-event, quit)
|
||||
# --display MODE off (default, -nographic) | on (gtk window) | headless
|
||||
@@ -35,7 +32,7 @@ QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
OUT="${OUT:-$QEMU_DIR/out}"
|
||||
|
||||
KERNEL="" INITRD="$OUT/initramfs.cpio.gz" DISK="" NO_DISK=0 SLOT="_a"
|
||||
RTC="" RS485="" CTL="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
RTC="" RS485="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
SSH_PORT=2222 HTTP_PORT=8080 API_PORT=28443
|
||||
EXTRA=()
|
||||
|
||||
@@ -48,7 +45,6 @@ while [ $# -gt 0 ]; do
|
||||
--slot) SLOT="${2:?}"; shift 2 ;;
|
||||
--rtc) RTC="${2:?}"; shift 2 ;;
|
||||
--rs485) RS485="${2:?}"; shift 2 ;;
|
||||
--ctl) CTL="${2:?}"; shift 2 ;;
|
||||
--watchdog) WATCHDOG=1; shift ;;
|
||||
--qmp) QMP="${2:?}"; shift 2 ;;
|
||||
--display) DISPLAY_MODE="${2:?}"; shift 2 ;;
|
||||
@@ -82,12 +78,7 @@ fi
|
||||
|
||||
# NOTE: never add `earlyprintk`: the config's DEBUG_UART_PHYS is the RV1106's
|
||||
# 0xff4c0000, which does not exist on -M virt.
|
||||
# vt.global_cursor_default=0: the virt kernel binds fbcon to the virtio-gpu
|
||||
# framebuffer, and its blinking cursor lands on /dev/fb0 under warden-ui (an
|
||||
# 8x2 block at the top-left, present in one boot and absent in the next). The
|
||||
# panel has no fbcon on its display, and a pixel reference captured with the
|
||||
# cursor in frame fails without it (issue #18).
|
||||
APPEND="console=ttyAMA0 rdinit=/init vt.global_cursor_default=0"
|
||||
APPEND="console=ttyAMA0 rdinit=/init"
|
||||
# Port 0 disables a forward. A boot smoke needs no host ports and must not
|
||||
# fail on a busy default port.
|
||||
NETDEV="user,id=n0"
|
||||
@@ -111,32 +102,11 @@ if [ -n "$DISK" ] && [ "$NO_DISK" -eq 0 ]; then
|
||||
-device "virtio-blk-device,drive=vd0" )
|
||||
fi
|
||||
[ "$SHELL_FLAG" -eq 1 ] && APPEND="$APPEND warden.shell"
|
||||
# Tells init the FIRST 8250 is the control bridge. Without this marker init
|
||||
# bridges nothing, so a VM launched with --rs485 alone never has its Modbus
|
||||
# wire mistaken for the debug channel.
|
||||
[ -n "$CTL" ] && APPEND="$APPEND warden.ctl"
|
||||
[ "$ALLOW_APPLY" -eq 1 ] && APPEND="$APPEND warden.fwapply"
|
||||
[ -n "$RTC" ] && ARGS+=( -rtc "base=$RTC" )
|
||||
[ "$WATCHDOG" -eq 1 ] && ARGS+=( -device i6300esb -action watchdog=reset )
|
||||
# The UI's debug channel, bridged out of the VM: rootfs/sbin/init relays lines
|
||||
# between this port and warden-ui's control FIFO (see qmp.py --ctl). Same
|
||||
# pci-serial the RS485 bridge rides. Listed BEFORE rs485 so that, whichever
|
||||
# combination is requested, this port enumerates as ttyS0 -- the first port
|
||||
# init's bridge probes. Put rs485 first and the bridge would be talking to the
|
||||
# Modbus wire.
|
||||
[ -n "$CTL" ] && ARGS+=( -chardev "socket,id=ctl,path=$CTL,server=on,wait=off"
|
||||
-device "pci-serial,chardev=ctl" )
|
||||
# Without --rs485 the UART is still there, wired to nothing: warden-modbus
|
||||
# then polls a port that never answers, which is what a panel with an empty
|
||||
# RS485 header looks like, rather than failing to open a port that does not
|
||||
# exist (a different UI state) or, worse, being aliased onto the control
|
||||
# channel by init (which happened: Modbus frames in the wake reply).
|
||||
if [ -n "$RS485" ]; then
|
||||
ARGS+=( -chardev "socket,id=rs485,path=$RS485,server=on,wait=off"
|
||||
-device "pci-serial,chardev=rs485" )
|
||||
else
|
||||
ARGS+=( -chardev "null,id=rs485" -device "pci-serial,chardev=rs485" )
|
||||
fi
|
||||
[ -n "$RS485" ] && ARGS+=( -chardev "socket,id=rs485,path=$RS485,server=on,wait=off"
|
||||
-device "pci-serial,chardev=rs485" )
|
||||
[ -n "$QMP" ] && ARGS+=( -qmp "unix:$QMP,server=on,wait=off" )
|
||||
|
||||
case "$DISPLAY_MODE" in
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
QEMU_DIR="$(cd "$TEST_DIR/.." && pwd)"
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/busybox-fetch.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
|
||||
FAKE_BIN="$SCRATCH/bin"
|
||||
FAKE_CURL_COUNT="$SCRATCH/curl-count"
|
||||
mkdir -p "$FAKE_BIN" "$SCRATCH/qemu"
|
||||
printf 'good payload' > "$SCRATCH/good"
|
||||
sha256sum "$SCRATCH/good" | awk '{print $1}' > "$SCRATCH/qemu/busybox.sha256"
|
||||
|
||||
FAKE_CURL="$FAKE_BIN/curl"
|
||||
apply_fake_curl() {
|
||||
chmod 0755 "$FAKE_CURL"
|
||||
export PATH="$FAKE_BIN:$PATH"
|
||||
export FAKE_CURL_COUNT FAKE_CURL_MODE
|
||||
}
|
||||
|
||||
# The path is resolved at runtime from this file's location.
|
||||
# shellcheck disable=SC1091
|
||||
source "$QEMU_DIR/lib.sh"
|
||||
QEMU_DIR="$SCRATCH/qemu"
|
||||
# Read by qemu_get_busybox from the sourced helper.
|
||||
# shellcheck disable=SC2034
|
||||
BB_URL="https://invalid.example/busybox"
|
||||
|
||||
# These single-quoted lines are the literal source of the fake curl program.
|
||||
# shellcheck disable=SC2016
|
||||
printf '%s\n' '#!/bin/sh' \
|
||||
'count=0' \
|
||||
'[ ! -f "$FAKE_CURL_COUNT" ] || count=$(cat "$FAKE_CURL_COUNT")' \
|
||||
'count=$((count + 1))' \
|
||||
'printf "%s\n" "$count" > "$FAKE_CURL_COUNT"' \
|
||||
'out=' \
|
||||
'while [ "$#" -gt 0 ]; do' \
|
||||
' if [ "$1" = "-o" ]; then shift; out="$1"; fi' \
|
||||
' shift' \
|
||||
'done' \
|
||||
'[ -n "$out" ] || exit 2' \
|
||||
'if [ "$FAKE_CURL_MODE" = "flaky" ] && [ "$count" -gt 1 ]; then' \
|
||||
' printf "good payload" > "$out"' \
|
||||
'else' \
|
||||
' printf "bad payload" > "$out"' \
|
||||
'fi' > "$FAKE_CURL"
|
||||
|
||||
FAKE_CURL_MODE=flaky
|
||||
apply_fake_curl
|
||||
OUT="$SCRATCH/flaky" qemu_get_busybox
|
||||
test "$(cat "$FAKE_CURL_COUNT")" = 2
|
||||
test "$(sha256sum "$BB" | awk '{print $1}')" = "$(cat "$QEMU_DIR/busybox.sha256")"
|
||||
|
||||
printf '0\n' > "$FAKE_CURL_COUNT"
|
||||
FAKE_CURL_MODE=bad
|
||||
apply_fake_curl
|
||||
if (OUT="$SCRATCH/always-bad" qemu_get_busybox) >"$SCRATCH/failure.log" 2>&1; then
|
||||
echo "FAIL: an unverified download was accepted" >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(cat "$FAKE_CURL_COUNT")" = 3
|
||||
test ! -e "$SCRATCH/always-bad/busybox-armv7l"
|
||||
grep -q 'after 3 verified attempts' "$SCRATCH/failure.log"
|
||||
|
||||
printf '0\n' > "$FAKE_CURL_COUNT"
|
||||
mkdir -p "$SCRATCH/cached"
|
||||
cp "$SCRATCH/good" "$SCRATCH/cached/busybox-armv7l"
|
||||
OUT="$SCRATCH/cached" qemu_get_busybox
|
||||
test "$(cat "$FAKE_CURL_COUNT")" = 0
|
||||
|
||||
echo "busybox fetch tests passed"
|
||||
@@ -1,563 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PPM loading, cropping and image comparison for UI flow region asserts.
|
||||
|
||||
Standalone (no VM, no other module in this repo needed): a screendump is
|
||||
QEMU's own P6 PPM file, and everything below works straight off that file
|
||||
plus a JSON reference. Pure Python plus Pillow only.
|
||||
|
||||
imgtools.py compare REFS NAME SHOT.ppm
|
||||
imgtools.py capture REFS NAME SHOT.ppm X Y W H TOL # TOL: exact|loose|structural
|
||||
imgtools.py hash SHOT.ppm
|
||||
imgtools.py bench [SHOT.ppm] [N] # per-call phash/structural timing, N iterations
|
||||
imgtools.py selftest
|
||||
|
||||
`compare` and `capture` read/write a reference file: JSON mapping a region
|
||||
name to {"x","y","w","h","tolerance","phash","structural"}. `capture` always
|
||||
fills in both hashes so an existing entry's tolerance class can be changed
|
||||
later without re-shooting the region.
|
||||
|
||||
Public API (imported directly by the driver, not just via the CLI above):
|
||||
|
||||
load_ppm(path) -> (w, h, rgb_bytes)
|
||||
crop(img, x, y, w, h) -> img
|
||||
phash(img) -> int 8x8 DCT of a 32x32 grey downscale, 64-bit
|
||||
structural(img) -> bytes 16x16 edge/nonblack occupancy mask, 32 bytes
|
||||
compare(ref_entry, cur_img, tolerance) -> (ok, detail)
|
||||
|
||||
`img` is always the (w, h, rgb_bytes) triple load_ppm/crop return -- there is
|
||||
no separate image type. rgb_bytes is tightly packed row-major RGB, 3 bytes
|
||||
per pixel, no padding, matching both PPM P6 and PIL's "RGB" raw layout.
|
||||
"""
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
# occupancy thresholds for structural(): a cell is occupied when its grey is
|
||||
# this far from the crop's median (its background), or its FIND_EDGES energy
|
||||
# exceeds the edge threshold. Both are 0..255 greyscale/edge-magnitude
|
||||
# averages over the cell.
|
||||
# Validated on real captures: a switch knob left/right differs in 240/256
|
||||
# cells, a dark card's icon and text stand out from its (7,13,29) ground.
|
||||
DEVIATION_THRESHOLD = 28
|
||||
EDGE_THRESHOLD = 24
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# PPM
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def load_ppm(path):
|
||||
"""Read a binary PPM (P6), return (w, h, rgb_bytes).
|
||||
|
||||
Delegates to Pillow's own P6 decoder (Image.open, format auto-detected
|
||||
from the magic) instead of re-parsing the PPM grammar by hand: skipping
|
||||
whitespace runs and '#' comments, and normalising any maxval to 8-bit,
|
||||
are Pillow's problem here, not ours. convert("RGB") guarantees the
|
||||
tightly-packed 3-bytes-per-pixel layout every caller in this file
|
||||
assumes regardless of the source channel depth.
|
||||
"""
|
||||
with Image.open(path) as im:
|
||||
im = im.convert("RGB")
|
||||
return im.width, im.height, im.tobytes()
|
||||
|
||||
|
||||
def crop(img, x, y, w, h):
|
||||
"""Crop (W,H,rgb) to the x,y,w,h box, return a new (w,h,rgb) image.
|
||||
|
||||
The bounds check stays explicit and fails loudly (see main()'s own
|
||||
comment on that) rather than delegating to PIL's crop, which silently
|
||||
zero-pads a box that runs outside the source image instead of raising --
|
||||
exactly the kind of stale/mistyped region box this check exists to catch.
|
||||
"""
|
||||
width, height, data = img
|
||||
if x < 0 or y < 0 or w <= 0 or h <= 0 or x + w > width or y + h > height:
|
||||
raise ValueError(f"crop box {x},{y},{w}x{h} outside image {width}x{height}")
|
||||
cropped = _to_pil(img).crop((x, y, x + w, y + h))
|
||||
return w, h, cropped.tobytes()
|
||||
|
||||
|
||||
def _to_pil(img):
|
||||
w, h, data = img
|
||||
return Image.frombytes("RGB", (w, h), data)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# perceptual hash (phash): 8x8 DCT of a 32x32 grey downscale
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _dct_basis(n):
|
||||
"""n x n DCT-II basis matrix. Unnormalised -- fine since phash only
|
||||
thresholds coefficients against each other, never compares magnitudes
|
||||
across images."""
|
||||
return [[math.cos(math.pi / n * (col + 0.5) * row) for col in range(n)] for row in range(n)]
|
||||
|
||||
|
||||
_DCT32 = _dct_basis(32)
|
||||
|
||||
# phash() only ever reads the low-frequency _DCT_KEEP x _DCT_KEEP corner of
|
||||
# the 32x32 DCT (see its docstring), so _dct2d_32 stops both passes at this
|
||||
# many frequencies instead of computing all 1024 coefficients -- same 64
|
||||
# coefficients out, roughly 6x less pure-Python multiply-add work per call.
|
||||
_DCT_KEEP = 8
|
||||
|
||||
|
||||
def _dct2d_32(rows):
|
||||
"""2D DCT-II of a 32x32 list-of-lists via two separable 1D passes,
|
||||
truncated to the low-frequency _DCT_KEEP x _DCT_KEEP corner -- the only
|
||||
coefficients any caller reads."""
|
||||
n = 32
|
||||
# columns first: tmp[u][x] = DCT of column x at frequency u. Frequencies
|
||||
# u >= _DCT_KEEP never feed a returned coefficient, so skip them.
|
||||
tmp = [[0.0] * n for _ in range(_DCT_KEEP)]
|
||||
for u in range(_DCT_KEEP):
|
||||
b = _DCT32[u]
|
||||
for x in range(n):
|
||||
s = 0.0
|
||||
for y in range(n):
|
||||
s += rows[y][x] * b[y]
|
||||
tmp[u][x] = s
|
||||
# then rows: out[u][v] = DCT of tmp's row u at frequency v. Same cutoff
|
||||
# on v; the y/x summations stay full since each kept coefficient still
|
||||
# needs the whole 32-wide signal.
|
||||
out = [[0.0] * _DCT_KEEP for _ in range(_DCT_KEEP)]
|
||||
for u in range(_DCT_KEEP):
|
||||
row = tmp[u]
|
||||
for v in range(_DCT_KEEP):
|
||||
b = _DCT32[v]
|
||||
s = 0.0
|
||||
for x in range(n):
|
||||
s += row[x] * b[x]
|
||||
out[u][v] = s
|
||||
return out
|
||||
|
||||
|
||||
def phash(img):
|
||||
"""8x8-DCT perceptual hash of a 32x32 greyscale downscale, as a 64-bit
|
||||
int. Classic pHash recipe: downscale, DCT, keep the low-frequency 8x8
|
||||
corner, threshold each coefficient against the block's mean (DC term
|
||||
excluded from the mean -- it is just overall brightness and would bias
|
||||
every bit the same way)."""
|
||||
small = _to_pil(img).convert("L").resize((32, 32), Image.LANCZOS)
|
||||
px = small.load()
|
||||
rows = [[px[x, y] for x in range(32)] for y in range(32)]
|
||||
coeffs = _dct2d_32(rows)
|
||||
block = [coeffs[u][v] for u in range(_DCT_KEEP) for v in range(_DCT_KEEP)]
|
||||
mean = sum(block[1:]) / (len(block) - 1)
|
||||
bits = 0
|
||||
for c in block:
|
||||
bits = (bits << 1) | (1 if c > mean else 0)
|
||||
return bits
|
||||
|
||||
|
||||
def hamming(a, b):
|
||||
"""Bit-differences between two phash ints."""
|
||||
return (a ^ b).bit_count()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# structural occupancy hash: 16x16 edge/nonblack mask
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def structural(img):
|
||||
"""16x16 binary occupancy mask as 32 bytes (256 bits, MSB first,
|
||||
row-major). A cell is "occupied" if it carries ink relative to the crop's
|
||||
OWN background -- its grey deviates from the crop's median by more than
|
||||
DEVIATION_THRESHOLD -- or sits on an edge, so the mask is robust to a
|
||||
recolour (still occupied) but sensitive to a shape disappearing (goes
|
||||
from occupied to empty).
|
||||
|
||||
Relative to the median, not to black: the WardenOS page background is
|
||||
(7,13,29), grey 16, and an absolute non-black test read every cell of
|
||||
every region as occupied, so no structural check could ever fail
|
||||
(SDK #19, flare-edge #156). Measured on real captures with this rule: a
|
||||
Bluetooth switch off/on differs in 240 of 256 cells, a dark card reads
|
||||
its icon and text and nothing else."""
|
||||
grey = _to_pil(img).convert("L")
|
||||
edges = grey.filter(ImageFilter.FIND_EDGES)
|
||||
grey_small = grey.resize((16, 16), Image.BOX)
|
||||
edge_small = edges.resize((16, 16), Image.BOX)
|
||||
median = _median_grey(grey)
|
||||
gpx, epx = grey_small.load(), edge_small.load()
|
||||
bits = bytearray(32)
|
||||
idx = 0
|
||||
for y in range(16):
|
||||
for x in range(16):
|
||||
occupied = abs(gpx[x, y] - median) > DEVIATION_THRESHOLD or epx[x, y] > EDGE_THRESHOLD
|
||||
if occupied:
|
||||
bits[idx // 8] |= 1 << (7 - (idx % 8))
|
||||
idx += 1
|
||||
return bytes(bits)
|
||||
|
||||
|
||||
def _median_grey(grey):
|
||||
"""The crop's dominant luminance: the background of a card, the fill of a
|
||||
switch, whatever most of the pixels are."""
|
||||
hist = grey.histogram()
|
||||
total = sum(hist)
|
||||
acc = 0
|
||||
for value, count in enumerate(hist):
|
||||
acc += count
|
||||
if acc * 2 >= total:
|
||||
return value
|
||||
return 0
|
||||
|
||||
|
||||
def _structural_diff(a, b):
|
||||
"""Count of differing bits between two 32-byte occupancy masks."""
|
||||
return (int.from_bytes(a, "big") ^ int.from_bytes(b, "big")).bit_count()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# compare
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def compare(ref_entry, cur_img, tolerance):
|
||||
"""Compare cur_img (already cropped to the reference's box) against
|
||||
ref_entry under the given tolerance class. Returns (ok, detail); detail
|
||||
explains the verdict either way, for results.jsonl.
|
||||
|
||||
exact: phash hamming distance == 0
|
||||
loose: phash hamming distance <= 6
|
||||
structural: occupancy mask bytes equal (no distance, no tolerance)
|
||||
"""
|
||||
if tolerance in ("exact", "loose"):
|
||||
if "phash" not in ref_entry:
|
||||
return False, "reference missing 'phash' field"
|
||||
try:
|
||||
ref_hash = int(ref_entry["phash"], 16)
|
||||
except (TypeError, ValueError):
|
||||
return False, f"reference 'phash' is not valid hex: {ref_entry.get('phash')!r}"
|
||||
cur_hash = phash(cur_img)
|
||||
dist = hamming(ref_hash, cur_hash)
|
||||
limit = 0 if tolerance == "exact" else 6
|
||||
ok = dist <= limit
|
||||
detail = f"phash hamming={dist} limit={limit} ref={ref_hash:016x} cur={cur_hash:016x}"
|
||||
return ok, detail
|
||||
|
||||
if tolerance == "structural":
|
||||
if "structural" not in ref_entry:
|
||||
return False, "reference missing 'structural' field"
|
||||
try:
|
||||
ref_bits = bytes.fromhex(ref_entry["structural"])
|
||||
except (TypeError, ValueError):
|
||||
return False, f"reference 'structural' is not valid hex: {ref_entry.get('structural')!r}"
|
||||
cur_bits = structural(cur_img)
|
||||
ok = ref_bits == cur_bits
|
||||
if ok:
|
||||
detail = "structural mask matches (0/256 cells differ)"
|
||||
else:
|
||||
diff = _structural_diff(ref_bits, cur_bits)
|
||||
detail = f"structural mask differs in {diff}/256 cells"
|
||||
return ok, detail
|
||||
|
||||
return False, f"unknown tolerance class: {tolerance!r}"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# CLI
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _load_refs(path):
|
||||
if not os.path.exists(path):
|
||||
return {}
|
||||
with open(path) as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def _save_refs(path, refs):
|
||||
with open(path, "w") as f:
|
||||
json.dump(refs, f, indent=2, sort_keys=True)
|
||||
f.write("\n")
|
||||
|
||||
|
||||
def cmd_compare(argv):
|
||||
if len(argv) != 3:
|
||||
print("usage: imgtools.py compare REFS NAME SHOT.ppm", file=sys.stderr)
|
||||
return 2
|
||||
refs_path, name, shot_path = argv
|
||||
refs = _load_refs(refs_path)
|
||||
if name not in refs:
|
||||
print(f"FAIL {name}: no such reference (run capture first)")
|
||||
return 1
|
||||
entry = refs[name]
|
||||
for key in ("x", "y", "w", "h", "tolerance"):
|
||||
if key not in entry:
|
||||
print(f"FAIL {name}: reference entry missing '{key}'")
|
||||
return 1
|
||||
w, h, data = load_ppm(shot_path)
|
||||
cropped = crop((w, h, data), entry["x"], entry["y"], entry["w"], entry["h"])
|
||||
ok, detail = compare(entry, cropped, entry["tolerance"])
|
||||
print(f"{'PASS' if ok else 'FAIL'} {name}: {detail}")
|
||||
return 0 if ok else 1
|
||||
|
||||
|
||||
def cmd_capture(argv):
|
||||
if len(argv) != 8:
|
||||
print("usage: imgtools.py capture REFS NAME SHOT.ppm X Y W H TOL", file=sys.stderr)
|
||||
return 2
|
||||
refs_path, name, shot_path, x, y, w, h, tol = argv
|
||||
if tol not in ("exact", "loose", "structural"):
|
||||
print(f"usage: TOL must be exact|loose|structural, got {tol!r}", file=sys.stderr)
|
||||
return 2
|
||||
x, y, w, h = int(x), int(y), int(w), int(h)
|
||||
iw, ih, data = load_ppm(shot_path)
|
||||
cropped = crop((iw, ih, data), x, y, w, h)
|
||||
entry = {
|
||||
"x": x, "y": y, "w": w, "h": h,
|
||||
"tolerance": tol,
|
||||
"phash": f"{phash(cropped):016x}",
|
||||
"structural": structural(cropped).hex(),
|
||||
}
|
||||
refs = _load_refs(refs_path)
|
||||
refs[name] = entry
|
||||
_save_refs(refs_path, refs)
|
||||
print(f"captured {name}: {entry}")
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_hash(argv):
|
||||
if len(argv) != 1:
|
||||
print("usage: imgtools.py hash SHOT.ppm", file=sys.stderr)
|
||||
return 2
|
||||
w, h, data = load_ppm(argv[0])
|
||||
img = (w, h, data)
|
||||
print(f"{w}x{h} phash={phash(img):016x} structural={structural(img).hex()}")
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_bench(argv):
|
||||
"""Time phash()/structural() -- the per-step cost of every
|
||||
assert_region/wait_region/capture_region in a flow run (wait_region polls
|
||||
at 0.5s intervals, calling back into these on every poll), so a change to
|
||||
the DCT size, the downscale filter, or the occupancy thresholds shows up
|
||||
as a number here instead of only as a slower flow run nobody investigates.
|
||||
|
||||
usage: imgtools.py bench [SHOT.ppm] [N]
|
||||
|
||||
SHOT.ppm: a real screendump to benchmark against a representative crop
|
||||
of; default is a synthetic 720x720 image (the virt.fragment screendump
|
||||
size) so bench never depends on a committed fixture or a live rig.
|
||||
N: iterations per function, default 200.
|
||||
"""
|
||||
import timeit
|
||||
|
||||
if len(argv) > 2:
|
||||
print("usage: imgtools.py bench [SHOT.ppm] [N]", file=sys.stderr)
|
||||
return 2
|
||||
shot_path = next((a for a in argv if not a.isdigit()), None)
|
||||
n = int(next((a for a in argv if a.isdigit()), "200"))
|
||||
|
||||
if shot_path:
|
||||
w, h, data = load_ppm(shot_path)
|
||||
else:
|
||||
w, h = 720, 720
|
||||
data = _make_test_rgb(w, h, (220, 20, 20))
|
||||
img = (w, h, data)
|
||||
# a representative crop, not the whole screen: every real region assert
|
||||
# crops first, and structural()'s edge filter cost scales with crop
|
||||
# size even though phash's fixed 32x32 downscale mostly doesn't.
|
||||
cw, ch = min(200, w), min(200, h)
|
||||
region = crop(img, 0, 0, cw, ch)
|
||||
|
||||
def percentiles(samples):
|
||||
s = sorted(samples)
|
||||
p50 = s[min(len(s) - 1, int(len(s) * 0.50))]
|
||||
p95 = s[min(len(s) - 1, int(len(s) * 0.95))]
|
||||
return s[0], p50, p95, s[-1]
|
||||
|
||||
print(f"bench: {cw}x{ch} region, n={n} iterations")
|
||||
for label, fn in (("phash", lambda: phash(region)),
|
||||
("structural", lambda: structural(region))):
|
||||
for _ in range(5):
|
||||
fn() # warm up: first call can carry one-off costs (e.g. module-
|
||||
# level caches settling) that don't belong in the steady-state
|
||||
# population below
|
||||
samples = timeit.repeat(fn, repeat=n, number=1)
|
||||
lo, p50, p95, hi = percentiles(samples)
|
||||
print(f" {label:<10} min={lo * 1000:7.3f}ms p50={p50 * 1000:7.3f}ms "
|
||||
f"p95={p95 * 1000:7.3f}ms max={hi * 1000:7.3f}ms")
|
||||
return 0
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# selftest
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _make_test_rgb(w, h, colour, shift=(0, 0)):
|
||||
"""Black canvas with a coloured square near one corner: the self-test's
|
||||
synthetic images, and bench's default when it isn't given a real
|
||||
SHOT.ppm. colour=None means no square at all (removed shape)."""
|
||||
from PIL import ImageDraw
|
||||
img = Image.new("RGB", (w, h), (0, 0, 0))
|
||||
if colour is not None:
|
||||
draw = ImageDraw.Draw(img)
|
||||
ox, oy = shift
|
||||
x0, y0 = 8 + ox, 8 + oy
|
||||
draw.rectangle([x0, y0, x0 + 20, y0 + 20], fill=colour)
|
||||
return img.tobytes()
|
||||
|
||||
|
||||
def _write_ppm(path, w, h, rgb_bytes):
|
||||
with open(path, "wb") as f:
|
||||
f.write(f"P6\n{w} {h}\n255\n".encode("ascii"))
|
||||
f.write(rgb_bytes)
|
||||
|
||||
|
||||
def _dct2d_32_brute(rows):
|
||||
"""Unoptimised reference DCT: the full 32x32 transform with no early
|
||||
cutoff. selftest()-only, so _dct2d_32's _DCT_KEEP truncation has
|
||||
something independent to be checked against -- a future edit that moves
|
||||
the cutoff on the wrong loop would otherwise change captured phash bits
|
||||
with nothing catching it."""
|
||||
n = 32
|
||||
tmp = [[0.0] * n for _ in range(n)]
|
||||
for u in range(n):
|
||||
b = _DCT32[u]
|
||||
for x in range(n):
|
||||
s = 0.0
|
||||
for y in range(n):
|
||||
s += rows[y][x] * b[y]
|
||||
tmp[u][x] = s
|
||||
out = [[0.0] * n for _ in range(n)]
|
||||
for u in range(n):
|
||||
row = tmp[u]
|
||||
for v in range(n):
|
||||
b = _DCT32[v]
|
||||
s = 0.0
|
||||
for x in range(n):
|
||||
s += row[x] * b[x]
|
||||
out[u][v] = s
|
||||
return out
|
||||
|
||||
|
||||
def selftest():
|
||||
import tempfile
|
||||
|
||||
w, h = 128, 128
|
||||
failures = []
|
||||
|
||||
def check(label, cond):
|
||||
print(f"[{'ok' if cond else 'FAIL'}] {label}")
|
||||
if not cond:
|
||||
failures.append(label)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
refs_path = os.path.join(tmp, "refs.json")
|
||||
|
||||
base_path = os.path.join(tmp, "base.ppm")
|
||||
_write_ppm(base_path, w, h, _make_test_rgb(w, h, (220, 20, 20)))
|
||||
|
||||
# capture the same corner box under all three tolerance classes
|
||||
for tol in ("exact", "loose", "structural"):
|
||||
rc = main(["capture", refs_path, f"corner-{tol}", base_path, "4", "4", "32", "32", tol])
|
||||
check(f"capture corner-{tol} succeeds", rc == 0)
|
||||
|
||||
# load_ppm/crop sanity: the drawn pixel lands where expected
|
||||
bw, bh, bdata = load_ppm(base_path)
|
||||
check("load_ppm reads back the written size", (bw, bh) == (w, h))
|
||||
cropped = crop((bw, bh, bdata), 4, 4, 32, 32)
|
||||
px_off = ((8 - 4) * 32 + (8 - 4)) * 3
|
||||
check("crop keeps the drawn pixel in place",
|
||||
cropped[2][px_off:px_off + 3] == bytes((220, 20, 20)))
|
||||
|
||||
# a header QEMU never writes but the P6 grammar allows: a '#'
|
||||
# comment line and a non-255 maxval. Pillow's decoder (load_ppm no
|
||||
# longer hand-parses the header) must still read it correctly.
|
||||
odd_path = os.path.join(tmp, "odd-header.ppm")
|
||||
with open(odd_path, "wb") as f:
|
||||
f.write(b"P6\n# generated for a selftest, not by QEMU\n2 2\n100\n")
|
||||
f.write(bytes((100, 0, 0, 0, 100, 0, 0, 0, 100, 100, 100, 100)))
|
||||
ow, oh, odata = load_ppm(odd_path)
|
||||
check("load_ppm reads width/height past a comment line", (ow, oh) == (2, 2))
|
||||
check("load_ppm scales a non-255 maxval channel to 8-bit",
|
||||
odata[0:3] == bytes((255, 0, 0)))
|
||||
|
||||
# crop box outside the image must still fail loudly, not silently
|
||||
# zero-pad the way PIL's own Image.crop does
|
||||
try:
|
||||
crop((bw, bh, bdata), bw - 4, bh - 4, 32, 32)
|
||||
check("crop rejects a box past the image edge", False)
|
||||
except ValueError:
|
||||
check("crop rejects a box past the image edge", True)
|
||||
|
||||
# _dct2d_32's _DCT_KEEP truncation must land on the exact same
|
||||
# coefficients an untruncated 32x32 DCT would produce
|
||||
small = _to_pil((bw, bh, bdata)).convert("L").resize((32, 32), Image.LANCZOS)
|
||||
px = small.load()
|
||||
dct_rows = [[px[x, y] for x in range(32)] for y in range(32)]
|
||||
fast, brute = _dct2d_32(dct_rows), _dct2d_32_brute(dct_rows)
|
||||
check("_dct2d_32's truncated corner matches the untruncated DCT",
|
||||
all(fast[u][v] == brute[u][v]
|
||||
for u in range(_DCT_KEEP) for v in range(_DCT_KEEP)))
|
||||
|
||||
# identical shot: exact must pass
|
||||
same_path = os.path.join(tmp, "same.ppm")
|
||||
_write_ppm(same_path, w, h, _make_test_rgb(w, h, (220, 20, 20)))
|
||||
rc = main(["compare", refs_path, "corner-exact", same_path])
|
||||
check("exact passes for an identical shot", rc == 0)
|
||||
|
||||
# small shift: exact must fail, loose must still pass
|
||||
shift_path = os.path.join(tmp, "shift.ppm")
|
||||
_write_ppm(shift_path, w, h, _make_test_rgb(w, h, (220, 20, 20), shift=(1, 1)))
|
||||
rc = main(["compare", refs_path, "corner-exact", shift_path])
|
||||
check("exact fails for a slight shift", rc == 1)
|
||||
rc = main(["compare", refs_path, "corner-loose", shift_path])
|
||||
check("loose passes for a slight shift", rc == 0)
|
||||
|
||||
# colour change, same footprint: structural must still pass
|
||||
colour_path = os.path.join(tmp, "colour.ppm")
|
||||
_write_ppm(colour_path, w, h, _make_test_rgb(w, h, (20, 20, 220)))
|
||||
rc = main(["compare", refs_path, "corner-structural", colour_path])
|
||||
check("structural passes for a colour change", rc == 0)
|
||||
|
||||
# shape removed entirely: structural must fail
|
||||
removed_path = os.path.join(tmp, "removed.ppm")
|
||||
_write_ppm(removed_path, w, h, _make_test_rgb(w, h, None))
|
||||
rc = main(["compare", refs_path, "corner-structural", removed_path])
|
||||
check("structural fails when the shape is removed", rc == 1)
|
||||
|
||||
# bad-path coverage
|
||||
rc = main(["compare", refs_path, "no-such-name", base_path])
|
||||
check("compare on an unknown reference name fails loudly", rc == 1)
|
||||
rc = main(["hash", base_path])
|
||||
check("hash on a real ppm succeeds", rc == 0)
|
||||
rc = main(["bench", base_path, "3"])
|
||||
check("bench runs to completion", rc == 0)
|
||||
|
||||
if failures:
|
||||
print(f"\n{len(failures)} check(s) failed:")
|
||||
for label in failures:
|
||||
print(f" - {label}")
|
||||
return 1
|
||||
print("\nall checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def main(argv):
|
||||
if not argv:
|
||||
print(__doc__, file=sys.stderr)
|
||||
return 2
|
||||
cmd, rest = argv[0], argv[1:]
|
||||
if cmd == "selftest":
|
||||
return selftest()
|
||||
handlers = {"compare": cmd_compare, "capture": cmd_capture, "hash": cmd_hash, "bench": cmd_bench}
|
||||
if cmd not in handlers:
|
||||
print(f"unknown command: {cmd!r}", file=sys.stderr)
|
||||
return 2
|
||||
# A missing file, unreadable ref JSON, or malformed PPM/crop box is a
|
||||
# prerequisite failure -- report it plainly and fail loudly (exit 1),
|
||||
# never let it fall through as a silent pass or a raw traceback.
|
||||
try:
|
||||
return handlers[cmd](rest)
|
||||
except (OSError, ValueError, json.JSONDecodeError) as exc:
|
||||
print(f"FATAL: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
+15
-1169
File diff suppressed because it is too large
Load Diff
@@ -1,149 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline regression test for run.sh's own argv construction: no real QEMU,
|
||||
# no kernel image. A fake `qemu-system-arm` placed first on PATH dumps the
|
||||
# argv it was handed (one token per line) and exits, so this pins the exact
|
||||
# contract run.sh:121-138 and rootfs/sbin/init:54,161 share without either
|
||||
# side moving: init decides ttyS0 vs ttyS1 for the Modbus alias purely by
|
||||
# grepping warden.ctl off /proc/cmdline, so run.sh has to keep two promises
|
||||
# every single invocation -- the ctl pci-serial device, when present, comes
|
||||
# BEFORE the rs485 one in argv (virt's PCI bus enumerates in that order),
|
||||
# and an rs485 pci-serial device (real or null-backed) is always there so
|
||||
# the port count init relies on never shifts.
|
||||
#
|
||||
# What is worth pinning: nothing else exercises this. test-ui-drive-rs485.sh
|
||||
# stubs run.sh out entirely (a fake VM), and the only real boot in CI
|
||||
# (boot-smoke.sh) passes neither --ctl nor --rs485, so a swapped
|
||||
# `[ -n "$CTL" ]`/`[ -n "$RS485" ]` block, or a dropped null-chardev
|
||||
# fallback, would reach a panel as Modbus polls landing on the debug channel
|
||||
# (run.sh:131-133's own incident) before anything here caught it.
|
||||
#
|
||||
# bash run-sh-args-test.sh
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
RUN_SH="$HERE/../run.sh"
|
||||
SCRATCH="$(mktemp -d /tmp/runshargs.XXXXXX)"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
FAIL=0
|
||||
pass() { printf '[PASS] %s\n' "$1"; }
|
||||
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
KERNEL="$SCRATCH/fake-zImage"
|
||||
INITRD="$SCRATCH/fake-initramfs.cpio.gz"
|
||||
: > "$KERNEL"
|
||||
: > "$INITRD"
|
||||
|
||||
BIN="$SCRATCH/bin"
|
||||
mkdir -p "$BIN"
|
||||
cat > "$BIN/qemu-system-arm" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
# Stand-in for the real binary: record argv, one token per line, and exit
|
||||
# straight away. $ARGV_CAPTURE names where -- run.sh always `exec`s this as
|
||||
# its very last step, so nothing downstream of it ever runs.
|
||||
printf '%s\n' "$@" > "$ARGV_CAPTURE"
|
||||
STUB
|
||||
chmod +x "$BIN/qemu-system-arm"
|
||||
|
||||
# run_case ARGV_FILE EXTRA_ARGS...: invoke the real run.sh --no-disk (so
|
||||
# nothing under the real qemu/out/ is ever touched) with the fake binary
|
||||
# first on PATH, capturing its argv into ARGV_FILE. Fails the case loudly if
|
||||
# run.sh itself exits nonzero -- a silent empty capture would otherwise look
|
||||
# just like "the assertions below simply found nothing".
|
||||
run_case() {
|
||||
local argv_file="$1"; shift
|
||||
local out rc
|
||||
out="$(cd "$SCRATCH" && PATH="$BIN:$PATH" ARGV_CAPTURE="$argv_file" \
|
||||
bash "$RUN_SH" --kernel "$KERNEL" --initrd "$INITRD" --no-disk "$@" 2>&1)"
|
||||
rc=$?
|
||||
[ "$rc" -eq 0 ] || { fail "run.sh exited $rc for: $* -- output: $out"; return 1; }
|
||||
[ -s "$argv_file" ] || { fail "run.sh produced no captured argv for: $*"; return 1; }
|
||||
return 0
|
||||
}
|
||||
|
||||
# chardev_line ARGV_FILE PREFIX: 1-indexed line number of the first argv
|
||||
# token starting with PREFIX (the socket/null chardev spec, which always
|
||||
# immediately follows the "-chardev" token it belongs to), or empty.
|
||||
chardev_line() { grep -n -m1 "^$2" "$1" | cut -d: -f1; }
|
||||
|
||||
# --- case: neither --ctl nor --rs485 -> null-backed rs485, no ctl device ---
|
||||
argv="$SCRATCH/argv-neither.txt"
|
||||
if run_case "$argv"; then
|
||||
if ! grep -qF 'id=ctl' "$argv"; then
|
||||
pass "neither flag: no ctl chardev/device at all"
|
||||
else
|
||||
fail "neither flag: a ctl chardev/device appeared unrequested"
|
||||
fi
|
||||
if grep -qF -- '-append' "$argv" && ! grep -qw 'warden.ctl' "$argv"; then
|
||||
pass "neither flag: -append omits warden.ctl"
|
||||
else
|
||||
fail "neither flag: -append should omit warden.ctl"
|
||||
fi
|
||||
if [ -n "$(chardev_line "$argv" 'null,id=rs485')" ] \
|
||||
&& grep -qF 'pci-serial,chardev=rs485' "$argv"; then
|
||||
pass "neither flag: null-backed rs485 pci-serial device is still present"
|
||||
else
|
||||
fail "neither flag: expected a null-backed rs485 device (port count must not shift)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- case: --rs485 alone -> real rs485 device, still no ctl device ---------
|
||||
argv="$SCRATCH/argv-rs485-only.txt"
|
||||
if run_case "$argv" --rs485 "$SCRATCH/rs.sock"; then
|
||||
if ! grep -qF 'id=ctl' "$argv"; then
|
||||
pass "rs485 only: no ctl chardev/device"
|
||||
else
|
||||
fail "rs485 only: a ctl chardev/device appeared unrequested"
|
||||
fi
|
||||
if ! grep -qw 'warden.ctl' "$argv"; then
|
||||
pass "rs485 only: -append omits warden.ctl"
|
||||
else
|
||||
fail "rs485 only: -append should omit warden.ctl"
|
||||
fi
|
||||
if [ -n "$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")" ]; then
|
||||
pass "rs485 only: rs485 chardev carries the requested socket path"
|
||||
else
|
||||
fail "rs485 only: rs485 chardev did not carry the requested socket path"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- case: --ctl alone -> ctl device first, null-backed rs485 still present,
|
||||
# and warden.ctl on the cmdline ------------------------------------------
|
||||
argv="$SCRATCH/argv-ctl-only.txt"
|
||||
if run_case "$argv" --ctl "$SCRATCH/ctl.sock"; then
|
||||
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,path=$SCRATCH/ctl.sock,")"
|
||||
rs_ln="$(chardev_line "$argv" 'null,id=rs485')"
|
||||
if [ -n "$ctl_ln" ] && [ -n "$rs_ln" ] && [ "$ctl_ln" -lt "$rs_ln" ]; then
|
||||
pass "ctl only: ctl chardev (line $ctl_ln) precedes the null rs485 chardev (line $rs_ln)"
|
||||
else
|
||||
fail "ctl only: expected ctl chardev before a null-backed rs485 chardev, got ctl=$ctl_ln rs485=$rs_ln"
|
||||
fi
|
||||
if grep -qw 'warden.ctl' "$argv"; then
|
||||
pass "ctl only: -append carries warden.ctl"
|
||||
else
|
||||
fail "ctl only: -append should carry warden.ctl"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- case: --ctl and --rs485 together -> ctl device still enumerates first -
|
||||
argv="$SCRATCH/argv-both.txt"
|
||||
if run_case "$argv" --ctl "$SCRATCH/ctl.sock" --rs485 "$SCRATCH/rs.sock"; then
|
||||
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,path=$SCRATCH/ctl.sock,")"
|
||||
rs_ln="$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")"
|
||||
if [ -n "$ctl_ln" ] && [ -n "$rs_ln" ] && [ "$ctl_ln" -lt "$rs_ln" ]; then
|
||||
pass "both flags: ctl chardev (line $ctl_ln) precedes the rs485 chardev (line $rs_ln)"
|
||||
else
|
||||
fail "both flags: expected ctl chardev before rs485 chardev, got ctl=$ctl_ln rs485=$rs_ln"
|
||||
fi
|
||||
if grep -qw 'warden.ctl' "$argv"; then
|
||||
pass "both flags: -append carries warden.ctl"
|
||||
else
|
||||
fail "both flags: -append should carry warden.ctl"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "ALL RUN.SH ARGV TESTS PASSED"
|
||||
exit 0
|
||||
else
|
||||
echo "RUN.SH ARGV TESTS FAILED"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,39 +0,0 @@
|
||||
# `fullscreen toggle` must read the dashboard's REAL state, not a belief the
|
||||
# FIFO's own `fullscreen` verb tracked on the side.
|
||||
#
|
||||
# warden_debug.c's `fullscreen` command used to keep a private `static bool
|
||||
# on` as its only record of state, and nothing kept it in step with the real
|
||||
# dashboard: `home` clears fullscreen by calling
|
||||
# warden_screen_overview_set_fullscreen(false) directly (every hardware run's
|
||||
# preamble, since a live panel is wherever the last flow or an operator left
|
||||
# it), and a real tap on the dashboard toggles it through the UI's own
|
||||
# tap-catcher. Either way the FIFO's belief was left stale. A `fullscreen
|
||||
# toggle` right after either one then decided its next state from that stale
|
||||
# belief: if `on` was still true from an earlier `fullscreen on`, toggling
|
||||
# set it to false -- which coincidentally MATCHED the already-off real state,
|
||||
# so the dashboard never actually turned on, yet the reply still said
|
||||
# "fullscreen off: ok". See test_qmp_drive.py's FullscreenToggleTracksRealState
|
||||
# for the same scenario driven offline against a faked control channel (both
|
||||
# the pre-fix and fixed shapes).
|
||||
#
|
||||
# `wake` first, as every compiled flow does: by the time the control bridge
|
||||
# is up the rig may already sit dimmed, and sleep.c swallows the touch that
|
||||
# wakes a dimmed panel (flare-edge #148).
|
||||
wake
|
||||
sleep 1
|
||||
assert_page Dashboard/Dashboard
|
||||
assert_hit 47 676 obj box=12,640,72x72
|
||||
ctl fullscreen on
|
||||
sleep 1
|
||||
assert_hit 47 676 widget box=0,0,720x720
|
||||
home
|
||||
sleep 1
|
||||
assert_page Dashboard/Dashboard
|
||||
# home must have cleared the REAL state -- this is home-leaves-fullscreen.txt's
|
||||
# own check, repeated here so a failure below is unambiguously the toggle's
|
||||
# fault and not a home regression.
|
||||
assert_hit 47 676 obj box=12,640,72x72
|
||||
# The dashboard is really off now. A correct toggle from here can only go on.
|
||||
ctl fullscreen toggle
|
||||
sleep 1
|
||||
assert_hit 47 676 widget box=0,0,720x720
|
||||
@@ -1,35 +0,0 @@
|
||||
# `home` must leave dashboard fullscreen, not only reach Dashboard/Dashboard.
|
||||
#
|
||||
# On the dashboard a tap anywhere toggles fullscreen (screen_overview.c's
|
||||
# tap-catcher). On a panel a flow's `wake` is a real finger on the glass, so
|
||||
# a flow that woke the panel on the dashboard left the next flow a 720x720
|
||||
# canvas over the chrome: the rail gear at (47,676) resolved to
|
||||
# `widget box=0,0,720x720` instead of `obj box=12,640,72x72`, and every
|
||||
# hit against chrome failed from there (bench sample 2026-09-08, flare-edge
|
||||
# #176). The runner's `home` preamble now clears fullscreen last, after the
|
||||
# dashboard is the page again, so this is the regression guard for it.
|
||||
#
|
||||
# `wake` first, as every compiled flow does: by the time the control bridge is
|
||||
# up the rig may already sit dimmed, and sleep.c swallows the touch that wakes
|
||||
# a dimmed panel (flare-edge #148) -- the tap below must reach the tap-catcher.
|
||||
wake
|
||||
sleep 1
|
||||
assert_page Dashboard/Dashboard
|
||||
assert_hit 47 676 obj box=12,640,72x72
|
||||
tap 360 360
|
||||
sleep 1
|
||||
assert_hit 47 676 widget box=0,0,720x720
|
||||
home
|
||||
sleep 1
|
||||
assert_page Dashboard/Dashboard
|
||||
assert_hit 47 676 obj box=12,640,72x72
|
||||
# The same from another page: fullscreen on, leave, come home.
|
||||
tap 360 360
|
||||
sleep 1
|
||||
assert_hit 47 676 widget box=0,0,720x720
|
||||
nav Mining Devices/ASICs
|
||||
sleep 1
|
||||
home
|
||||
sleep 1
|
||||
assert_page Dashboard/Dashboard
|
||||
assert_hit 47 676 obj box=12,640,72x72
|
||||
@@ -1,55 +0,0 @@
|
||||
# Navigation stress: the sequence that used to kill warden-ui.
|
||||
#
|
||||
# Settings > Apps reads the PROJECTED MENU TABLE (app.c's all_proj, populated
|
||||
# lazily on that page's first build). Walking the app rows writes one timestamp
|
||||
# per row into app.c's s_row_left. While that array was sized 8 and the shipped
|
||||
# registry projected 18 rows, leaving any row from index 8 up wrote past it --
|
||||
# straight over all_count and all_proj, which the linker places immediately
|
||||
# after. Coming back to Settings > Apps then walked a tick value as a `const
|
||||
# char *` and the process died with SIGSEGV (rc=139).
|
||||
#
|
||||
# So the order matters and is the whole test: populate the table, walk the late
|
||||
# rows, come BACK. A run that only walks rows never triggers it, because with
|
||||
# all_count still zero the page's lazy init quietly repairs the array.
|
||||
#
|
||||
# Run: ui-drive.sh <zImage> tests/scripts/nav-stress.txt <outdir>
|
||||
# PASS is ui-drive.sh finding no "warden-ui EXITED" on the console.
|
||||
|
||||
echo == populate the projected menu table
|
||||
tap 47 676
|
||||
sleep 2
|
||||
tap 464 40
|
||||
sleep 4
|
||||
shot 01-apps-first
|
||||
|
||||
echo == back to column 0, where the rail is on screen
|
||||
tap 174 40
|
||||
sleep 2
|
||||
|
||||
echo == walk the app rows, the late ones included
|
||||
tap 47 512
|
||||
sleep 2
|
||||
tap 47 592
|
||||
sleep 2
|
||||
swipe 47 560 47 220 500
|
||||
sleep 1
|
||||
tap 47 420
|
||||
sleep 2
|
||||
tap 47 500
|
||||
sleep 2
|
||||
swipe 47 560 47 220 500
|
||||
sleep 1
|
||||
tap 47 380
|
||||
sleep 2
|
||||
tap 47 520
|
||||
sleep 2
|
||||
shot 02-late-rows
|
||||
|
||||
echo == and back: this is the step that used to segfault
|
||||
tap 47 676
|
||||
sleep 2
|
||||
tap 464 40
|
||||
sleep 4
|
||||
shot 03-apps-again
|
||||
sleep 3
|
||||
shot 04-still-alive
|
||||
@@ -1,190 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for mkimage.sh's SEED_DIR hook (see its Env note and the
|
||||
# block right after --state is applied): a caller-supplied directory of
|
||||
# pre-built userdata/warden files, copied in whole and applied AFTER --state
|
||||
# so a seeded file can override a same-named --state value, after each entry
|
||||
# is validated the same way --state's own KEY=VALUE is validated -- a
|
||||
# symlink, a non-plain-file entry (a subdirectory included), or a name
|
||||
# outside [A-Za-z0-9_.-]+ fails closed before cp -a runs. Nothing else in
|
||||
# the qemu test suite ever sets SEED_DIR -- the CI qemu-tools job runs
|
||||
# mkimage.sh unseeded, and only ui-drive.sh --seed exercises this path, and
|
||||
# only when booting a real VM with a flare-edge checkout on hand -- so this
|
||||
# is the only offline coverage of it.
|
||||
#
|
||||
# Builds a real disk image the same way mkimage.sh always does (unprivileged
|
||||
# mkfs.ext4 -d), then reads the userdata partition back with debugfs -R
|
||||
# (read-only, no mount or loop device needed) to check what actually landed
|
||||
# on disk rather than trusting the script's own log output.
|
||||
#
|
||||
# bash seed-dir.sh
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
|
||||
QEMU_DIR="$(cd "$HERE/.." && pwd)" # qemu/
|
||||
FAIL=0
|
||||
pass() { printf '[PASS] %s\n' "$1"; }
|
||||
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
# mkfs.ext4 and debugfs both live in sbin, which user shells on Debian don't
|
||||
# put on PATH -- same fix mkimage.sh itself applies.
|
||||
PATH="$PATH:/usr/sbin:/sbin"
|
||||
command -v debugfs >/dev/null || {
|
||||
echo "FATAL: debugfs (e2fsprogs) not found: needed to read the userdata partition back" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# shellcheck source=../lib.sh disable=SC1091
|
||||
. "$QEMU_DIR/lib.sh"
|
||||
# shellcheck source=../blkdevparts.conf disable=SC1091
|
||||
. "$QEMU_DIR/blkdevparts.conf"
|
||||
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-seed-dir.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
|
||||
# userdata's byte offset/size come from the same blkdevparts string
|
||||
# mkimage.sh itself parses, not a hardcoded number: a future layout change
|
||||
# doesn't strand this test.
|
||||
USERDATA_OFF=""
|
||||
USERDATA_SIZE=""
|
||||
capture_userdata() { [ "$1" = userdata ] && { USERDATA_OFF="$2"; USERDATA_SIZE="$3"; }; return 0; }
|
||||
qemu_each_partition capture_userdata
|
||||
[ -n "$USERDATA_OFF" ] || { echo "FATAL: no 'userdata' entry in blkdevparts.conf" >&2; exit 1; }
|
||||
|
||||
# extract_userdata DISK OUTFILE: pull the userdata partition window out of a
|
||||
# built disk image. Sparse output so an otherwise near-empty 1G partition
|
||||
# costs kilobytes of scratch space, not a real gigabyte, per scenario.
|
||||
extract_userdata() {
|
||||
dd if="$1" of="$2" bs=4096 skip=$((USERDATA_OFF / 4096)) \
|
||||
count=$((USERDATA_SIZE / 4096)) conv=sparse status=none
|
||||
}
|
||||
|
||||
# Reuse an already-verified busybox (read-only) so this test stays offline
|
||||
# wherever a prior build has already produced one; only a checkout that has
|
||||
# never run mkimage.sh falls back to the same fetch+verify mkimage.sh always
|
||||
# does, once, shared by every scenario below.
|
||||
BUSYBOX_BIN="$QEMU_DIR/out/busybox-armv7l"
|
||||
if [ ! -f "$BUSYBOX_BIN" ]; then
|
||||
OUT="$SCRATCH" qemu_get_busybox
|
||||
BUSYBOX_BIN="$BB"
|
||||
fi
|
||||
|
||||
# --- scenario 1: seed applied verbatim, secret mode preserved, seed beats a same-named --state ---
|
||||
SEED="$SCRATCH/seed"
|
||||
mkdir -p "$SEED"
|
||||
printf 'plain-value\n' > "$SEED/plain.key"
|
||||
printf 'secret-value\n' > "$SEED/secret.key"
|
||||
chmod 0600 "$SEED/secret.key"
|
||||
printf 'seeded-value\n' > "$SEED/override.key"
|
||||
|
||||
OUT1="$SCRATCH/out1"
|
||||
if OUT="$OUT1" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED" \
|
||||
bash "$QEMU_DIR/mkimage.sh" --state "override.key=state-value" \
|
||||
> "$SCRATCH/mkimage1.log" 2>&1; then
|
||||
UIMG="$SCRATCH/userdata1.img"
|
||||
extract_userdata "$OUT1/disk.img" "$UIMG"
|
||||
|
||||
plain_stat="$(debugfs -R "stat /warden/plain.key" "$UIMG" 2>/dev/null)"
|
||||
if [ -n "$plain_stat" ]; then
|
||||
pass "SEED_DIR: plain.key landed under userdata/warden"
|
||||
else
|
||||
fail "SEED_DIR: plain.key missing from userdata/warden"
|
||||
fi
|
||||
|
||||
secret_stat="$(debugfs -R "stat /warden/secret.key" "$UIMG" 2>/dev/null)"
|
||||
secret_mode="$(printf '%s' "$secret_stat" | grep -oE 'Mode: *[0-7]+' | grep -oE '[0-7]+$')"
|
||||
if [ "$secret_mode" = "0600" ]; then
|
||||
pass "SEED_DIR: secret.key kept mode 0600 through cp -a"
|
||||
else
|
||||
fail "SEED_DIR: secret.key mode '$secret_mode', want 0600"
|
||||
fi
|
||||
|
||||
override_content="$(debugfs -R "cat /warden/override.key" "$UIMG" 2>/dev/null)"
|
||||
if [ "$override_content" = "seeded-value" ]; then
|
||||
pass "SEED_DIR: seeded override.key beats the same-named --state value"
|
||||
else
|
||||
fail "SEED_DIR: override.key = '$override_content', want 'seeded-value' (seed must apply after --state)"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh exited nonzero with a valid seed dir (see $SCRATCH/mkimage1.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 2: SEED_DIR that is not a directory fails closed ---
|
||||
NOTADIR="$SCRATCH/notadir"
|
||||
: > "$NOTADIR"
|
||||
OUT2="$SCRATCH/out2"
|
||||
err2="$(OUT="$OUT2" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$NOTADIR" \
|
||||
bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc2=$?
|
||||
if [ "$rc2" -ne 0 ] && printf '%s' "$err2" | grep -qF "FATAL: SEED_DIR '$NOTADIR' is not a directory"; then
|
||||
pass "SEED_DIR: a non-directory path fails closed with the FATAL message"
|
||||
else
|
||||
fail "SEED_DIR: non-directory path gave rc=$rc2, stderr='$err2' (want nonzero + the FATAL message)"
|
||||
fi
|
||||
|
||||
# --- scenario 3: a symlink entry fails closed instead of being copied verbatim ---
|
||||
SEED3="$SCRATCH/seed3"
|
||||
mkdir -p "$SEED3"
|
||||
printf 'plain-value\n' > "$SEED3/plain.key"
|
||||
ln -s /etc/passwd "$SEED3/evil.key"
|
||||
OUT3="$SCRATCH/out3"
|
||||
err3="$(OUT="$OUT3" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED3" \
|
||||
bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc3=$?
|
||||
if [ "$rc3" -ne 0 ] && printf '%s' "$err3" | grep -qF "FATAL: SEED_DIR entry 'evil.key' is a symlink"; then
|
||||
pass "SEED_DIR: a symlink entry fails closed instead of being copied verbatim"
|
||||
else
|
||||
fail "SEED_DIR: symlink entry gave rc=$rc3, stderr='$err3' (want nonzero + the symlink FATAL message)"
|
||||
fi
|
||||
[ -e "$OUT3/disk.img" ] && fail "SEED_DIR: a disk image was written despite the symlink entry"
|
||||
|
||||
# --- scenario 4: an entry with a character outside [A-Za-z0-9_.-]+ fails closed ---
|
||||
SEED4="$SCRATCH/seed4"
|
||||
mkdir -p "$SEED4"
|
||||
printf 'x\n' > "$SEED4/bad key"
|
||||
OUT4="$SCRATCH/out4"
|
||||
err4="$(OUT="$OUT4" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED4" \
|
||||
bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc4=$?
|
||||
if [ "$rc4" -ne 0 ] && printf '%s' "$err4" | grep -qF "FATAL: SEED_DIR entry 'bad key' must match [A-Za-z0-9_.-]+"; then
|
||||
pass "SEED_DIR: an entry name outside [A-Za-z0-9_.-]+ fails closed"
|
||||
else
|
||||
fail "SEED_DIR: bad-name entry gave rc=$rc4, stderr='$err4' (want nonzero + the charset FATAL message)"
|
||||
fi
|
||||
|
||||
# --- scenario 5: a subdirectory entry fails closed (not a plain file) ---
|
||||
SEED5="$SCRATCH/seed5"
|
||||
mkdir -p "$SEED5/subdir"
|
||||
printf 'x\n' > "$SEED5/subdir/leaf.key"
|
||||
OUT5="$SCRATCH/out5"
|
||||
err5="$(OUT="$OUT5" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED5" \
|
||||
bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc5=$?
|
||||
if [ "$rc5" -ne 0 ] && printf '%s' "$err5" | grep -qF "FATAL: SEED_DIR entry 'subdir' is not a plain file"; then
|
||||
pass "SEED_DIR: a subdirectory entry fails closed instead of being recursed into"
|
||||
else
|
||||
fail "SEED_DIR: subdirectory entry gave rc=$rc5, stderr='$err5' (want nonzero + the plain-file FATAL message)"
|
||||
fi
|
||||
|
||||
# --- scenario 6: a hyphenated key (seed-fixtures.py's KEY_RE, e.g.
|
||||
# "gas-plant.devices") still seeds cleanly -- guards against tightening the
|
||||
# charset to --state's stricter [A-Za-z0-9_.]+ by mistake, which would
|
||||
# reject keys committed flow specs already seed through this path ---
|
||||
SEED6="$SCRATCH/seed6"
|
||||
mkdir -p "$SEED6"
|
||||
printf 'r5\n' > "$SEED6/gas-plant.devices"
|
||||
OUT6="$SCRATCH/out6"
|
||||
if OUT="$OUT6" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED6" \
|
||||
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage6.log" 2>&1; then
|
||||
UIMG6="$SCRATCH/userdata6.img"
|
||||
extract_userdata "$OUT6/disk.img" "$UIMG6"
|
||||
hyphen_content="$(debugfs -R "cat /warden/gas-plant.devices" "$UIMG6" 2>/dev/null)"
|
||||
if [ "$hyphen_content" = "r5" ]; then
|
||||
pass "SEED_DIR: a hyphenated key (gas-plant.devices) still seeds cleanly"
|
||||
else
|
||||
fail "SEED_DIR: gas-plant.devices = '$hyphen_content', want 'r5'"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline regression test for qemu_stage_rootfs() (qemu/lib.sh): the staged
|
||||
# etc/shadow must come out mode 0600 regardless of the mode the SOURCE
|
||||
# qemu/rootfs/etc/shadow happens to carry in the working tree. Git tracks
|
||||
# only the executable bit, so a fresh checkout can land that source file at
|
||||
# anything a non-executable blob gets under the checking-out user's umask
|
||||
# (644 under the common 022) -- world readable, exposing root's crypt hash
|
||||
# to any unprivileged process in the guest. The test stages from an isolated
|
||||
# copy of qemu/rootfs with etc/shadow deliberately set to 0644 first, so it
|
||||
# still catches the regression even when the real working tree's copy
|
||||
# already happens to be 0600 locally (that local mode is never what ships;
|
||||
# only what git tracks does). No real busybox or QEMU needed: a stub binary
|
||||
# is enough to exercise the staging function itself.
|
||||
#
|
||||
# bash stage-rootfs-perms.sh
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REAL_QEMU_DIR="$(cd "$HERE/.." && pwd)"
|
||||
SCRATCH="$(mktemp -d /tmp/wqperm.XXXXXX)"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
FAIL=0
|
||||
pass() { printf '[PASS] %s\n' "$1"; }
|
||||
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
# shellcheck source=../lib.sh disable=SC1091
|
||||
. "$REAL_QEMU_DIR/lib.sh"
|
||||
|
||||
# Isolated QEMU_DIR: a copy of the real rootfs skeleton, source etc/shadow
|
||||
# forced to 0644 to simulate the permissive-umask checkout this test must
|
||||
# catch regardless of what the working tree's own copy happens to be.
|
||||
QEMU_DIR="$SCRATCH/qemu"
|
||||
mkdir -p "$QEMU_DIR"
|
||||
cp -a "$REAL_QEMU_DIR/rootfs" "$QEMU_DIR/rootfs"
|
||||
chmod 0644 "$QEMU_DIR/rootfs/etc/shadow"
|
||||
|
||||
# Stand in for a verified busybox download: qemu_stage_rootfs only installs
|
||||
# it, never reads its content.
|
||||
BB="$SCRATCH/fake-busybox"
|
||||
printf '#!/bin/sh\nexit 0\n' > "$BB"
|
||||
chmod 0755 "$BB"
|
||||
|
||||
ROOT="$SCRATCH/root"
|
||||
qemu_stage_rootfs "$ROOT"
|
||||
|
||||
shadow_mode="$(stat -c '%a' "$ROOT/etc/shadow")"
|
||||
if [ "$shadow_mode" = "600" ]; then
|
||||
pass "etc/shadow staged at 0600"
|
||||
else
|
||||
fail "etc/shadow staged at $shadow_mode, want 600"
|
||||
fi
|
||||
|
||||
# Control: passwd/group carry no secrets and stay world-readable, same as
|
||||
# every other Linux system -- confirms the fix targets shadow specifically
|
||||
# rather than locking the whole /etc tree down.
|
||||
passwd_mode="$(stat -c '%a' "$ROOT/etc/passwd")"
|
||||
if [ "$passwd_mode" = "644" ] || [ "$passwd_mode" = "664" ]; then
|
||||
pass "etc/passwd untouched by the shadow chmod (mode $passwd_mode)"
|
||||
else
|
||||
fail "etc/passwd unexpectedly mode $passwd_mode"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL STAGE-ROOTFS PERM TESTS PASSED" || echo "STAGE-ROOTFS PERM TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
@@ -1,193 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline regression test for ui-drive.sh's rs485 simulator startup and its
|
||||
# process cleanup: no real QEMU or kernel image. A fake qemu/run.sh stands in
|
||||
# for the VM (it optionally binds the rs.sock qemu's --rs485 chardev would
|
||||
# create) and, for one case, a fake socat stands in ahead of it on PATH. This
|
||||
# is the same "copy the real script beside stand-in siblings" trick
|
||||
# tests/flows/run-flow-run-all-tests.sh uses for flow-run-rig.sh, one layer
|
||||
# down at ui-drive.sh's own dependencies.
|
||||
#
|
||||
# What is worth pinning:
|
||||
# - the rs.sock/rs.pty/rs.ctl waits fail closed instead of printing
|
||||
# "== rs485 simulator: ..." over a bus nothing is actually serving --
|
||||
# before this fix, a socat or mbsim.py that never came up looked, from
|
||||
# ui-drive.sh's own output, exactly like a live one, and every later
|
||||
# rs485 assertion failed for a reason buried in a log nobody was pointed
|
||||
# at.
|
||||
# - cleanup() escalates to SIGKILL for a sim process that ignores SIGTERM,
|
||||
# instead of leaving it to outlive the script (an accumulation of
|
||||
# orphaned simulator processes on a loaded CI runner).
|
||||
#
|
||||
# bash test-ui-drive-rs485.sh
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRATCH="$(mktemp -d /tmp/uidrs485.XXXXXX)"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
FAIL=0
|
||||
pass() { printf '[PASS] %s\n' "$1"; }
|
||||
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
ZIMAGE="$SCRATCH/fake-zImage"
|
||||
SCRIPT="$SCRATCH/fake.txt"
|
||||
: > "$ZIMAGE"
|
||||
printf 'wake\n' > "$SCRIPT"
|
||||
|
||||
# build_rig WORKDIR: lay out WORKDIR/qemu with a copy of the real (fixed)
|
||||
# ui-drive.sh and qmp.py next to stand-in mkinitramfs.sh/mkimage.sh/run.sh/
|
||||
# payload, so ui-drive.sh's own HERE/QDIR resolve inside WORKDIR and nothing
|
||||
# under the real qemu/out/ is ever touched.
|
||||
build_rig() {
|
||||
local work="$1"
|
||||
mkdir -p "$work/qemu/tests" "$work/qemu/payload"
|
||||
cp "$HERE/ui-drive.sh" "$work/qemu/tests/ui-drive.sh"
|
||||
cp "$HERE/qmp.py" "$work/qemu/tests/qmp.py"
|
||||
chmod +x "$work/qemu/tests/ui-drive.sh"
|
||||
printf '#!/usr/bin/env bash\nexit 0\n' > "$work/qemu/mkinitramfs.sh"
|
||||
printf '#!/usr/bin/env bash\nexit 0\n' > "$work/qemu/mkimage.sh"
|
||||
cat > "$work/qemu/run.sh" <<'EOS'
|
||||
#!/usr/bin/env bash
|
||||
# Stand-in for qemu/run.sh: no real VM, just enough to drive ui-drive.sh's
|
||||
# rs485 startup logic offline. TEST_MAKE_RS_SOCK=1 binds a listening AF_UNIX
|
||||
# socket at --rs485's path (as qemu's server=on,wait=off chardev would);
|
||||
# unset/0 leaves it absent, simulating qemu never wiring up the bus. Stays
|
||||
# up 8s -- past ui-drive.sh's 3s post-launch liveness check and the rs485
|
||||
# waits' poll budgets -- then exits, so a run that gets past the rs485 block
|
||||
# still fails fast (VM exited early) instead of idling out the 180s deadline.
|
||||
rs485_sock=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--rs485) rs485_sock="$2"; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
exec python3 -c '
|
||||
import os, socket, sys, time
|
||||
sock_path = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
if sock_path and os.environ.get("TEST_MAKE_RS_SOCK") == "1":
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.bind(sock_path)
|
||||
s.listen(1)
|
||||
time.sleep(8)
|
||||
' "$rs485_sock"
|
||||
EOS
|
||||
chmod +x "$work/qemu/mkinitramfs.sh" "$work/qemu/mkimage.sh" "$work/qemu/run.sh"
|
||||
: > "$work/qemu/payload/warden-ui"
|
||||
chmod +x "$work/qemu/payload/warden-ui"
|
||||
}
|
||||
|
||||
# run_rig WORKDIR: invoke the copied ui-drive.sh with a bounded outer timeout
|
||||
# (the test's own safety net, matching run-flow-run-all-tests.sh) and stash
|
||||
# combined output + exit code in the globals below.
|
||||
RIG_OUT=""
|
||||
RIG_RC=0
|
||||
run_rig() {
|
||||
local work="$1"
|
||||
RIG_OUT="$(cd "$work" && timeout -k 5 40 bash "$work/qemu/tests/ui-drive.sh" \
|
||||
--rs485-devices "5:bare" "$ZIMAGE" "$SCRIPT" "$work/out" 2>&1)"
|
||||
RIG_RC=$?
|
||||
}
|
||||
|
||||
# --- case A: qemu's rs.sock never appears -----------------------------------
|
||||
work="$SCRATCH/a"; build_rig "$work"
|
||||
FLARE_EDGE="$SCRATCH/flare-edge-a"
|
||||
mkdir -p "$FLARE_EDGE/tools/modbus-sim"
|
||||
printf '#!/usr/bin/env python3\nimport sys; sys.exit(1)\n' > "$FLARE_EDGE/tools/modbus-sim/mbsim.py"
|
||||
# A VAR=val prefix on a function call exports VAR into that one call only
|
||||
# (and any children it spawns) and restores whatever VAR held before once the
|
||||
# call returns -- the same per-case scoping a wrapping subshell gave us, but
|
||||
# without a subshell: run_rig's RIG_OUT/RIG_RC writes land here directly, so
|
||||
# nothing needs to be re-serialized as text and re-parsed back out below.
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK='' run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared' \
|
||||
&& pass "case A: FATAL names the missing rs.sock" \
|
||||
|| fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:' \
|
||||
&& fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT" \
|
||||
|| pass "case A: never claims the bus is live"
|
||||
|
||||
# --- case B: rs.sock is up but socat never creates rs.pty -------------------
|
||||
work="$SCRATCH/b"; build_rig "$work"
|
||||
FLARE_EDGE="$SCRATCH/flare-edge-b"
|
||||
mkdir -p "$FLARE_EDGE/tools/modbus-sim"
|
||||
printf '#!/usr/bin/env python3\nimport sys; sys.exit(1)\n' > "$FLARE_EDGE/tools/modbus-sim/mbsim.py"
|
||||
FAKEBIN="$SCRATCH/fakebin-b"; mkdir -p "$FAKEBIN"
|
||||
printf '#!/usr/bin/env bash\necho "FAKE SOCAT: simulated failure" >&2\nexit 1\n' > "$FAKEBIN/socat"
|
||||
chmod +x "$FAKEBIN/socat"
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 PATH="$FAKEBIN:$PATH" run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty' \
|
||||
&& pass "case B: FATAL names the missing rs.pty" \
|
||||
|| fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
|
||||
|
||||
# --- case C: rs.sock+rs.pty are up but mbsim.py crashes before rs.ctl -------
|
||||
work="$SCRATCH/c"; build_rig "$work"
|
||||
FLARE_EDGE="$SCRATCH/flare-edge-c"
|
||||
mkdir -p "$FLARE_EDGE/tools/modbus-sim"
|
||||
cat > "$FLARE_EDGE/tools/modbus-sim/mbsim.py" <<'EOS'
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
sys.stderr.write("FAKE MBSIM: simulated crash before opening the control socket\n")
|
||||
sys.exit(1)
|
||||
EOS
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 TEST_MBSIM_PID_FILE='' run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up' \
|
||||
&& pass "case C: FATAL names the dead simulator" \
|
||||
|| fail "case C: FATAL names the dead simulator: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash' \
|
||||
&& pass "case C: mbsim.log is dumped on failure" \
|
||||
|| fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
|
||||
|
||||
# --- case D: a sim process that ignores SIGTERM is still reaped ------------
|
||||
work="$SCRATCH/d"; build_rig "$work"
|
||||
FLARE_EDGE="$SCRATCH/flare-edge-d"
|
||||
mkdir -p "$FLARE_EDGE/tools/modbus-sim"
|
||||
cat > "$FLARE_EDGE/tools/modbus-sim/mbsim.py" <<'EOS'
|
||||
#!/usr/bin/env python3
|
||||
# Comes up cleanly (binds --control so ui-drive.sh's rs.ctl wait passes),
|
||||
# then ignores SIGTERM -- the process cleanup() must still SIGKILL.
|
||||
import argparse, os, signal, socket, sys, time
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('--port')
|
||||
ap.add_argument('--control')
|
||||
ap.add_argument('--device', action='append', default=[])
|
||||
args = ap.parse_args()
|
||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||
if args.control:
|
||||
try:
|
||||
os.unlink(args.control)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.bind(args.control)
|
||||
s.listen(1)
|
||||
pidfile = os.environ.get('TEST_MBSIM_PID_FILE')
|
||||
if pidfile:
|
||||
with open(pidfile, 'w') as f:
|
||||
f.write(str(os.getpid()))
|
||||
while True:
|
||||
time.sleep(1)
|
||||
EOS
|
||||
PIDFILE="$SCRATCH/mbsim-d.pid"
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 TEST_MBSIM_PID_FILE="$PIDFILE" run_rig "$work"
|
||||
if [ -s "$PIDFILE" ]; then
|
||||
mbsim_pid="$(cat "$PIDFILE")"
|
||||
if ! kill -0 "$mbsim_pid" 2>/dev/null; then
|
||||
pass "case D: a SIGTERM-ignoring sim process is dead once ui-drive.sh returns (SIGKILL fallback)"
|
||||
else
|
||||
fail "case D: pid $mbsim_pid is still alive after ui-drive.sh returned -- SIGKILL fallback did not fire"
|
||||
kill -KILL "$mbsim_pid" 2>/dev/null || true # don't leak it out of the test either
|
||||
fi
|
||||
else
|
||||
fail "case D: the fake mbsim.py never wrote its pid file, out: $RIG_OUT"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL UI-DRIVE RS485 TESTS PASSED" || echo "UI-DRIVE RS485 TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,334 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Drive the LVGL UI through a scripted interaction and collect screenshots.
|
||||
#
|
||||
# ui-shot.sh proves touch reaches the UI in one tap; this is the same rig for
|
||||
# work that needs a SEQUENCE (swipe through the app rows, open a submenu, tap a
|
||||
# tab, bring up the keyboard) with a screendump wherever the script asks for
|
||||
# one. One boot serves the whole script, because booting per step (TCG, no KVM)
|
||||
# costs about a minute and a real interaction is thirty steps.
|
||||
#
|
||||
# It also FAILS on a UI that died mid-script. The framebuffer keeps its last
|
||||
# frame when warden-ui crashes, so screendumps carry on returning a plausible
|
||||
# picture of a program that no longer exists; stage-2 init announces the exit on
|
||||
# the console (see rootfs/sbin/init) and this greps for it after the run.
|
||||
#
|
||||
# FAILS CLOSED on missing prerequisites.
|
||||
#
|
||||
# Usage: ui-drive.sh [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage-virt> <script> [out-dir]
|
||||
# <script> is a qmp.py `drive` script: see its docstring for the commands.
|
||||
# --seed FILE a seed manifest (flat YAML key: value, see flare-edge
|
||||
# tools/seed-fixtures.py) run through that tool and staged
|
||||
# into userdata/warden BEFORE boot, via mkimage.sh's SEED_DIR
|
||||
# hook -- so a screen's first read at startup already sees
|
||||
# it, not a value written after the race is already lost.
|
||||
# Needs FLARE_EDGE=<checkout> to find the tool (same
|
||||
# convention as ota-apply.sh / portal-scenario.sh).
|
||||
# --refs FILE passed straight through to qmp.py drive's --refs (the
|
||||
# region/ocr reference JSON); see qmp.py's own docstring.
|
||||
# --rs485-devices ADDR:SLUG[,ADDR:SLUG...]
|
||||
# put simulated Modbus devices on the VM's RS485 bus: the
|
||||
# UART is attached to a unix socket (run.sh --rs485), socat
|
||||
# turns it into a pty, and flare-edge tools/modbus-sim/mbsim.py
|
||||
# serves the named corpus profiles on it, so warden-modbus in
|
||||
# the guest discovers and identifies devices the way it does
|
||||
# on a panel with real controllers on the header. Needs
|
||||
# FLARE_EDGE and socat.
|
||||
set -euo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
|
||||
QDIR="$(cd "$HERE/.." && pwd)" # qemu/
|
||||
|
||||
SEED_FILE=""
|
||||
REFS_FILE=""
|
||||
RS485_DEVICES=""
|
||||
ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--seed) SEED_FILE="${2:?--seed needs a manifest path}"; shift 2 ;;
|
||||
--refs) REFS_FILE="${2:?--refs needs a path}"; shift 2 ;;
|
||||
--rs485-devices) RS485_DEVICES="${2:?--rs485-devices needs ADDR:SLUG[,...]}"; shift 2 ;;
|
||||
--) shift; ARGS+=("$@"); break ;;
|
||||
-*) echo "FATAL: unknown option '$1' (usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir])" >&2; exit 1 ;;
|
||||
*) ARGS+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
ZIMAGE="${ARGS[0]:-}"
|
||||
SCRIPT="${ARGS[1]:-}"
|
||||
OUTDIR="${ARGS[2]:-$QDIR/out/ui-drive}"
|
||||
|
||||
if [ -z "$ZIMAGE" ] || [ ! -f "$ZIMAGE" ]; then
|
||||
echo "FATAL: usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir]: the virt.fragment kernel variant" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SCRIPT" ] || [ ! -f "$SCRIPT" ]; then
|
||||
echo "FATAL: no drive script at '$SCRIPT'" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$SEED_FILE" ] && [ ! -f "$SEED_FILE" ]; then
|
||||
echo "FATAL: no seed manifest at '$SEED_FILE'" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$SEED_FILE" ] && { [ -z "${FLARE_EDGE:-}" ] || [ ! -f "$FLARE_EDGE/tools/seed-fixtures.py" ]; }; then
|
||||
echo "FATAL: --seed needs FLARE_EDGE to point at a flare-edge checkout (seed-fixtures.py not found under '${FLARE_EDGE:-}')" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ -x "$QDIR/payload/warden-ui" ] || {
|
||||
echo "FATAL: no qemu/payload/warden-ui: build it with flare-edge tools/build-ui-vm.sh" >&2
|
||||
exit 1
|
||||
}
|
||||
command -v qemu-system-arm >/dev/null || {
|
||||
echo "FATAL: qemu-system-arm not on PATH: see qemu/README.md" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p "$OUTDIR"
|
||||
# Short-named scratch: AF_UNIX socket paths are capped at ~108 chars.
|
||||
WORK="$(mktemp -d /tmp/wqd.XXXXXX)"
|
||||
# Every run gets its own image and initramfs: mkinitramfs.sh, mkimage.sh and
|
||||
# run.sh all read $OUT, and with the shared default (qemu/out) two concurrent
|
||||
# runs built and booted the SAME disk.img, so a seeded VM could read back
|
||||
# another run's state (SDK #20). The image is sparse but is written by the
|
||||
# guest, and /tmp is a tmpfs on the dev box, so this lives under $TMPDIR on
|
||||
# real disk; the pinned busybox stays shared and read-only through BUSYBOX.
|
||||
avail_kb="$(df --output=avail -k "${TMPDIR:-/tmp}" | tail -1 | tr -d ' ')"
|
||||
if [ "${avail_kb:-0}" -lt 1048576 ]; then
|
||||
echo "FATAL: ${TMPDIR:-/tmp} has under 1 GB free; point TMPDIR at real disk (see flows README)" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$QDIR/out"
|
||||
RUN_OUT="$(mktemp -d "${TMPDIR:-/tmp}/wqd-out.XXXXXX")"
|
||||
export OUT="$RUN_OUT"
|
||||
export BUSYBOX="${BUSYBOX:-$QDIR/out/busybox-armv7l}"
|
||||
QEMU_PID=""
|
||||
SIM_PIDS=""
|
||||
# SIGTERM first (lets qemu/socat/mbsim.py close their sockets and pty
|
||||
# cleanly), then SIGKILL if that didn't take: a process wedged on a full pty
|
||||
# buffer or an uninterruptible I/O wait under host load must not outlive this
|
||||
# script, or a long batch (flow-run-all.sh --jobs N) slowly accumulates
|
||||
# orphaned simulator/VM processes competing with the runs still in flight.
|
||||
reap() {
|
||||
local p="$1"
|
||||
kill "$p" 2>/dev/null || return 0
|
||||
for _i in $(seq 1 20); do
|
||||
kill -0 "$p" 2>/dev/null || return 0
|
||||
sleep 0.1
|
||||
done
|
||||
kill -KILL "$p" 2>/dev/null || true
|
||||
}
|
||||
# Poll for PATH to appear, checking every 0.1s for up to 5 seconds -- the
|
||||
# rs.sock/rs.pty/rs.ctl handshake budget below, now set in one place instead
|
||||
# of three copies that could drift out of step with each other. When PID is
|
||||
# given, also stop the moment PID has died: a process that's already gone
|
||||
# will never create the path, so there is no reason to spend the rest of the
|
||||
# budget waiting on it. The exit status carries no verdict -- each call site
|
||||
# still makes its own existence (and, for rs.ctl, liveness) check right after
|
||||
# this returns, exactly as it did before the loop was pulled out.
|
||||
wait_for_path() {
|
||||
local path="$1" pid="${2:-}" _i
|
||||
for _i in $(seq 1 50); do
|
||||
[ -e "$path" ] && return 0
|
||||
if [ -n "$pid" ]; then
|
||||
kill -0 "$pid" 2>/dev/null || return 0
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
cleanup() {
|
||||
for p in $SIM_PIDS; do reap "$p"; done
|
||||
if [ -n "$QEMU_PID" ]; then
|
||||
# `timeout` here is a second, independent bound on top of qmp.py's own
|
||||
# QMP_TIMEOUT_S socket timeout: whichever one it is that stalls, this
|
||||
# call must not itself keep cleanup() from reaching reap "$QEMU_PID"
|
||||
# below -- the one thing meant to guarantee a wedged qemu-system-arm
|
||||
# cannot outlive this script.
|
||||
timeout -k 5 25 python3 "$HERE/qmp.py" "$WORK/qmp.sock" quit 2>/dev/null || true
|
||||
sleep 1
|
||||
reap "$QEMU_PID"
|
||||
fi
|
||||
cp "$WORK/console.log" "$OUTDIR/console.log" 2>/dev/null || true
|
||||
cp "$WORK/mbsim.log" "$OUTDIR/mbsim.log" 2>/dev/null || true
|
||||
rm -rf "$WORK" "$RUN_OUT"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
bash "$QDIR/mkinitramfs.sh"
|
||||
if [ -n "$SEED_FILE" ]; then
|
||||
# Stage the settings files BEFORE mkimage.sh builds the disk: userdata is
|
||||
# baked into the image up front (see qemu/README.md's boundary table --
|
||||
# there is no mount-after-boot step this rig could inject files through),
|
||||
# so anything a screen reads at startup has to be in place before -kernel
|
||||
# even runs, not written into a running VM.
|
||||
python3 "$FLARE_EDGE/tools/seed-fixtures.py" "$SEED_FILE" "$WORK/seed"
|
||||
SEED_DIR="$WORK/seed" bash "$QDIR/mkimage.sh"
|
||||
else
|
||||
bash "$QDIR/mkimage.sh"
|
||||
fi
|
||||
|
||||
# Random hostfwd ports can collide. Detect qemu's early bind failure and retry
|
||||
# with a fresh base rather than failing spuriously.
|
||||
for _attempt in 1 2 3; do
|
||||
PORT=$((21000 + RANDOM % 20000))
|
||||
: > "$WORK/console.log"
|
||||
bash "$QDIR/run.sh" --kernel "$ZIMAGE" --display headless --qmp "$WORK/qmp.sock" \
|
||||
--ctl "$WORK/ctl.sock" ${RS485_DEVICES:+--rs485 "$WORK/rs.sock"} \
|
||||
--ssh-port "$PORT" --http-port $((PORT + 1)) --api-port $((PORT + 2)) \
|
||||
> "$WORK/console.log" 2>&1 &
|
||||
QEMU_PID=$!
|
||||
sleep 3
|
||||
kill -0 "$QEMU_PID" 2>/dev/null && break
|
||||
if grep -aq 'Could not set up host forwarding' "$WORK/console.log"; then
|
||||
echo "== hostfwd port collision on base $PORT, retrying"
|
||||
QEMU_PID=""
|
||||
continue
|
||||
fi
|
||||
echo "FATAL: VM died at launch:" >&2
|
||||
tail -20 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
done
|
||||
if [ -z "$QEMU_PID" ] || ! kill -0 "$QEMU_PID" 2>/dev/null; then
|
||||
echo "FATAL: could not launch the VM after 3 port attempts" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$RS485_DEVICES" ]; then
|
||||
# qemu created rs.sock at launch (server=on,wait=off). socat gives the
|
||||
# simulator the serial device it expects; mbsim then answers the guest's
|
||||
# Modbus polls with the corpus profiles' own register maps.
|
||||
command -v socat >/dev/null || { echo "FATAL: --rs485-devices needs socat" >&2; exit 1; }
|
||||
[ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ] || {
|
||||
echo "FATAL: --rs485-devices needs FLARE_EDGE to point at a flare-edge checkout (mbsim.py)" >&2; exit 1; }
|
||||
wait_for_path "$WORK/rs.sock"
|
||||
[ -S "$WORK/rs.sock" ] || {
|
||||
echo "FATAL: rs485 bus socket never appeared at $WORK/rs.sock (qemu's --rs485 chardev never came up)" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
socat "UNIX-CONNECT:$WORK/rs.sock" "PTY,link=$WORK/rs.pty,raw,echo=0" > "$WORK/socat.log" 2>&1 &
|
||||
socat_pid=$!
|
||||
SIM_PIDS="$SIM_PIDS $socat_pid"
|
||||
# Break out the moment socat dies rather than always spending the full
|
||||
# poll budget: a socat that never links the pty is usually already gone
|
||||
# (bad UNIX-CONNECT target, no pty node available), and kill -0 catches
|
||||
# that in one tick instead of five seconds.
|
||||
wait_for_path "$WORK/rs.pty" "$socat_pid"
|
||||
[ -e "$WORK/rs.pty" ] || {
|
||||
echo "FATAL: rs485 socat never created rs.pty (see $WORK/socat.log)" >&2
|
||||
cat "$WORK/socat.log" >&2
|
||||
exit 1
|
||||
}
|
||||
dev_args=()
|
||||
IFS=',' read -r -a _devs <<< "$RS485_DEVICES"
|
||||
for d in "${_devs[@]}"; do dev_args+=(--device "$d"); done
|
||||
# --control is the runtime lever: qmp.py's `rs485 silence|restore ADDR`
|
||||
# verb talks to it, so a flow can take a device off the bus mid-run.
|
||||
python3 "$FLARE_EDGE/tools/modbus-sim/mbsim.py" --port "$WORK/rs.pty" --control "$WORK/rs.ctl" "${dev_args[@]}" > "$WORK/mbsim.log" 2>&1 &
|
||||
mbsim_pid=$!
|
||||
SIM_PIDS="$SIM_PIDS $mbsim_pid"
|
||||
wait_for_path "$WORK/rs.ctl" "$mbsim_pid"
|
||||
{ [ -S "$WORK/rs.ctl" ] && kill -0 "$mbsim_pid" 2>/dev/null; } || {
|
||||
echo "FATAL: rs485 simulator (mbsim.py) never came up (see $WORK/mbsim.log)" >&2
|
||||
cat "$WORK/mbsim.log" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "== rs485 simulator: $RS485_DEVICES on $WORK/rs.pty"
|
||||
fi
|
||||
|
||||
echo "== waiting for warden-ui"
|
||||
deadline=$((SECONDS + 180))
|
||||
while [ $SECONDS -lt $deadline ]; do
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" && break
|
||||
kill -0 "$QEMU_PID" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$WORK/console.log" >&2; exit 1; }
|
||||
sleep 2
|
||||
done
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" || {
|
||||
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# A started process is not a rendered frame. Poll screendumps until the panel
|
||||
# stops being a single flat colour, on a bounded deadline: TCG renders CPU-bound
|
||||
# and a loaded host can be arbitrarily slow, so this is never a fixed sleep.
|
||||
#
|
||||
# The count only has to clear a fixed threshold (32), not be exact, so this
|
||||
# samples every 32nd pixel instead of all ~518K (720x720) of them, and bails
|
||||
# the moment the threshold clears instead of always finishing the scan. A
|
||||
# still-flat splash reads identically under any stride -- every sampled pixel
|
||||
# is the same colour either way, so sampling can never manufacture a false
|
||||
# "ready" -- and a rendered frame has enough variety that a sparse sample
|
||||
# clears 32 distinct colours just as reliably. This loop runs on the same
|
||||
# host CPU the comment above names as the bottleneck, on every poll tick of
|
||||
# every flow's boot, so the per-tick cost matters; a plain byte loop here also
|
||||
# avoids adding a Pillow dependency to a boot check that today has none (see
|
||||
# qmp.py's own imgtools/Pillow deferral -- a plain nav/tap flow must keep
|
||||
# booting on a host without Pillow installed).
|
||||
echo "== waiting for the first real frame"
|
||||
deadline=$((SECONDS + 180))
|
||||
ready=0
|
||||
while [ $SECONDS -lt $deadline ]; do
|
||||
python3 "$HERE/qmp.py" "$WORK/qmp.sock" screendump "$WORK/probe.ppm" 2>/dev/null || { sleep 2; continue; }
|
||||
colors="$(python3 -c "
|
||||
d = open('$WORK/probe.ppm', 'rb').read()
|
||||
colors = set()
|
||||
for i in range(15, len(d), 32 * 3):
|
||||
colors.add(d[i:i+3])
|
||||
if len(colors) > 32:
|
||||
break
|
||||
print(len(colors))
|
||||
" 2>/dev/null || echo 0)"
|
||||
[ "${colors:-0}" -gt 32 ] && { ready=1; break; }
|
||||
sleep 3
|
||||
done
|
||||
[ "$ready" = 1 ] || {
|
||||
echo "FATAL: the UI never rendered a real frame" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The control bridge (init -> warden-ui's debug FIFO, see run.sh --ctl) comes
|
||||
# up with the UI; a script's first `page`/`hit` must not race it. Bounded, and
|
||||
# fail-closed: a scenario that asserts on UI state needs the channel, and a
|
||||
# silently absent one would turn every assertion into an infrastructure error
|
||||
# dressed as a test result.
|
||||
echo "== waiting for the control bridge"
|
||||
deadline=$((SECONDS + 60))
|
||||
until grep -aq 'init: control bridge on' "$WORK/console.log"; do
|
||||
[ $SECONDS -lt $deadline ] || {
|
||||
echo "FATAL: the control bridge never announced itself (run.sh --ctl / init marker)" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "== driving $SCRIPT"
|
||||
# Every step lands in results.jsonl (ok / fail / fatal); an assertion mismatch
|
||||
# is a `fail` and the run continues, so one run reports every broken
|
||||
# expectation. The driver's exit status is the verdict; capture it rather than
|
||||
# let `set -e` skip the backstop and the summary below.
|
||||
drive_rc=0
|
||||
DRIVE_ARGS=(--ctl "$WORK/ctl.sock" --console "$WORK/console.log")
|
||||
# Only passed when given: qmp.py's own default (<outdir>/refs.json, see its
|
||||
# docstring) is right for the common case of one refs file living next to a
|
||||
# flow's other fixtures, and forcing a path here would just duplicate that
|
||||
# default in two places.
|
||||
[ -n "$REFS_FILE" ] && DRIVE_ARGS+=(--refs "$REFS_FILE")
|
||||
python3 "$HERE/qmp.py" "$WORK/qmp.sock" drive "$SCRIPT" "$OUTDIR" \
|
||||
${RS485_DEVICES:+--rs485-control "$WORK/rs.ctl"} \
|
||||
"${DRIVE_ARGS[@]}" || drive_rc=$?
|
||||
|
||||
# The UI must still be alive: see the header. The driver checks this after
|
||||
# every step and pins a crash to the step that caused it; this is the
|
||||
# backstop for a death after the last step, or a driver that itself fell over.
|
||||
if grep -aq 'warden-ui EXITED' "$WORK/console.log"; then
|
||||
echo "FATAL: warden-ui DIED during the run:" >&2
|
||||
grep -a -A22 'warden-ui EXITED' "$WORK/console.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$drive_rc" -ne 0 ]; then
|
||||
echo "UI-DRIVE-FAIL: see $OUTDIR/results.jsonl" >&2
|
||||
grep -E '"status": "(fail|fatal)"' "$OUTDIR/results.jsonl" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "UI-DRIVE-PASS (results in $OUTDIR/results.jsonl, screenshots in $OUTDIR)"
|
||||
@@ -1,135 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression tests for build/fetch-buildroot-tarball.sh's retry/verify path.
|
||||
#
|
||||
# The script had never been exercised by anything (nothing calls it yet --
|
||||
# see its own header) or by a test, so its retry-on-mismatch, cleanup, and
|
||||
# already-verified short-circuit had never actually run. It also fetched with
|
||||
# no --connect-timeout/--max-time, so a connection that opens and then stalls
|
||||
# (a blackholed route, a hung proxy) would block forever instead of retrying;
|
||||
# issue tracked separately.
|
||||
#
|
||||
# Runs the real script (copied into a fixture dir so its own HERE-relative pin
|
||||
# lookup finds a pin we control) with a fake curl first on PATH, so no network
|
||||
# is used and the outcome of each attempt is exact.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/fetch-buildroot-tarball.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)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
WANT_SHA="$(printf 'good-bytes' | sha256sum | awk '{print $1}')"
|
||||
|
||||
# A private copy of the real script plus a pin file we control, in its own
|
||||
# directory: the script resolves its pin relative to itself, so this is the
|
||||
# shipping file under test, not a reimplementation of it.
|
||||
setup() { # setup <case-name> -> prints the fixture dir
|
||||
local dir="$TMP/$1"
|
||||
mkdir -p "$dir/bin"
|
||||
cp "$SCRIPT" "$dir/fetch-buildroot-tarball.sh"
|
||||
printf '%s buildroot-2025.02.8.tar.xz\n' "$WANT_SHA" \
|
||||
> "$dir/buildroot-2025.02.8.tar.xz.sha256"
|
||||
printf '%s' "$dir"
|
||||
}
|
||||
|
||||
run() { # run <dir> <dest> -> stdout+stderr on stdout, $? in $RC
|
||||
local dir="$1" dest="$2"
|
||||
OUT="$(PATH="$dir/bin:$PATH" bash "$dir/fetch-buildroot-tarball.sh" "$dest" 2>&1)"
|
||||
RC=$?
|
||||
}
|
||||
|
||||
# --- case A: destination already matches the pin -> curl never runs -------
|
||||
dir="$(setup case-a)"
|
||||
printf 'good-bytes' > "$dir/dest.tar.xz"
|
||||
cat > "$dir/bin/curl" <<'FAKE'
|
||||
#!/bin/sh
|
||||
echo "curl should not have run" >&2
|
||||
exit 1
|
||||
FAKE
|
||||
chmod +x "$dir/bin/curl"
|
||||
run "$dir" "$dir/dest.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q 'already present and verified'; then
|
||||
ok "already-verified destination: curl never invoked"
|
||||
else
|
||||
bad "already-verified destination: curl never invoked (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# --- case B: fails once, succeeds on retry -> verified, no extra attempts -
|
||||
dir="$(setup case-b)"
|
||||
cat > "$dir/bin/curl" <<FAKE
|
||||
#!/bin/sh
|
||||
cnt_file="$dir/curl-calls"
|
||||
n=0
|
||||
[ -f "\$cnt_file" ] && n=\$(cat "\$cnt_file")
|
||||
n=\$((n + 1))
|
||||
echo "\$n" > "\$cnt_file"
|
||||
out="" prev=""
|
||||
for a in "\$@"; do
|
||||
[ "\$prev" = "-o" ] && out="\$a"
|
||||
prev="\$a"
|
||||
done
|
||||
if [ "\$n" -lt 2 ]; then printf 'bad-bytes' > "\$out"
|
||||
else printf 'good-bytes' > "\$out"
|
||||
fi
|
||||
FAKE
|
||||
chmod +x "$dir/bin/curl"
|
||||
run "$dir" "$dir/dest.tar.xz"
|
||||
calls="$(cat "$dir/curl-calls" 2>/dev/null || echo 0)"
|
||||
if [ "$RC" -eq 0 ] && [ "$calls" -eq 2 ] && printf '%s' "$OUT" | grep -q 'sha256 verified'; then
|
||||
ok "mismatch then match: verified on attempt 2, stops retrying"
|
||||
else
|
||||
bad "mismatch then match: verified on attempt 2, stops retrying (rc=$RC calls=$calls out=$OUT)"
|
||||
fi
|
||||
|
||||
# --- case C: every attempt mismatches -> fails closed, no partial file left
|
||||
dir="$(setup case-c)"
|
||||
cat > "$dir/bin/curl" <<'FAKE'
|
||||
#!/bin/sh
|
||||
out="" prev=""
|
||||
for a in "$@"; do
|
||||
[ "$prev" = "-o" ] && out="$a"
|
||||
prev="$a"
|
||||
done
|
||||
printf 'always-bad' > "$out"
|
||||
FAKE
|
||||
chmod +x "$dir/bin/curl"
|
||||
run "$dir" "$dir/dest.tar.xz"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'FATAL: could not fetch'; then
|
||||
ok "persistent mismatch: exits nonzero with FATAL"
|
||||
else
|
||||
bad "persistent mismatch: exits nonzero with FATAL (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
if [ ! -e "$dir/dest.tar.xz" ]; then
|
||||
ok "persistent mismatch: no partial/corrupt tarball left at the destination"
|
||||
else
|
||||
bad "persistent mismatch: no partial/corrupt tarball left at the destination"
|
||||
fi
|
||||
attempts="$(printf '%s' "$OUT" | grep -c '== fetching')"
|
||||
if [ "$attempts" -eq 3 ]; then
|
||||
ok "persistent mismatch: exactly 3 attempts"
|
||||
else
|
||||
bad "persistent mismatch: exactly 3 attempts (got $attempts)"
|
||||
fi
|
||||
|
||||
# --- guard: the fetch carries a connect and overall timeout ---------------
|
||||
# Without these, --retry never fires (it only re-attempts a transfer curl has
|
||||
# already decided failed) and a connection that opens then stalls blocks
|
||||
# forever -- exactly the routing failure this workspace sees from some hosts.
|
||||
if grep -q -- '--connect-timeout' "$SCRIPT" && grep -q -- '--max-time' "$SCRIPT"; then
|
||||
ok "fetch carries --connect-timeout and --max-time"
|
||||
else
|
||||
bad "fetch carries --connect-timeout and --max-time"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "ALL FETCH-BUILDROOT-TARBALL TESTS PASSED"
|
||||
else
|
||||
echo "FETCH-BUILDROOT-TARBALL TESTS FAILED"
|
||||
fi
|
||||
exit "$FAIL"
|
||||
@@ -1,304 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression and coverage tests for build/fetch-vendor.sh.
|
||||
#
|
||||
# The script had no test of any kind before this: not the --check/--fetch
|
||||
# state machine (MISSING/OK/DRIFTED, the lvgl/luckfox-pico path mapping, the
|
||||
# "locally modified" annotation), not --help, not the clone stall guard. Two
|
||||
# concrete regressions motivate the first two cases:
|
||||
#
|
||||
# - --help sliced its own source with a hardcoded line range that stopped
|
||||
# one line too late, so it printed "set -uo pipefail" -- the first line
|
||||
# of code -- as the last line of help text.
|
||||
# - git clone ran with no bound on a stalled transfer: a dead peer or a
|
||||
# wedged proxy mid-clone (the luckfox-pico tree alone is ~21 GB) hung the
|
||||
# script forever with no way for a caller to tell "still working" from
|
||||
# "wedged". The fix sets GIT_HTTP_LOW_SPEED_LIMIT/TIME so a stalled
|
||||
# transfer aborts while a merely slow one is left alone.
|
||||
#
|
||||
# --help runs the shipping script directly. The --fetch/--check cases run a
|
||||
# copy of it in a private fixture dir (its manifest lookup is relative to
|
||||
# itself, so a copy is how its own HERE-relative resolution can be pointed at
|
||||
# a manifest we control) against local, throwaway origin repos -- no network,
|
||||
# and the real git binary does the work throughout (a thin logging wrapper
|
||||
# only intercepts "clone" to record the env it saw, then execs straight
|
||||
# through), so these exercise the shipping script's actual git calls.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/fetch-vendor.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; }
|
||||
|
||||
WORK="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
GITC() { git -c user.email=t@t.invalid -c user.name=t "$@"; }
|
||||
|
||||
# mkrepo1 <dir> -> one commit on main, prints its hash
|
||||
mkrepo1() {
|
||||
local dir="$1"
|
||||
git init -q -b main "$dir"
|
||||
printf 'v1\n' > "$dir/file.txt"
|
||||
git -C "$dir" add file.txt
|
||||
GITC -C "$dir" commit -q -m v1
|
||||
git -C "$dir" rev-parse HEAD
|
||||
}
|
||||
|
||||
# mkrepo2 <dir> -> two commits on main, prints "C1 C2" (C1 older)
|
||||
mkrepo2() {
|
||||
local dir="$1" c1 c2
|
||||
git init -q -b main "$dir"
|
||||
printf 'v1\n' > "$dir/file.txt"
|
||||
git -C "$dir" add file.txt
|
||||
GITC -C "$dir" commit -q -m v1
|
||||
c1="$(git -C "$dir" rev-parse HEAD)"
|
||||
printf 'v2\n' > "$dir/file.txt"
|
||||
git -C "$dir" add file.txt
|
||||
GITC -C "$dir" commit -q -m v2
|
||||
c2="$(git -C "$dir" rev-parse HEAD)"
|
||||
printf '%s %s\n' "$c1" "$c2"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Regression: --help must not spill into the script's own code.
|
||||
# ---------------------------------------------------------------------------
|
||||
HELP_OUT="$(bash "$SCRIPT" --help)"
|
||||
if printf '%s\n' "$HELP_OUT" | grep -q 'set -uo pipefail'; then
|
||||
bad "--help does not print the script's own code"
|
||||
else
|
||||
ok "--help does not print the script's own code"
|
||||
fi
|
||||
LAST_LINE="$(printf '%s\n' "$HELP_OUT" | tail -1)"
|
||||
if [ "$LAST_LINE" = "# someone's debugging session, not something to silently throw away." ]; then
|
||||
ok "--help ends on the last comment line, not past it"
|
||||
else
|
||||
bad "--help ends on the last comment line, not past it (got: $LAST_LINE)"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Regression: the clone stall guard reaches git clone's environment.
|
||||
# ---------------------------------------------------------------------------
|
||||
REALGIT="$(command -v git)"
|
||||
FAKEBIN="$WORK/fakebin"
|
||||
mkdir -p "$FAKEBIN"
|
||||
CAPTURE="$WORK/clone-env.txt"
|
||||
cat > "$FAKEBIN/git" <<FAKEGIT
|
||||
#!/bin/sh
|
||||
if [ "\$1" = "clone" ]; then
|
||||
printf '%s %s\n' "\$GIT_HTTP_LOW_SPEED_LIMIT" "\$GIT_HTTP_LOW_SPEED_TIME" >> "$CAPTURE"
|
||||
fi
|
||||
exec "$REALGIT" "\$@"
|
||||
FAKEGIT
|
||||
chmod +x "$FAKEBIN/git"
|
||||
|
||||
ORIGIN_GUARD="$WORK/origin-guard"
|
||||
GUARD_C="$(mkrepo1 "$ORIGIN_GUARD")"
|
||||
|
||||
MANIFEST_GUARD="$WORK/manifest-guard"
|
||||
printf 'widget\t%s\t%s\tguard test tree\n' "$ORIGIN_GUARD" "$GUARD_C" > "$MANIFEST_GUARD"
|
||||
|
||||
# fetch-vendor.sh finds its manifest next to itself, so give it a private
|
||||
# fixture dir carrying a copy of the real script alongside our manifest.
|
||||
GUARD_FIXTURE="$WORK/guard-fixture"
|
||||
mkdir -p "$GUARD_FIXTURE"
|
||||
cp "$SCRIPT" "$GUARD_FIXTURE/fetch-vendor.sh"
|
||||
cp "$MANIFEST_GUARD" "$GUARD_FIXTURE/vendor.manifest"
|
||||
|
||||
: > "$CAPTURE"
|
||||
PATH="$FAKEBIN:$PATH" bash "$GUARD_FIXTURE/fetch-vendor.sh" --fetch "$WORK/vendor-default" \
|
||||
> "$WORK/guard-default.log" 2>&1
|
||||
if [ "$(cat "$CAPTURE")" = "1000 60" ]; then
|
||||
ok "clone runs with the default low-speed guard (1000 bytes/sec, 60s)"
|
||||
else
|
||||
bad "clone runs with the default low-speed guard (got: $(cat "$CAPTURE" 2>/dev/null))"
|
||||
fi
|
||||
|
||||
: > "$CAPTURE"
|
||||
PATH="$FAKEBIN:$PATH" WARDEN_VENDOR_LOW_SPEED_LIMIT=5 WARDEN_VENDOR_LOW_SPEED_TIME=9 \
|
||||
bash "$GUARD_FIXTURE/fetch-vendor.sh" --fetch "$WORK/vendor-override" \
|
||||
> "$WORK/guard-override.log" 2>&1
|
||||
if [ "$(cat "$CAPTURE")" = "5 9" ]; then
|
||||
ok "the low-speed guard is overridable"
|
||||
else
|
||||
bad "the low-speed guard is overridable (got: $(cat "$CAPTURE" 2>/dev/null))"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Coverage: the --check/--fetch state machine and the name-to-path mapping.
|
||||
# ---------------------------------------------------------------------------
|
||||
ORIGIN_WIDGET="$WORK/origin-widget"
|
||||
read -r WIDGET_C1 WIDGET_C2 <<< "$(mkrepo2 "$ORIGIN_WIDGET")"
|
||||
ORIGIN_LVGL="$WORK/origin-lvgl"
|
||||
LVGL_C="$(mkrepo1 "$ORIGIN_LVGL")"
|
||||
ORIGIN_SDK="$WORK/origin-sdk"
|
||||
SDK_C="$(mkrepo1 "$ORIGIN_SDK")"
|
||||
|
||||
MANIFEST="$WORK/vendor.manifest"
|
||||
write_manifest() { # write_manifest <widget-commit>
|
||||
{
|
||||
printf 'widget\t%s\t%s\tgeneric tree, default path mapping\n' "$ORIGIN_WIDGET" "$1"
|
||||
printf 'lvgl\t%s\t%s\tlvgl name maps under ui/lvgl\n' "$ORIGIN_LVGL" "$LVGL_C"
|
||||
printf 'luckfox-pico\t%s\t%s\tluckfox-pico name maps under sdk\n' "$ORIGIN_SDK" "$SDK_C"
|
||||
} > "$MANIFEST"
|
||||
}
|
||||
|
||||
STATE_FIXTURE="$WORK/state-fixture"
|
||||
mkdir -p "$STATE_FIXTURE"
|
||||
cp "$SCRIPT" "$STATE_FIXTURE/fetch-vendor.sh"
|
||||
VENDOR_DIR="$WORK/vendor"
|
||||
|
||||
write_manifest "$WIDGET_C1"
|
||||
cp "$MANIFEST" "$STATE_FIXTURE/vendor.manifest"
|
||||
|
||||
# Case 1: nothing cloned yet -> --check reports MISSING for all three, rc=1.
|
||||
OUT="$(bash "$STATE_FIXTURE/fetch-vendor.sh" --check "$VENDOR_DIR")"; RC=$?
|
||||
if [ "$RC" -ne 0 ] \
|
||||
&& printf '%s\n' "$OUT" | grep -q '^MISSING widget' \
|
||||
&& printf '%s\n' "$OUT" | grep -q '^MISSING lvgl' \
|
||||
&& printf '%s\n' "$OUT" | grep -q '^MISSING luckfox-pico'; then
|
||||
ok "--check reports MISSING and rc=1 when nothing is cloned"
|
||||
else
|
||||
bad "--check reports MISSING and rc=1 when nothing is cloned (rc=$RC)"
|
||||
fi
|
||||
|
||||
# Case 2: --fetch clones each tree under its mapped path and checks out the pin.
|
||||
OUT="$(bash "$STATE_FIXTURE/fetch-vendor.sh" --fetch "$VENDOR_DIR")"; RC=$?
|
||||
if [ "$RC" -eq 0 ] \
|
||||
&& [ -e "$VENDOR_DIR/widget/.git" ] \
|
||||
&& [ -e "$VENDOR_DIR/ui/lvgl/.git" ] \
|
||||
&& [ -e "$VENDOR_DIR/sdk/.git" ]; then
|
||||
ok "--fetch clones lvgl under ui/lvgl and luckfox-pico under sdk"
|
||||
else
|
||||
bad "--fetch clones lvgl under ui/lvgl and luckfox-pico under sdk (rc=$RC)"
|
||||
fi
|
||||
if [ "$(git -C "$VENDOR_DIR/widget" rev-parse HEAD 2>/dev/null)" = "$WIDGET_C1" ]; then
|
||||
ok "--fetch checks out the manifest-pinned commit"
|
||||
else
|
||||
bad "--fetch checks out the manifest-pinned commit"
|
||||
fi
|
||||
|
||||
# Case 3: a checkout sitting at its pin --check's clean, rc=0.
|
||||
OUT="$(bash "$STATE_FIXTURE/fetch-vendor.sh" --check "$VENDOR_DIR")"; RC=$?
|
||||
if [ "$RC" -eq 0 ] && printf '%s\n' "$OUT" | grep -q "^OK widget ${WIDGET_C1:0:12}$"; then
|
||||
ok "--check reports OK with no suffix for a clean checkout at the pin"
|
||||
else
|
||||
bad "--check reports OK with no suffix for a clean checkout at the pin"
|
||||
fi
|
||||
|
||||
# Case 4: manifest moves to a commit the checkout is not on -> DRIFTED,
|
||||
# rc=1, and the checkout itself is left untouched (never reset).
|
||||
write_manifest "$WIDGET_C2"
|
||||
cp "$MANIFEST" "$STATE_FIXTURE/vendor.manifest"
|
||||
OUT="$(bash "$STATE_FIXTURE/fetch-vendor.sh" --check "$VENDOR_DIR")"; RC=$?
|
||||
if [ "$RC" -ne 0 ] \
|
||||
&& printf '%s\n' "$OUT" | grep -q "^DRIFTED widget want ${WIDGET_C2:0:12} have ${WIDGET_C1:0:12}"; then
|
||||
ok "--check reports DRIFTED when HEAD does not match the pin"
|
||||
else
|
||||
bad "--check reports DRIFTED when HEAD does not match the pin"
|
||||
fi
|
||||
if [ "$(git -C "$VENDOR_DIR/widget" rev-parse HEAD 2>/dev/null)" = "$WIDGET_C1" ]; then
|
||||
ok "a drifted checkout is reported, never reset"
|
||||
else
|
||||
bad "a drifted checkout is reported, never reset"
|
||||
fi
|
||||
|
||||
# Case 5: back at the pin but with an uncommitted local change -> OK, but
|
||||
# annotated, and still rc=0 (a dirty vendor tree is expected, not a failure).
|
||||
write_manifest "$WIDGET_C1"
|
||||
cp "$MANIFEST" "$STATE_FIXTURE/vendor.manifest"
|
||||
echo "local debugging change" >> "$VENDOR_DIR/widget/file.txt"
|
||||
OUT="$(bash "$STATE_FIXTURE/fetch-vendor.sh" --check "$VENDOR_DIR")"; RC=$?
|
||||
if [ "$RC" -eq 0 ] && printf '%s\n' "$OUT" | grep -q "^OK widget ${WIDGET_C1:0:12} (locally modified)$"; then
|
||||
ok "--check reports OK (locally modified) for a dirty checkout at the pin, rc=0"
|
||||
else
|
||||
bad "--check reports OK (locally modified) for a dirty checkout at the pin, rc=0"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Case 6: git clone fails (bad origin) -> reported, rc=1, no directory left
|
||||
# behind for that tree, and -- the actual regression this guards -- the loop
|
||||
# still reaches the remaining manifest entries and reports exactly one
|
||||
# failure line for widget, not a second "FAILED to check out" once the
|
||||
# clone's own continue has fired.
|
||||
# ---------------------------------------------------------------------------
|
||||
ORIGIN_BAD="$WORK/no-such-origin"
|
||||
CLONEFAIL_FIXTURE="$WORK/clonefail-fixture"
|
||||
mkdir -p "$CLONEFAIL_FIXTURE"
|
||||
cp "$SCRIPT" "$CLONEFAIL_FIXTURE/fetch-vendor.sh"
|
||||
{
|
||||
printf 'widget\t%s\t%s\tbad origin, clone must fail\n' "$ORIGIN_BAD" "$WIDGET_C1"
|
||||
printf 'lvgl\t%s\t%s\tlvgl name maps under ui/lvgl\n' "$ORIGIN_LVGL" "$LVGL_C"
|
||||
printf 'luckfox-pico\t%s\t%s\tluckfox-pico name maps under sdk\n' "$ORIGIN_SDK" "$SDK_C"
|
||||
} > "$CLONEFAIL_FIXTURE/vendor.manifest"
|
||||
|
||||
CLONEFAIL_DIR="$WORK/vendor-clonefail"
|
||||
OUT="$(bash "$CLONEFAIL_FIXTURE/fetch-vendor.sh" --fetch "$CLONEFAIL_DIR" 2>&1)"; RC=$?
|
||||
FAILED_COUNT="$(printf '%s\n' "$OUT" | grep -c 'FAILED to clone widget')"
|
||||
if [ "$RC" -ne 0 ] && [ "$FAILED_COUNT" -eq 1 ] \
|
||||
&& ! printf '%s\n' "$OUT" | grep -q 'FAILED to check out'; then
|
||||
ok "--fetch reports FAILED to clone once and rc=1 for a bad origin"
|
||||
else
|
||||
bad "--fetch reports FAILED to clone once and rc=1 for a bad origin (rc=$RC, count=$FAILED_COUNT)"
|
||||
fi
|
||||
if [ ! -e "$CLONEFAIL_DIR/widget/.git" ]; then
|
||||
ok "a failed clone leaves no checkout behind for that tree"
|
||||
else
|
||||
bad "a failed clone leaves no checkout behind for that tree"
|
||||
fi
|
||||
if [ -e "$CLONEFAIL_DIR/ui/lvgl/.git" ] && [ -e "$CLONEFAIL_DIR/sdk/.git" ]; then
|
||||
ok "a clone failure on one tree does not stop the remaining trees from being fetched"
|
||||
else
|
||||
bad "a clone failure on one tree does not stop the remaining trees from being fetched"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Case 7: git checkout fails (pinned commit missing from the origin) ->
|
||||
# reported, rc=1, the remaining trees still get fetched, and the checkout is
|
||||
# left wherever the failed checkout left it -- a later --check must report
|
||||
# that as DRIFTED, never mistake it for success.
|
||||
# ---------------------------------------------------------------------------
|
||||
BOGUS_COMMIT="deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
||||
CHECKOUTFAIL_FIXTURE="$WORK/checkoutfail-fixture"
|
||||
mkdir -p "$CHECKOUTFAIL_FIXTURE"
|
||||
cp "$SCRIPT" "$CHECKOUTFAIL_FIXTURE/fetch-vendor.sh"
|
||||
{
|
||||
printf 'widget\t%s\t%s\tcommit missing from the origin, checkout must fail\n' "$ORIGIN_WIDGET" "$BOGUS_COMMIT"
|
||||
printf 'lvgl\t%s\t%s\tlvgl name maps under ui/lvgl\n' "$ORIGIN_LVGL" "$LVGL_C"
|
||||
printf 'luckfox-pico\t%s\t%s\tluckfox-pico name maps under sdk\n' "$ORIGIN_SDK" "$SDK_C"
|
||||
} > "$CHECKOUTFAIL_FIXTURE/vendor.manifest"
|
||||
|
||||
CHECKOUTFAIL_DIR="$WORK/vendor-checkoutfail"
|
||||
OUT="$(bash "$CHECKOUTFAIL_FIXTURE/fetch-vendor.sh" --fetch "$CHECKOUTFAIL_DIR" 2>&1)"; RC=$?
|
||||
if [ "$RC" -ne 0 ] && printf '%s\n' "$OUT" | grep -q "FAILED to check out $BOGUS_COMMIT"; then
|
||||
ok "--fetch reports FAILED to check out for a commit missing from the origin"
|
||||
else
|
||||
bad "--fetch reports FAILED to check out for a commit missing from the origin (rc=$RC)"
|
||||
fi
|
||||
# The regression this guards: if the checkout failure's own "continue" were
|
||||
# ever dropped, the same loop iteration falls through into the have-vs-pin
|
||||
# comparison below and prints a bogus DRIFTED/OK line for widget in this same
|
||||
# --fetch run, on top of the FAILED line above.
|
||||
if ! printf '%s\n' "$OUT" | grep -qE '^(DRIFTED {2}|OK {7})widget'; then
|
||||
ok "a checkout failure does not fall through to a DRIFTED/OK line in the same run"
|
||||
else
|
||||
bad "a checkout failure does not fall through to a DRIFTED/OK line in the same run"
|
||||
fi
|
||||
if [ -e "$CHECKOUTFAIL_DIR/widget/.git" ] \
|
||||
&& [ -e "$CHECKOUTFAIL_DIR/ui/lvgl/.git" ] && [ -e "$CHECKOUTFAIL_DIR/sdk/.git" ]; then
|
||||
ok "a checkout failure on one tree does not stop the remaining trees from being fetched"
|
||||
else
|
||||
bad "a checkout failure on one tree does not stop the remaining trees from being fetched"
|
||||
fi
|
||||
|
||||
OUT="$(bash "$CHECKOUTFAIL_FIXTURE/fetch-vendor.sh" --check "$CHECKOUTFAIL_DIR" 2>&1)"; RC=$?
|
||||
if [ "$RC" -ne 0 ] && printf '%s\n' "$OUT" | grep -q "^DRIFTED widget want ${BOGUS_COMMIT:0:12}"; then
|
||||
ok "a later --check reports the failed checkout as DRIFTED, never as success"
|
||||
else
|
||||
bad "a later --check reports the failed checkout as DRIFTED, never as success"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "All fetch-vendor tests passed." || echo "Some fetch-vendor tests failed."
|
||||
exit "$FAIL"
|
||||
@@ -1,124 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Regression tests for the post-build boot.img validation in
|
||||
# build/mk-bootimg.sh: the FIT metadata %512 check, the per-image
|
||||
# data-position %512 check (and fdtget's own failure path, issue #22 --
|
||||
# a missing or erroring fdtget used to be swallowed and treated as nothing
|
||||
# to check), and the >=4096 embedded-data-FIT check.
|
||||
#
|
||||
# Runs the real script end to end with stub mkimage/resource_tool/fdtget so
|
||||
# the arithmetic is exercised as it actually ships, not copied out and
|
||||
# re-tested in isolation. The stub mkimage answers the -B capability probe
|
||||
# and, for the real build invocation, writes a synthetic boot.img whose
|
||||
# 4-byte big-endian metadata-size word and total length are test-controlled --
|
||||
# the same field mk-bootimg.sh reads with `od -An -tu4 -j4 -N4 --endian=big`.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/mk-bootimg.sh"
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
STUBS="$TMP/stubs"
|
||||
mkdir -p "$STUBS"
|
||||
|
||||
cat > "$STUBS/mkimage" <<'EOF'
|
||||
#!/bin/bash
|
||||
if [ "$#" -eq 0 ]; then
|
||||
echo "Usage: mkimage [-T type] -l image" >&2
|
||||
echo " -B => align size in hex for FIT structure and header" >&2
|
||||
exit 1
|
||||
fi
|
||||
out=""
|
||||
for a in "$@"; do out="$a"; done
|
||||
python3 -c '
|
||||
import sys
|
||||
out, meta, total = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
|
||||
total = max(total, 8)
|
||||
data = bytearray(total)
|
||||
data[4:8] = (meta & 0xffffffff).to_bytes(4, "big")
|
||||
open(out, "wb").write(bytes(data))
|
||||
' "$out" "${MKBI_META:-512}" "${MKBI_TOTAL:-8192}"
|
||||
EOF
|
||||
chmod +x "$STUBS/mkimage"
|
||||
|
||||
cat > "$STUBS/resource_tool" <<'EOF'
|
||||
#!/bin/bash
|
||||
img=""
|
||||
for a in "$@"; do
|
||||
case "$a" in --image=*) img="${a#--image=}" ;; esac
|
||||
done
|
||||
echo stub > "$img"
|
||||
EOF
|
||||
chmod +x "$STUBS/resource_tool"
|
||||
|
||||
cat > "$STUBS/fdtget" <<'EOF'
|
||||
#!/bin/bash
|
||||
# Invoked as: fdtget -t u FILE /images/NAME data-position
|
||||
node="$4"
|
||||
name="${node#/images/}"
|
||||
var="FDTGET_$(printf '%s' "$name" | tr '[:lower:]' '[:upper:]')_POS"
|
||||
val="${!var-}"
|
||||
if [ -z "$val" ] || [ "$val" = "FAIL" ]; then
|
||||
echo "fdtget: FDT_ERR_NOTFOUND, $node data-position" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "$val"
|
||||
EOF
|
||||
chmod +x "$STUBS/fdtget"
|
||||
|
||||
KERNEL="$TMP/zImage"; DTB="$TMP/rv1106-warden.dtb"
|
||||
head -c 4096 /dev/urandom > "$KERNEL"
|
||||
head -c 512 /dev/urandom > "$DTB"
|
||||
|
||||
fails=0
|
||||
run_case() { # run_case <name> <want_rc:ok|fail> <want_grep>
|
||||
local name="$1" want_rc="$2" want_grep="$3" out rc
|
||||
out="$(PATH="$STUBS:$PATH" "$SCRIPT" --kernel "$KERNEL" --dtb "$DTB" \
|
||||
--resource-tool "$STUBS/resource_tool" --out "$TMP/boot.img" 2>&1)"
|
||||
rc=$?
|
||||
if [ "$want_rc" = ok ] && [ "$rc" -ne 0 ]; then
|
||||
echo "FAIL: $name (expected success, got rc=$rc: $out)"; fails=$((fails + 1)); return
|
||||
fi
|
||||
if [ "$want_rc" = fail ] && [ "$rc" -eq 0 ]; then
|
||||
echo "FAIL: $name (expected failure, script exited 0: $out)"; fails=$((fails + 1)); return
|
||||
fi
|
||||
if ! printf '%s' "$out" | grep -qF -- "$want_grep"; then
|
||||
echo "FAIL: $name (output missing '$want_grep'): $out"; fails=$((fails + 1)); return
|
||||
fi
|
||||
echo "PASS: $name"
|
||||
}
|
||||
|
||||
# A well-formed image: metadata 512-aligned and small, every data-position
|
||||
# 512-aligned. The baseline every failure case below is a single change from.
|
||||
MKBI_META=512 MKBI_TOTAL=8192 \
|
||||
FDTGET_FDT_POS=512 FDTGET_KERNEL_POS=1024 FDTGET_RESOURCE_POS=1536 \
|
||||
run_case "well-formed image accepted" ok "FIT metadata 512 bytes"
|
||||
|
||||
# Metadata size itself not a multiple of 512 (the exact value measured from
|
||||
# the SDK's vendored mkimage 2017.09, see the comment above the probe).
|
||||
MKBI_META=1064 MKBI_TOTAL=8192 \
|
||||
FDTGET_FDT_POS=512 FDTGET_KERNEL_POS=1024 FDTGET_RESOURCE_POS=1536 \
|
||||
run_case "unaligned metadata size rejected" fail "not a multiple of 512"
|
||||
|
||||
# One sub-image's data-position not a multiple of 512; the FATAL must name it.
|
||||
MKBI_META=512 MKBI_TOTAL=8192 \
|
||||
FDTGET_FDT_POS=512 FDTGET_KERNEL_POS=148 FDTGET_RESOURCE_POS=1536 \
|
||||
run_case "unaligned data-position rejected" fail "/images/kernel data-position 148 is not 512-aligned"
|
||||
|
||||
# fdtget itself fails (not on PATH, or the FIT it just built is malformed).
|
||||
# Regression for issue #22: this used to be swallowed by `|| true` and
|
||||
# treated as "nothing to check" instead of a build failure.
|
||||
MKBI_META=512 MKBI_TOTAL=8192 \
|
||||
FDTGET_FDT_POS=512 FDTGET_KERNEL_POS=FAIL FDTGET_RESOURCE_POS=1536 \
|
||||
run_case "fdtget failure fails the build, not skips the check" fail \
|
||||
"fdtget could not read /images/kernel data-position"
|
||||
|
||||
# Metadata swelled to >=4096 bytes: an embedded-data FIT, which this U-Boot
|
||||
# rejects outright. 4096 is itself a multiple of 512 so this must be caught
|
||||
# by the second check, not mistaken for the first.
|
||||
MKBI_META=4096 MKBI_TOTAL=8192 \
|
||||
FDTGET_FDT_POS=512 FDTGET_KERNEL_POS=1024 FDTGET_RESOURCE_POS=1536 \
|
||||
run_case "embedded-data FIT rejected" fail "embedded-data FIT"
|
||||
|
||||
[ "$fails" -eq 0 ] && echo "All mk-bootimg boot.img validation tests passed." || echo "$fails test(s) failed."
|
||||
exit "$fails"
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Regression test: every offline regression-test script this job ships must
|
||||
# actually be invoked by the qemu-tools CI job, not just committed.
|
||||
#
|
||||
# run-probe-tests.sh (guards issue #17) sat in the tree unwired into
|
||||
# .github/workflows/ci.yml: it passed by hand but ran nowhere in CI, so a
|
||||
# regression in the mkimage probe would only have surfaced on the next
|
||||
# workflow_dispatch kernel build, not on every push/PR. The same gap later
|
||||
# reopened for six more scripts written the same way, so this now checks
|
||||
# every one of them (including itself) instead of only the first: it
|
||||
# isolates the qemu-tools job and checks each script's basename appears in
|
||||
# its steps.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
CI_YML="$HERE/../../.github/workflows/ci.yml"
|
||||
|
||||
[ -f "$CI_YML" ] || { echo "FAIL: no workflow file at $CI_YML"; exit 1; }
|
||||
|
||||
# Isolate the qemu-tools job: from its own header line up to (but not
|
||||
# including) the next job at the same two-space indent.
|
||||
job="$(awk '
|
||||
/^ qemu-tools:/ { inside = 1; print; next }
|
||||
inside && /^ [A-Za-z0-9_-]+:/ { exit }
|
||||
inside { print }
|
||||
' "$CI_YML")"
|
||||
|
||||
[ -n "$job" ] || { echo "FAIL: qemu-tools job not found in $CI_YML"; exit 1; }
|
||||
|
||||
# Every offline regression-test script the qemu-tools job owns. Add new
|
||||
# scripts here when they are written, not only when someone remembers to
|
||||
# wire them in -- that is the failure this test exists to catch.
|
||||
scripts=(
|
||||
"tests/mk-bootimg/run-probe-tests.sh"
|
||||
"qemu/tests/run-sh-args-test.sh"
|
||||
"qemu/tests/seed-dir.sh"
|
||||
"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/mk-bootimg/run-boot-img-validate-tests.sh"
|
||||
"tests/mk-bootimg/run-help-tests.sh"
|
||||
"tests/mk-bootimg/run-ci-wiring-tests.sh"
|
||||
)
|
||||
|
||||
fail=0
|
||||
for s in "${scripts[@]}"; do
|
||||
base="$(basename "$s")"
|
||||
if echo "$job" | grep -q -- "$base"; then
|
||||
echo "PASS: qemu-tools job invokes $s"
|
||||
else
|
||||
echo "FAIL: qemu-tools job never runs $s"
|
||||
fail=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit "$fail"
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Regression test: --help must not spill into build/mk-bootimg.sh's own code.
|
||||
#
|
||||
# build/fetch-vendor.sh's --help sliced its own source with a hardcoded line
|
||||
# range that stopped one line too late, printing "set -uo pipefail" -- the
|
||||
# first line of code -- as the last line of help text. mk-bootimg.sh's
|
||||
# --help used the same hardcoded-range shape (currently pointed at the right
|
||||
# span), so the same slip was one header-comment edit away here too. It now
|
||||
# uses the same self-terminating awk pattern fetch-vendor.sh was fixed to
|
||||
# use, so this pins both that it stays in sync as the header grows or
|
||||
# shrinks and that it matches the header verbatim today.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/mk-bootimg.sh"
|
||||
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
|
||||
|
||||
fail=0
|
||||
|
||||
HELP_OUT="$(bash "$SCRIPT" --help)"
|
||||
|
||||
if printf '%s\n' "$HELP_OUT" | grep -q 'set -euo pipefail'; then
|
||||
echo "FAIL: --help prints the script's own code"
|
||||
fail=1
|
||||
else
|
||||
echo "PASS: --help does not print the script's own code"
|
||||
fi
|
||||
|
||||
LAST_LINE="$(printf '%s\n' "$HELP_OUT" | tail -1)"
|
||||
if [ "$LAST_LINE" = "# [--resource-tool PATH]" ]; then
|
||||
echo "PASS: --help ends on the last header comment line, not past it"
|
||||
else
|
||||
echo "FAIL: --help ends on the last header comment line, not past it (got: $LAST_LINE)"
|
||||
fail=1
|
||||
fi
|
||||
|
||||
FIRST_LINE="$(printf '%s\n' "$HELP_OUT" | head -1)"
|
||||
if [ "$FIRST_LINE" = "# Package a bootable boot.img from a kernel this SDK built." ]; then
|
||||
echo "PASS: --help starts after the shebang, not on it"
|
||||
else
|
||||
echo "FAIL: --help starts after the shebang, not on it (got: $FIRST_LINE)"
|
||||
fail=1
|
||||
fi
|
||||
|
||||
exit "$fail"
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Regression tests for the mkimage capability probe in build/mk-bootimg.sh.
|
||||
#
|
||||
# Guards issue #17: the probe ran the candidate binary and piped it into grep.
|
||||
# mkimage with no arguments prints usage and exits non-zero, and mk-bootimg.sh
|
||||
# runs under `set -euo pipefail`, so the pipeline reported failure even when
|
||||
# grep matched. Every mkimage was rejected and the script failed closed with
|
||||
# "no mkimage on PATH supports -B" while a capable mkimage sat first on PATH.
|
||||
#
|
||||
# The probe is extracted verbatim from mk-bootimg.sh between its sentinel
|
||||
# comments, so these tests exercise the shipping code rather than a copy.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/mk-bootimg.sh"
|
||||
PROBE="$(mktemp)"; TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$PROBE" "$TMP"' EXIT
|
||||
|
||||
sed -n '/^# >>> mkimage-probe/,/^# <<< mkimage-probe/p' "$SCRIPT" > "$PROBE"
|
||||
grep -q 'MKIMAGE=' "$PROBE" || { echo "FAIL: probe not extracted (sentinels missing)"; exit 1; }
|
||||
|
||||
# The probe needs grep on PATH, but the real /usr/bin must stay off it or the
|
||||
# host's own mkimage would answer these tests. Give it a directory holding
|
||||
# nothing but grep.
|
||||
mkdir -p "$TMP/util"
|
||||
ln -s "$(command -v grep)" "$TMP/util/grep"
|
||||
|
||||
# A faithful stand-in for real mkimage: usage on stderr, non-zero exit.
|
||||
mk_fake() { # mk_fake <dir> <supports-B:0|1>
|
||||
mkdir -p "$1"
|
||||
{ echo '#!/bin/sh'
|
||||
echo 'echo "Usage: mkimage [-T type] -l image" >&2'
|
||||
[ "$2" = 1 ] && echo 'echo " -B => align size in hex for FIT structure and header" >&2'
|
||||
echo 'exit 1'
|
||||
} > "$1/mkimage"
|
||||
chmod +x "$1/mkimage"
|
||||
}
|
||||
|
||||
fails=0
|
||||
check() { # check <name> <expected-basename-or-empty> <dir...>
|
||||
local name="$1" want="$2"; shift 2
|
||||
local path=""; for d in "$@"; do path="$path${path:+:}$d"; done
|
||||
path="$path${path:+:}$TMP/util"
|
||||
local got
|
||||
# /bin/bash by absolute path: a PATH holding only the fixture dirs cannot
|
||||
# locate the interpreter itself.
|
||||
got="$(TEST_PATH="$path" PROBE="$PROBE" /bin/bash -c \
|
||||
'set -euo pipefail; PATH="$TEST_PATH"; . "$PROBE"; echo "${MKIMAGE:-}"' 2>/dev/null)"
|
||||
got="${got##*/}"
|
||||
if [ "$got" = "$want" ]; then
|
||||
echo "PASS: $name"
|
||||
else
|
||||
echo "FAIL: $name (wanted '${want:-<none>}', got '${got:-<none>}')"
|
||||
fails=$((fails + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
mk_fake "$TMP/good" 1
|
||||
mk_fake "$TMP/old" 0
|
||||
|
||||
# The regression itself: a capable mkimage that exits non-zero must be accepted.
|
||||
check "capable mkimage accepted despite non-zero exit" mkimage "$TMP/good"
|
||||
# The guarantee the FATAL message depends on: no false positives.
|
||||
check "mkimage without -B rejected" "" "$TMP/old"
|
||||
# PATH order decides, and an incapable earlier entry must not stop the scan.
|
||||
check "scan continues past an incapable mkimage" mkimage "$TMP/old" "$TMP/good"
|
||||
check "no mkimage anywhere selects nothing" "" "$TMP/none"
|
||||
|
||||
[ "$fails" -eq 0 ] && echo "All mk-bootimg probe tests passed." || echo "$fails test(s) failed."
|
||||
exit "$fails"
|
||||
Reference in New Issue
Block a user