Repository navigation
Expand file tree
/
Copy pathbuild-rootfs.sh
More file actions
102 lines (91 loc) · 3.79 KB
/
Copy pathbuild-rootfs.sh
File metadata and controls
102 lines (91 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
# build-rootfs.sh — reproducible Debian riscv64 rootfs for the LILYGO T-Display-K230
#
# Produces a Debian trixie riscv64 root filesystem with the meshtasticd build/runtime
# dependencies preinstalled, then installs the kernel + DTB + extlinux config from the
# Phase 1 boot build. Meant to run on a Linux host (or WSL Debian) with qemu-user-static
# for the foreign-arch second stage. NOT run on the Windows host directly.
#
# This is the "install your own distro on partition 5" step that k230-debian leaves to
# the user (its own rootfs target is only a stub kernel carrier).
#
# Usage:
# sudo ./build-rootfs.sh --out ./out/rootfs --suite trixie \
# --kernel /path/to/ulinux.bin --dtb /path/to/t-display-k230.dtb
#
set -euo pipefail
SUITE=trixie
MIRROR=http://deb.debian.org/debian
ARCH=riscv64
OUT=./out/rootfs
KERNEL="" # mkimage-wrapped kernel payload (ulinux.bin) from Phase 1
DTB="" # board DTB from Phase 1
HOSTNAME=k230
ROOT_PW=meshtastic
while [ $# -gt 0 ]; do
case "$1" in
--out) OUT="$2"; shift 2 ;;
--suite) SUITE="$2"; shift 2 ;;
--mirror) MIRROR="$2"; shift 2 ;;
--kernel) KERNEL="$2"; shift 2 ;;
--dtb) DTB="$2"; shift 2 ;;
--hostname) HOSTNAME="$2"; shift 2 ;;
*) echo "unknown arg: $1" >&2; exit 2 ;;
esac
done
command -v debootstrap >/dev/null || { echo "install debootstrap"; exit 1; }
command -v qemu-riscv64-static >/dev/null || echo "warn: qemu-riscv64-static not found (needed for foreign second stage)"
# Build/runtime deps for meshtasticd (from firmware Dockerfile + native portduino.ini).
# libgpiod2.x is what platform-native's LinuxGPIOPin targets; trixie ships libgpiod3.
PKGS="ca-certificates locales sudo openssh-server \
libgpiod-dev libgpiod3 libyaml-cpp-dev libjsoncpp-dev \
libbluetooth-dev libusb-1.0-0-dev libi2c-dev libuv1-dev \
libxkbcommon-dev libinput-dev libsqlite3-dev \
libx11-dev libsdl2-dev \
i2c-tools gpiod spi-tools \
wpasupplicant iw ethtool"
mkdir -p "$OUT"
echo "== Stage 1: debootstrap $SUITE/$ARCH =="
# --foreign so the second stage runs under qemu on a non-riscv64 host.
debootstrap --arch="$ARCH" --foreign \
--include="$(echo "$PKGS" | tr -s ' ' ',')" \
"$SUITE" "$OUT" "$MIRROR"
echo "== Stage 2: second stage (qemu) =="
if [ -x /usr/bin/qemu-riscv64-static ]; then
install -m0755 /usr/bin/qemu-riscv64-static "$OUT/usr/bin/"
fi
chroot "$OUT" /debootstrap/debootstrap --second-stage
echo "== Basic system config =="
echo "$HOSTNAME" > "$OUT/etc/hostname"
chroot "$OUT" bash -c "echo 'root:$ROOT_PW' | chpasswd"
# serial console (matches k230-debian extlinux cmdline: ttyS0,115200)
chroot "$OUT" systemctl enable serial-getty@ttyS0.service || true
# rootfs grows to fill partition on first boot
cat > "$OUT/etc/fstab" <<EOF
/dev/mmcblk1p5 / ext4 rw,relatime 0 1
EOF
echo "== Install kernel + DTB (Phase 1 artefacts) =="
if [ -n "$KERNEL" ]; then
install -Dm0644 "$KERNEL" "$OUT/boot/vmlinuz-k230"
fi
if [ -n "$DTB" ]; then
install -Dm0644 "$DTB" "$OUT/boot/dtbs/t-display-k230.dtb"
fi
# extlinux entry (U-Boot distro boot). Mirrors k230-debian/src/extlinux.conf.
install -d "$OUT/boot/extlinux"
cat > "$OUT/boot/extlinux/extlinux.conf" <<EOF
TIMEOUT 30
DEFAULT l0
MENU TITLE T-Display-K230 boot
LABEL l0
MENU LABEL Debian (T-Display-K230)
LINUX /boot/vmlinuz-k230
FDT /boot/dtbs/t-display-k230.dtb
APPEND root=/dev/mmcblk1p5 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 earlycon=sbi
EOF
echo "== meshtasticd config =="
install -Dm0644 "$(dirname "$0")/config.yaml" "$OUT/etc/meshtasticd/config.yaml" || \
echo "note: drop k230-linux/config.yaml into /etc/meshtasticd/ after building meshtasticd"
echo "Done. rootfs at: $OUT"
echo "Next: write this rootfs to SD partition 5 (see k230-debian sdcard.dump layout),"
echo "then flash the Phase 1 SPL/U-Boot to the earlier partitions."