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