-
Notifications
You must be signed in to change notification settings - Fork 126
/
convert-pine64-image.sh
executable file
·48 lines (39 loc) · 1.15 KB
/
convert-pine64-image.sh
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
#!/bin/sh
#
# This scripts converts an existing uncompressed Pine64 disk image between the
# different Pine64 variants by replacing the bootloader (boot0 and U-Boot) while
# keeping all the rest intact.
#
set -e
DISKIMAGE="$1"
MODEL="$2"
if [ -z "$DISKIMAGE" -o -z "$MODEL" ]; then
echo "Usage: $0 <disk or diskimage> <pine64|so|pinebook>"
exit 1
fi
if [ "$MODEL" = "pine64" ]; then
MODEL=""
fi
SUFFIX=""
if [ -n "$MODEL" ]; then
SUFFIX="-$MODEL"
fi
DISKIMAGE=$(readlink -f "$DISKIMAGE")
# check image for boot0
boot0headerpos=$((8*1024+4))
boot0header=$(xxd -p -s $boot0headerpos -l 4 "$DISKIMAGE")
if [ "$boot0header" != "65474f4e" ]; then
echo "Error: Target image has no eGON header, aborting!"
exit 1
fi
ubootheaderpos=$((19096*1024+4))
ubootheader=$(xxd -p -s $ubootheaderpos -l 5 "$DISKIMAGE")
if [ "$ubootheader" != "75626f6f74" ]; then
echo "Error: Target image has no uboot header, aborting!"
exit 1
fi
set -x
(cd simpleimage && ./flash_boot0_only.sh "$DISKIMAGE" "../blobs/boot0$MODEL.bin")
(cd simpleimage && ./flash_u-boot_only.sh "$DISKIMAGE" "../build/u-boot-with-dtb$SUFFIX.bin")
set +x
echo "Done - image converted to $2"