-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_lpi4a.sh
146 lines (118 loc) · 4.41 KB
/
build_lpi4a.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
build_kernel() {
if [ ! -d $build_dir/thead-kernel ]; then
git clone --depth=1 https://github.com/revyos/thead-kernel.git -b lpi4a
fi
cd thead-kernel
if [ -f arch/riscv/configs/linux-thead-current_defconfig ]; then
rm arch/riscv/configs/linux-thead-current_defconfig
fi
cp $build_dir/config/linux-thead-current.config arch/riscv/configs/linux-thead-current_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- linux-thead-current_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc)
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- modules_install INSTALL_MOD_PATH=kmod
cd $build_dir
cp -rfp thead-kernel/kmod/lib/modules/* rootfs/lib/modules
}
build_u-boot() {
if [ ! -d $build_dir/thead-u-boot ]; then
git clone --depth=1 https://github.com/chainsx/thead-u-boot.git -b extlinux
fi
cd thead-u-boot
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- light_lpi4a_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc)
cp u-boot-with-spl.bin $build_dir/firmware/lpi4a-8gb-u-boot-with-spl.bin
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- clean
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- light_lpi4a_16g_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc)
cp u-boot-with-spl.bin $build_dir/firmware/lpi4a-16gb-u-boot-with-spl.bin
cd $build_dir
}
build_opensbi() {
if [ ! -d $build_dir/thead-opensbi ]; then
git clone --depth=1 https://github.com/revyos/thead-opensbi.git -b lpi4a
fi
cd thead-opensbi
make PLATFORM=generic FW_PIC=y CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc)
cp build/platform/generic/firmware/fw_dynamic.bin $build_dir/firmware
cd $build_dir
}
mk_img() {
cd $build_dir
device=""
LOSETUP_D_IMG
UMOUNT_ALL
size=`du -sh --block-size=1MiB ${build_dir}/rootfs | cut -f 1 | xargs`
size=$(($size+720))
losetup -D
img_file=${build_dir}/sd.img
dd if=/dev/zero of=${img_file} bs=1MiB count=$size status=progress && sync
parted ${img_file} mklabel gpt mkpart primary fat32 32768s 524287s
parted ${img_file} mkpart primary ext4 524288s 100%
device=`losetup -f --show -P ${img_file}`
trap 'LOSETUP_D_IMG' EXIT
kpartx -va ${device}
loopX=${device##*\/}
partprobe ${device}
sdbootp=/dev/mapper/${loopX}p1
sdrootp=/dev/mapper/${loopX}p2
mkfs.vfat -n fedora-boot ${sdbootp}
mkfs.ext4 -L fedora-root ${sdrootp}
mkdir -p ${root_mnt} ${boot_mnt}
mount ${sdbootp} ${boot_mnt}
mount ${sdrootp} ${root_mnt}
if [ -d $boot_mnt/extlinux ]; then
rm -rf $boot_mnt/extlinux
fi
mkdir -p $boot_mnt/extlinux
line=$(blkid | grep $sdrootp)
uuid=${line#*UUID=\"}
uuid=${uuid%%\"*}
echo "label Fedora
kernel /Image
initrd /initrd.img
fdtdir /
append console=ttyS0,115200 root=UUID=${uuid} rootfstype=ext4 rootwait rw earlycon clk_ignore_unused loglevel=7 eth=$ethaddr rootrwoptions=rw,noatime rootrwreset=yes init=/lib/systemd/systemd" \
> $boot_mnt/extlinux/extlinux.conf
cp $build_dir/firmware/light_aon_fpga.bin $boot_mnt
cp $build_dir/firmware/light_c906_audio.bin $boot_mnt
cp $build_dir/firmware/fw_dynamic.bin $boot_mnt
cp $build_dir/thead-kernel/arch/riscv/boot/Image $boot_mnt
cp $build_dir/thead-kernel/arch/riscv/boot/dts/thead/*lpi4a*dtb $boot_mnt
echo "LABEL=fedora-root / ext4 defaults,noatime 0 0" > ${build_dir}/rootfs/etc/fstab
echo "LABEL=fedora-boot /boot vfat defaults,noatime 0 0" >> ${build_dir}/rootfs/etc/fstab
cp -rfp ${build_dir}/rootfs/boot/* $boot_mnt
rm -rf ${build_dir}/rootfs/boot/*
rsync -avHAXq ${build_dir}/rootfs/* ${root_mnt}
sync
sleep 10
umount $sdrootp
umount $sdbootp
LOSETUP_D_IMG
UMOUNT_ALL
losetup -D
kpartx -d ${img_file}
}
comp_img() {
if [ ! -f $build_dir/sd.img ]; then
echo "sd flash file build failed!"
exit 2
fi
xz -v sd.img
mv sd.img.xz Fedora-38-Minimal-LicheePi-4A-riscv64-sd.img.xz
sha256sum Fedora-38-Minimal-LicheePi-4A-riscv64-sd.img.xz >> Fedora-38-Minimal-LicheePi-4A-riscv64-sd.img.xz.sha256
}
build_dir=$(pwd)
boot_mnt=${build_dir}/boot_tmp
root_mnt=${build_dir}/root_tmp
rootfs_dir=${build_dir}/rootfs
source scripts/common.sh
source scripts/fedora_rootfs.sh
install_reqpkg
get_riscv_system
UMOUNT_ALL
build_kernel
build_u-boot
build_opensbi
mk_img
comp_img