@@ -12,9 +12,9 @@ LOSETUP_D_IMG(){
1212 umount ${boot_mnt}
1313 fi
1414 fi
15- if [ -d $img_mnt ]; then
16- if grep -q " $img_mnt " /proc/mounts ; then
17- umount $img_mnt
15+ if [ -d $image_mnt ]; then
16+ if grep -q " $image_mnt " /proc/mounts ; then
17+ umount $image_mnt
1818 fi
1919 fi
2020 if [ " x$device " != " x" ]; then
@@ -28,23 +28,30 @@ LOSETUP_D_IMG(){
2828 if [ -d ${boot_mnt} ]; then
2929 rm -rf ${boot_mnt}
3030 fi
31+ if [ -d ${image_mnt} ]; then
32+ rm -rf ${image_mnt}
33+ fi
3134 set -e
3235}
3336
3437install_reqpkg () {
35- apt install make bision bc flex xz kpartx qemu-user-static
38+ apt install make bison bc flex kpartx xz-utils qemu-user-static
3639}
3740
3841get_riscv_system () {
3942 cd $build_dir
43+ if [ -f $build_dir /system.img* ]; then
44+ echo " clean..."
45+ rm $build_dir /system.img*
46+ fi
4047 wget https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/Fedora-Developer-37-20221130.n.0-mmc.raw.img.xz -O system.img.xz
41- unxz -v system.img.xz
42- img_file=system.img
43-
4448 if [ ! -f $build_dir /system.img.xz ]; then
4549 echo " system image download failed!"
4650 exit 2
4751 fi
52+ unxz -v system.img.xz
53+ img_file=system.img
54+
4855 LOSETUP_D_IMG
4956
5057 device=` losetup -f --show -P ${img_file} `
@@ -56,42 +63,51 @@ get_riscv_system() {
5663 bootp=/dev/mapper/${loopX} p3
5764 rootp=/dev/mapper/${loopX} p4
5865
59- if [ -d $img_mnt ]; then
66+ if [ -d $image_mnt ]; then
6067 LOSETUP_D_IMG
61- rmdir $img_mnt
68+ rmdir $image_mnt
6269 fi
63- mkdir $img_mnt
70+ mkdir $image_mnt
6471
65- mount $rootp $img_mnt
66- mount $bootp $img_mnt /boot
72+ mount $rootp $image_mnt
73+ mount $bootp $image_mnt /boot
6774
68- chroot $img_mnt dnf remove kernel* opensbi* * bootloader*
75+ chroot $image_mnt dnf remove kernel* -y
76+ chroot $image_mnt dnf remove opensbi* -y
77+ chroot $image_mnt dnf remove * bootloader* -y
6978
70- cp -rfp $img_mnt $build_dir /rootfs
79+ cp -rfp $image_mnt $build_dir /rootfs
7180 sync
7281
73- umount $img_mnt /boot
74- umount $img_mnt
82+ umount $image_mnt /boot
83+ umount $image_mnt
7584 kpartx -d ${device}
7685
77- rmdir $img_mnt
86+ rmdir $image_mnt
7887}
7988
8089prepare_toolchain () {
8190 cd $build_dir
82- wget https://github.com/chainsx/armbian-riscv-build/releases/download/toolchain/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz
83- tar -zxvf Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz
84- rm * tar.gz && mv Xuantie* riscv64-gcc
91+ if [ ! -d $build_dir /riscv64-gcc ]; then
92+ wget https://github.com/chainsx/armbian-riscv-build/releases/download/toolchain/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz
93+ tar -zxf Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz
94+ rm * tar.gz && mv Xuantie* riscv64-gcc
95+ fi
8596}
8697
8798
8899build_kernel () {
89- git clone --depth=1 http://github.com/revyos/thead-kernel.get -b lpi4a
100+ if [ ! -d $build_dir /thead-kernel ]; then
101+ git clone --depth=1 https://github.com/revyos/thead-kernel.git -b lpi4a
102+ fi
90103 cd thead-kernel
91- wget https://github.com/chainsx/armbian-riscv-build/raw/main/config/kernel/linux-thead-current.config -O arch/riscv/configs/linux-thead-current_defconfig
104+ if [ -f arch/riscv/configs/linux-thead-current_defconfig ]; then
105+ rm arch/riscv/configs/linux-thead-current_defconfig
106+ fi
107+ cp $build_dir /config/linux-thead-current.config arch/riscv/configs/linux-thead-current_defconfig
92108 make ARCH=riscv CROSS_COMPILE=${build_dir} /riscv64-gcc/bin/riscv64-unknown-linux-gnu- linux-thead-current_defconfig
93109 make ARCH=riscv CROSS_COMPILE=${build_dir} /riscv64-gcc/bin/riscv64-unknown-linux-gnu- -j$( nproc)
94- make ARCH=riscv CROSS_COMPILE=${build_dir} /riscv64-gcc/bin/riscv64-unknown-linux-gnu- modules_install INSTALL_MOD =kmod
110+ make ARCH=riscv CROSS_COMPILE=${build_dir} /riscv64-gcc/bin/riscv64-unknown-linux-gnu- modules_install INSTALL_MOD_PATH =kmod
95111 cd $build_dir
96112 cp -rfp thead-kernel/kmod/lib/modules/* rootfs/lib/modules
97113}
@@ -106,7 +122,7 @@ mk_img() {
106122 img_file=${build_dir} /sd.img
107123 dd if=/dev/zero of=${img_file} bs=1MiB count=$size status=progress && sync
108124
109- parted ${img_file} mklabel gpt mkpart primary fat32 32768s 524287s
125+ parted ${img_file} mklabel gpt mkpart primary ext4 32768s 524287s
110126 parted ${img_file} mkpart primary ext4 524288s 100%
111127
112128 device=` losetup -f --show -P ${img_file} `
@@ -118,61 +134,61 @@ mk_img() {
118134 sdbootp=/dev/mapper/${loopX} p1
119135 sdrootp=/dev/mapper/${loopX} p2
120136
121- mkfs.vfat -n boot ${sdbootp}
122- mkfs.ext4 -L rootfs ${sdrootp}
137+ mkfs.ext4 -L boot ${sdbootp}
138+ mkfs.ext4 -L root ${sdrootp}
123139 mkdir -p ${root_mnt} ${boot_mnt}
124140 mount -t ext4 ${sdbootp} ${boot_mnt}
125141 mount -t ext4 ${sdrootp} ${root_mnt}
126142
127- echo " fdt_file=light-lpi4a.dtb
128- kernel_file=Image
129- bootargs=console=ttyS0,115200 root=/dev/mmcblk1p2 rootfstype=ext4 rootwait rw earlycon clk_ignore_unused loglevel=7 eth=$ethaddr rootrwoptions=rw,noatime rootrwreset=yes init=/lib/systemd/systemd" >> $boot_mnt /config.txt
130-
131- cd $boot_mnt
132- wget https://github.com/chainsx/armbian-riscv-build/raw/main/packages/blobs/riscv64/thead/light_aon_fpga.bin
133- wget https://github.com/chainsx/armbian-riscv-build/raw/main/packages/blobs/riscv64/thead/light_c906_audio.bin
143+ if [ -f $boot_mnt /config.txt ]; then
144+ rm $boot_mnt /config.txt
145+ fi
146+ cp $build_dir /config/config.txt $boot_mnt /config.txt
134147
135- cp $build_dir /thead-kernel/arch/riscv/boot/Image .
136- cp $build_dir /thead-kernel/arch/riscv/boot/dts/thrad/* lpi4a* dtb .
148+ cp $build_dir /firmware/light_aon_fpga.bin $boot_mnt
149+ cp $build_dir /firmware/light_c906_audio.bin $boot_mnt
150+ cp $build_dir /thead-kernel/arch/riscv/boot/Image $boot_mnt
151+ cp $build_dir /thead-kernel/arch/riscv/boot/dts/thead/* lpi4a* dtb $boot_mnt
137152
138- sync
139-
140- rsync -avHAXq ${build_dir} /rootfs/* ${root_mnt}
141153 echo " /dev/mmcblk1p2 / ext4 defaults,noatime 0 0" > ${build_dir} /rootfs/etc/fstab
142154 echo " /dev/mmcblk1p1 /boot ext4 defaults,noatime 0 0" >> ${build_dir} /rootfs/etc/fstab
143155
156+ rsync -avHAXq ${build_dir} /rootfs/* ${root_mnt}
157+
144158 sync
145159
146160 umount $sdrootp
147161 umount $sdbootp
148162
149- LOSETUP_D_IMG
150-
151163 dd if=$sdbootp of=boot.img status=progress
152164 dd if=$sdrootp of=rootfs.img status=progress
153165 sync
154166
155167 mount -t ext4 boot.img ${boot_mnt}
156168 mount -t ext4 rootfs.img ${root_mnt}
157169
158- rm $boot_mnt /config.txt
159- echo " fdt_file=light-lpi4a.dtb
160- kernel_file=Image
161- bootargs=console=ttyS0,115200 root=/dev/mmcblk0p3 rootfstype=ext4 rootwait rw earlycon clk_ignore_unused loglevel=7 eth=$ethaddr rootrwoptions=rw,noatime rootrwreset=yes init=/lib/systemd/systemd" >> $boot_mnt /config.txt
162- echo " /dev/mmcblk0p3 / ext4 defaults,noatime 0 0" > ${build_dir} /rootfs/etc/fstab
163- echo " /dev/mmcblk0p2 /boot ext4 defaults,noatime 0 0" >> ${build_dir} /rootfs/etc/fstab
170+ if [ -f $boot_mnt /config.txt ]; then
171+ rm $boot_mnt /config.txt
172+ fi
173+ cp $build_dir /config/config-emmc.txt $boot_mnt /config.txt
174+
175+ echo " /dev/mmcblk0p3 / ext4 defaults,noatime 0 0" > ${root_mnt} /etc/fstab
176+ echo " /dev/mmcblk0p2 /boot ext4 defaults,noatime 0 0" >> ${root_mnt} /etc/fstab
177+ sync
178+ sleep 10
164179
165- umount $sdrootp
166- umount $sdbootp
180+ LOSETUP_D_IMG
167181
168182 losetup -D
169183 kpartx -d ${img_file}
184+ rm system.img
170185}
171186
172187build_dir=$( pwd)
173- img_mnt =${build_dir} /img_mnt
188+ image_mnt =${build_dir} /image_mnt
174189boot_mnt=${build_dir} /boot_tmp
175190root_mnt=${build_dir} /root_tmp
191+
176192install_reqpkg
177193get_riscv_system
178194prepare_toolchain
0 commit comments