##// END OF EJS Templates
a
burnbabyburn -
r557:8d4b204c1336
parent child
Show More
@@ -1,603 +1,605
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 11 # Clear Branch and KernelSRC_DIR if using nexmon. Everyone will forget to clone kali kernel instead of nomrla kernel
12 12 KERNEL_BRANCH=""
13 13 KERNELSRC_DIR=""
14 14 fi
15 15
16 16 # Fetch and build latest raspberry kernel
17 17 if [ "$BUILD_KERNEL" = true ] ; then
18 18 # Setup source directory
19 19 mkdir -p "${KERNEL_DIR}"
20 20
21 21 # Copy existing kernel sources into chroot directory
22 22 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
23 23 # Copy kernel sources and include hidden files
24 24 cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}"
25 25
26 26 # Clean the kernel sources
27 27 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
28 28 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
29 29 fi
30 30 else # KERNELSRC_DIR=""
31 31 # Create temporary directory for kernel sources
32 32 temp_dir=$(as_nobody mktemp -d)
33 33
34 34 # Fetch current RPi2/3 kernel sources
35 35 if [ -z "${KERNEL_BRANCH}" ] ; then
36 36 as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux
37 37 else
38 38 as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux
39 39 fi
40 40
41 41 # Copy downloaded kernel sources
42 42 cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}"
43 43
44 44 # Remove temporary directory for kernel sources
45 45 rm -fr "${temp_dir}"
46 46
47 47 # Set permissions of the kernel sources
48 48 chown -R root:root "${R}/usr/src"
49 49 fi
50 50
51 51 # Calculate optimal number of kernel building threads
52 52 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
53 53 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
54 54 fi
55 55
56 56 # Configure and build kernel
57 57 if [ "$KERNELSRC_PREBUILT" = false ] ; then
58 58 # Remove device, network and filesystem drivers from kernel configuration
59 59 if [ "$KERNEL_REDUCE" = true ] ; then
60 60 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
61 61 sed -i\
62 62 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
63 63 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
64 64 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
65 65 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
66 66 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
67 67 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
68 68 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
69 69 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
70 70 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
71 71 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
72 72 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
73 73 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
74 74 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
75 75 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
76 76 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
77 77 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
78 78 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
79 79 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
80 80 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
81 81 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
82 82 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
83 83 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
84 84 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
85 85 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
86 86 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
87 87 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
88 88 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
89 89 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
90 90 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
91 91 "${KERNEL_DIR}/.config"
92 92 fi
93 93
94 94 if [ "$KERNELSRC_CONFIG" = true ] ; then
95 95 # Load default raspberry kernel configuration
96 96 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
97 97
98 98 #Switch to KERNELSRC_DIR so we can use set_kernel_config
99 99 cd "${KERNEL_DIR}" || exit
100 100
101 101 # enable ZSWAP see https://askubuntu.com/a/472227 or https://wiki.archlinux.org/index.php/zswap
102 102 if [ "$KERNEL_ZSWAP" = true ] ; then
103 103 set_kernel_config CONFIG_ZPOOL y
104 104 set_kernel_config CONFIG_ZSWAP y
105 105 set_kernel_config CONFIG_ZBUD y
106 106 set_kernel_config CONFIG_Z3FOLD y
107 107 set_kernel_config CONFIG_ZSMALLOC y
108 108 set_kernel_config CONFIG_PGTABLE_MAPPING y
109 109 set_kernel_config CONFIG_LZO_COMPRESS y
110 set_kernel_config CONFIG_MMC_SDHCI_IPROC n
111 set_kernel_config CONFIG_USB_DWC2 n
110 112 fi
111 113
112 114 # enable basic KVM support; see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453
113 115 if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
114 116 set_kernel_config CONFIG_HAVE_KVM_IRQCHIP y
115 117 set_kernel_config CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL y
116 118 set_kernel_config CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT y
117 119 set_kernel_config CONFIG_HAVE_KVM_EVENTFD y
118 120 set_kernel_config CONFIG_HAVE_KVM_IRQFD y
119 121 set_kernel_config CONFIG_HAVE_KVM_IRQ_ROUTING y
120 122 set_kernel_config CONFIG_HAVE_KVM_MSI y
121 123 set_kernel_config CONFIG_KVM y
122 124 set_kernel_config CONFIG_KVM_ARM_HOST y
123 125 set_kernel_config CONFIG_KVM_ARM_PMU y
124 126 set_kernel_config CONFIG_KVM_COMPAT y
125 127 set_kernel_config CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT y
126 128 set_kernel_config CONFIG_KVM_MMIO y
127 129 set_kernel_config CONFIG_KVM_VFIO y
128 130 set_kernel_config CONFIG_VHOST m
129 131 set_kernel_config CONFIG_VHOST_CROSS_ENDIAN_LEGACY y
130 132 set_kernel_config CONFIG_VHOST_NET m
131 133 set_kernel_config CONFIG_VIRTUALIZATION y
132 134
133 135 set_kernel_config CONFIG_MMU_NOTIFIER y
134 136
135 137 # erratum
136 138 set_kernel_config ARM64_ERRATUM_834220 y
137 139
138 140 # https://sourceforge.net/p/kvm/mailman/message/18440797/
139 141 set_kernel_config CONFIG_PREEMPT_NOTIFIERS y
140 142 fi
141 143
142 144 # enable apparmor,integrity audit,
143 145 if [ "$KERNEL_SECURITY" = true ] ; then
144 146
145 147 # security filesystem, security models and audit
146 148 set_kernel_config CONFIG_SECURITYFS y
147 149 set_kernel_config CONFIG_SECURITY y
148 150 set_kernel_config CONFIG_AUDIT y
149 151
150 152 # harden strcpy and memcpy
151 153 set_kernel_config CONFIG_HARDENED_USERCOPY y
152 154 set_kernel_config CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR y
153 155 set_kernel_config CONFIG_FORTIFY_SOURCE y
154 156
155 157 # integrity sub-system
156 158 set_kernel_config CONFIG_INTEGRITY y
157 159 set_kernel_config CONFIG_INTEGRITY_ASYMMETRIC_KEYS y
158 160 set_kernel_config CONFIG_INTEGRITY_AUDIT y
159 161 set_kernel_config CONFIG_INTEGRITY_SIGNATURE y
160 162 set_kernel_config CONFIG_INTEGRITY_TRUSTED_KEYRING y
161 163 set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYS ""
162 164
163 165 # This option provides support for retaining authentication tokens and access keys in the kernel.
164 166 set_kernel_config CONFIG_KEYS=y
165 167 set_kernel_config CONFIG_KEYS_COMPAT=y
166 168
167 169 # Apparmor
168 170 set_kernel_config CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE 0
169 171 set_kernel_config CONFIG_SECURITY_APPARMOR_HASH_DEFAULT y
170 172 set_kernel_config CONFIG_DEFAULT_SECURITY_APPARMOR y
171 173 set_kernel_config CONFIG_SECURITY_APPARMOR y
172 174 set_kernel_config CONFIG_SECURITY_APPARMOR_HASH y
173 175 set_kernel_config CONFIG_DEFAULT_SECURITY "apparmor"
174 176
175 177 # restrictions on unprivileged users reading the kernel
176 178 set_kernel_config CONFIG_SECURITY_DMESG_RESTRICT=y
177 179
178 180 # network security hooks
179 181 set_kernel_config CONFIG_SECURITY_NETWORK y
180 182 set_kernel_config CONFIG_SECURITY_NETWORK_XFRM=y
181 183 set_kernel_config CONFIG_SECURITY_PATH=y
182 184 set_kernel_config CONFIG_SECURITY_YAMA=y
183 185
184 186 # New Options
185 187 if [ "$KERNEL_NF" = true ] ; then
186 188 set_kernel_config CONFIG_IP_NF_SECURITY m
187 189 set_kernel_config CONFIG_NETLABEL y
188 190 set_kernel_config CONFIG_IP6_NF_SECURITY m
189 191 fi
190 192 set_kernel_config CONFIG_SECURITY_SELINUX n
191 193 set_kernel_config CONFIG_SECURITY_SMACK n
192 194 set_kernel_config CONFIG_SECURITY_TOMOYO n
193 195 set_kernel_config CONFIG_SECURITY_APPARMOR_DEBUG n
194 196 set_kernel_config CONFIG_SECURITY_LOADPIN n
195 197 set_kernel_config CONFIG_HARDENED_USERCOPY_PAGESPAN n
196 198 set_kernel_config CONFIG_IMA n
197 199 set_kernel_config CONFIG_EVM n
198 200 set_kernel_config CONFIG_FANOTIFY_ACCESS_PERMISSIONS y
199 201 set_kernel_config CONFIG_NFSD_V4_SECURITY_LABEL y
200 202 set_kernel_config CONFIG_PKCS7_MESSAGE_PARSER y
201 203 set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYRING y
202 204 set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYS y
203 205 set_kernel_config CONFIG_SYSTEM_EXTRA_CERTIFICATE y
204 206 set_kernel_config CONFIG_SECONDARY_TRUSTED_KEYRING y
205 207 set_kernel_config CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY n
206 208 set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYS m
207 209 set_kernel_config CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE 4096
208 210
209 211 set_kernel_config CONFIG_ARM64_CRYPTO y
210 212 set_kernel_config CONFIG_CRYPTO_SHA256_ARM64 m
211 213 set_kernel_config CONFIG_CRYPTO_SHA512_ARM64 m
212 214 set_kernel_config CONFIG_CRYPTO_SHA1_ARM64_CE m
213 215 set_kernel_config CRYPTO_GHASH_ARM64_CE m
214 216 set_kernel_config CRYPTO_SHA2_ARM64_CE m
215 217 set_kernel_config CONFIG_CRYPTO_CRCT10DIF_ARM64_CE m
216 218 set_kernel_config CONFIG_CRYPTO_CRC32_ARM64_CE m
217 219 set_kernel_config CONFIG_CRYPTO_AES_ARM64 m
218 220 set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE m
219 221 set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE_CCM y
220 222 set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE_BLK y
221 223 set_kernel_config CONFIG_CRYPTO_AES_ARM64_NEON_BLK m
222 224 set_kernel_config CONFIG_CRYPTO_CHACHA20_NEON m
223 225 set_kernel_config CONFIG_CRYPTO_AES_ARM64_BS m
224 226 echo SYSTEM_TRUSTED_KEYS >> .config
225 227 fi
226 228
227 229 # Netfilter kernel support See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406
228 230 if [ "$KERNEL_NF" = true ] ; then
229 231 set_kernel_config CONFIG_IP_NF_TARGET_SYNPROXY m
230 232 set_kernel_config CONFIG_NETFILTER_XT_TARGET_AUDIT m
231 233 set_kernel_config CONFIG_NETFILTER_XT_MATCH_CGROUP m
232 234 set_kernel_config CONFIG_NETFILTER_XT_MATCH_IPCOMP m
233 235 set_kernel_config CONFIG_NETFILTER_XT_MATCH_SOCKET m
234 236 set_kernel_config CONFIG_NFT_FIB_INET m
235 237 set_kernel_config CONFIG_NFT_FIB_IPV4 m
236 238 set_kernel_config CONFIG_NFT_FIB_IPV6 m
237 239 set_kernel_config CONFIG_NFT_FIB_NETDEV m
238 240 set_kernel_config CONFIG_NFT_OBJREF m
239 241 set_kernel_config CONFIG_NFT_RT m
240 242 set_kernel_config CONFIG_NFT_SET_BITMAP m
241 243 set_kernel_config CONFIG_NF_CONNTRACK_TIMEOUT y
242 244 set_kernel_config CONFIG_NF_LOG_ARP m
243 245 set_kernel_config CONFIG_NF_SOCKET_IPV4 m
244 246 set_kernel_config CONFIG_NF_SOCKET_IPV6 m
245 247 set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m
246 248 set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m
247 249 set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m
248 250 set_kernel_config CONFIG_IP6_NF_IPTABLES m
249 251 set_kernel_config CONFIG_IP6_NF_MATCH_AH m
250 252 set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m
251 253 set_kernel_config CONFIG_IP6_NF_NAT m
252 254 set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m
253 255 set_kernel_config CONFIG_IP6_NF_TARGET_NPT m
254 256 set_kernel_config CONFIG_IP_NF_SECURITY m
255 257 set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m
256 258 set_kernel_config CONFIG_IP_SET_BITMAP_PORT m
257 259 set_kernel_config CONFIG_IP_SET_HASH_IP m
258 260 set_kernel_config CONFIG_IP_SET_HASH_IPMARK m
259 261 set_kernel_config CONFIG_IP_SET_HASH_IPPORT m
260 262 set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m
261 263 set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m
262 264 set_kernel_config CONFIG_IP_SET_HASH_MAC m
263 265 set_kernel_config CONFIG_IP_SET_HASH_NET m
264 266 set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m
265 267 set_kernel_config CONFIG_IP_SET_HASH_NETNET m
266 268 set_kernel_config CONFIG_IP_SET_HASH_NETPORT m
267 269 set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m
268 270 set_kernel_config CONFIG_IP_SET_LIST_SET m
269 271 set_kernel_config CONFIG_NETFILTER_XTABLES m
270 272 set_kernel_config CONFIG_NETFILTER_XTABLES m
271 273 set_kernel_config CONFIG_NFT_BRIDGE_META m
272 274 set_kernel_config CONFIG_NFT_BRIDGE_REJECT m
273 275 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m
274 276 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m
275 277 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m
276 278 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m
277 279 set_kernel_config CONFIG_NFT_COMPAT m
278 280 set_kernel_config CONFIG_NFT_COUNTER m
279 281 set_kernel_config CONFIG_NFT_CT m
280 282 set_kernel_config CONFIG_NFT_DUP_IPV4 m
281 283 set_kernel_config CONFIG_NFT_DUP_IPV6 m
282 284 set_kernel_config CONFIG_NFT_DUP_NETDEV m
283 285 set_kernel_config CONFIG_NFT_EXTHDR m
284 286 set_kernel_config CONFIG_NFT_FWD_NETDEV m
285 287 set_kernel_config CONFIG_NFT_HASH m
286 288 set_kernel_config CONFIG_NFT_LIMIT m
287 289 set_kernel_config CONFIG_NFT_LOG m
288 290 set_kernel_config CONFIG_NFT_MASQ m
289 291 set_kernel_config CONFIG_NFT_MASQ_IPV4 m
290 292 set_kernel_config CONFIG_NFT_MASQ_IPV6 m
291 293 set_kernel_config CONFIG_NFT_META m
292 294 set_kernel_config CONFIG_NFT_NAT m
293 295 set_kernel_config CONFIG_NFT_NUMGEN m
294 296 set_kernel_config CONFIG_NFT_QUEUE m
295 297 set_kernel_config CONFIG_NFT_QUOTA m
296 298 set_kernel_config CONFIG_NFT_REDIR m
297 299 set_kernel_config CONFIG_NFT_REDIR_IPV4 m
298 300 set_kernel_config CONFIG_NFT_REDIR_IPV6 m
299 301 set_kernel_config CONFIG_NFT_REJECT m
300 302 set_kernel_config CONFIG_NFT_REJECT_INET m
301 303 set_kernel_config CONFIG_NFT_REJECT_IPV4 m
302 304 set_kernel_config CONFIG_NFT_REJECT_IPV6 m
303 305 set_kernel_config CONFIG_NFT_SET_HASH m
304 306 set_kernel_config CONFIG_NFT_SET_RBTREE m
305 307 set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m
306 308 set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m
307 309 set_kernel_config CONFIG_NF_DEFRAG_IPV4 m
308 310 set_kernel_config CONFIG_NF_DEFRAG_IPV6 m
309 311 set_kernel_config CONFIG_NF_DUP_IPV4 m
310 312 set_kernel_config CONFIG_NF_DUP_IPV6 m
311 313 set_kernel_config CONFIG_NF_DUP_NETDEV m
312 314 set_kernel_config CONFIG_NF_LOG_BRIDGE m
313 315 set_kernel_config CONFIG_NF_LOG_IPV4 m
314 316 set_kernel_config CONFIG_NF_LOG_IPV6 m
315 317 set_kernel_config CONFIG_NF_NAT_IPV4 m
316 318 set_kernel_config CONFIG_NF_NAT_IPV6 m
317 319 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m
318 320 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m
319 321 set_kernel_config CONFIG_NF_NAT_PPTP m
320 322 set_kernel_config CONFIG_NF_NAT_PROTO_GRE m
321 323 set_kernel_config CONFIG_NF_NAT_REDIRECT m
322 324 set_kernel_config CONFIG_NF_NAT_SIP m
323 325 set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m
324 326 set_kernel_config CONFIG_NF_NAT_TFTP m
325 327 set_kernel_config CONFIG_NF_REJECT_IPV4 m
326 328 set_kernel_config CONFIG_NF_REJECT_IPV6 m
327 329 set_kernel_config CONFIG_NF_TABLES m
328 330 set_kernel_config CONFIG_NF_TABLES_ARP m
329 331 set_kernel_config CONFIG_NF_TABLES_BRIDGE m
330 332 set_kernel_config CONFIG_NF_TABLES_INET m
331 333 set_kernel_config CONFIG_NF_TABLES_IPV4 m
332 334 set_kernel_config CONFIG_NF_TABLES_IPV6 m
333 335 set_kernel_config CONFIG_NF_TABLES_NETDEV m
334 336 fi
335 337
336 338 # 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
337 339 if [ "$KERNEL_BPF" = true ] ; then
338 340 set_kernel_config CONFIG_BPF_SYSCALL y
339 341 set_kernel_config CONFIG_BPF_EVENTS y
340 342 set_kernel_config CONFIG_BPF_STREAM_PARSER y
341 343 set_kernel_config CONFIG_CGROUP_BPF y
342 344 fi
343 345
344 346 # KERNEL_DEFAULT_GOV was set by user
345 347 if [ "$KERNEL_DEFAULT_GOV" != powersave ] && [ -n "$KERNEL_DEFAULT_GOV" ] ; then
346 348
347 349 case "$KERNEL_DEFAULT_GOV" in
348 350 performance)
349 351 set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE y
350 352 ;;
351 353 userspace)
352 354 set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE y
353 355 ;;
354 356 ondemand)
355 357 set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND y
356 358 ;;
357 359 conservative)
358 360 set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE y
359 361 ;;
360 362 shedutil)
361 363 set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL y
362 364 ;;
363 365 *)
364 366 echo "error: unsupported default cpu governor"
365 367 exit 1
366 368 ;;
367 369 esac
368 370
369 371 # unset previous default governor
370 372 unset_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
371 373 fi
372 374
373 375 #Revert to previous directory
374 376 cd "${WORKDIR}" || exit
375 377
376 378 # Set kernel configuration parameters to enable qemu emulation
377 379 if [ "$ENABLE_QEMU" = true ] ; then
378 380 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
379 381 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
380 382
381 383 if [ "$ENABLE_CRYPTFS" = true ] ; then
382 384 {
383 385 echo "CONFIG_EMBEDDED=y"
384 386 echo "CONFIG_EXPERT=y"
385 387 echo "CONFIG_DAX=y"
386 388 echo "CONFIG_MD=y"
387 389 echo "CONFIG_BLK_DEV_MD=y"
388 390 echo "CONFIG_MD_AUTODETECT=y"
389 391 echo "CONFIG_BLK_DEV_DM=y"
390 392 echo "CONFIG_BLK_DEV_DM_BUILTIN=y"
391 393 echo "CONFIG_DM_CRYPT=y"
392 394 echo "CONFIG_CRYPTO_BLKCIPHER=y"
393 395 echo "CONFIG_CRYPTO_CBC=y"
394 396 echo "CONFIG_CRYPTO_XTS=y"
395 397 echo "CONFIG_CRYPTO_SHA512=y"
396 398 echo "CONFIG_CRYPTO_MANAGER=y"
397 399 } >> "${KERNEL_DIR}"/.config
398 400 fi
399 401 fi
400 402
401 403 # Copy custom kernel configuration file
402 404 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
403 405 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
404 406 fi
405 407
406 408 # Set kernel configuration parameters to their default values
407 409 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
408 410 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
409 411 fi
410 412
411 413 # Start menu-driven kernel configuration (interactive)
412 414 if [ "$KERNEL_MENUCONFIG" = true ] ; then
413 415 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
414 416 fi
415 417 # end if "$KERNELSRC_CONFIG" = true
416 418 fi
417 419
418 420 # Use ccache to cross compile the kernel
419 421 if [ "$KERNEL_CCACHE" = true ] ; then
420 422 cc="ccache ${CROSS_COMPILE}gcc"
421 423 else
422 424 cc="${CROSS_COMPILE}gcc"
423 425 fi
424 426
425 427 # Cross compile kernel and dtbs
426 428 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
427 429
428 430 # Cross compile kernel modules
429 431 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
430 432 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
431 433 fi
432 434 # end if "$KERNELSRC_PREBUILT" = false
433 435 fi
434 436
435 437 # Check if kernel compilation was successful
436 438 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
437 439 echo "error: kernel compilation failed! (kernel image not found)"
438 440 cleanup
439 441 exit 1
440 442 fi
441 443
442 444 # Install kernel modules
443 445 if [ "$ENABLE_REDUCE" = true ] ; then
444 446 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
445 447 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
446 448 fi
447 449 else
448 450 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
449 451 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
450 452 fi
451 453
452 454 # Install kernel firmware
453 455 if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then
454 456 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
455 457 fi
456 458 fi
457 459
458 460 # Install kernel headers
459 461 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
460 462 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
461 463 fi
462 464
463 465 # Prepare boot (firmware) directory
464 466 mkdir "${BOOT_DIR}"
465 467
466 468 # Get kernel release version
467 469 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
468 470
469 471 # Copy kernel configuration file to the boot directory
470 472 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
471 473
472 474 # Prepare device tree directory
473 475 mkdir "${BOOT_DIR}/overlays"
474 476
475 477 # Ensure the proper .dtb is located
476 478 if [ "$KERNEL_ARCH" = "arm" ] ; then
477 479 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
478 480 if [ -f "${dtb}" ] ; then
479 481 install_readonly "${dtb}" "${BOOT_DIR}/"
480 482 fi
481 483 done
482 484 else
483 485 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
484 486 if [ -f "${dtb}" ] ; then
485 487 install_readonly "${dtb}" "${BOOT_DIR}/"
486 488 fi
487 489 done
488 490 fi
489 491
490 492 # Copy compiled dtb device tree files
491 493 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
492 494 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtbo ; do
493 495 if [ -f "${dtb}" ] ; then
494 496 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
495 497 fi
496 498 done
497 499
498 500 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
499 501 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
500 502 fi
501 503 fi
502 504
503 505 if [ "$ENABLE_UBOOT" = false ] ; then
504 506 # Convert and copy kernel image to the boot directory
505 507 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
506 508 else
507 509 # Copy kernel image to the boot directory
508 510 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
509 511 fi
510 512
511 513 # Remove kernel sources
512 514 if [ "$KERNEL_REMOVESRC" = true ] ; then
513 515 rm -fr "${KERNEL_DIR}"
514 516 else
515 517 # Prepare compiled kernel modules
516 518 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
517 519 if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then
518 520 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
519 521 fi
520 522
521 523 # Create symlinks for kernel modules
522 524 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
523 525 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
524 526 fi
525 527 fi
526 528
527 529 else # BUILD_KERNEL=false
528 530 if [ "$SET_ARCH" = 64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
529 531
530 532 # Use Sakakis modified kernel if ZSWAP is active
531 533 if [ "$KERNEL_ZSWAP" = true ] || [ "$KERNEL_VIRT" = true ] || [ "$KERNEL_NF" = true ] || [ "$KERNEL_BPF" = true ] ; then
532 534 RPI3_64_KERNEL_URL="${RPI3_64_BIS_KERNEL_URL}"
533 535 fi
534 536
535 537 # Create temporary directory for dl
536 538 temp_dir=$(as_nobody mktemp -d)
537 539
538 540 # Fetch kernel dl
539 541 as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL"
540 542
541 543 #extract download
542 544 tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}"
543 545
544 546 #move extracted kernel to /boot/firmware
545 547 mkdir "${R}/boot/firmware"
546 548 cp "${temp_dir}"/boot/* "${R}"/boot/firmware/
547 549 cp -r "${temp_dir}"/lib/* "${R}"/lib/
548 550
549 551 # Remove temporary directory for kernel sources
550 552 rm -fr "${temp_dir}"
551 553
552 554 # Set permissions of the kernel sources
553 555 chown -R root:root "${R}/boot/firmware"
554 556 chown -R root:root "${R}/lib/modules"
555 557 fi
556 558
557 559 # Install Kernel from hypriot comptabile with all Raspberry PI
558 560 if [ "$SET_ARCH" = 32 ] ; then
559 561 # Create temporary directory for dl
560 562 temp_dir=$(as_nobody mktemp -d)
561 563
562 564 # Fetch kernel
563 565 as_nobody wget -O "${temp_dir}"/kernel.deb -c "$RPI_32_KERNEL_URL"
564 566
565 567 # Copy downloaded U-Boot sources
566 568 mv "${temp_dir}"/kernel.deb "${R}"/tmp/kernel.deb
567 569
568 570 # Set permissions
569 571 chown -R root:root "${R}"/tmp/kernel.deb
570 572
571 573 # Install kernel
572 574 chroot_exec dpkg -i /tmp/kernel.deb
573 575
574 576 # move /boot to /boot/firmware to fit script env.
575 577 #mkdir "${BOOT_DIR}"
576 578 mkdir "${temp_dir}"/firmware
577 579 mv "${R}"/boot/* "${temp_dir}"/firmware/
578 580 mv "${temp_dir}"/firmware "${R}"/boot/
579 581
580 582 #same for kernel headers
581 583 if [ "$KERNEL_HEADERS" = true ] ; then
582 584 # Fetch kernel header
583 585 as_nobody wget -O "${temp_dir}"/kernel-header.deb -c "$RPI_32_KERNELHEADER_URL"
584 586 mv "${temp_dir}"/kernel-header.deb "${R}"/tmp/kernel-header.deb
585 587 chown -R root:root "${R}"/tmp/kernel-header.deb
586 588 # Install kernel header
587 589 chroot_exec dpkg -i /tmp/kernel-header.deb
588 590 rm -f "${R}"/tmp/kernel-header.deb
589 591 fi
590 592
591 593 # Remove temporary directory and files
592 594 rm -fr "${temp_dir}"
593 595 rm -f "${R}"/tmp/kernel.deb
594 596 fi
595 597
596 598 # Check if kernel installation was successful
597 599 KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)"
598 600 if [ -z "$KERNEL" ] ; then
599 601 echo "error: kernel installation failed! (/boot/kernel* not found)"
600 602 cleanup
601 603 exit 1
602 604 fi
603 605 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant