-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuboot-cycle.sh
More file actions
executable file
·63 lines (58 loc) · 2.57 KB
/
Copy pathuboot-cycle.sh
File metadata and controls
executable file
·63 lines (58 loc) · 2.57 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
#!/bin/bash
# One complete self-recovering U-Boot test cycle, with no physical access.
# build -> pack -> flash to recovery -> boot once -> read the log back
#
# The BCB is deliberately never written: `fastboot reboot recovery` is a
# one-shot command that lk obeys directly. If U-Boot hangs, the watchdog resets
# the phone, the BCB is still empty so lk boots the normal `boot` partition
# (LineageOS), and U-Boot's log is still sitting in the ramoops console zone.
#
# Setting BCB `boot-recovery` instead once cost both fallbacks at the same time
# and needed an mtkclient BROM rescue. Do not do it.
#
# Environment:
# UBOOT_DIR U-Boot source tree (default ~/Projects/redmi9/mt6768-uboot)
# TOOLS_DIR this directory's tool set (default ~/Projects/redmi9/pmos)
# ADB_SERIAL device serial for adb/fastboot; leave empty to use the only device
set -e
U="${UBOOT_DIR:-$HOME/Projects/redmi9/mt6768-uboot}"
P="${TOOLS_DIR:-$HOME/Projects/redmi9/pmos}"
SER="${ADB_SERIAL:-}"
cd "$U"
make CROSS_COMPILE=aarch64-linux-gnu- -j"$(nproc)" > /tmp/ub-build.log 2>&1 || {
echo "BUILD FAILED:"; grep -iE "error:|undefined ref" /tmp/ub-build.log | head -8; exit 1; }
echo "build OK $(stat -c%s u-boot.bin) B"
cd "$P"
rm -f boot-uboot.img
python3 pack-uboot-boot.py boot-devmem.img "$U/u-boot.bin" boot-uboot.img > /dev/null
python3 avbtool.py add_hash_footer --image boot-uboot.img \
--partition_name recovery --partition_size 67108864 --algorithm NONE > /dev/null
# Delete the old pstore record before running, otherwise it is easy to read the
# previous boot's log and draw the wrong conclusion (this happened once).
adb root > /dev/null 2>&1 || true
sleep 2
adb shell 'rm -f /sys/fs/pstore/console-ramoops' > /dev/null 2>&1 || true
adb reboot bootloader > /dev/null 2>&1 || true
for _ in $(seq 1 20); do
if [ -n "$SER" ]; then
fastboot devices 2>/dev/null | grep -q "$SER" && break
else
fastboot devices 2>/dev/null | grep -q fastboot && break
fi
sleep 2
done
fastboot flash recovery boot-uboot.img > /dev/null 2>&1
fastboot reboot recovery > /dev/null 2>&1
echo "U-Boot started; waiting for the watchdog to bring LineageOS back..."
for _ in $(seq 1 40); do
if [ -n "$SER" ]; then
[ "$(adb devices 2>/dev/null | grep "$SER" | awk '{print $2}')" = "device" ] && break
else
adb devices 2>/dev/null | grep -qw device && break
fi
sleep 4
done
adb root > /dev/null 2>&1; sleep 3; adb wait-for-device
echo "=== U-BOOT LOG ==="
adb shell 'sed -n "1,200p" /sys/fs/pstore/console-ramoops' 2>/dev/null \
| grep -avE "^\[ *[0-9]+\.[0-9]+\]" | head -40