@@ -1,496 +1,498 | |||
|
1 | 1 | # |
|
2 | 2 | # Build and Setup RPi2/3 Kernel |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Fetch and build latest raspberry kernel |
|
9 | 9 | if [ "$BUILD_KERNEL" = true ] ; then |
|
10 | 10 | # Setup source directory |
|
11 | 11 | mkdir -p "${KERNEL_DIR}" |
|
12 | 12 | |
|
13 | 13 | # Copy existing kernel sources into chroot directory |
|
14 | 14 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then |
|
15 | 15 | # Copy kernel sources and include hidden files |
|
16 | 16 | cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}" |
|
17 | 17 | |
|
18 | 18 | # Clean the kernel sources |
|
19 | 19 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
20 | 20 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper |
|
21 | 21 | fi |
|
22 | 22 | else # KERNELSRC_DIR="" |
|
23 | 23 | # Create temporary directory for kernel sources |
|
24 | 24 | temp_dir=$(as_nobody mktemp -d) |
|
25 | 25 | |
|
26 | # Use kali kernel src if nexmon is enabled | |
|
26 | 27 | if [ "$ENABLE_NEXMON" = true ] ; then |
|
27 | NEXMON_URL | |
|
28 | KERNEL_URL="${NEXMON_URL}" | |
|
29 | fi | |
|
30 | ||
|
31 | # Fetch current RPi2/3 kernel sources | |
|
32 | if [ -z "${KERNEL_BRANCH}" ] ; then | |
|
33 | as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux | |
|
28 | 34 | else |
|
29 | # Fetch current RPi2/3 kernel sources | |
|
30 | if [ -z "${KERNEL_BRANCH}" ] ; then | |
|
31 | as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux | |
|
32 | else | |
|
33 | as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux | |
|
34 | fi | |
|
35 | as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux | |
|
35 | 36 | fi |
|
37 | ||
|
36 | 38 | # Copy downloaded kernel sources |
|
37 | 39 | cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}" |
|
38 | 40 | |
|
39 | 41 | # Remove temporary directory for kernel sources |
|
40 | 42 | rm -fr "${temp_dir}" |
|
41 | 43 | |
|
42 | 44 | # Set permissions of the kernel sources |
|
43 | 45 | chown -R root:root "${R}/usr/src" |
|
44 | 46 | fi |
|
45 | 47 | |
|
46 | 48 | # Calculate optimal number of kernel building threads |
|
47 | 49 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then |
|
48 | 50 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) |
|
49 | 51 | fi |
|
50 | 52 | |
|
51 | 53 | # Configure and build kernel |
|
52 | 54 | if [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
53 | 55 | # Remove device, network and filesystem drivers from kernel configuration |
|
54 | 56 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
55 | 57 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
56 | 58 | sed -i\ |
|
57 | 59 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ |
|
58 | 60 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ |
|
59 | 61 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ |
|
60 | 62 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ |
|
61 | 63 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ |
|
62 | 64 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ |
|
63 | 65 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ |
|
64 | 66 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ |
|
65 | 67 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ |
|
66 | 68 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ |
|
67 | 69 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ |
|
68 | 70 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ |
|
69 | 71 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ |
|
70 | 72 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ |
|
71 | 73 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ |
|
72 | 74 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ |
|
73 | 75 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ |
|
74 | 76 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ |
|
75 | 77 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ |
|
76 | 78 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ |
|
77 | 79 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ |
|
78 | 80 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ |
|
79 | 81 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ |
|
80 | 82 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ |
|
81 | 83 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ |
|
82 | 84 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ |
|
83 | 85 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ |
|
84 | 86 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ |
|
85 | 87 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ |
|
86 | 88 | "${KERNEL_DIR}/.config" |
|
87 | 89 | fi |
|
88 | 90 | |
|
89 | 91 | if [ "$KERNELSRC_CONFIG" = true ] ; then |
|
90 | 92 | # Load default raspberry kernel configuration |
|
91 | 93 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
92 | 94 | |
|
93 | 95 | #Switch to KERNELSRC_DIR so we can use set_kernel_config |
|
94 | 96 | cd "${KERNEL_DIR}" || exit |
|
95 | 97 | |
|
96 | 98 | # enable ZSWAP see https://askubuntu.com/a/472227 or https://wiki.archlinux.org/index.php/zswap |
|
97 | 99 | if [ "$KERNEL_ZSWAP" = true ] ; then |
|
98 | 100 | set_kernel_config CONFIG_ZPOOL y |
|
99 | 101 | set_kernel_config CONFIG_ZSWAP y |
|
100 | 102 | set_kernel_config CONFIG_ZBUD y |
|
101 | 103 | set_kernel_config CONFIG_Z3FOLD y |
|
102 | 104 | set_kernel_config CONFIG_ZSMALLOC y |
|
103 | 105 | set_kernel_config CONFIG_PGTABLE_MAPPING y |
|
104 | 106 | fi |
|
105 | 107 | |
|
106 | 108 | # enable basic KVM support; see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453 |
|
107 | 109 | if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then |
|
108 | 110 | set_kernel_config CONFIG_VIRTUALIZATION y |
|
109 | 111 | set_kernel_config CONFIG_KVM y |
|
110 | 112 | set_kernel_config CONFIG_VHOST_NET m |
|
111 | 113 | set_kernel_config CONFIG_VHOST_CROSS_ENDIAN_LEGACY y |
|
112 | 114 | fi |
|
113 | 115 | |
|
114 | 116 | # Netfilter kernel support See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406 |
|
115 | 117 | if [ "$KERNEL_NF" = true ] ; then |
|
116 | 118 | set_kernel_config CONFIG_IP_NF_TARGET_SYNPROXY m |
|
117 | 119 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_CGROUP m |
|
118 | 120 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_IPCOMP m |
|
119 | 121 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_SOCKET m |
|
120 | 122 | set_kernel_config CONFIG_NFT_FIB_INET m |
|
121 | 123 | set_kernel_config CONFIG_NFT_FIB_IPV4 m |
|
122 | 124 | set_kernel_config CONFIG_NFT_FIB_IPV6 m |
|
123 | 125 | set_kernel_config CONFIG_NFT_FIB_NETDEV m |
|
124 | 126 | set_kernel_config CONFIG_NFT_OBJREF m |
|
125 | 127 | set_kernel_config CONFIG_NFT_RT m |
|
126 | 128 | set_kernel_config CONFIG_NFT_SET_BITMAP m |
|
127 | 129 | set_kernel_config CONFIG_NF_CONNTRACK_TIMEOUT y |
|
128 | 130 | set_kernel_config CONFIG_NF_LOG_ARP m |
|
129 | 131 | set_kernel_config CONFIG_NF_SOCKET_IPV4 m |
|
130 | 132 | set_kernel_config CONFIG_NF_SOCKET_IPV6 m |
|
131 | 133 | set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m |
|
132 | 134 | set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m |
|
133 | 135 | set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m |
|
134 | 136 | set_kernel_config CONFIG_IP6_NF_IPTABLES m |
|
135 | 137 | set_kernel_config CONFIG_IP6_NF_MATCH_AH m |
|
136 | 138 | set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m |
|
137 | 139 | set_kernel_config CONFIG_IP6_NF_NAT m |
|
138 | 140 | set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m |
|
139 | 141 | set_kernel_config CONFIG_IP6_NF_TARGET_NPT m |
|
140 | 142 | set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m |
|
141 | 143 | set_kernel_config CONFIG_IP_SET_BITMAP_PORT m |
|
142 | 144 | set_kernel_config CONFIG_IP_SET_HASH_IP m |
|
143 | 145 | set_kernel_config CONFIG_IP_SET_HASH_IPMARK m |
|
144 | 146 | set_kernel_config CONFIG_IP_SET_HASH_IPPORT m |
|
145 | 147 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m |
|
146 | 148 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m |
|
147 | 149 | set_kernel_config CONFIG_IP_SET_HASH_MAC m |
|
148 | 150 | set_kernel_config CONFIG_IP_SET_HASH_NET m |
|
149 | 151 | set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m |
|
150 | 152 | set_kernel_config CONFIG_IP_SET_HASH_NETNET m |
|
151 | 153 | set_kernel_config CONFIG_IP_SET_HASH_NETPORT m |
|
152 | 154 | set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m |
|
153 | 155 | set_kernel_config CONFIG_IP_SET_LIST_SET m |
|
154 | 156 | set_kernel_config CONFIG_NETFILTER_XTABLES m |
|
155 | 157 | set_kernel_config CONFIG_NETFILTER_XTABLES m |
|
156 | 158 | set_kernel_config CONFIG_NFT_BRIDGE_META m |
|
157 | 159 | set_kernel_config CONFIG_NFT_BRIDGE_REJECT m |
|
158 | 160 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m |
|
159 | 161 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m |
|
160 | 162 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m |
|
161 | 163 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m |
|
162 | 164 | set_kernel_config CONFIG_NFT_COMPAT m |
|
163 | 165 | set_kernel_config CONFIG_NFT_COUNTER m |
|
164 | 166 | set_kernel_config CONFIG_NFT_CT m |
|
165 | 167 | set_kernel_config CONFIG_NFT_DUP_IPV4 m |
|
166 | 168 | set_kernel_config CONFIG_NFT_DUP_IPV6 m |
|
167 | 169 | set_kernel_config CONFIG_NFT_DUP_NETDEV m |
|
168 | 170 | set_kernel_config CONFIG_NFT_EXTHDR m |
|
169 | 171 | set_kernel_config CONFIG_NFT_FWD_NETDEV m |
|
170 | 172 | set_kernel_config CONFIG_NFT_HASH m |
|
171 | 173 | set_kernel_config CONFIG_NFT_LIMIT m |
|
172 | 174 | set_kernel_config CONFIG_NFT_LOG m |
|
173 | 175 | set_kernel_config CONFIG_NFT_MASQ m |
|
174 | 176 | set_kernel_config CONFIG_NFT_MASQ_IPV4 m |
|
175 | 177 | set_kernel_config CONFIG_NFT_MASQ_IPV6 m |
|
176 | 178 | set_kernel_config CONFIG_NFT_META m |
|
177 | 179 | set_kernel_config CONFIG_NFT_NAT m |
|
178 | 180 | set_kernel_config CONFIG_NFT_NUMGEN m |
|
179 | 181 | set_kernel_config CONFIG_NFT_QUEUE m |
|
180 | 182 | set_kernel_config CONFIG_NFT_QUOTA m |
|
181 | 183 | set_kernel_config CONFIG_NFT_REDIR m |
|
182 | 184 | set_kernel_config CONFIG_NFT_REDIR_IPV4 m |
|
183 | 185 | set_kernel_config CONFIG_NFT_REDIR_IPV6 m |
|
184 | 186 | set_kernel_config CONFIG_NFT_REJECT m |
|
185 | 187 | set_kernel_config CONFIG_NFT_REJECT_INET m |
|
186 | 188 | set_kernel_config CONFIG_NFT_REJECT_IPV4 m |
|
187 | 189 | set_kernel_config CONFIG_NFT_REJECT_IPV6 m |
|
188 | 190 | set_kernel_config CONFIG_NFT_SET_HASH m |
|
189 | 191 | set_kernel_config CONFIG_NFT_SET_RBTREE m |
|
190 | 192 | set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m |
|
191 | 193 | set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m |
|
192 | 194 | set_kernel_config CONFIG_NF_DEFRAG_IPV4 m |
|
193 | 195 | set_kernel_config CONFIG_NF_DEFRAG_IPV6 m |
|
194 | 196 | set_kernel_config CONFIG_NF_DUP_IPV4 m |
|
195 | 197 | set_kernel_config CONFIG_NF_DUP_IPV6 m |
|
196 | 198 | set_kernel_config CONFIG_NF_DUP_NETDEV m |
|
197 | 199 | set_kernel_config CONFIG_NF_LOG_BRIDGE m |
|
198 | 200 | set_kernel_config CONFIG_NF_LOG_IPV4 m |
|
199 | 201 | set_kernel_config CONFIG_NF_LOG_IPV6 m |
|
200 | 202 | set_kernel_config CONFIG_NF_NAT_IPV4 m |
|
201 | 203 | set_kernel_config CONFIG_NF_NAT_IPV6 m |
|
202 | 204 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m |
|
203 | 205 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m |
|
204 | 206 | set_kernel_config CONFIG_NF_NAT_PPTP m |
|
205 | 207 | set_kernel_config CONFIG_NF_NAT_PROTO_GRE m |
|
206 | 208 | set_kernel_config CONFIG_NF_NAT_REDIRECT m |
|
207 | 209 | set_kernel_config CONFIG_NF_NAT_SIP m |
|
208 | 210 | set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m |
|
209 | 211 | set_kernel_config CONFIG_NF_NAT_TFTP m |
|
210 | 212 | set_kernel_config CONFIG_NF_REJECT_IPV4 m |
|
211 | 213 | set_kernel_config CONFIG_NF_REJECT_IPV6 m |
|
212 | 214 | set_kernel_config CONFIG_NF_TABLES m |
|
213 | 215 | set_kernel_config CONFIG_NF_TABLES_ARP m |
|
214 | 216 | set_kernel_config CONFIG_NF_TABLES_BRIDGE m |
|
215 | 217 | set_kernel_config CONFIG_NF_TABLES_INET m |
|
216 | 218 | set_kernel_config CONFIG_NF_TABLES_IPV4 m |
|
217 | 219 | set_kernel_config CONFIG_NF_TABLES_IPV6 m |
|
218 | 220 | set_kernel_config CONFIG_NF_TABLES_NETDEV m |
|
219 | 221 | fi |
|
220 | 222 | |
|
221 | 223 | # Enables BPF syscall for systemd-journald see https://github.com/torvalds/linux/blob/master/init/Kconfig#L848 or https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA |
|
222 | 224 | if [ "$KERNEL_BPF" = true ] ; then |
|
223 | 225 | set_kernel_config CONFIG_BPF_SYSCALL y |
|
224 | 226 | set_kernel_config CONFIG_BPF_EVENTS y |
|
225 | 227 | set_kernel_config CONFIG_BPF_STREAM_PARSER y |
|
226 | 228 | set_kernel_config CONFIG_CGROUP_BPF y |
|
227 | 229 | fi |
|
228 | 230 | |
|
229 | 231 | # KERNEL_DEFAULT_GOV was set by user |
|
230 | 232 | if ! [ "$KERNEL_DEFAULT_GOV" = POWERSAVE ] && [ -n "$KERNEL_DEFAULT_GOV" ]; then |
|
231 | 233 | # unset default governor |
|
232 | 234 | unset_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE |
|
233 | 235 | |
|
234 | 236 | case "$KERNEL_DEFAULT_GOV" in |
|
235 | 237 | "PERFORMANCE") |
|
236 | 238 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE y |
|
237 | 239 | ;; |
|
238 | 240 | "USERSPACE") |
|
239 | 241 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE y |
|
240 | 242 | ;; |
|
241 | 243 | "ONDEMAND") |
|
242 | 244 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND y |
|
243 | 245 | ;; |
|
244 | 246 | "CONSERVATIVE") |
|
245 | 247 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE y |
|
246 | 248 | ;; |
|
247 | 249 | "CONSERVATIVE") |
|
248 | 250 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL y |
|
249 | 251 | ;; |
|
250 | 252 | *) |
|
251 | 253 | echo "error: unsupported default cpu governor" |
|
252 | 254 | exit 1 |
|
253 | 255 | ;; |
|
254 | 256 | esac |
|
255 | 257 | fi |
|
256 | 258 | |
|
257 | 259 | |
|
258 | 260 | |
|
259 | 261 | #Revert to previous directory |
|
260 | 262 | cd "${WORKDIR}" || exit |
|
261 | 263 | |
|
262 | 264 | # Set kernel configuration parameters to enable qemu emulation |
|
263 | 265 | if [ "$ENABLE_QEMU" = true ] ; then |
|
264 | 266 | echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config |
|
265 | 267 | echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config |
|
266 | 268 | |
|
267 | 269 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
268 | 270 | { |
|
269 | 271 | echo "CONFIG_EMBEDDED=y" |
|
270 | 272 | echo "CONFIG_EXPERT=y" |
|
271 | 273 | echo "CONFIG_DAX=y" |
|
272 | 274 | echo "CONFIG_MD=y" |
|
273 | 275 | echo "CONFIG_BLK_DEV_MD=y" |
|
274 | 276 | echo "CONFIG_MD_AUTODETECT=y" |
|
275 | 277 | echo "CONFIG_BLK_DEV_DM=y" |
|
276 | 278 | echo "CONFIG_BLK_DEV_DM_BUILTIN=y" |
|
277 | 279 | echo "CONFIG_DM_CRYPT=y" |
|
278 | 280 | echo "CONFIG_CRYPTO_BLKCIPHER=y" |
|
279 | 281 | echo "CONFIG_CRYPTO_CBC=y" |
|
280 | 282 | echo "CONFIG_CRYPTO_XTS=y" |
|
281 | 283 | echo "CONFIG_CRYPTO_SHA512=y" |
|
282 | 284 | echo "CONFIG_CRYPTO_MANAGER=y" |
|
283 | 285 | } >> "${KERNEL_DIR}"/.config |
|
284 | 286 | fi |
|
285 | 287 | fi |
|
286 | 288 | |
|
287 | 289 | # Copy custom kernel configuration file |
|
288 | 290 | if [ -n "$KERNELSRC_USRCONFIG" ] ; then |
|
289 | 291 | cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config |
|
290 | 292 | fi |
|
291 | 293 | |
|
292 | 294 | # Set kernel configuration parameters to their default values |
|
293 | 295 | if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then |
|
294 | 296 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig |
|
295 | 297 | fi |
|
296 | 298 | |
|
297 | 299 | # Start menu-driven kernel configuration (interactive) |
|
298 | 300 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
299 | 301 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig |
|
300 | 302 | fi |
|
301 | 303 | # end if "$KERNELSRC_CONFIG" = true |
|
302 | 304 | fi |
|
303 | 305 | |
|
304 | 306 | # Use ccache to cross compile the kernel |
|
305 | 307 | if [ "$KERNEL_CCACHE" = true ] ; then |
|
306 | 308 | cc="ccache ${CROSS_COMPILE}gcc" |
|
307 | 309 | else |
|
308 | 310 | cc="${CROSS_COMPILE}gcc" |
|
309 | 311 | fi |
|
310 | 312 | |
|
311 | 313 | # Cross compile kernel and dtbs |
|
312 | 314 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs |
|
313 | 315 | |
|
314 | 316 | # Cross compile kernel modules |
|
315 | 317 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
316 | 318 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules |
|
317 | 319 | fi |
|
318 | 320 | # end if "$KERNELSRC_PREBUILT" = false |
|
319 | 321 | fi |
|
320 | 322 | |
|
321 | 323 | # Check if kernel compilation was successful |
|
322 | 324 | if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then |
|
323 | 325 | echo "error: kernel compilation failed! (kernel image not found)" |
|
324 | 326 | cleanup |
|
325 | 327 | exit 1 |
|
326 | 328 | fi |
|
327 | 329 | |
|
328 | 330 | # Install kernel modules |
|
329 | 331 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
330 | 332 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
331 | 333 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install |
|
332 | 334 | fi |
|
333 | 335 | else |
|
334 | 336 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
335 | 337 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install |
|
336 | 338 | fi |
|
337 | 339 | |
|
338 | 340 | # Install kernel firmware |
|
339 | 341 | if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then |
|
340 | 342 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install |
|
341 | 343 | fi |
|
342 | 344 | fi |
|
343 | 345 | |
|
344 | 346 | # Install kernel headers |
|
345 | 347 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then |
|
346 | 348 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install |
|
347 | 349 | fi |
|
348 | 350 | # make tar.gz kernel package - missing os bzw. modules |
|
349 | 351 | #** ** ** WARNING ** ** ** |
|
350 | 352 | #Your architecture did not define any architecture-dependent files |
|
351 | 353 | #to be placed into the tarball. Please add those to ./scripts/package/buildtar . |
|
352 | 354 | # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg |
|
353 | 355 | |
|
354 | 356 | # Prepare boot (firmware) directory |
|
355 | 357 | mkdir "${BOOT_DIR}" |
|
356 | 358 | |
|
357 | 359 | # Get kernel release version |
|
358 | 360 | KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release") |
|
359 | 361 | |
|
360 | 362 | # Copy kernel configuration file to the boot directory |
|
361 | 363 | install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" |
|
362 | 364 | |
|
363 | 365 | # Prepare device tree directory |
|
364 | 366 | mkdir "${BOOT_DIR}/overlays" |
|
365 | 367 | |
|
366 | 368 | # Ensure the proper .dtb is located |
|
367 | 369 | if [ "$KERNEL_ARCH" = "arm" ] ; then |
|
368 | 370 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do |
|
369 | 371 | if [ -f "${dtb}" ] ; then |
|
370 | 372 | install_readonly "${dtb}" "${BOOT_DIR}/" |
|
371 | 373 | fi |
|
372 | 374 | done |
|
373 | 375 | else |
|
374 | 376 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do |
|
375 | 377 | if [ -f "${dtb}" ] ; then |
|
376 | 378 | install_readonly "${dtb}" "${BOOT_DIR}/" |
|
377 | 379 | fi |
|
378 | 380 | done |
|
379 | 381 | fi |
|
380 | 382 | |
|
381 | 383 | # Copy compiled dtb device tree files |
|
382 | 384 | if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then |
|
383 | 385 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do |
|
384 | 386 | if [ -f "${dtb}" ] ; then |
|
385 | 387 | install_readonly "${dtb}" "${BOOT_DIR}/overlays/" |
|
386 | 388 | fi |
|
387 | 389 | done |
|
388 | 390 | |
|
389 | 391 | if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then |
|
390 | 392 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" |
|
391 | 393 | fi |
|
392 | 394 | fi |
|
393 | 395 | |
|
394 | 396 | if [ "$ENABLE_UBOOT" = false ] ; then |
|
395 | 397 | # Convert and copy kernel image to the boot directory |
|
396 | 398 | "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" |
|
397 | 399 | else |
|
398 | 400 | # Copy kernel image to the boot directory |
|
399 | 401 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" |
|
400 | 402 | fi |
|
401 | 403 | |
|
402 | 404 | # Remove kernel sources |
|
403 | 405 | if [ "$KERNEL_REMOVESRC" = true ] ; then |
|
404 | 406 | rm -fr "${KERNEL_DIR}" |
|
405 | 407 | else |
|
406 | 408 | # Prepare compiled kernel modules |
|
407 | 409 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
408 | 410 | if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then |
|
409 | 411 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare |
|
410 | 412 | fi |
|
411 | 413 | |
|
412 | 414 | # Create symlinks for kernel modules |
|
413 | 415 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build" |
|
414 | 416 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source" |
|
415 | 417 | fi |
|
416 | 418 | fi |
|
417 | 419 | |
|
418 | 420 | else # BUILD_KERNEL=false |
|
419 | 421 | # echo Install precompiled kernel... |
|
420 | 422 | # echo error: not implemented |
|
421 | 423 | if [ "$SET_ARCH" = 64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then |
|
422 | 424 | |
|
423 | 425 | # Use Sakakis modified kernel if ZSWAP is active |
|
424 | 426 | if [ "$KERNEL_ZSWAP" = true ] || [ "$KERNEL_VIRT" = true ] || [ "$KERNEL_NF" = true ] || [ "$KERNEL_BPF" = true ] ; then |
|
425 | 427 | RPI3_64_KERNEL_URL=RPI3_64_BIS_KERNEL_URL |
|
426 | 428 | fi |
|
427 | 429 | |
|
428 | 430 | # Create temporary directory for dl |
|
429 | 431 | temp_dir=$(as_nobody mktemp -d) |
|
430 | 432 | |
|
431 | 433 | # Fetch kernel dl |
|
432 | 434 | as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL" |
|
433 | 435 | |
|
434 | 436 | #extract download |
|
435 | 437 | tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}" |
|
436 | 438 | |
|
437 | 439 | #move extracted kernel to /boot/firmware |
|
438 | 440 | mkdir "${R}/boot/firmware" |
|
439 | 441 | cp "${temp_dir}"/boot/* "${R}"/boot/firmware/ |
|
440 | 442 | cp -r "${temp_dir}"/lib/* "${R}"/lib/ |
|
441 | 443 | |
|
442 | 444 | # Remove temporary directory for kernel sources |
|
443 | 445 | rm -fr "${temp_dir}" |
|
444 | 446 | |
|
445 | 447 | # Set permissions of the kernel sources |
|
446 | 448 | chown -R root:root "${R}/boot/firmware" |
|
447 | 449 | chown -R root:root "${R}/lib/modules" |
|
448 | 450 | fi |
|
449 | 451 | |
|
450 | 452 | # INstall Kernel from hypriot comptabile with all Raspberry PI |
|
451 | 453 | if [ "$SET_ARCH" = 32 ] ; then |
|
452 | 454 | # Create temporary directory for dl |
|
453 | 455 | temp_dir=$(as_nobody mktemp -d) |
|
454 | 456 | |
|
455 | 457 | # Fetch kernel |
|
456 | 458 | as_nobody wget -O "${temp_dir}"/kernel.deb -c "$RPI_32_KERNEL_URL" |
|
457 | 459 | |
|
458 | 460 | # Copy downloaded U-Boot sources |
|
459 | 461 | mv "${temp_dir}"/kernel.deb "${R}"/tmp/kernel.deb |
|
460 | 462 | |
|
461 | 463 | # Set permissions |
|
462 | 464 | chown -R root:root "${R}"/tmp/kernel.deb |
|
463 | 465 | |
|
464 | 466 | # Install kernel |
|
465 | 467 | chroot_exec dpkg -i /tmp/kernel.deb |
|
466 | 468 | |
|
467 | 469 | # move /boot to /boot/firmware to fit script env. |
|
468 | 470 | #mkdir "${BOOT_DIR}" |
|
469 | 471 | mkdir "${temp_dir}"/firmware |
|
470 | 472 | mv "${R}"/boot/* "${temp_dir}"/firmware/ |
|
471 | 473 | mv "${temp_dir}"/firmware "${R}"/boot/ |
|
472 | 474 | |
|
473 | 475 | #same for kernel headers |
|
474 | 476 | if [ "$KERNEL_HEADERS" = true ] ; then |
|
475 | 477 | # Fetch kernel header |
|
476 | 478 | as_nobody wget -O "${temp_dir}"/kernel-header.deb -c "$RPI_32_KERNELHEADER_URL" |
|
477 | 479 | mv "${temp_dir}"/kernel-header.deb "${R}"/tmp/kernel-header.deb |
|
478 | 480 | chown -R root:root "${R}"/tmp/kernel-header.deb |
|
479 | 481 | # Install kernel header |
|
480 | 482 | chroot_exec dpkg -i /tmp/kernel-header.deb |
|
481 | 483 | rm -f "${R}"/tmp/kernel-header.deb |
|
482 | 484 | fi |
|
483 | 485 | |
|
484 | 486 | # Remove temporary directory and files |
|
485 | 487 | rm -fr "${temp_dir}" |
|
486 | 488 | rm -f "${R}"/tmp/kernel.deb |
|
487 | 489 | fi |
|
488 | 490 | |
|
489 | 491 | # Check if kernel installation was successful |
|
490 | 492 | KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)" |
|
491 | 493 | if [ -z "$KERNEL" ] ; then |
|
492 | 494 | echo "error: kernel installation failed! (/boot/kernel* not found)" |
|
493 | 495 | cleanup |
|
494 | 496 | exit 1 |
|
495 | 497 | fi |
|
496 | 498 | fi |
@@ -1,852 +1,854 | |||
|
1 | 1 | #!/bin/sh |
|
2 | 2 | ######################################################################## |
|
3 | 3 | # rpi23-gen-image.sh 2015-2017 |
|
4 | 4 | # |
|
5 | 5 | # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3 |
|
6 | 6 | # |
|
7 | 7 | # This program is free software; you can redistribute it and/or |
|
8 | 8 | # modify it under the terms of the GNU General Public License |
|
9 | 9 | # as published by the Free Software Foundation; either version 2 |
|
10 | 10 | # of the License, or (at your option) any later version. |
|
11 | 11 | # |
|
12 | 12 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> |
|
13 | 13 | # |
|
14 | 14 | # Big thanks for patches and enhancements by 20+ github contributors! |
|
15 | 15 | ######################################################################## |
|
16 | 16 | |
|
17 | 17 | # Are we running as root? |
|
18 | 18 | if [ "$(id -u)" -ne "0" ] ; then |
|
19 | 19 | echo "error: this script must be executed with root privileges!" |
|
20 | 20 | exit 1 |
|
21 | 21 | fi |
|
22 | 22 | |
|
23 | 23 | # Check if ./functions.sh script exists |
|
24 | 24 | if [ ! -r "./functions.sh" ] ; then |
|
25 | 25 | echo "error: './functions.sh' required script not found!" |
|
26 | 26 | exit 1 |
|
27 | 27 | fi |
|
28 | 28 | |
|
29 | 29 | # Load utility functions |
|
30 | 30 | . ./functions.sh |
|
31 | 31 | |
|
32 | 32 | # Load parameters from configuration template file |
|
33 | 33 | if [ -n "$CONFIG_TEMPLATE" ] ; then |
|
34 | 34 | use_template |
|
35 | 35 | fi |
|
36 | 36 | |
|
37 | 37 | # Introduce settings |
|
38 | 38 | set -e |
|
39 | 39 | echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n" |
|
40 | 40 | set -x |
|
41 | 41 | |
|
42 | 42 | # Raspberry Pi model configuration |
|
43 | 43 | RPI_MODEL=${RPI_MODEL:=2} |
|
44 | 44 | |
|
45 | 45 | # Debian release |
|
46 | 46 | RELEASE=${RELEASE:=buster} |
|
47 | 47 | |
|
48 | 48 | # Kernel Branch |
|
49 | 49 | KERNEL_BRANCH=${KERNEL_BRANCH:=""} |
|
50 | 50 | |
|
51 | 51 | # URLs |
|
52 | 52 | KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux} |
|
53 | 53 | FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot} |
|
54 | 54 | WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm} |
|
55 | 55 | COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian} |
|
56 | 56 | FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git} |
|
57 | 57 | UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} |
|
58 | 58 | VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} |
|
59 | #BIS= Kernel has KVM and zswap enabled | |
|
60 | RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz} | |
|
61 | #default bcmrpi3_defconfig target kernel | |
|
62 | RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz} | |
|
63 | #enhanced kernel | |
|
64 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL} | |
|
65 | 59 | BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} |
|
66 | 60 | NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git} |
|
67 | 61 | SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git} |
|
62 | ||
|
63 | # Kernel deb packages for 32bit kernel | |
|
68 | 64 | RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb} |
|
69 | 65 | RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb} |
|
66 | # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used | |
|
67 | RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz} | |
|
68 | # Default precompiled 64bit kernel | |
|
69 | RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz} | |
|
70 | # Generic | |
|
71 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL} | |
|
70 | 72 | |
|
71 | 73 | # Build directories |
|
72 | 74 | WORKDIR=$(pwd) |
|
73 | 75 | BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}} |
|
74 | 76 | BUILDDIR="${BASEDIR}/build" |
|
75 | 77 | |
|
76 | 78 | # Chroot directories |
|
77 | 79 | R="${BUILDDIR}/chroot" |
|
78 | 80 | ETC_DIR="${R}/etc" |
|
79 | 81 | LIB_DIR="${R}/lib" |
|
80 | 82 | BOOT_DIR="${R}/boot/firmware" |
|
81 | 83 | KERNEL_DIR="${R}/usr/src/linux" |
|
82 | 84 | WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" |
|
83 | 85 | BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt" |
|
84 | 86 | |
|
85 | 87 | # Firmware directory: Blank if download from github |
|
86 | 88 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} |
|
87 | 89 | |
|
88 | 90 | # General settings |
|
89 | 91 | SET_ARCH=${SET_ARCH:=32} |
|
90 | 92 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} |
|
91 | 93 | PASSWORD=${PASSWORD:=raspberry} |
|
92 | 94 | USER_PASSWORD=${USER_PASSWORD:=raspberry} |
|
93 | 95 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} |
|
94 | 96 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} |
|
95 | 97 | EXPANDROOT=${EXPANDROOT:=true} |
|
96 | 98 | |
|
97 | 99 | # Keyboard settings |
|
98 | 100 | XKB_MODEL=${XKB_MODEL:=""} |
|
99 | 101 | XKB_LAYOUT=${XKB_LAYOUT:=""} |
|
100 | 102 | XKB_VARIANT=${XKB_VARIANT:=""} |
|
101 | 103 | XKB_OPTIONS=${XKB_OPTIONS:=""} |
|
102 | 104 | |
|
103 | 105 | # Network settings (DHCP) |
|
104 | 106 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
105 | 107 | |
|
106 | 108 | # Network settings (static) |
|
107 | 109 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
108 | 110 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
109 | 111 | NET_DNS_1=${NET_DNS_1:=""} |
|
110 | 112 | NET_DNS_2=${NET_DNS_2:=""} |
|
111 | 113 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} |
|
112 | 114 | NET_NTP_1=${NET_NTP_1:=""} |
|
113 | 115 | NET_NTP_2=${NET_NTP_2:=""} |
|
114 | 116 | |
|
115 | 117 | # APT settings |
|
116 | 118 | APT_PROXY=${APT_PROXY:=""} |
|
117 | 119 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} |
|
118 | 120 | |
|
119 | 121 | # Feature settings |
|
120 | 122 | ENABLE_PRINTK=${ENABLE_PRINTK:=false} |
|
121 | 123 | ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false} |
|
122 | 124 | ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false} |
|
123 | 125 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} |
|
124 | 126 | ENABLE_I2C=${ENABLE_I2C:=false} |
|
125 | 127 | ENABLE_SPI=${ENABLE_SPI:=false} |
|
126 | 128 | ENABLE_IPV6=${ENABLE_IPV6:=true} |
|
127 | 129 | ENABLE_SSHD=${ENABLE_SSHD:=true} |
|
128 | 130 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} |
|
129 | 131 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} |
|
130 | 132 | ENABLE_SOUND=${ENABLE_SOUND:=true} |
|
131 | 133 | ENABLE_DBUS=${ENABLE_DBUS:=true} |
|
132 | 134 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} |
|
133 | 135 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} |
|
134 | 136 | ENABLE_XORG=${ENABLE_XORG:=false} |
|
135 | 137 | ENABLE_WM=${ENABLE_WM:=""} |
|
136 | 138 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} |
|
137 | 139 | ENABLE_USER=${ENABLE_USER:=true} |
|
138 | 140 | USER_NAME=${USER_NAME:="pi"} |
|
139 | 141 | ENABLE_ROOT=${ENABLE_ROOT:=false} |
|
140 | 142 | ENABLE_QEMU=${ENABLE_QEMU:=false} |
|
141 | 143 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} |
|
142 | 144 | |
|
143 | 145 | # SSH settings |
|
144 | 146 | SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} |
|
145 | 147 | SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} |
|
146 | 148 | SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} |
|
147 | 149 | SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} |
|
148 | 150 | SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} |
|
149 | 151 | |
|
150 | 152 | # Advanced settings |
|
151 | 153 | ENABLE_SYSTEMDSWAP=${ENABLE_MINBASE:=false} |
|
152 | 154 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} |
|
153 | 155 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} |
|
154 | 156 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} |
|
155 | 157 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} |
|
156 | 158 | ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false} |
|
157 | 159 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
158 | 160 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false} |
|
159 | 161 | ENABLE_NEXMON=${ENABLE_NEXMON:=false} |
|
160 | 162 | VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} |
|
161 | 163 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} |
|
162 | 164 | NEXMONSRC_DIR=${NEXMONSRC_DIR:=""} |
|
163 | 165 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
164 | 166 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
165 | 167 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} |
|
166 | 168 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} |
|
167 | 169 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} |
|
168 | 170 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} |
|
169 | 171 | |
|
170 | 172 | # Kernel compilation settings |
|
171 | 173 | BUILD_KERNEL=${BUILD_KERNEL:=true} |
|
172 | 174 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} |
|
173 | 175 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
174 | 176 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
175 | 177 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
176 | 178 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} |
|
177 | 179 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} |
|
178 | 180 | KERNEL_CCACHE=${KERNEL_CCACHE:=false} |
|
179 | 181 | KERNEL_ZSWAP=${KERNEL_ZSWAP:=false} |
|
180 | 182 | KERNEL_VIRT=${KERNEL_VIRT:=false} |
|
181 | 183 | KERNEL_BPF=${KERNEL_BPF:=false} |
|
182 | 184 | KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=POWERSAVE} |
|
183 | 185 | |
|
184 | 186 | # Kernel compilation from source directory settings |
|
185 | 187 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} |
|
186 | 188 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} |
|
187 | 189 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
188 | 190 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
189 | 191 | |
|
190 | 192 | # Reduce disk usage settings |
|
191 | 193 | REDUCE_APT=${REDUCE_APT:=true} |
|
192 | 194 | REDUCE_DOC=${REDUCE_DOC:=true} |
|
193 | 195 | REDUCE_MAN=${REDUCE_MAN:=true} |
|
194 | 196 | REDUCE_VIM=${REDUCE_VIM:=false} |
|
195 | 197 | REDUCE_BASH=${REDUCE_BASH:=false} |
|
196 | 198 | REDUCE_HWDB=${REDUCE_HWDB:=true} |
|
197 | 199 | REDUCE_SSHD=${REDUCE_SSHD:=true} |
|
198 | 200 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} |
|
199 | 201 | |
|
200 | 202 | # Encrypted filesystem settings |
|
201 | 203 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} |
|
202 | 204 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} |
|
203 | 205 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} |
|
204 | 206 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} |
|
205 | 207 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} |
|
206 | 208 | #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup |
|
207 | 209 | CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false} |
|
208 | 210 | #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated |
|
209 | 211 | CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""} |
|
210 | 212 | |
|
211 | 213 | # Chroot scripts directory |
|
212 | 214 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
213 | 215 | |
|
214 | 216 | # Packages required in the chroot build environment |
|
215 | 217 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
216 | 218 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd" |
|
217 | 219 | |
|
218 | 220 | #Packages to exclude from chroot build environment |
|
219 | 221 | APT_EXCLUDES=${APT_EXCLUDES:=""} |
|
220 | 222 | |
|
221 | 223 | # Packages required for bootstrapping |
|
222 | 224 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt" |
|
223 | 225 | MISSING_PACKAGES="" |
|
224 | 226 | |
|
225 | 227 | # Packages installed for c/c++ build environment in chroot (keep empty) |
|
226 | 228 | COMPILER_PACKAGES="" |
|
227 | 229 | |
|
228 | 230 | #Check if apt-cacher-ng has port 3142 open and set APT_PROXY |
|
229 | 231 | APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d') |
|
230 | 232 | if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then |
|
231 | 233 | APT_PROXY=http://127.0.0.1:3142/ |
|
232 | 234 | fi |
|
233 | 235 | |
|
234 | 236 | #netselect-apt does not know buster yet |
|
235 | 237 | if [ "$RELEASE" = "buster" ] ; then |
|
236 | 238 | RLS=testing |
|
237 | 239 | else |
|
238 | 240 | RLS="$RELEASE" |
|
239 | 241 | fi |
|
240 | 242 | |
|
241 | 243 | if [ -f "$(pwd)/files/apt/sources.list" ] ; then |
|
242 | 244 | rm "$(pwd)/files/apt/sources.list" |
|
243 | 245 | fi |
|
244 | 246 | |
|
245 | 247 | if [ "$ENABLE_NONFREE" = true ] ; then |
|
246 | 248 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
247 | 249 | else |
|
248 | 250 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
249 | 251 | fi |
|
250 | 252 | |
|
251 | 253 | #sed and cut the result string so we can use it as APT_SERVER |
|
252 | 254 | APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|') |
|
253 | 255 | |
|
254 | 256 | #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! |
|
255 | 257 | if [ -n "$SET_ARCH" ] ; then |
|
256 | 258 | # 64 bit configuration |
|
257 | 259 | if [ "$SET_ARCH" = 64 ] ; then |
|
258 | 260 | # General 64 bit depended settings |
|
259 | 261 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} |
|
260 | 262 | KERNEL_ARCH=${KERNEL_ARCH:=arm64} |
|
261 | 263 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} |
|
262 | 264 | |
|
263 | 265 | # Board specific settings |
|
264 | 266 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
265 | 267 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" |
|
266 | 268 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} |
|
267 | 269 | RELEASE_ARCH=${RELEASE_ARCH:=arm64} |
|
268 | 270 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} |
|
269 | 271 | CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} |
|
270 | 272 | else |
|
271 | 273 | echo "error: Only Raspberry PI 3 and 3B+ support 64 bit" |
|
272 | 274 | exit 1 |
|
273 | 275 | fi |
|
274 | 276 | fi |
|
275 | 277 | |
|
276 | 278 | # 32 bit configuration |
|
277 | 279 | if [ "$SET_ARCH" = 32 ] ; then |
|
278 | 280 | # General 32 bit dependend settings |
|
279 | 281 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
280 | 282 | KERNEL_ARCH=${KERNEL_ARCH:=arm} |
|
281 | 283 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} |
|
282 | 284 | |
|
283 | 285 | # Hardware specific settings |
|
284 | 286 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then |
|
285 | 287 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" |
|
286 | 288 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} |
|
287 | 289 | RELEASE_ARCH=${RELEASE_ARCH:=armel} |
|
288 | 290 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} |
|
289 | 291 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} |
|
290 | 292 | fi |
|
291 | 293 | |
|
292 | 294 | # Hardware specific settings |
|
293 | 295 | if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
294 | 296 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
295 | 297 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
296 | 298 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} |
|
297 | 299 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} |
|
298 | 300 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} |
|
299 | 301 | fi |
|
300 | 302 | fi |
|
301 | 303 | #SET_ARCH not set |
|
302 | 304 | else |
|
303 | 305 | echo "error: Please set '32' or '64' as value for SET_ARCH" |
|
304 | 306 | exit 1 |
|
305 | 307 | fi |
|
306 | 308 | # Device specific configuration and U-Boot configuration |
|
307 | 309 | case "$RPI_MODEL" in |
|
308 | 310 | 0) |
|
309 | 311 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} |
|
310 | 312 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
311 | 313 | ;; |
|
312 | 314 | 1) |
|
313 | 315 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} |
|
314 | 316 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
315 | 317 | ;; |
|
316 | 318 | 1P) |
|
317 | 319 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} |
|
318 | 320 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
319 | 321 | ;; |
|
320 | 322 | 2) |
|
321 | 323 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} |
|
322 | 324 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} |
|
323 | 325 | ;; |
|
324 | 326 | 3) |
|
325 | 327 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
326 | 328 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
327 | 329 | ;; |
|
328 | 330 | 3P) |
|
329 | 331 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
330 | 332 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
331 | 333 | ;; |
|
332 | 334 | *) |
|
333 | 335 | echo "error: Raspberry Pi model $RPI_MODEL is not supported!" |
|
334 | 336 | exit 1 |
|
335 | 337 | ;; |
|
336 | 338 | esac |
|
337 | 339 | |
|
338 | 340 | # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard |
|
339 | 341 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
340 | 342 | # Include bluetooth packages on supported boards |
|
341 | 343 | if [ "$ENABLE_BLUETOOTH" = true ] && [ "$ENABLE_CONSOLE" = false ]; then |
|
342 | 344 | APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" |
|
343 | 345 | fi |
|
344 | 346 | else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard |
|
345 | 347 | # Check if the internal wireless interface is not supported by the RPi model |
|
346 | 348 | if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then |
|
347 | 349 | echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth" |
|
348 | 350 | exit 1 |
|
349 | 351 | fi |
|
350 | 352 | fi |
|
351 | 353 | |
|
352 | 354 | # Prepare date string for default image file name |
|
353 | 355 | DATE="$(date +%Y-%m-%d)" |
|
354 | 356 | if [ -z "$KERNEL_BRANCH" ] ; then |
|
355 | 357 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
356 | 358 | else |
|
357 | 359 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
358 | 360 | fi |
|
359 | 361 | |
|
360 | 362 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported |
|
361 | 363 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then |
|
362 | 364 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then |
|
363 | 365 | echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" |
|
364 | 366 | exit 1 |
|
365 | 367 | fi |
|
366 | 368 | fi |
|
367 | 369 | |
|
368 | 370 | set +x |
|
369 | 371 | |
|
370 | 372 | # Add cmake to compile videocore sources |
|
371 | 373 | if [ "$ENABLE_VIDEOCORE" = true ] ; then |
|
372 | 374 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" |
|
373 | 375 | fi |
|
374 | 376 | |
|
375 | 377 | # Add deps for nexmon |
|
376 | 378 | if [ "$ENABLE_NEXMON" = true ] ; then |
|
377 | 379 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES},libgmp3-dev,gawk,qpdf,bison,flex,make,autoconf,automake,build-essential,libtool" |
|
378 | 380 | fi |
|
379 | 381 | |
|
380 | 382 | # Add libncurses5 to enable kernel menuconfig |
|
381 | 383 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
382 | 384 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" |
|
383 | 385 | fi |
|
384 | 386 | |
|
385 | 387 | # Add ccache compiler cache for (faster) kernel cross (re)compilation |
|
386 | 388 | if [ "$KERNEL_CCACHE" = true ] ; then |
|
387 | 389 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" |
|
388 | 390 | fi |
|
389 | 391 | |
|
390 | 392 | # Add cryptsetup package to enable filesystem encryption |
|
391 | 393 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
392 | 394 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" |
|
393 | 395 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" |
|
394 | 396 | |
|
395 | 397 | #If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package |
|
396 | 398 | if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then |
|
397 | 399 | APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs" |
|
398 | 400 | fi |
|
399 | 401 | |
|
400 | 402 | if [ -z "$CRYPTFS_PASSWORD" ] ; then |
|
401 | 403 | echo "error: no password defined (CRYPTFS_PASSWORD)!" |
|
402 | 404 | exit 1 |
|
403 | 405 | fi |
|
404 | 406 | ENABLE_INITRAMFS=true |
|
405 | 407 | fi |
|
406 | 408 | |
|
407 | 409 | # Add initramfs generation tools |
|
408 | 410 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
409 | 411 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" |
|
410 | 412 | fi |
|
411 | 413 | |
|
412 | 414 | # Add device-tree-compiler required for building the U-Boot bootloader |
|
413 | 415 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
414 | 416 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" |
|
415 | 417 | else |
|
416 | 418 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
417 | 419 | echo "error: Enabling UBOOTUSB requires u-boot to be enabled" |
|
418 | 420 | exit 1 |
|
419 | 421 | fi |
|
420 | 422 | fi |
|
421 | 423 | |
|
422 | 424 | # Check if root SSH (v2) public key file exists |
|
423 | 425 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then |
|
424 | 426 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then |
|
425 | 427 | echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" |
|
426 | 428 | exit 1 |
|
427 | 429 | fi |
|
428 | 430 | fi |
|
429 | 431 | |
|
430 | 432 | # Check if $USER_NAME SSH (v2) public key file exists |
|
431 | 433 | if [ -n "$SSH_USER_PUB_KEY" ] ; then |
|
432 | 434 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then |
|
433 | 435 | echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" |
|
434 | 436 | exit 1 |
|
435 | 437 | fi |
|
436 | 438 | fi |
|
437 | 439 | |
|
438 | 440 | # Check if all required packages are installed on the build system |
|
439 | 441 | for package in $REQUIRED_PACKAGES ; do |
|
440 | 442 | if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then |
|
441 | 443 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
442 | 444 | fi |
|
443 | 445 | done |
|
444 | 446 | |
|
445 | 447 | # If there are missing packages ask confirmation for install, or exit |
|
446 | 448 | if [ -n "$MISSING_PACKAGES" ] ; then |
|
447 | 449 | echo "the following packages needed by this script are not installed:" |
|
448 | 450 | echo "$MISSING_PACKAGES" |
|
449 | 451 | |
|
450 | 452 | printf "\ndo you want to install the missing packages right now? [y/n] " |
|
451 | 453 | read -r confirm |
|
452 | 454 | [ "$confirm" != "y" ] && exit 1 |
|
453 | 455 | |
|
454 | 456 | # Make sure all missing required packages are installed |
|
455 | 457 | apt-get -qq -y install "${MISSING_PACKAGES}" |
|
456 | 458 | fi |
|
457 | 459 | |
|
458 | 460 | # Check if ./bootstrap.d directory exists |
|
459 | 461 | if [ ! -d "./bootstrap.d/" ] ; then |
|
460 | 462 | echo "error: './bootstrap.d' required directory not found!" |
|
461 | 463 | exit 1 |
|
462 | 464 | fi |
|
463 | 465 | |
|
464 | 466 | # Check if ./files directory exists |
|
465 | 467 | if [ ! -d "./files/" ] ; then |
|
466 | 468 | echo "error: './files' required directory not found!" |
|
467 | 469 | exit 1 |
|
468 | 470 | fi |
|
469 | 471 | |
|
470 | 472 | # Check if specified KERNELSRC_DIR directory exists |
|
471 | 473 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
472 | 474 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" |
|
473 | 475 | exit 1 |
|
474 | 476 | fi |
|
475 | 477 | |
|
476 | 478 | # Check if specified UBOOTSRC_DIR directory exists |
|
477 | 479 | if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then |
|
478 | 480 | echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" |
|
479 | 481 | exit 1 |
|
480 | 482 | fi |
|
481 | 483 | |
|
482 | 484 | # Check if specified VIDEOCORESRC_DIR directory exists |
|
483 | 485 | if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then |
|
484 | 486 | echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" |
|
485 | 487 | exit 1 |
|
486 | 488 | fi |
|
487 | 489 | |
|
488 | 490 | # Check if specified FBTURBOSRC_DIR directory exists |
|
489 | 491 | if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then |
|
490 | 492 | echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" |
|
491 | 493 | exit 1 |
|
492 | 494 | fi |
|
493 | 495 | |
|
494 | 496 | # Check if specified NEXMONSRC_DIR directory exists |
|
495 | 497 | if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then |
|
496 | 498 | echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!" |
|
497 | 499 | exit 1 |
|
498 | 500 | fi |
|
499 | 501 | |
|
500 | 502 | # Check if specified CHROOT_SCRIPTS directory exists |
|
501 | 503 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
502 | 504 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" |
|
503 | 505 | exit 1 |
|
504 | 506 | fi |
|
505 | 507 | |
|
506 | 508 | # Check if specified device mapping already exists (will be used by cryptsetup) |
|
507 | 509 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then |
|
508 | 510 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" |
|
509 | 511 | exit 1 |
|
510 | 512 | fi |
|
511 | 513 | |
|
512 | 514 | # Don't clobber an old build |
|
513 | 515 | if [ -e "$BUILDDIR" ] ; then |
|
514 | 516 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
515 | 517 | exit 1 |
|
516 | 518 | fi |
|
517 | 519 | |
|
518 | 520 | # Setup chroot directory |
|
519 | 521 | mkdir -p "${R}" |
|
520 | 522 | |
|
521 | 523 | # Check if build directory has enough of free disk space >512MB |
|
522 | 524 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then |
|
523 | 525 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" |
|
524 | 526 | exit 1 |
|
525 | 527 | fi |
|
526 | 528 | |
|
527 | 529 | set -x |
|
528 | 530 | |
|
529 | 531 | # Call "cleanup" function on various signals and errors |
|
530 | 532 | trap cleanup 0 1 2 3 6 |
|
531 | 533 | |
|
532 | 534 | # Add required packages for the minbase installation |
|
533 | 535 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
534 | 536 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" |
|
535 | 537 | fi |
|
536 | 538 | |
|
537 | 539 | # Add parted package, required to get partprobe utility |
|
538 | 540 | if [ "$EXPANDROOT" = true ] ; then |
|
539 | 541 | APT_INCLUDES="${APT_INCLUDES},parted" |
|
540 | 542 | fi |
|
541 | 543 | |
|
542 | 544 | # Add dbus package, recommended if using systemd |
|
543 | 545 | if [ "$ENABLE_DBUS" = true ] ; then |
|
544 | 546 | APT_INCLUDES="${APT_INCLUDES},dbus" |
|
545 | 547 | fi |
|
546 | 548 | |
|
547 | 549 | # Add iptables IPv4/IPv6 package |
|
548 | 550 | if [ "$ENABLE_IPTABLES" = true ] ; then |
|
549 | 551 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" |
|
550 | 552 | fi |
|
551 | 553 | |
|
552 | 554 | # Add openssh server package |
|
553 | 555 | if [ "$ENABLE_SSHD" = true ] ; then |
|
554 | 556 | APT_INCLUDES="${APT_INCLUDES},openssh-server" |
|
555 | 557 | fi |
|
556 | 558 | |
|
557 | 559 | # Add alsa-utils package |
|
558 | 560 | if [ "$ENABLE_SOUND" = true ] ; then |
|
559 | 561 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" |
|
560 | 562 | fi |
|
561 | 563 | |
|
562 | 564 | # Add rng-tools package |
|
563 | 565 | if [ "$ENABLE_HWRANDOM" = true ] ; then |
|
564 | 566 | APT_INCLUDES="${APT_INCLUDES},rng-tools" |
|
565 | 567 | fi |
|
566 | 568 | |
|
567 | 569 | # Add fbturbo video driver |
|
568 | 570 | if [ "$ENABLE_FBTURBO" = true ] ; then |
|
569 | 571 | # Enable xorg package dependencies |
|
570 | 572 | ENABLE_XORG=true |
|
571 | 573 | fi |
|
572 | 574 | |
|
573 | 575 | # Add user defined window manager package |
|
574 | 576 | if [ -n "$ENABLE_WM" ] ; then |
|
575 | 577 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" |
|
576 | 578 | |
|
577 | 579 | # Enable xorg package dependencies |
|
578 | 580 | ENABLE_XORG=true |
|
579 | 581 | fi |
|
580 | 582 | |
|
581 | 583 | # Add xorg package |
|
582 | 584 | if [ "$ENABLE_XORG" = true ] ; then |
|
583 | 585 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" |
|
584 | 586 | fi |
|
585 | 587 | |
|
586 | 588 | # Replace selected packages with smaller clones |
|
587 | 589 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
588 | 590 | # Add levee package instead of vim-tiny |
|
589 | 591 | if [ "$REDUCE_VIM" = true ] ; then |
|
590 | 592 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" |
|
591 | 593 | fi |
|
592 | 594 | |
|
593 | 595 | # Add dropbear package instead of openssh-server |
|
594 | 596 | if [ "$REDUCE_SSHD" = true ] ; then |
|
595 | 597 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" |
|
596 | 598 | fi |
|
597 | 599 | fi |
|
598 | 600 | |
|
599 | 601 | # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available |
|
600 | 602 | if [ "$ENABLE_SYSVINIT" = false ] ; then |
|
601 | 603 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" |
|
602 | 604 | fi |
|
603 | 605 | |
|
604 | 606 | # Configure kernel sources if no KERNELSRC_DIR |
|
605 | 607 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
606 | 608 | KERNELSRC_CONFIG=true |
|
607 | 609 | fi |
|
608 | 610 | |
|
609 | 611 | # Configure reduced kernel |
|
610 | 612 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
611 | 613 | KERNELSRC_CONFIG=false |
|
612 | 614 | fi |
|
613 | 615 | |
|
614 | 616 | # Configure qemu compatible kernel |
|
615 | 617 | if [ "$ENABLE_QEMU" = true ] ; then |
|
616 | 618 | DTB_FILE=vexpress-v2p-ca15_a7.dtb |
|
617 | 619 | UBOOT_CONFIG=vexpress_ca15_tc2_defconfig |
|
618 | 620 | KERNEL_DEFCONFIG="vexpress_defconfig" |
|
619 | 621 | if [ "$KERNEL_MENUCONFIG" = false ] ; then |
|
620 | 622 | KERNEL_OLDDEFCONFIG=true |
|
621 | 623 | fi |
|
622 | 624 | fi |
|
623 | 625 | |
|
624 | 626 | # Execute bootstrap scripts |
|
625 | 627 | for SCRIPT in bootstrap.d/*.sh; do |
|
626 | 628 | head -n 3 "$SCRIPT" |
|
627 | 629 | . "$SCRIPT" |
|
628 | 630 | done |
|
629 | 631 | |
|
630 | 632 | ## Execute custom bootstrap scripts |
|
631 | 633 | if [ -d "custom.d" ] ; then |
|
632 | 634 | for SCRIPT in custom.d/*.sh; do |
|
633 | 635 | . "$SCRIPT" |
|
634 | 636 | done |
|
635 | 637 | fi |
|
636 | 638 | |
|
637 | 639 | # Execute custom scripts inside the chroot |
|
638 | 640 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
639 | 641 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
640 | 642 | chroot_exec /bin/bash -x <<'EOF' |
|
641 | 643 | for SCRIPT in /chroot_scripts/* ; do |
|
642 | 644 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
643 | 645 | $SCRIPT |
|
644 | 646 | fi |
|
645 | 647 | done |
|
646 | 648 | EOF |
|
647 | 649 | rm -rf "${R}/chroot_scripts" |
|
648 | 650 | fi |
|
649 | 651 | |
|
650 | 652 | # Remove c/c++ build environment from the chroot |
|
651 | 653 | chroot_remove_cc |
|
652 | 654 | |
|
653 | 655 | # Generate required machine-id |
|
654 | 656 | MACHINE_ID=$(dbus-uuidgen) |
|
655 | 657 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" |
|
656 | 658 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" |
|
657 | 659 | |
|
658 | 660 | # APT Cleanup |
|
659 | 661 | chroot_exec apt-get -y clean |
|
660 | 662 | chroot_exec apt-get -y autoclean |
|
661 | 663 | chroot_exec apt-get -y autoremove |
|
662 | 664 | |
|
663 | 665 | # Unmount mounted filesystems |
|
664 | 666 | umount -l "${R}/proc" |
|
665 | 667 | umount -l "${R}/sys" |
|
666 | 668 | |
|
667 | 669 | # Clean up directories |
|
668 | 670 | rm -rf "${R}/run/*" |
|
669 | 671 | rm -rf "${R}/tmp/*" |
|
670 | 672 | |
|
671 | 673 | # Clean up files |
|
672 | 674 | rm -f "${ETC_DIR}/ssh/ssh_host_*" |
|
673 | 675 | rm -f "${ETC_DIR}/dropbear/dropbear_*" |
|
674 | 676 | rm -f "${ETC_DIR}/apt/sources.list.save" |
|
675 | 677 | rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" |
|
676 | 678 | rm -f "${ETC_DIR}/*-" |
|
677 | 679 | rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" |
|
678 | 680 | rm -f "${ETC_DIR}/resolv.conf" |
|
679 | 681 | rm -f "${R}/root/.bash_history" |
|
680 | 682 | rm -f "${R}/var/lib/urandom/random-seed" |
|
681 | 683 | rm -f "${R}/initrd.img" |
|
682 | 684 | rm -f "${R}/vmlinuz" |
|
683 | 685 | rm -f "${R}${QEMU_BINARY}" |
|
684 | 686 | |
|
685 | 687 | if [ "$ENABLE_QEMU" = true ] ; then |
|
686 | 688 | # Setup QEMU directory |
|
687 | 689 | mkdir "${BASEDIR}/qemu" |
|
688 | 690 | |
|
689 | 691 | # Copy kernel image to QEMU directory |
|
690 | 692 | install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" |
|
691 | 693 | |
|
692 | 694 | # Copy kernel config to QEMU directory |
|
693 | 695 | install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" |
|
694 | 696 | |
|
695 | 697 | # Copy kernel dtbs to QEMU directory |
|
696 | 698 | for dtb in "${BOOT_DIR}/"*.dtb ; do |
|
697 | 699 | if [ -f "${dtb}" ] ; then |
|
698 | 700 | install_readonly "${dtb}" "${BASEDIR}/qemu/" |
|
699 | 701 | fi |
|
700 | 702 | done |
|
701 | 703 | |
|
702 | 704 | # Copy kernel overlays to QEMU directory |
|
703 | 705 | if [ -d "${BOOT_DIR}/overlays" ] ; then |
|
704 | 706 | # Setup overlays dtbs directory |
|
705 | 707 | mkdir "${BASEDIR}/qemu/overlays" |
|
706 | 708 | |
|
707 | 709 | for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do |
|
708 | 710 | if [ -f "${dtb}" ] ; then |
|
709 | 711 | install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" |
|
710 | 712 | fi |
|
711 | 713 | done |
|
712 | 714 | fi |
|
713 | 715 | |
|
714 | 716 | # Copy u-boot files to QEMU directory |
|
715 | 717 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
716 | 718 | if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then |
|
717 | 719 | install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" |
|
718 | 720 | fi |
|
719 | 721 | if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then |
|
720 | 722 | install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" |
|
721 | 723 | fi |
|
722 | 724 | if [ -f "${BOOT_DIR}/boot.scr" ] ; then |
|
723 | 725 | install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" |
|
724 | 726 | fi |
|
725 | 727 | fi |
|
726 | 728 | |
|
727 | 729 | # Copy initramfs to QEMU directory |
|
728 | 730 | if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then |
|
729 | 731 | install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" |
|
730 | 732 | fi |
|
731 | 733 | fi |
|
732 | 734 | |
|
733 | 735 | # Calculate size of the chroot directory in KB |
|
734 | 736 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") |
|
735 | 737 | |
|
736 | 738 | # Calculate the amount of needed 512 Byte sectors |
|
737 | 739 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
738 | 740 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) |
|
739 | 741 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") |
|
740 | 742 | |
|
741 | 743 | # The root partition is EXT4 |
|
742 | 744 | # This means more space than the actual used space of the chroot is used. |
|
743 | 745 | # As overhead for journaling and reserved blocks 35% are added. |
|
744 | 746 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) |
|
745 | 747 | |
|
746 | 748 | # Calculate required image size in 512 Byte sectors |
|
747 | 749 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") |
|
748 | 750 | |
|
749 | 751 | # Prepare image file |
|
750 | 752 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
751 | 753 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" |
|
752 | 754 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" |
|
753 | 755 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" |
|
754 | 756 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" |
|
755 | 757 | |
|
756 | 758 | # Write firmware/boot partition tables |
|
757 | 759 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM |
|
758 | 760 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
759 | 761 | EOM |
|
760 | 762 | |
|
761 | 763 | # Write root partition table |
|
762 | 764 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM |
|
763 | 765 | ${TABLE_SECTORS},${ROOT_SECTORS},83 |
|
764 | 766 | EOM |
|
765 | 767 | |
|
766 | 768 | # Setup temporary loop devices |
|
767 | 769 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" |
|
768 | 770 | ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" |
|
769 | 771 | else # ENABLE_SPLITFS=false |
|
770 | 772 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" |
|
771 | 773 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" |
|
772 | 774 | |
|
773 | 775 | # Write partition table |
|
774 | 776 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM |
|
775 | 777 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
776 | 778 | ${ROOT_OFFSET},${ROOT_SECTORS},83 |
|
777 | 779 | EOM |
|
778 | 780 | |
|
779 | 781 | # Setup temporary loop devices |
|
780 | 782 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" |
|
781 | 783 | ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" |
|
782 | 784 | fi |
|
783 | 785 | |
|
784 | 786 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
785 | 787 | # Create dummy ext4 fs |
|
786 | 788 | mkfs.ext4 "$ROOT_LOOP" |
|
787 | 789 | |
|
788 | 790 | # Setup password keyfile |
|
789 | 791 | touch .password |
|
790 | 792 | chmod 600 .password |
|
791 | 793 | echo -n ${CRYPTFS_PASSWORD} > .password |
|
792 | 794 | |
|
793 | 795 | # Initialize encrypted partition |
|
794 | 796 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password |
|
795 | 797 | |
|
796 | 798 | # Open encrypted partition and setup mapping |
|
797 | 799 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" |
|
798 | 800 | |
|
799 | 801 | # Secure delete password keyfile |
|
800 | 802 | shred -zu .password |
|
801 | 803 | |
|
802 | 804 | # Update temporary loop device |
|
803 | 805 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" |
|
804 | 806 | |
|
805 | 807 | # Wipe encrypted partition (encryption cipher is used for randomness) |
|
806 | 808 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" |
|
807 | 809 | fi |
|
808 | 810 | |
|
809 | 811 | # Build filesystems |
|
810 | 812 | mkfs.vfat "$FRMW_LOOP" |
|
811 | 813 | mkfs.ext4 "$ROOT_LOOP" |
|
812 | 814 | |
|
813 | 815 | # Mount the temporary loop devices |
|
814 | 816 | mkdir -p "$BUILDDIR/mount" |
|
815 | 817 | mount "$ROOT_LOOP" "$BUILDDIR/mount" |
|
816 | 818 | |
|
817 | 819 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
818 | 820 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" |
|
819 | 821 | |
|
820 | 822 | # Copy all files from the chroot to the loop device mount point directory |
|
821 | 823 | rsync -a "${R}/" "$BUILDDIR/mount/" |
|
822 | 824 | |
|
823 | 825 | # Unmount all temporary loop devices and mount points |
|
824 | 826 | cleanup |
|
825 | 827 | |
|
826 | 828 | # Create block map file(s) of image(s) |
|
827 | 829 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
828 | 830 | # Create block map files for "bmaptool" |
|
829 | 831 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" |
|
830 | 832 | bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" |
|
831 | 833 | |
|
832 | 834 | # Image was successfully created |
|
833 | 835 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
834 | 836 | echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
835 | 837 | else |
|
836 | 838 | # Create block map file for "bmaptool" |
|
837 | 839 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" |
|
838 | 840 | |
|
839 | 841 | # Image was successfully created |
|
840 | 842 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
841 | 843 | |
|
842 | 844 | # Create qemu qcow2 image |
|
843 | 845 | if [ "$ENABLE_QEMU" = true ] ; then |
|
844 | 846 | QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
845 | 847 | QEMU_SIZE=16G |
|
846 | 848 | |
|
847 | 849 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 |
|
848 | 850 | qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE |
|
849 | 851 | |
|
850 | 852 | echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" |
|
851 | 853 | fi |
|
852 | 854 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant