-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrite_sd.sh
More file actions
executable file
·85 lines (67 loc) · 2.08 KB
/
Copy pathwrite_sd.sh
File metadata and controls
executable file
·85 lines (67 loc) · 2.08 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# What am I doing wrong here?
# Guess I can try using buildroot.
DEVICE=$1
[ -z "$DEVICE" ] && echo "please specify device" && exit 1
sudo umount ${DEVICE}*
DEVP=""
if [[ "$DEVICE" == *"loop"* ]]; then
echo "Loop device detected."
DEVP="p"
fi
echo "Zeroing device"
dd if=/dev/zero of=$DEVICE bs=1M count=32
echo "Making GPT label"
parted -s $DEVICE mklabel gpt
echo "Creating rockchip bootloader partitions"
# Only this one seems to be required
parted -s $DEVICE unit s mkpart uboot 16384 24575
echo "Creating boot partition"
parted -s $DEVICE -a min unit s mkpart boot fat32 32768 262143
BOOT=2
parted -s $DEVICE set $BOOT boot on
mkfs.fat ${DEVICE}$DEVP$BOOT
echo "Creating rootfs"
parted -s $DEVICE -a min unit s mkpart rootfs ext4 262144 100%
ROOT=3
mkfs.ext4 ${DEVICE}$DEVP$ROOT
echo "Copying rootfs files"
mkdir devroot
sync
mount ${DEVICE}$DEVP$ROOT devroot
echo "Copying Arch rootfs"
ROOTFS=../archroot/rootfs/
rsync -a --info=progress2 $ROOTFS devroot/
sync
echo "Copying kernel modules"
rsync -a linux/modules_build/ devroot/usr/
sync
umount devroot
sync
rmdir devroot
echo "Writing u-boot-rockchip.bin..."
dd if=u-boot/u-boot-rockchip.bin of=$DEVICE seek=64 status=progress
echo "Mounting boot partition"
mkdir tmp
sync
mount ${DEVICE}$DEVP$BOOT tmp
echo "Copying kernel"
cp linux/arch/arm64/boot/Image tmp/Image
zstd -c10 tmp/Image > tmp/Image.zst
# TODO: uboot set reset gpio?
echo "Creating extlinux.conf"
mkdir tmp/extlinux
echo "LABEL linux" >> tmp/extlinux/extlinux.conf
echo " LINUX /Image.zst" >> tmp/extlinux/extlinux.conf
echo " FDTDIR /boot/" >> tmp/extlinux/extlinux.conf
UUID=$(blkid -o value -s PARTUUID ${DEVICE}$DEVP$ROOT)
echo " APPEND console=uart8250,mmio32,0xfe660000 console=tty0 root=PARTUUID=$UUID rw rootwait rootfstype=ext4 init=/sbin/init video=DSI-1:640x480@60" >> tmp/extlinux/extlinux.conf
echo "Copying devicetree files"
mkdir -p tmp/boot/rockchip
cp u-boot/arch/arm/dts/rk3566-anbernic-rgxx3.dtb tmp/
cp linux/arch/arm64/boot/dts/rockchip/rk3566-anbernic*.dtb tmp/boot/rockchip/
echo "Unmounting boot partition"
sync
umount tmp
rmdir tmp
echo "Done."