forked from android-rpi/device_arpi_rpi4
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmkimg.sh
83 lines (80 loc) · 1.72 KB
/
mkimg.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
78
79
80
81
82
83
#/bin/bash
ARPIVERSION=arpi-11
DATE=`date +%Y%m%d`
IMGNAME=$ARPIVERSION-$DATE-rpi4.img
IMGSIZE=4
OUTDIR=${ANDROID_PRODUCT_OUT:="../../../out/target/product/rpi4"}
if [ `id -u` != 0 ]; then
echo "Must be root to run script!"
exit
fi
if [ -f $IMGNAME ]; then
echo "File $IMGNAME already exists!"
else
echo "Creating image file $IMGNAME..."
dd if=/dev/zero of=$IMGNAME bs=512k count=$(echo "$IMGSIZE*1024*2" | bc)
sync
echo "Creating partitions..."
(
echo o
echo n
echo p
echo 1
echo
echo +128M
echo n
echo p
echo 2
echo
echo +1600M
echo n
echo p
echo 3
echo
echo +256M
echo n
echo p
echo
echo
echo t
echo 1
echo c
echo a
echo 1
echo w
) | fdisk $IMGNAME
sync
LOOPDEV=`kpartx -av $IMGNAME | awk 'NR==1{ sub(/p[0-9]$/, "", $3); print $3 }'`
sync
if [ -z "$LOOPDEV" ]; then
echo "Unable to find loop device!"
kpartx -d $IMGNAME
exit
fi
echo "Image mounted as $LOOPDEV"
sleep 5
mkfs.fat -F 32 /dev/mapper/${LOOPDEV}p1
mkfs.ext4 /dev/mapper/${LOOPDEV}p4
resize2fs /dev/mapper/${LOOPDEV}p4 687868
echo "Copying system..."
dd if=$OUTDIR/system.img of=/dev/mapper/${LOOPDEV}p2 bs=1M
echo "Copying vendor..."
dd if=$OUTDIR/vendor.img of=/dev/mapper/${LOOPDEV}p3 bs=1M
echo "Copying boot..."
mkdir -p sdcard/boot
sync
mount /dev/mapper/${LOOPDEV}p1 sdcard/boot
sync
cp boot/* sdcard/boot
cp ../../../kernel/arpi/arch/arm64/boot/Image.gz sdcard/boot
cp ../../../kernel/arpi/arch/arm64/boot/dts/broadcom/bcm2711-rpi-4-b.dtb sdcard/boot
mkdir -p sdcard/boot/overlays
cp ../../../kernel/arpi/arch/arm64/boot/dts/overlays/vc4-kms-v3d-pi4.dtbo sdcard/boot/overlays
cp $OUTDIR/ramdisk.img sdcard/boot
sync
umount /dev/mapper/${LOOPDEV}p1
rm -rf sdcard
kpartx -d $IMGNAME
sync
echo "Done, created $IMGNAME!"
fi