Skip to content

Commit 042f9f8

Browse files
authored
Merge pull request #1198 from kernelkit/misc
Mixed bag of fixes mostly for RPi4 Signed-off-by: Joachim Wiberg <[email protected]>
2 parents 5f00184 + acb6cdc commit 042f9f8

File tree

14 files changed

+518
-143
lines changed

14 files changed

+518
-143
lines changed

board/aarch64/linux_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CONFIG_JUMP_LABEL=y
5656
# CONFIG_GCC_PLUGINS is not set
5757
CONFIG_MODULES=y
5858
CONFIG_MODULE_UNLOAD=y
59+
CONFIG_PARTITION_ADVANCED=y
5960
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
6061
# CONFIG_COMPAT_BRK is not set
6162
CONFIG_KSM=y

board/common/rootfs/usr/libexec/infix/mnt

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,140 @@ factory_reset()
5151
sync
5252
}
5353

54+
is_rpi()
55+
{
56+
[ -r /sys/firmware/devicetree/base/model ] || return 1
57+
58+
model=$(cat /sys/firmware/devicetree/base/model 2>/dev/null | tr -d '\0')
59+
echo "$model" | grep -q "^Raspberry Pi"
60+
}
61+
62+
wait_mmc()
63+
{
64+
# Try up to 50 times with 0.2s sleep = 10 second timeout
65+
for _ in $(seq 50); do
66+
if ls /dev/mmcblk* >/dev/null 2>&1; then
67+
logger $opt -p user.notice -t "$nm" "MMC device available after delay"
68+
return 0
69+
fi
70+
sleep .2
71+
done
72+
73+
logger $opt -p user.warn -t "$nm" "Timeout waiting for MMC device"
74+
return 1
75+
}
76+
77+
# This early on we don't have the luxury of /dev/disk/by-label/$1
78+
find_partition_by_label()
79+
{
80+
label="$1"
81+
82+
for diskpath in /sys/class/block/*; do
83+
devname=$(basename "$diskpath")
84+
[ -f "$diskpath/partition" ] && continue
85+
86+
disk="/dev/$devname"
87+
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
88+
/^ *[0-9]/ {
89+
if ($7 == label) {
90+
if (devname ~ /^(mmcblk|nvme|loop)/) {
91+
print devname "p" $1
92+
} else {
93+
print devname $1
94+
}
95+
exit 0
96+
}
97+
}
98+
')
99+
100+
if [ -n "$result" ]; then
101+
echo "$result"
102+
return 0
103+
fi
104+
done
105+
return 1
106+
}
107+
108+
# Expand the given partition to fill up the rest of storage (sdcard)
109+
resize_by_label()
110+
{
111+
label="$1"
112+
113+
devname=$(find_partition_by_label "$label")
114+
if [ -z "$devname" ]; then
115+
logger $opt -p user.err -t "$nm" "Label \"$label\" not found"
116+
return 1
117+
fi
118+
119+
part="/dev/$devname"
120+
diskname=$(basename "$(readlink -f "/sys/class/block/$devname/..")")
121+
disk="/dev/$diskname"
122+
partnum="${devname##*[^0-9]}"
123+
124+
logger $opt -p user.notice -t "$nm" "Found partition $part (partition $partnum on $disk)"
125+
126+
start=$(sgdisk -i "$partnum" "$disk" 2>/dev/null | grep "First sector:" | awk '{print $3}')
127+
if [ -z "$start" ]; then
128+
logger $opt -p user.err -t "$nm" "Could not determine start sector for partition $partnum"
129+
return 1
130+
fi
131+
132+
printf "\r\033[K[ ⋯ ] Resizing /var partition on sdcard, please wait ..." > /dev/console
133+
logger $opt -p user.notice -t "$nm" "Expanding partition $partnum from sector $start to end of disk"
134+
135+
if ! sgdisk -e "$disk" 2>&1 | logger $opt -p user.notice -t "$nm"; then
136+
logger $opt -p user.warn -t "$nm" "Failed expanding GPT on $disk"
137+
return 1
138+
fi
139+
140+
if ! sgdisk -d "$partnum" "$disk" >/dev/null 2>&1; then
141+
logger $opt -p user.warn -t "$nm" "Failed deleting partition $partnum on $disk"
142+
return 1
143+
fi
144+
145+
if ! sgdisk -n "$partnum:$start:0" "$disk" >/dev/null 2>&1; then
146+
logger $opt -p user.warn -t "$nm" "Failed recreating partition $partnum on $disk"
147+
return 1
148+
fi
149+
150+
if ! sgdisk -t "$partnum:8300" "$disk" >/dev/null 2>&1; then
151+
logger $opt -p user.warn -t "$nm" "Failed setting partition type on $disk"
152+
return 1
153+
fi
154+
155+
if ! sgdisk -c "$partnum:$label" "$disk" >/dev/null 2>&1; then
156+
logger $opt -p user.warn -t "$nm" "Failed setting partition label on $disk"
157+
return 1
158+
fi
159+
160+
logger $opt -p user.notice -t "$nm" "Partition table updated on $disk"
161+
partprobe "$disk" 2>/dev/null
162+
163+
logger $opt -p user.notice -t "$nm" "Resizing filesystem on $part"
164+
if ! resize2fs "$part" 2>&1 | logger $opt -p user.notice -t "$nm"; then
165+
logger $opt -p user.warn -t "$nm" "Failed resizing filesystem on $part"
166+
return 1
167+
fi
168+
169+
tune2fs -O resize_inode "$part" 2>/dev/null
170+
printf "\r\033[K[ \033[32mOK\033[0m ] Resizing /var partition on sdcard, done. Rebooting ...\n" > /dev/console
171+
logger $opt -p user.notice -t "$nm" "Partition expanded, rebooting to complete filesystem resize"
172+
173+
reboot -f
174+
}
175+
54176
mount_rw()
55177
{
56178
# If something is already setup, leave it be.
57179
mountpoint -q "/$1" && return 0
58180

181+
if [ "$1" = "var" ]; then
182+
if is_rpi && [ ! -e /mnt/aux/resized ] ; then
183+
touch /mnt/aux/resized
184+
resize_by_label "$1"
185+
fi
186+
fi
187+
59188
# TODO: Also look for UBI partitions
60189
mount LABEL="$1" 2>/dev/null && return 0
61190

@@ -103,6 +232,15 @@ if ! logger -? |grep -q "Log to kernel"; then
103232
opt="-c"
104233
fi
105234

235+
236+
# On Raspberry Pi, MMC controller may probe slowly, in particular if we
237+
# netboot (ram load) the devcice wait for it
238+
if is_rpi && ! ls /dev/mmcblk* >/dev/null 2>&1; then
239+
wait_mmc
240+
fi
241+
242+
# The aux partition must be mounted before everything else since it's used
243+
# for internal bookkeeping.
106244
if ! mount_rw aux >/dev/null 2>&1; then
107245
logger $opt -p user.warn -t "$nm" \
108246
"No auxiliary partition found, software updates not supported."

doc/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ All notable changes to the project are documented in this file.
1111
- Upgrade Linux kernel to 6.12.50 (LTS)
1212
- Extend NETCONF and RESTCONF scripting documentation with operational
1313
data examples, discovery patterns, and common workflow examples, issue #1156
14+
- Initial support for a zone-based firewall, based on `firewalld`, issue #448
15+
- Automatically expand `/var` partition on SD card at first boot on RPi
1416

1517
### Fixes
1618

19+
- Fix #1194: CLI `text-editor` command does not do proper input sanitation
20+
- Fix #1197: RPi4 no longer boots after BPi-R3 merge, introduced in v25.09
1721

1822
[v25.09.0][] - 2025-09-30
1923
-------------------------
@@ -1656,6 +1660,7 @@ Supported YANG models in addition to those used by sysrepo and netopeer:
16561660

16571661
[buildroot]: https://buildroot.org/
16581662
[UNRELEASED]: https://github.com/kernelkit/infix/compare/v25.09.0...HEAD
1663+
[v25.10.0]: https://github.com/kernelkit/infix/compare/v25.09.0...v26.10.0
16591664
[v25.09.0]: https://github.com/kernelkit/infix/compare/v25.08.0...v26.09.0
16601665
[v25.08.0]: https://github.com/kernelkit/infix/compare/v25.06.1...v26.08.0
16611666
[v25.06.0]: https://github.com/kernelkit/infix/compare/v25.05.1...v26.06.0

doc/TODO.org

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)