usb: backend UDisks2 et écriture de la mise à jour sur clé
- API UsbBackend (liste, formatage FAT32, éjection) + implémentation UDisks2 via GDBus : disques USB amovibles uniquement (jamais HintSystem), table MBR + partition 0x0c à 1 Mio formatée vfat, montage, PowerOff ; autorisation déléguée à polkit (pas de root) - writeToUsb : vérification des archives AVANT effacement, formatage, licence dans license/, extraction fw puis carte, éjection - règles de l'app officielle : label assaini (11 car., majuscules, NEW), taille de clé minimale 2/4/8… Go avec marge de 10 % - CLI : usb-list, write-usb (confirmation YES), write-dir - tests : faux backend (ordre des étapes, archive corrompue => clé intacte), labels, tailles - tools/e2e-usb.sh : image loop via UDisks2 + contrôle sfdisk/fsck/mtools ; tools/dev-polkit.sh pour WSL/CI - validé de bout en bout avec le vrai firmware RCC 8,39 Go : MBR, FAT32, label, arborescence, fsck propre, en environ 20 s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
543347a1e6
commit
6a7a2f1ee9
11 files changed
+1047
-8
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
# End-to-end USB test on Linux without a real stick: a sparse disk image is attached as a loop
|
||||
# device through UDisks2, `openpu-cli write-usb` formats and fills it, then the result is checked
|
||||
# with sfdisk / fsck.fat / mtools. Needs udisks2, dosfstools, mtools and, in a session without a
|
||||
# polkit agent (WSL, CI), the rule installed by `sudo tools/dev-polkit.sh install`.
|
||||
#
|
||||
# usage: tools/e2e-usb.sh <openpu-cli> [--license file.key] <archive.tar>...
|
||||
set -eu
|
||||
|
||||
CLI=$1; shift
|
||||
# Not /tmp: often a small tmpfs, and the image plus the extracted partition need ~2x the payload.
|
||||
WORK=$(mktemp -d "${OPENPU_E2E_DIR:-$HOME}/openpu-e2e.XXXXXX")
|
||||
IMG=$WORK/usb.img
|
||||
LOOP=
|
||||
cleanup() {
|
||||
[ -n "$LOOP" ] && udisksctl loop-delete --no-user-interaction -b "$LOOP" >/dev/null 2>&1 || true
|
||||
rm -rf "$WORK"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
truncate -s 16G "$IMG"
|
||||
LOOP=$(udisksctl loop-setup --no-user-interaction -f "$IMG" | grep -o '/dev/loop[0-9]*' | head -1)
|
||||
echo "loop device: $LOOP"
|
||||
|
||||
OPENPU_USB_ALLOW_LOOP=1 "$CLI" write-usb "$LOOP" --yes --label "openpu e2e" "$@" 2>&1 | tr '\r' '\n' | grep -vE '^\s*$' | tail -2
|
||||
|
||||
fail() { echo "FAIL: $*" >&2; exit 1; }
|
||||
|
||||
echo "--- partition table"
|
||||
TABLE=$(sfdisk -d "$IMG")
|
||||
echo "$TABLE" | grep -q '^label: dos' || fail "no MBR partition table"
|
||||
echo "$TABLE" | grep -qE 'start= *2048, .*type=c$' || fail "expected one FAT32 LBA (0x0c) partition at 1 MiB"
|
||||
echo "MBR, partition type 0x0c at 1 MiB: ok"
|
||||
|
||||
echo "--- file system"
|
||||
dd if="$IMG" of="$WORK/part.img" bs=1M skip=1 conv=sparse status=none
|
||||
fsck.vfat -n "$WORK/part.img" | tail -1
|
||||
minfo -i "$WORK/part.img" :: | grep -q 'disk type="FAT32' || fail "not FAT32"
|
||||
LABEL=$(mlabel -s -i "$WORK/part.img" :: | sed 's/.*is //; s/ *$//')
|
||||
[ "$LABEL" = "OPENPUE2E" ] || fail "label is '$LABEL'"
|
||||
echo "FAT32, label $LABEL: ok"
|
||||
|
||||
echo "--- content"
|
||||
mdir -/ -b -i "$WORK/part.img" :: | sed 's/license_[0-9A-Fa-f]*\.key/license_<UIN>.key/' | sort
|
||||
if mdir -/ -b -i "$WORK/part.img" :: | grep -q 'UpdateInfo.xml'; then fail "UpdateInfo.xml was copied"; fi
|
||||
echo "PASS"
|
||||
Reference in new issue
Block a user