forked from Joshua-Riek/ubuntu-rockchip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·174 lines (152 loc) · 4.53 KB
/
build.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
set -eE
trap 'echo Error: in $0 on line $LINENO' ERR
cd "$(dirname -- "$(readlink -f -- "$0")")"
usage() {
cat << HEREDOC
Usage: $0 --board=[orangepi-5|orangepi-5b|orangepi-5-plus|armsom-w3|armsom-sige7|rock-5b|rock-5a|rock-5-itx|radxa-nx5-io|radxa-cm5-io|nanopc-t6|nanopi-r6c|nanopi-r6s|indiedroid-nova|mixtile-blade3|mixtile-core3588e|lubancat-4|turing-rk1|roc-rk3588s-pc]
Required arguments:
-b, --board=BOARD target board
Optional arguments:
-h, --help show this help message and exit
-c, --clean clean the build directory
-d, --docker use docker to build
-k, --kernel-only only compile the kernel
-u, --uboot-only only compile uboot
-ro, --rootfs-only only build rootfs
-so, --server-only only build server image
-do, --desktop-only only build desktop image
-m, --mainline use mainline linux sources
-l, --launchpad use kernel and uboot from launchpad repo
-v, --verbose increase the verbosity of the bash script
HEREDOC
}
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
cd "$(dirname -- "$(readlink -f -- "$0")")"
for i in "$@"; do
case $i in
-h|--help)
usage
exit 0
;;
-b=*|--board=*)
export BOARD="${i#*=}"
shift
;;
-b|--board)
export BOARD="${2}"
shift
;;
-d|--docker)
DOCKER="docker run --privileged --network=host --rm -it -v \"$(pwd)\":/opt -e BOARD -e VENDOR -e LAUNCHPAD -e MAINLINE -e SERVER_ONLY -e DESKTOP_ONLY -e KERNEL_ONLY -e UBOOT_ONLY ubuntu-rockchip-build /bin/bash"
docker build -t ubuntu-rockchip-build docker
shift
;;
-k|--kernel-only)
export KERNEL_ONLY=Y
shift
;;
-u|--uboot-only)
export UBOOT_ONLY=Y
shift
;;
-ro|--rootfs-only)
export ROOTFS_ONLY=Y
shift
;;
-do|--desktop-only)
export DESKTOP_ONLY=Y
shift
;;
-so|--server-only)
export SERVER_ONLY=Y
shift
;;
-m|--mainline)
export KERNEL_TARGET=mainline
shift
;;
-l|--launchpad)
export LAUNCHPAD=Y
shift
;;
-c|--clean)
export CLEAN=Y
;;
-v|--verbose)
set -x
shift
;;
-*)
echo "Error: unknown argument \"$i\""
exit 1
;;
*)
;;
esac
done
if [[ "${KERNEL_TARGET}" != "mainline" ]]; then
export KERNEL_TARGET=bsp
fi
# No board param passed
if [[ -z ${BOARD} ]]; then
usage
exit 1
fi
# Clean the build directory
if [[ ${CLEAN} == "Y" ]]; then
if [ -d build/rootfs ]; then
umount -lf build/rootfs/dev/pts 2> /dev/null || true
umount -lf build/rootfs/* 2> /dev/null || true
fi
rm -rf build
fi
# Read board configuration files
for file in config/boards/*; do
if [ "${BOARD}" == "$(basename "${file%.conf}")" ]; then
# shellcheck source=/dev/null
set -o allexport && source "${file}" && set +o allexport
fi
done
# Exit with error if invalid board
if [[ -z ${BOARD_NAME} ]]; then
echo "Error: \"${BOARD}\" is an unsupported board"
exit 1
fi
# Start logging the build process
mkdir -p build/logs && exec > >(tee "build/logs/build-$(date +"%Y%m%d%H%M%S").log") 2>&1
# Build only the Linux kernel then exit
if [[ ${KERNEL_ONLY} == "Y" ]]; then
eval "${DOCKER}" ./scripts/build-kernel.sh
exit 0
fi
# Build only U-Boot then exit
if [[ ${UBOOT_ONLY} == "Y" ]]; then
eval "${DOCKER}" ./scripts/build-u-boot.sh
exit 0
fi
# Build only the rootfs then exit
if [[ ${ROOTFS_ONLY} == "Y" ]]; then
eval "${DOCKER}" ./scripts/build-rootfs.sh
exit 0
fi
# Build the Linux kernel if not found
if [[ ${LAUNCHPAD} != "Y" ]]; then
if [[ ! -e "$(find build/linux-image-*.deb | sort | tail -n1)" || ! -e "$(find build/linux-headers-*.deb | sort | tail -n1)" ]]; then
eval "${DOCKER}" ./scripts/build-kernel.sh
fi
fi
# Build U-Boot if not found
if [[ ${LAUNCHPAD} != "Y" ]]; then
if [[ ! -e "$(find build/u-boot-"${BOARD}"_*.deb | sort | tail -n1)" ]]; then
eval "${DOCKER}" ./scripts/build-u-boot.sh
fi
fi
# Create the root filesystem
eval "${DOCKER}" ./scripts/build-rootfs.sh
# Create the disk image
eval "${DOCKER}" ./scripts/config-image.sh
exit 0