forked from hanwckf/build-beikeyun
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-lakka.sh
executable file
·77 lines (67 loc) · 2.27 KB
/
build-lakka.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
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
#!/bin/bash
# requirements: sfdisk mtools jq axel
TMPDIR="tmp"
origin="ROCK64"
target="beikeyun"
output="output"
func_modify() {
local DISK="$1"
local DTB="$2"
local IDB="$3"
local UBOOT="$4"
[ ! -f "$DISK" -o ! -f "$DTB" ] && echo "file not found!" && exit 1
# get offset of 1st partition
SYSTEM_PART_START=$(sfdisk -J ${DISK} |jq .partitiontable.partitions[0].start)
OFFSET=$(( ${SYSTEM_PART_START} * 512 ))
echo "SYSTEM_PART_START: $SYSTEM_PART_START"
echo "OFFSET: $OFFSET"
mkdir -p ${TMPDIR}
# patch extlinux.conf
mcopy -no -i ${DISK}@@${OFFSET} ::/extlinux/extlinux.conf ./${TMPDIR} || { echo "extlinux.conf dump failed!"; exit 1; }
sed -i "/^ fdt/c\ \ \ \ fdt \/$(basename ${DTB})" ./${TMPDIR}/extlinux.conf
sed -i '/^ append/s/quiet//' ./${TMPDIR}/extlinux.conf
if [ -z "`grep panic ./${TMPDIR}/extlinux.conf`" ]; then
sed -i '/^ append/s/$/ panic=10/' ./${TMPDIR}/extlinux.conf
fi
echo "extlinux.conf:"
echo "#################"
cat ./${TMPDIR}/extlinux.conf
echo "#################"
mcopy -no -i ${DISK}@@${OFFSET} ./${TMPDIR}/extlinux.conf ::/extlinux/extlinux.conf && \
echo "extlinux.conf patched!" || { echo "extlinux.conf patch failed!"; exit 1; }
# copy dtb
mcopy -no -i ${DISK}@@${OFFSET} ${DTB} ::/ && echo "dtb patched: ${DTB}" || { echo "dtb patch failed!"; exit 1; }
# replace u-boot and idbloader from libreelec
dd if=${IDB} of=${DISK} seek=64 bs=512 conv=notrunc status=none && echo "idb patched: ${IDB}" || { echo "idb patch failed!"; exit 1; }
dd if=${UBOOT} of=${DISK} seek=16384 bs=512 conv=notrunc status=none && echo "u-boot patched: ${UBOOT}" || { echo "u-boot patch failed!"; exit 1; }
sync
rm -rf ${TMPDIR}
}
func_release() {
local PKG="$1"
local DTB="$2"
local IDB="$3"
local UBOOT="$4"
[ ! -f "$PKG" -o ! -f "$DTB" ] && echo "file not found!" && exit 1
IMG="$(sed 's/.gz//' <<< $PKG)"
gzip -d -k "$PKG"
func_modify $IMG $DTB $IDB $UBOOT
IMG_NEW=$(basename $IMG |sed "s/${origin}/${target}/")
echo "IMG_NEW: $IMG_NEW"
mv $IMG $output/$IMG_NEW
if [ -n "$TRAVIS_TAG" ]; then
xz -f -T0 -v $output/$IMG_NEW
fi
}
case "$1" in
modify)
func_modify "$2" "$3" "$4" "$5"
;;
release)
func_release "$2" "$3" "$4" "$5"
;;
*)
echo "Usage: $0 { modify [img] [dtb] [idb] [u-boot] | release [archive] [dtb] [idb] [u-boot] }"
exit 1
;;
esac