-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkimage.sh
More file actions
executable file
·138 lines (117 loc) · 2.26 KB
/
Copy pathmkimage.sh
File metadata and controls
executable file
·138 lines (117 loc) · 2.26 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
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
#!/bin/bash
set -e
# Supported machine name:
# sifive_unmatched
# allwinner_d1
# starfive_jh7110
# PS: "" means preserve variant
# MACHINE=sifive_unmatched
machine_list=("sifive_unmatched" "allwinner_d1" "starfive_jh7110")
BOARD=
IMAGE_SIZE=4G
IMAGE_FILE=""
LOOP_DEVICE=""
EFI_MOUNTPOINT=""
BOOT_MOUNTPOINT=""
ROOT_MOUNTPOINT=""
CHROOT_TARGET=rootfs
install_depends()
{
sudo apt install -y git gdisk dosfstools mmdebstrap qemu-system-misc binfmt-support qemu-user-static \
wget make gcc flex bison gcc-riscv64-linux-gnu libssl-dev bc dpkg-dev rsync
}
unmount_image()
{
echo "Finished and cleaning..."
if mount | grep "$CHROOT_TARGET" > /dev/null; then
umount -l "$CHROOT_TARGET"
fi
if losetup -l | grep "$LOOP_DEVICE" > /dev/null; then
losetup -d "$LOOP_DEVICE"
fi
if [ "$(ls -A $CHROOT_TARGET)" ]; then
echo "folder not empty! umount may fail!"
exit 2
else
echo "Deleting chroot temp folder..."
if [ -d "$CHROOT_TARGET" ]; then
rmdir "$CHROOT_TARGET"
fi
echo "Done."
fi
}
cleanup_env()
{
echo "Cleanup..."
if [ -d kernel ]; then
rm -rv kernel
rm -v *.deb
rm -v *.buildinfo
rm -v *.changes
fi
if [ -d opensbi ]; then
rm -rv opensbi
fi
if [ -d u-boot ]; then
rm -rv u-boot
fi
if [ -f *.bin ]; then
rm -v *.bin
fi
if [ -f *.itb ]; then
rm -v *.itb
fi
echo "Done."
}
main()
{
install_depends
make_imagefile
pre_chroot
make_rootfs
make_kernel
make_bootable
after_chroot
exit
}
source $(pwd)/scripts/after_chroot.sh
source $(pwd)/scripts/make_bootable.sh
source $(pwd)/scripts/make_imagefile.sh
source $(pwd)/scripts/make_kernel.sh
source $(pwd)/scripts/make_rootfs.sh
source $(pwd)/scripts/pre_chroot.sh
# Check root privileges:
if (( $EUID != 0 )); then
echo "Please run as root"
exit 1
fi
if [ -z "$MACHINE" ]; then
echo "MACHINE not set!!"
exit 1
else
if [[ " ${machine_list[*]} " =~ " ${MACHINE} " ]]; then
echo "MACHINE=$MACHINE"
else
echo "$MACHINE is not compatible with this script!!"
exit 1
fi
fi
trap return 2 INT
trap clean_on_exit EXIT
clean_on_exit()
{
if [ $? -eq 0 ]; then
unmount_image
cleanup_env
echo "exit."
else
unmount_image
cleanup_env
if [ -f $IMAGE_FILE ]; then
echo "delete image $IMAGE_FILE ..."
rm -v "$IMAGE_FILE"
fi
echo "interrupted exit."
fi
}
main