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