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