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