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