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