uefi stick: write-stick.sh (guarded) moves the backup GPT to the device end; STUPID.md goes (t0086)
The stick boots under OVMF (measured 2026-11-17); the old finding was a serial-line artefact. The lesson is in tools/AGENTS.md; the status file is deleted as docs/AGENTS.md wants.
This commit is contained in:
1 parent
f515106b5b
commit
1dbc4b8734
3 files changed
+153
-135
No files matched your search
-134
@@ -1,134 +0,0 @@
|
||||
# STUPID.md — was hier „gemischt“/falsch gelaufen ist (2026-11-09)
|
||||
|
||||
Zweck: ehrliche Bestandsaufnahme für Review (Konrad: „Claude soll drüber gucken“).
|
||||
Fakten, keine Ausreden. Stand beim Schreiben: debug3-Boottest läuft noch
|
||||
(PID `2086239`, Log `build/logs/test-smoke-usb-uefi-debug3-2026-11-09.log`,
|
||||
Temp-Image `/tmp/makronix-gpt-debug2.img`).
|
||||
|
||||
## Kontext
|
||||
|
||||
Anforderung (Konrad, 3.2 in `docs/NEXT.md`): Quell-Sets gehören **auf den USB-Stick
|
||||
und mit installiert** — „alles auf den Stick … die sources sind doch einfach nur
|
||||
ein weiteres Set“. Patch 0018 (`patches/src/0018-installimage-sources.patch`) sollte
|
||||
das liefern.
|
||||
|
||||
## Was ich verbrochen habe
|
||||
|
||||
### 1. Workaround committet, der die Anforderung für GPT/UEFI nicht erfüllt
|
||||
- `9312fd0` fixte 0018 technisch (`MD_IMGSPEC_DIRS` in
|
||||
`src/distrib/common/bootimage/Makefile.bootimage`, damit makefs `-xx` `/source`
|
||||
wirklich ins FFS nimmt) — das war nötig/sachlich richtig.
|
||||
- `1615fe2` („fix 0018: /source only on BIOS USB … test usb-bios+sources, smoke usb-uefi“)
|
||||
machte dann den **pragmatischen Workaround**: `/source` nur im BIOS/MBR-Image,
|
||||
GPT/UEFI-Image ohne `/source`, Test auf `install-usb-bios -U` umgestellt.
|
||||
- Grund (gemessen): GPT-Image mit `/source` im Root-FFS (~7 GB, `INSTIMAGEMB=7168`,
|
||||
Spec-Einträge) bootet unter OVMF/UEFI nicht bis sysinst:
|
||||
`BdsDxe` startet Boot0002 → `mem[...]` → `efiboot...`/`0` → `:-(`, Timeout auf
|
||||
`Terminal type|Installation messages in English`
|
||||
(`build/logs/test-install-usb-uefi-2026-11-09.log`, Kette `2026-11-09d`).
|
||||
BIOS-USB mit gleichem `/source`-Inhalt: Smoke/Boot-Pfad ok.
|
||||
- **Problem:** Workaround committed, obwohl Konrad explizit „alles auf den Stick“
|
||||
(auch UEFI) will. Das ist kein Root-Cause-Fix, sondern ein Zurückweichen.
|
||||
Konrad hat danach klar Option 2 gewählt: Root-Cause in efiboot/libsa.
|
||||
|
||||
### 2. Falsche efiboot-Quelldateien editiert (sys/stand statt arch/i386/stand)
|
||||
- Debugprints zuerst in `src/sys/stand/efiboot/{efiboot,boot}.c` eingebaut — **falsche
|
||||
Kopie**. Der amd64-EFI-Bootloader baut aus
|
||||
`src/sys/arch/i386/stand/efiboot/*` (Compile-Pfad zeigte
|
||||
`arch/i386/stand/efiboot/bootx64/../boot.c`).
|
||||
- `sys/stand/efiboot/boot.c` und `sys/stand/efiboot/efiboot.c` habe ich danach mit
|
||||
`git -C src checkout -- ...` zurückgesetzt. Aber das war erst nach unnötiger
|
||||
Verwirrung; ein Edit-Tool-Report „Edited“ auf `arch/i386/.../boot.c` führte nicht
|
||||
sichtbar zum erwarteten Inhalt (ich musste neu prüfen/neu editieren). Ich habe die
|
||||
Ursache nicht sauber aufgeklärt, sondern drumherum gearbeitet.
|
||||
|
||||
### 3. Diagnose-`printf` stehen noch in `src/` (ad-hoc, uncommittet)
|
||||
Aktuell modifiziert in `src/` (arch/i386 efiboot, **Diagnose, nicht Patch**):
|
||||
- `src/sys/arch/i386/stand/efiboot/efiboot.c`: `printf("efiboot: probes done, calling boot\n");`
|
||||
- `src/sys/arch/i386/stand/efiboot/boot.c`: `efiboot: boot() entered`, `bios2dev done`,
|
||||
`parsebootconf EFI/BOOT ...` Prints.
|
||||
|
||||
Diese gehören **nicht** so committed/getestet in ein Release; sie sind nur zur
|
||||
Eingrenzung eingebaut. Außerdem: ad-hoc Debug in Stand/Boot-Code — kein geprüfter
|
||||
NetBSD-Konventions-/Style-Abgleich für einen finalen Patch.
|
||||
|
||||
### 4. Ad-hoc Rebuilds statt sauberem Buildweg
|
||||
- efiboot im Objdir mit `nbmake-amd64` aus dem Source-Dir nachgebaut (Include-/Objdir-
|
||||
Tücken, erst nach `MAKEOBJDIRPREFIX/TOOLDIR/DESTDIR`-Setzen erfolgreich).
|
||||
- Debug-`bootx64.efi` in **/tmp-Kopien** von GPT-Images per `dd`+`mcopy` injiziert.
|
||||
Dabei erst falscher mcopy-Overwrite (Datei nicht wirklich ersetzt), dann korrigiert.
|
||||
- Das ist für Diagnose ok, aber kein reproduzierbarer, im Baum dokumentierter
|
||||
Testpfad.
|
||||
|
||||
### 5. Experimente in `src/` (FFSv1, Quellen an/aus) erzeugten inkonsistenten Zustand
|
||||
- GPT-Installimage testweise auf `/source` + `IMGFFSVERSION=1` gesetzt (Log
|
||||
`build/logs/x-usb-2026-11-09f-ffs1.log`, `make usb exit=0`), Boottest
|
||||
`build/logs/test-smoke-usb-uefi-debug-2026-11-09.log` bzw. ffs1-Test:
|
||||
**gleiches UEFI-Versagen** (`:-(`) → FFS-Version nicht die Ursache.
|
||||
- `src/distrib/amd64/installimage/Makefile` danach wieder auf „GPT ohne `/source`,
|
||||
Messhinweis“ zurückgesetzt — passt zum committeten Patch `1615fe2`.
|
||||
- **Aber:** `build/obj/releasedir/images/Makronix-0.99.10-amd64-install.img` wurde durch
|
||||
den ffs1-`make usb` als **GPT mit `/source` (FFSv1, 7 GB)** gebaut; diese
|
||||
releasedir-Images sind nicht der „bootbare Zwischenstand“, den der aktuelle
|
||||
Patch beschreibt. (Nicht per Hand in releasedir gefuscht — durch `make usb` erzeugt,
|
||||
aber Zustand passt nicht zum gewünschten/committeten Stand.)
|
||||
|
||||
### 6. Kette `2026-11-09e` mittendrin gestoppt
|
||||
- `2026-11-09e` lief bis `release/iso/sourcesets/usb exit=0` (usb baute noch den
|
||||
„GPT ohne Quellen“-Zwischenstand). Auf Konrads „alles auf den Stick“ gestoppt
|
||||
(PIDs 1308045/1308046/Kind), bevor isosrc/test fertig waren.
|
||||
- Spart Zeit, hinterlässt aber keinen sauberen Ketten-Endzustand.
|
||||
|
||||
### 7. Kette `2026-11-09d` lieferte rote Tests, Diagnose teilweise verloren
|
||||
- `chain ok=0` (10:50:50Z): Build/Images grün, `make test exit=2`.
|
||||
`install-dvd` FAIL (Timeout auf `^ENDCHK`, `test-install-dvd-2026-11-09.log` endet
|
||||
bei `pkg_info | grep`, keine `SRC_OK/ENDCHK` im Testlog); `install-usb-uefi` FAIL
|
||||
(oben). DVD-Konsolenlog wurde durch Folgetest überschrieben — Ursache nicht belegt.
|
||||
|
||||
### 8. „Gemischt“ bei der Strategie
|
||||
- Erst Root-Cause-Analyse angefangen (richtig), dann auf schnellen Workaround
|
||||
(BIOS-only) committed (falsch bezogen auf Anforderung), dann auf Drängen wieder
|
||||
Richtung Root-Cause (richtig), dann FFSv1 geraten/getestet (ok als Experiment,
|
||||
aber in `src`/releasedir Spuren hinterlassen). Zu wenig Disziplin: Diagnosepfade
|
||||
sauber trennen (Temp/Patch-Entwurf) von committetem Zustand.
|
||||
|
||||
## Aktueller technischer Stand (relevant für efiboot-Fix)
|
||||
|
||||
- Symptom (FFSv1 **und** FFSv2, GPT+`/source`, 7 GB Root-FFS): efiboot erreicht
|
||||
`efi_main` → „probes done, calling boot“ (debug2/3 zeigt das in
|
||||
`install-simple-uefi-failed-2026-11-09.log` / debug-Logs), aber **nicht** bis
|
||||
`boot()`-Banner/Installer; Ausgabe endet mit `mem[...]`, `0`, `:-(`, dann Timeout.
|
||||
- BIOS bootet eine große Root-FFS mit `/source` (Smoke 09d PASS). Unterschied liegt
|
||||
im **UEFI/efiboot(+libsa)-Pfad** beim Zugriff auf das große FFS / Boot-Medium, nicht
|
||||
in makefs/Set-Inhalt an sich.
|
||||
- debug3 (`/tmp/makronix-gpt-debug2.img`, korrekt injizierte Debug-EFI) lief beim
|
||||
Schreiben noch — auswerten: erscheinen `boot() entered`/`bios2dev`/`parsebootconf`?
|
||||
Das grenzt ein, ob es in `boot()` vor/nach BIOS/boot.cfg-Parse (FFS-I/O) hängt.
|
||||
|
||||
## Was als Nächstes sauber wäre
|
||||
|
||||
1. debug3 auswerten; Debugprints ggf. verfeinern (nur gezielt, später entfernen).
|
||||
2. Root-Cause in `src/sys/stand/efiboot` / `src/sys/lib/libsa` (FFS/UFS, Block-I/O,
|
||||
große FS/Offsets) finden; **NetBSD-konformen Patch** unter `patches/src/NNNN-*.patch`
|
||||
erstellen (git grep nach bestehendem Muster, Kommentar begründet, `patch --dry-run`).
|
||||
3. Diagnoseprints aus `arch/i386/stand/efiboot/*` entfernen; `src/`-Stand konsistent.
|
||||
4. 0018/Patch + `installimage` (GPT **mit** `/source`, weil „nur ein Set, alles auf den
|
||||
Stick“) + `tools/test.sh` wieder auf volle Anforderung bringen (UEFI-Stick bootet +
|
||||
Quellen installiert/prüfbar) — erst nach nachgewiesenem Fix.
|
||||
5. Saubere Kette neu (`"release ARCH=amd64" iso sourcesets usb isosrc test`) mit neuem Tag,
|
||||
Ergebnisse nur aus `exit=`-Zeilen/Logs; releasedir-Images danach konsistent.
|
||||
|
||||
## Dateien/Logs zum Nachsehen
|
||||
|
||||
- Patches/Commits: `9312fd0`, `1615fe2`, `c21721c`; `patches/src/0018-installimage-sources.patch`.
|
||||
- Ketten: `build/logs/x-{release,iso,sourcesets,usb,isosrc,test}-2026-11-09{d,e}.log`,
|
||||
`x-chain-2026-11-09d.done`.
|
||||
- Tests/Fehler: `build/logs/test-install-usb-uefi-2026-11-09.log`,
|
||||
`build/logs/test-install-dvd-2026-11-09.log`,
|
||||
`build/logs/test-smoke-usb-uefi-ffs1-2026-11-09.log`,
|
||||
`build/logs/test-smoke-usb-uefi-debug{,2,3}-2026-11-09.log`,
|
||||
`build/logs/install-simple-uefi-failed-2026-11-09.log`.
|
||||
- Ad-hoc: `/tmp/makronix-gpt-debug{,2}.img`, `/tmp/esp-*.img`.
|
||||
- Unsaubere src-Diagnose: `src/sys/arch/i386/stand/efiboot/{efiboot,boot}.c`.
|
||||
|
||||
(Ende der Bestandsaufnahme.)
|
||||
+7
-1
@@ -74,7 +74,13 @@ Tests (they run VMs; `docs/PLATFORMS.md`):
|
||||
- `vmsh.sh` -- a QEMU machine on a serial console driven from `sh`; state in
|
||||
`build/vmsession/`. The VM driver to use.
|
||||
- `vm-boot-iso.sh`, `vm-screendump.sh` -- boot an image once, log the serial
|
||||
console or save the screen.
|
||||
console or save the screen. A UEFI boot is judged on the SCREEN (`-U stick`),
|
||||
never on the serial line: after efiboot the kernel's console is the
|
||||
framebuffer, so a serial log ends at efiboot's `:-(` although the boot goes on
|
||||
(the stick was thought not to boot under OVMF until 2026-11-17, `t0086`).
|
||||
- `write-stick.sh` -- an image to a USB stick, guarded; afterwards the backup GPT
|
||||
is moved to the end of the device (fdisk) and the stale one in the image area
|
||||
is zeroed.
|
||||
- `install-simple.sh`, `install-cgd.sh` -- end-to-end installation tests.
|
||||
- `test.sh` (`make test`), `mediacheck.sh` -- the tests of a release.
|
||||
- `devvm.sh`, `host-nfs-setup.sh` -- the kept VM of `docs/BUILD-VM.md`.
|
||||
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/bin/sh
|
||||
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
||||
#
|
||||
# write-stick.sh -- write a Makronix image to a USB stick, safely
|
||||
#
|
||||
# usage: tools/write-stick.sh [-y] IMAGE DEVICE [DEVICE]
|
||||
#
|
||||
# refuses everything that is not a removable USB disk, larger-than-image, not
|
||||
# on the root/boot/swap list, and asks (or, with -y and the device given again,
|
||||
# expects) the device name before writing.
|
||||
|
||||
set -u
|
||||
|
||||
YES=0
|
||||
if [ "${1:-}" = "-y" ]; then
|
||||
YES=1
|
||||
shift
|
||||
fi
|
||||
[ $# -ge 2 ] || { echo "usage: ${0##*/} [-y] IMAGE DEVICE [DEVICE]" >&2; exit 2; }
|
||||
IMAGE=$1
|
||||
DEV=$2
|
||||
CONFIRM=${3:-}
|
||||
|
||||
[ -f "$IMAGE" ] || { echo "write-stick: image not found: $IMAGE" >&2; exit 1; }
|
||||
[ -b "$DEV" ] || { echo "write-stick: not a block device: $DEV" >&2; exit 1; }
|
||||
|
||||
NAME=$(basename "$DEV")
|
||||
BASE=${NAME%%[0-9]*}
|
||||
# whole disk only: /sys/block/<name> must exist
|
||||
[ -d "/sys/block/$NAME" ] || { echo "write-stick: '$DEV' looks like a partition, use the whole disk (e.g. /dev/sdb)" >&2; exit 1; }
|
||||
|
||||
# removable / USB transport
|
||||
REMOVABLE=$(cat "/sys/block/$NAME/removable" 2>/dev/null || echo 0)
|
||||
TRAN=""
|
||||
if command -v lsblk >/dev/null 2>&1; then
|
||||
TRAN=$(lsblk -d -n -o TRAN "$DEV" 2>/dev/null | tr -d ' ')
|
||||
fi
|
||||
if [ "$REMOVABLE" != "1" ] && [ "$TRAN" != "usb" ]; then
|
||||
echo "write-stick: $DEV is not a removable USB device (removable=$REMOVABLE, tran=${TRAN:-unknown})" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# root/boot/swap protection
|
||||
for src in $(findmnt -n -o SOURCE 2>/dev/null); do
|
||||
case $src in
|
||||
"$DEV"*) echo "write-stick: $DEV is in use ($src); refusing" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
if grep -q "^$DEV" /proc/swaps 2>/dev/null; then
|
||||
echo "write-stick: $DEV is swap; refusing" >&2; exit 1
|
||||
fi
|
||||
|
||||
# size check
|
||||
IMGSZ=$(stat -c %s "$IMAGE" 2>/dev/null || stat -f %z "$IMAGE")
|
||||
DEVSZ=$(($(cat "/sys/block/$NAME/size" 2>/dev/null || echo 0) * 512))
|
||||
if [ "$DEVSZ" -lt "$IMGSZ" ]; then
|
||||
echo "write-stick: device ($DEVSZ bytes) smaller than image ($IMGSZ bytes)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# sha512 sidecar
|
||||
DIR=$(dirname "$IMAGE")
|
||||
BASEN=$(basename "$IMAGE")
|
||||
FOUND=""
|
||||
for c in "$DIR/SHA512" "$DIR/$BASEN.sha512" "$DIR/$BASEN.SHA512"; do
|
||||
if [ -f "$c" ]; then FOUND=$c; break; fi
|
||||
done
|
||||
if [ -n "$FOUND" ]; then
|
||||
EXPECTED=$(grep -i "$BASEN" "$FOUND" 2>/dev/null | head -1 | awk '{print $NF}')
|
||||
# SHA512 lines are "SHA512 (file) = hash"; pick the hash
|
||||
EXPECTED=$(grep -i "$BASEN" "$FOUND" 2>/dev/null | sed -n 's/.*= *//p' | head -1 | tr -d ' ')
|
||||
if [ -n "$EXPECTED" ]; then
|
||||
GOT=$(sha256sum 2>/dev/null >/dev/null; sha512sum "$IMAGE" 2>/dev/null | awk '{print $1}')
|
||||
[ -n "$GOT" ] || GOT=$(shasum -a 512 "$IMAGE" 2>/dev/null | awk '{print $1}')
|
||||
if [ "$GOT" != "$EXPECTED" ]; then
|
||||
echo "write-stick: sha512 mismatch for $IMAGE" >&2
|
||||
echo " expected: $EXPECTED" >&2
|
||||
echo " got : $GOT" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Image : $IMAGE ($IMGSZ bytes)"
|
||||
echo "Device: $DEV ($DEVSZ bytes) removable=$REMOVABLE tran=${TRAN:-unknown}"
|
||||
if command -v lsblk >/dev/null 2>&1; then
|
||||
echo "Partitions:"; lsblk "$DEV" 2>/dev/null || true
|
||||
fi
|
||||
echo "SHA512: ${GOT:-unknown}"
|
||||
|
||||
if [ "$YES" = "1" ]; then
|
||||
if [ "$CONFIRM" != "$DEV" ]; then
|
||||
echo "write-stick: with -y you must repeat the device name exactly as the third argument" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
printf 'Type the device name to confirm (%s): ' "$DEV"
|
||||
read -r ANSWER
|
||||
[ "$ANSWER" = "$DEV" ] || { echo "write-stick: confirmation mismatch, aborting" >&2; exit 1; }
|
||||
fi
|
||||
|
||||
# unmount partitions
|
||||
for p in $(lsblk -ln -o NAME "$DEV" 2>/dev/null | tail -n +2); do
|
||||
umount "/dev/$p" 2>/dev/null || true
|
||||
done
|
||||
|
||||
echo "write-stick: writing..."
|
||||
dd if="$IMAGE" of="$DEV" bs=4M conv=fsync status=progress
|
||||
sync
|
||||
|
||||
echo "write-stick: verifying first/last 16 MiB..."
|
||||
BS=16777216
|
||||
cmp -n "$BS" "$IMAGE" "$DEV" || { echo "verify head failed" >&2; exit 1; }
|
||||
# tail verify via dd skip (best effort)
|
||||
if [ "$IMGSZ" -gt "$BS" ]; then
|
||||
dd if="$IMAGE" of=/tmp/opencode/wstick-tail.img bs=1 skip=$((IMGSZ-BS)) count=$BS 2>/dev/null
|
||||
dd if="$DEV" of=/tmp/opencode/wstick-tail.dev bs=1 skip=$((IMGSZ-BS)) count=$BS 2>/dev/null
|
||||
cmp /tmp/opencode/wstick-tail.img /tmp/opencode/wstick-tail.dev || { echo "verify tail failed" >&2; exit 1; }
|
||||
rm -f /tmp/opencode/wstick-tail.img /tmp/opencode/wstick-tail.dev
|
||||
fi
|
||||
|
||||
# The image is smaller than the stick: its backup GPT (header and entries) is in
|
||||
# the last 33 sectors of the IMAGE, not at the end of the DEVICE, and the
|
||||
# protective MBR names the image's size. The UEFI spec wants the backup header in
|
||||
# the device's last block and some firmware refuses a disk without it (fdisk -l:
|
||||
# "The backup GPT table is not on the end of the device"). fdisk(8) writes both
|
||||
# right; the boot code in the first 440 bytes and the partitions stay as they are
|
||||
# (measured 2026-11-17 on a copy: same checksum of the boot code, same two
|
||||
# partitions). The stale backup inside the image area is then zeroed.
|
||||
if [ "$DEVSZ" -gt "$IMGSZ" ]; then
|
||||
FDISK=$(command -v fdisk 2>/dev/null || true)
|
||||
[ -n "$FDISK" ] || [ ! -x /usr/sbin/fdisk ] || FDISK=/usr/sbin/fdisk
|
||||
if [ -n "$FDISK" ]; then
|
||||
echo "write-stick: moving the backup GPT to the end of the device..."
|
||||
printf 'w\n' | "$FDISK" "$DEV" > /dev/null 2>&1 ||
|
||||
echo "write-stick: warning: fdisk could not rewrite the GPT of $DEV" >&2
|
||||
dd if=/dev/zero of="$DEV" bs=512 seek=$((IMGSZ/512-33)) count=33 conv=fsync status=none ||
|
||||
echo "write-stick: warning: could not clear the old backup GPT" >&2
|
||||
"$FDISK" -l "$DEV" 2>&1 | grep -i -E 'backup|mismatch|corrupt' ||
|
||||
echo "write-stick: the GPT of $DEV is consistent"
|
||||
else
|
||||
echo "write-stick: fdisk not found: the backup GPT stays inside the image area" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "write-stick: done"
|
||||
Reference in new issue
Block a user