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