-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
122 lines (101 loc) · 3.09 KB
/
common.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
#!/bin/bash
func_generate() {
local rootfs=$1
local kdir=$2
[ "$os" != "debian" ] && [ ! -f "$rootfs" ] && echo "${os} rootfs file not found!" && return 1
[ ! -d "$kdir" ] && echo "kernel dir not found!" && return 1
# create ext4 rootfs img
mkdir -p ${tmpdir}
echo "create ext4 rootfs, size: ${rootsize}M"
dd if=/dev/zero bs=1M status=none count=$rootsize of=$tmpdir/rootfs.bin
mkfs.ext4 -q -m 2 $tmpdir/rootfs.bin
# mount rootfs
mkdir -p $rootfs_mount_point
mount -o loop $tmpdir/rootfs.bin $rootfs_mount_point
# extract rootfs
if [ "$os" = "debian" ]; then
generate_rootfs $rootfs_mount_point
else
echo "extract ${os} rootfs($rootfs) to $rootfs_mount_point"
if [ "$os" = "archlinux" ]; then
tarbin="bsdtar"
else
tarbin="tar"
fi
$tarbin -xpf $rootfs -C $rootfs_mount_point
fi
# configure binfmt
echo "configure binfmt to chroot"
modprobe binfmt_misc
if [ -e /proc/sys/fs/binfmt_misc/register ]; then
echo -1 > /proc/sys/fs/binfmt_misc/status
echo ":arm64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:OC" > /proc/sys/fs/binfmt_misc/register
echo "copy $qemu_static to $rootfs_mount_point/usr/bin/"
cp $qemu_static $rootfs_mount_point/usr/bin/qemu-aarch64-static
else
echo "Could not configure binfmt for qemu!" && exit 1
fi
cp ./tools/${os}/init.sh $rootfs_mount_point/init.sh
# prepare for chroot
chroot_prepare
# chroot
echo "chroot to ${os} rootfs"
eval $(ext_init_param) LANG=C LC_ALL=C chroot $rootfs_mount_point /init.sh
# clean rootfs
rm -f $rootfs_mount_point/init.sh
[ -n "$qemu" ] && rm -f $rootfs_mount_point/$qemu || rm -f $rootfs_mount_point/usr/bin/qemu-aarch64-static
# add resize script
add_resizemmc
# add /lib/modules
echo "add /lib/modules"
tar --no-same-owner -xf $kdir/modules.tar.xz --strip-components 1 -C $rootfs_mount_point/lib
# chroot post
chroot_post
umount $rootfs_mount_point
echo "generate ${os} rootfs done"
}
func_release() {
local rootfs=$1
local kdir=$2
func_generate $rootfs $kdir
tar cf $tmpdir/install.img \
-C $cur_dir/blob/bpi-w2 \
install_a \
-C $cur_dir/config \
config.txt \
-C $cur_dir/$kdir \
$DTB \
Image \
-C $cur_dir/$tmpdir \
rootfs.bin
mkdir -p $output/${os}
cp -f $tmpdir/install.img $output/${os}
cp -f blob/bpi-w2/bluecore.audio $output/${os}
cp -f blob/bpi-w2/rescue.emmc.dtb $output/${os}
cp -f blob/bpi-w2/rescue.root.emmc.cpio.gz_pad.img $output/${os}
cp -f blob/bpi-w2/emmc.uImage $output/${os}
rm -rf $tmpdir
tar cf $output/${os}/${os}.tar \
-C $cur_dir/$output/${os} \
install.img \
bluecore.audio \
rescue.emmc.dtb \
rescue.root.emmc.cpio.gz_pad.img \
emmc.uImage
xz -v -f -T0 $output/${os}/${os}.tar
mkdir -p $output/release
mv -f $output/${os}/${os}.tar.xz $output/release/"$(gen_new_name $rootfs)"
echo "release ${os} image done"
}
case "$1" in
generate)
func_generate "$2" "$3"
;;
release)
func_release "$2" "$3"
;;
*)
echo "Usage: $0 { generate [rootfs] [KDIR] | release [rootfs] [KDIR] }"
exit 1
;;
esac