##// END OF EJS Templates
get rid of errors in rpi23gen-image.sh
vidal -
r717:7d874bbf1d07
parent child
Show More
@@ -1,936 +1,930
1 1 #!/bin/sh
2 2 ########################################################################
3 3 # rpi23-gen-image.sh 2015-2017
4 4 #
5 5 # Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi
6 6 #
7 7 # This program is free software; you can redistribute it and/or
8 8 # modify it under the terms of the GNU General Public License
9 9 # as published by the Free Software Foundation; either version 2
10 10 # of the License, or (at your option) any later version.
11 11 #
12 12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 13 #
14 14 # Big thanks for patches and enhancements by 20+ github contributors!
15 15 ########################################################################
16 16
17 17 # Are we running as root?
18 18 if [ "$(id -u)" -ne "0" ] ; then
19 19 echo "error: this script must be executed with root privileges!"
20 20 exit 1
21 21 fi
22 22
23 23 # Check if ./functions.sh script exists
24 24 if [ ! -r "./functions.sh" ] ; then
25 25 echo "error: './functions.sh' required script not found!"
26 26 exit 1
27 27 fi
28 28
29 29 # Load utility functions
30 30 . ./functions.sh
31 31
32 32 # Load parameters from configuration template file
33 33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 34 use_template
35 35 fi
36 36
37 37 # Introduce settings
38 38 set -e
39 39 echo -n -e "\n#\n# RPi 0/1/2/3/4 Bootstrap Settings\n#\n"
40 40 set -x
41 41
42 42 # Raspberry Pi model configuration
43 43 RPI_MODEL=${RPI_MODEL:=2}
44 44
45 45 # Debian release
46 46 RELEASE=${RELEASE:=buster}
47 47 if [ $RELEASE = "bullseye" ] ; then
48 48 RELEASE=testing
49 49 fi
50 50
51 51 # Kernel Branch
52 52 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
53 53
54 54 # URLs
55 55 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
56 56 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
57 57 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
58 58 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
59 59 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
60 60 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
61 61 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
62 62 NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git}
63 63 SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git}
64 64
65 65 # Kernel deb packages for 32bit kernel
66 66 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}
67 67 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}
68 68 # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used
69 <<<<<<< HEAD
70 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}
71 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.19.80.20191022/bcmrpi3-kernel-bis-4.19.80.20191022.tar.xz}
72 69 # Default precompiled 64bit kernel
73 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}
74 =======
75 70 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.19.80.20191022/bcmrpi3-kernel-bis-4.19.80.20191022.tar.xz}
76 71 # Default precompiled 64bit kernel
77 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
78 72 RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.19.80.20191022/bcmrpi3-kernel-4.19.80.20191022.tar.xz}
79 73 # Sakaki BIS Kernel RPI4 - https://github.com/sakaki-/bcm2711-kernel-bis
80 74 RPI4_64_BIS_KERNEL_URL=${RPI4_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcm2711-kernel-bis/releases/download/4.19.59.20190724/bcm2711-kernel-bis-4.19.59.20190724.tar.xz}
81 75 # Default precompiled 64bit kernel - https://github.com/sakaki-/bcm2711-kernel
82 76 RPI4_64_DEF_KERNEL_URL=${RPI4_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcm2711-kernel-bis/releases/download/4.19.59.20190724/bcm2711-kernel-bis-4.19.59.20190724.tar.xz}
83 77 # Generic
84 78 RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL}
85 79 RPI4_64_KERNEL_URL=${RPI4_64_KERNEL_URL:=$RPI4_64_DEF_KERNEL_URL}
86 80 # Kali kernel src - used if ENABLE_NEXMON=true (they patch the wlan kernel modul)
87 81 KALI_KERNEL_URL=${KALI_KERNEL_URL:=https://github.com/Re4son/re4son-raspberrypi-linux.git}
88 82
89 83 # Build directories
90 84 WORKDIR=$(pwd)
91 85 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
92 86 BUILDDIR="${BASEDIR}/build"
93 87
94 88 # Chroot directories
95 89 R="${BUILDDIR}/chroot"
96 90 ETC_DIR="${R}/etc"
97 91 LIB_DIR="${R}/lib"
98 92 BOOT_DIR="${R}/boot/firmware"
99 93 KERNEL_DIR="${R}/usr/src/linux"
100 94 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
101 95 BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt"
102 96
103 97 # Firmware directory: Blank if download from github
104 98 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
105 99
106 100 # General settings
107 101 SET_ARCH=${SET_ARCH:=32}
108 102 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
109 103 PASSWORD=${PASSWORD:=raspberry}
110 104 USER_PASSWORD=${USER_PASSWORD:=raspberry}
111 105 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
112 106 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
113 107 EXPANDROOT=${EXPANDROOT:=true}
114 108 ENABLE_DPHYSSWAP=${ENABLE_DPHYSSWAP:=true}
115 109
116 110 # Keyboard settings
117 111 XKB_MODEL=${XKB_MODEL:=""}
118 112 XKB_LAYOUT=${XKB_LAYOUT:=""}
119 113 XKB_VARIANT=${XKB_VARIANT:=""}
120 114 XKB_OPTIONS=${XKB_OPTIONS:=""}
121 115
122 116 # Network settings (DHCP)
123 117 ENABLE_DHCP=${ENABLE_DHCP:=true}
124 118
125 119 # Network settings (static)
126 120 NET_ADDRESS=${NET_ADDRESS:=""}
127 121 NET_GATEWAY=${NET_GATEWAY:=""}
128 122 NET_DNS_1=${NET_DNS_1:=""}
129 123 NET_DNS_2=${NET_DNS_2:=""}
130 124 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
131 125 NET_NTP_1=${NET_NTP_1:=""}
132 126 NET_NTP_2=${NET_NTP_2:=""}
133 127
134 128 # APT settings
135 129 APT_PROXY=${APT_PROXY:=""}
136 130 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
137 131 KEEP_APT_PROXY=${KEEP_APT_PROXY:=false}
138 132
139 133 # Feature settings
140 134 ENABLE_PRINTK=${ENABLE_PRINTK:=false}
141 135 ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false}
142 136 ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false}
143 137 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
144 138 ENABLE_I2C=${ENABLE_I2C:=false}
145 139 ENABLE_SPI=${ENABLE_SPI:=false}
146 140 ENABLE_IPV6=${ENABLE_IPV6:=true}
147 141 ENABLE_SSHD=${ENABLE_SSHD:=true}
148 142 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
149 143 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
150 144 ENABLE_SOUND=${ENABLE_SOUND:=true}
151 145 ENABLE_DBUS=${ENABLE_DBUS:=true}
152 146 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
153 147 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
154 148 ENABLE_XORG=${ENABLE_XORG:=false}
155 149 ENABLE_WM=${ENABLE_WM:=""}
156 150 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
157 151 ENABLE_USER=${ENABLE_USER:=true}
158 152 USER_NAME=${USER_NAME:="pi"}
159 153 ENABLE_ROOT=${ENABLE_ROOT:=false}
160 154 ENABLE_QEMU=${ENABLE_QEMU:=false}
161 155 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
162 156
163 157 # SSH settings
164 158 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
165 159 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
166 160 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
167 161 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
168 162 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
169 163
170 164 # Advanced settings
171 165 ENABLE_SYSTEMDSWAP=${ENABLE_SYSTEMDSWAP:=false}
172 166 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
173 167 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
174 168 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
175 169 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
176 170 ENABLE_USBBOOT=${ENABLE_USBBOOT=false}
177 171 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
178 172 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false}
179 173 ENABLE_NEXMON=${ENABLE_NEXMON:=false}
180 174 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
181 175 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
182 176 NEXMONSRC_DIR=${NEXMONSRC_DIR:=""}
183 177 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
184 178 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
185 179 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
186 180 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
187 181 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
188 182 ENABLE_SPLASH=${ENABLE_SPLASH:=true}
189 183 ENABLE_LOGO=${ENABLE_LOGO:=true}
190 184 ENABLE_SILENT_BOOT=${ENABLE_SILENT_BOOT=false}
191 185 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
192 186
193 187 # Kernel compilation settings
194 188 BUILD_KERNEL=${BUILD_KERNEL:=true}
195 189 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
196 190 KERNEL_THREADS=${KERNEL_THREADS:=1}
197 191 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
198 192 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
199 193 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
200 194 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
201 195 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
202 196 KERNEL_ZSWAP=${KERNEL_ZSWAP:=false}
203 197 KERNEL_VIRT=${KERNEL_VIRT:=false}
204 198 KERNEL_BPF=${KERNEL_BPF:=false}
205 199 KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=ondemand}
206 200 KERNEL_SECURITY=${KERNEL_SECURITY:=false}
207 201 KERNEL_NF=${KERNEL_NF:=false}
208 202 KERNEL_DHKEY=${KERNEL_DHKEY:=true}
209 203 KERNEL_BTRFS=${KERNEL_BTRFS:=false}
210 204 KERNEL_NSPAN=${KERNEL_NSPAN:=false}
211 205 KERNEL_POEHAT=${KERNEL_POEHAT:=false}
212 206
213 207 # Kernel compilation from source directory settings
214 208 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
215 209 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
216 210 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
217 211 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
218 212
219 213 # Reduce disk usage settings
220 214 REDUCE_APT=${REDUCE_APT:=true}
221 215 REDUCE_DOC=${REDUCE_DOC:=true}
222 216 REDUCE_MAN=${REDUCE_MAN:=true}
223 217 REDUCE_VIM=${REDUCE_VIM:=false}
224 218 REDUCE_BASH=${REDUCE_BASH:=false}
225 219 REDUCE_HWDB=${REDUCE_HWDB:=true}
226 220 REDUCE_SSHD=${REDUCE_SSHD:=true}
227 221 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
228 222
229 223 # Encrypted filesystem settings
230 224 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
231 225 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
232 226 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
233 227 <<<<<<< HEAD
234 228 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
235 229 =======
236 230 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
237 231 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64"}
238 232 CRYPTFS_HASH=${CRYPTFS_HASH:="sha512"}
239 233 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
240 234 #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup
241 235 CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false}
242 236 #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated
243 237 CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""}
244 238
245 239 # Chroot scripts directory
246 240 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
247 241
248 242 # Packages required in the chroot build environment
249 243 APT_INCLUDES=${APT_INCLUDES:=""}
250 244 <<<<<<< HEAD
251 245 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"
252 246 =======
253 247 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
254 248 APT_INCLUDES="${APT_INCLUDES},flex,bison,libssl-dev,apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd"
255 249
256 250 # Packages to exclude from chroot build environment
257 251 APT_EXCLUDES=${APT_EXCLUDES:=""}
258 252
259 253 # Packages required for bootstrapping
260 254 <<<<<<< HEAD
261 255 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
262 256 =======
263 257 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
264 258 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus bison flex libssl-dev sudo"
265 259 MISSING_PACKAGES=""
266 260
267 261 # Packages installed for c/c++ build environment in chroot (keep empty)
268 262 COMPILER_PACKAGES=""
269 263
270 264 # Check if apt-cacher-ng has port 3142 open and set APT_PROXY
271 265 APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')
272 266 if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then
273 267 APT_PROXY=http://127.0.0.1:3142/
274 268 fi
275 269
276 270 # Setup architecture specific settings
277 271 if [ -n "$SET_ARCH" ] ; then
278 272 # 64-bit configuration
279 273 if [ "$SET_ARCH" = 64 ] ; then
280 274 # General 64-bit depended settings
281 275 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
282 276 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
283 277 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
284 278
285 279 # Raspberry Pi model specific settings
286 280 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then
287 281 if [ "$RPI_MODEL" != 4 ] ; then
288 282 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
289 283 else
290 284 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2711_defconfig}
291 285 fi
292 286
293 287 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
294 288 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
295 289 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
296 290 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
297 291 else
298 292 echo "error: Only Raspberry PI 3, 3B+ and 4 support 64-bit"
299 293 exit 1
300 294 fi
301 295 fi
302 296
303 297 # 32-bit configuration
304 298 if [ "$SET_ARCH" = 32 ] ; then
305 299 # General 32-bit dependend settings
306 300 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
307 301 KERNEL_ARCH=${KERNEL_ARCH:=arm}
308 302 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
309 303
310 304 # Raspberry Pi model specific settings
311 305 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
312 306 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
313 307 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
314 308 RELEASE_ARCH=${RELEASE_ARCH:=armel}
315 309 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
316 310 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
317 311 fi
318 312
319 313 # Raspberry Pi model specific settings
320 314 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then
321 315 if [ "$RPI_MODEL" != 4 ] ; then
322 316 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
323 317 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
324 318 else
325 319 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2711_defconfig}
326 320 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7l.img}
327 321 fi
328 322
329 323 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
330 324 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
331 325 <<<<<<< HEAD
332 326 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
333 327 =======
334 328 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
335 329
336 330 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
337 331 fi
338 332 fi
339 333 # SET_ARCH not set
340 334 else
341 335 echo "error: Please set '32' or '64' as value for SET_ARCH"
342 336 exit 1
343 337 fi
344 338 # Device specific configuration and U-Boot configuration
345 339 case "$RPI_MODEL" in
346 340 0)
347 341 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
348 342 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
349 343 ;;
350 344 1)
351 345 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
352 346 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
353 347 ;;
354 348 1P)
355 349 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
356 350 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
357 351 ;;
358 352 2)
359 353 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
360 354 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
361 355 ;;
362 356 3)
363 357 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
364 358 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
365 359 ;;
366 360 3P)
367 361 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
368 362 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
369 363 ;;
370 364 4)
371 365 DTB_FILE=${DTB_FILE:=bcm2711-rpi-4-b.dtb}
372 366 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_4_defconfig}
373 367 ;;
374 368 *)
375 369 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
376 370 exit 1
377 371 ;;
378 372 esac
379 373
380 374 # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard
381 375 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then
382 376 # Include bluetooth packages on supported boards
383 377 if [ "$ENABLE_BLUETOOTH" = true ] ; then
384 378 APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez"
385 379 fi
386 380 if [ "$ENABLE_WIRELESS" = true ] ; then
387 381 APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb"
388 382 fi
389 383 else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard
390 384 # Check if the internal wireless interface is not supported by the RPi model
391 385 if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then
392 386 echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth"
393 387 exit 1
394 388 fi
395 389 fi
396 390
397 391 if [ "$BUILD_KERNEL" = false ] && [ "$ENABLE_NEXMON" = true ]; then
398 392 echo "error: You have to compile kernel sources, if you want to enable nexmon"
399 393 exit 1
400 394 fi
401 395
402 396 # Prepare date string for default image file name
403 397 DATE="$(date +%Y-%m-%d)"
404 398 if [ -z "$KERNEL_BRANCH" ] ; then
405 399 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
406 400 else
407 401 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
408 402 fi
409 403
410 404 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
411 405 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
412 406 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
413 407 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
414 408 exit 1
415 409 fi
416 410 fi
417 411
418 412 # Add cmake to compile videocore sources
419 413 if [ "$ENABLE_VIDEOCORE" = true ] ; then
420 414 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
421 415 fi
422 416
423 417 # Add deps for nexmon
424 418 if [ "$ENABLE_NEXMON" = true ] ; then
425 419 <<<<<<< HEAD
426 420 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool"
427 421 =======
428 422 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
429 423 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf make autoconf automake build-essential libtool"
430 424 fi
431 425
432 426 # Add libncurses5 to enable kernel menuconfig
433 427 if [ "$KERNEL_MENUCONFIG" = true ] ; then
434 428 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
435 429 fi
436 430
437 431 # Add ccache compiler cache for (faster) kernel cross (re)compilation
438 432 if [ "$KERNEL_CCACHE" = true ] ; then
439 433 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
440 434 fi
441 435
442 436 # Add cryptsetup package to enable filesystem encryption
443 437 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
444 438 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
445 439 <<<<<<< HEAD
446 440 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
447 441 =======
448 442 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
449 443 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup,cryptsetup-initramfs"
450 444
451 445 # If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package
452 446 if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then
453 447 APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs"
454 448 fi
455 449
456 450 if [ -z "$CRYPTFS_PASSWORD" ] ; then
457 451 echo "error: no password defined (CRYPTFS_PASSWORD)!"
458 452 exit 1
459 453 fi
460 454 ENABLE_INITRAMFS=true
461 455 fi
462 456
463 457 # Add initramfs generation tools
464 458 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
465 459 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
466 460 fi
467 461
468 462 # Add device-tree-compiler required for building the U-Boot bootloader
469 463 if [ "$ENABLE_UBOOT" = true ] ; then
470 464 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
471 465 fi
472 466
473 467 if [ "$ENABLE_USBBOOT" = true ] ; then
474 468 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 2 ]; then
475 469 echo "error: Booting from USB alone is only supported by Raspberry Pi 3 and 3P"
476 470 exit 1
477 471 fi
478 472 fi
479 473
480 474 # Check if root SSH (v2) public key file exists
481 475 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
482 476 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
483 477 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
484 478 exit 1
485 479 fi
486 480 fi
487 481
488 482 # Check if $USER_NAME SSH (v2) public key file exists
489 483 if [ -n "$SSH_USER_PUB_KEY" ] ; then
490 484 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
491 485 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
492 486 exit 1
493 487 fi
494 488 fi
495 489
496 490 if [ "$ENABLE_NEXMON" = true ] && [ -n "$KERNEL_BRANCH" ] ; then
497 491 echo "error: Please unset KERNEL_BRANCH if using ENABLE_NEXMON"
498 492 exit 1
499 493 fi
500 494
501 495 # Check if all required packages are installed on the build system
502 496 for package in $REQUIRED_PACKAGES ; do
503 497 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
504 498 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
505 499 fi
506 500 done
507 501
508 502 # If there are missing packages ask confirmation for install, or exit
509 503 if [ -n "$MISSING_PACKAGES" ] ; then
510 504 echo "the following packages needed by this script are not installed:"
511 505 echo "$MISSING_PACKAGES"
512 506
513 507 printf "\ndo you want to install the missing packages right now? [y/n] "
514 508 read -r confirm
515 509 [ "$confirm" != "y" ] && exit 1
516 510
517 511 # Make sure all missing required packages are installed
518 512 <<<<<<< HEAD
519 513 apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"`
520 514 =======
521 515 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
522 516 apt-get update && apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"`
523 517 fi
524 518
525 519 # Check if ./bootstrap.d directory exists
526 520 if [ ! -d "./bootstrap.d/" ] ; then
527 521 echo "error: './bootstrap.d' required directory not found!"
528 522 exit 1
529 523 fi
530 524
531 525 # Check if ./files directory exists
532 526 if [ ! -d "./files/" ] ; then
533 527 echo "error: './files' required directory not found!"
534 528 exit 1
535 529 fi
536 530
537 531 # Check if specified KERNELSRC_DIR directory exists
538 532 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
539 533 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
540 534 exit 1
541 535 fi
542 536
543 537 # Check if specified UBOOTSRC_DIR directory exists
544 538 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
545 539 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
546 540 exit 1
547 541 fi
548 542
549 543 # Check if specified VIDEOCORESRC_DIR directory exists
550 544 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
551 545 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
552 546 exit 1
553 547 fi
554 548
555 549 # Check if specified FBTURBOSRC_DIR directory exists
556 550 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
557 551 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
558 552 exit 1
559 553 fi
560 554
561 555 # Check if specified NEXMONSRC_DIR directory exists
562 556 if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then
563 557 echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!"
564 558 exit 1
565 559 fi
566 560
567 561 # Check if specified CHROOT_SCRIPTS directory exists
568 562 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
569 563 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
570 564 exit 1
571 565 fi
572 566
573 567 # Check if specified device mapping already exists (will be used by cryptsetup)
574 568 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
575 569 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
576 570 exit 1
577 571 fi
578 572
579 573 # Don't clobber an old build
580 574 if [ -e "$BUILDDIR" ] ; then
581 575 echo "error: directory ${BUILDDIR} already exists, not proceeding"
582 576 exit 1
583 577 fi
584 578
585 579 # Setup chroot directory
586 580 mkdir -p "${R}"
587 581
588 582 # Check if build directory has enough of free disk space >512MB
589 583 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
590 584 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
591 585 exit 1
592 586 fi
593 587
594 588 set -x
595 589
596 590 # Call "cleanup" function on various signals and errors
597 591 trap cleanup 0 1 2 3 6
598 592
599 593 # Add required packages for the minbase installation
600 594 if [ "$ENABLE_MINBASE" = true ] ; then
601 595 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
602 596 fi
603 597
604 598 # Add parted package, required to get partprobe utility
605 599 if [ "$EXPANDROOT" = true ] ; then
606 600 APT_INCLUDES="${APT_INCLUDES},parted"
607 601 fi
608 602
609 603 # Add dphys-swapfile package, required to enable swap
610 604 if [ "$ENABLE_DPHYSSWAP" = true ] ; then
611 605 APT_INCLUDES="${APT_INCLUDES},dphys-swapfile"
612 606 fi
613 607
614 608 # Add dbus package, recommended if using systemd
615 609 if [ "$ENABLE_DBUS" = true ] ; then
616 610 APT_INCLUDES="${APT_INCLUDES},dbus"
617 611 fi
618 612
619 613 # Add iptables IPv4/IPv6 package
620 614 if [ "$ENABLE_IPTABLES" = true ] ; then
621 615 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
622 616 fi
623 617 # Add apparmor for KERNEL_SECURITY
624 618 if [ "$KERNEL_SECURITY" = true ] ; then
625 619 APT_INCLUDES="${APT_INCLUDES},apparmor,apparmor-utils,apparmor-profiles,apparmor-profiles-extra,libapparmor-perl"
626 620 fi
627 621
628 622 # Add openssh server package
629 623 if [ "$ENABLE_SSHD" = true ] ; then
630 624 APT_INCLUDES="${APT_INCLUDES},openssh-server"
631 625 fi
632 626
633 627 # Add alsa-utils package
634 628 if [ "$ENABLE_SOUND" = true ] ; then
635 629 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
636 630 fi
637 631
638 632 # Add rng-tools package
639 633 if [ "$ENABLE_HWRANDOM" = true ] ; then
640 634 APT_INCLUDES="${APT_INCLUDES},rng-tools"
641 635 fi
642 636
643 637 # Add fbturbo video driver
644 638 if [ "$ENABLE_FBTURBO" = true ] ; then
645 639 # Enable xorg package dependencies
646 640 ENABLE_XORG=true
647 641 fi
648 642
649 643 # Add user defined window manager package
650 644 if [ -n "$ENABLE_WM" ] ; then
651 645 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
652 646
653 647 # Enable xorg package dependencies
654 648 ENABLE_XORG=true
655 649 fi
656 650
657 651 # Add xorg package
658 652 if [ "$ENABLE_XORG" = true ] ; then
659 653 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
660 654 fi
661 655
662 656 # Replace selected packages with smaller clones
663 657 if [ "$ENABLE_REDUCE" = true ] ; then
664 658 # Add levee package instead of vim-tiny
665 659 if [ "$REDUCE_VIM" = true ] ; then
666 660 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
667 661 fi
668 662
669 663 # Add dropbear package instead of openssh-server
670 664 if [ "$REDUCE_SSHD" = true ] ; then
671 665 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
672 666 fi
673 667 fi
674 668
675 669 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
676 670 if [ "$ENABLE_SYSVINIT" = false ] ; then
677 671 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
678 672 fi
679 673
680 674 # Configure kernel sources if no KERNELSRC_DIR
681 675 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
682 676 KERNELSRC_CONFIG=true
683 677 fi
684 678
685 679 # Configure reduced kernel
686 680 if [ "$KERNEL_REDUCE" = true ] ; then
687 681 KERNELSRC_CONFIG=false
688 682 fi
689 683
690 684 # Configure qemu compatible kernel
691 685 if [ "$ENABLE_QEMU" = true ] ; then
692 686 DTB_FILE=vexpress-v2p-ca15_a7.dtb
693 687 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
694 688 KERNEL_DEFCONFIG="vexpress_defconfig"
695 689 if [ "$KERNEL_MENUCONFIG" = false ] ; then
696 690 KERNEL_OLDDEFCONFIG=true
697 691 fi
698 692 fi
699 693
700 694 # Execute bootstrap scripts
701 695 for SCRIPT in bootstrap.d/*.sh; do
702 696 head -n 3 "$SCRIPT"
703 697 . "$SCRIPT"
704 698 done
705 699
706 700 ## Execute custom bootstrap scripts
707 701 if [ -d "custom.d" ] ; then
708 702 for SCRIPT in custom.d/*.sh; do
709 703 . "$SCRIPT"
710 704 done
711 705 fi
712 706
713 707 # Execute custom scripts inside the chroot
714 708 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
715 709 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
716 710 chroot_exec /bin/bash -x <<'EOF'
717 711 for SCRIPT in /chroot_scripts/* ; do
718 712 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
719 713 $SCRIPT
720 714 fi
721 715 done
722 716 EOF
723 717 rm -rf "${R}/chroot_scripts"
724 718 fi
725 719
726 720 # Remove c/c++ build environment from the chroot
727 721 chroot_remove_cc
728 722
729 723 # Generate required machine-id
730 724 MACHINE_ID=$(dbus-uuidgen)
731 725 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
732 726 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
733 727
734 728 # APT Cleanup
735 729 chroot_exec apt-get -y clean
736 730 chroot_exec apt-get -y autoclean
737 731 chroot_exec apt-get -y autoremove
738 732
739 733 # Unmount mounted filesystems
740 734 umount -l "${R}/proc"
741 735 umount -l "${R}/sys"
742 736
743 737 # Clean up directories
744 738 rm -rf "${R}/run/*"
745 739 rm -rf "${R}/tmp/*"
746 740
747 741 # Clean up APT proxy settings
748 742 if [ "$KEEP_APT_PROXY" = false ] ; then
749 743 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
750 744 fi
751 745
752 746 # Clean up files
753 747 rm -f "${ETC_DIR}/ssh/ssh_host_*"
754 748 rm -f "${ETC_DIR}/dropbear/dropbear_*"
755 749 rm -f "${ETC_DIR}/apt/sources.list.save"
756 750 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
757 751 rm -f "${ETC_DIR}/*-"
758 752 rm -f "${ETC_DIR}/resolv.conf"
759 753 rm -f "${R}/root/.bash_history"
760 754 rm -f "${R}/var/lib/urandom/random-seed"
761 755 rm -f "${R}/initrd.img"
762 756 rm -f "${R}/vmlinuz"
763 757 rm -f "${R}${QEMU_BINARY}"
764 758
765 759 if [ "$ENABLE_QEMU" = true ] ; then
766 760 # Setup QEMU directory
767 761 mkdir "${BASEDIR}/qemu"
768 762
769 763 # Copy kernel image to QEMU directory
770 764 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
771 765
772 766 # Copy kernel config to QEMU directory
773 767 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
774 768
775 769 # Copy kernel dtbs to QEMU directory
776 770 for dtb in "${BOOT_DIR}/"*.dtb ; do
777 771 if [ -f "${dtb}" ] ; then
778 772 install_readonly "${dtb}" "${BASEDIR}/qemu/"
779 773 fi
780 774 done
781 775
782 776 # Copy kernel overlays to QEMU directory
783 777 if [ -d "${BOOT_DIR}/overlays" ] ; then
784 778 # Setup overlays dtbs directory
785 779 mkdir "${BASEDIR}/qemu/overlays"
786 780
787 781 for dtb in "${BOOT_DIR}/overlays/"*.dtbo ; do
788 782 if [ -f "${dtb}" ] ; then
789 783 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
790 784 fi
791 785 done
792 786 fi
793 787
794 788 # Copy u-boot files to QEMU directory
795 789 if [ "$ENABLE_UBOOT" = true ] ; then
796 790 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
797 791 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
798 792 fi
799 793 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
800 794 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
801 795 fi
802 796 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
803 797 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
804 798 fi
805 799 fi
806 800
807 801 # Copy initramfs to QEMU directory
808 802 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
809 803 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
810 804 fi
811 805 fi
812 806
813 807 # Calculate size of the chroot directory in KB
814 808 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
815 809
816 810 # Calculate the amount of needed 512 Byte sectors
817 811 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
818 812 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
819 813 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
820 814
821 815 # The root partition is EXT4
822 816 # This means more space than the actual used space of the chroot is used.
823 817 # As overhead for journaling and reserved blocks 35% are added.
824 818 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
825 819
826 820 # Calculate required image size in 512 Byte sectors
827 821 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
828 822
829 823 # Prepare image file
830 824 if [ "$ENABLE_SPLITFS" = true ] ; then
831 825 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
832 826 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
833 827 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
834 828 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
835 829
836 830 # Write firmware/boot partition tables
837 831 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
838 832 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
839 833 EOM
840 834
841 835 # Write root partition table
842 836 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
843 837 ${TABLE_SECTORS},${ROOT_SECTORS},83
844 838 EOM
845 839
846 840 # Setup temporary loop devices
847 841 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
848 842 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
849 843 else # ENABLE_SPLITFS=false
850 844 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
851 845 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
852 846
853 847 # Write partition table
854 848 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
855 849 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
856 850 ${ROOT_OFFSET},${ROOT_SECTORS},83
857 851 EOM
858 852
859 853 # Setup temporary loop devices
860 854 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
861 855 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
862 856 fi
863 857
864 858 if [ "$ENABLE_CRYPTFS" = true ] ; then
865 859 # Create dummy ext4 fs
866 860 mkfs.ext4 "$ROOT_LOOP"
867 861
868 862 # Setup password keyfile
869 863 touch .password
870 864 chmod 600 .password
871 865 echo -n ${CRYPTFS_PASSWORD} > .password
872 866
873 867 # Initialize encrypted partition
874 868 <<<<<<< HEAD
875 869 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
876 870 =======
877 871 >>>>>>> af203dbe173e4e5ca755058b3284dc61375ca579
878 872 cryptsetup --verbose --debug -q luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -h "${CRYPTFS_HASH}" -s "${CRYPTFS_XTSKEYSIZE}" .password
879 873
880 874 # Open encrypted partition and setup mapping
881 875 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
882 876
883 877 # Secure delete password keyfile
884 878 shred -zu .password
885 879
886 880 # Update temporary loop device
887 881 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
888 882
889 883 # Wipe encrypted partition (encryption cipher is used for randomness)
890 884 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
891 885 fi
892 886
893 887 # Build filesystems
894 888 mkfs.vfat "$FRMW_LOOP"
895 889 mkfs.ext4 "$ROOT_LOOP"
896 890
897 891 # Mount the temporary loop devices
898 892 mkdir -p "$BUILDDIR/mount"
899 893 mount "$ROOT_LOOP" "$BUILDDIR/mount"
900 894
901 895 mkdir -p "$BUILDDIR/mount/boot/firmware"
902 896 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
903 897
904 898 # Copy all files from the chroot to the loop device mount point directory
905 899 rsync -a "${R}/" "$BUILDDIR/mount/"
906 900
907 901 # Unmount all temporary loop devices and mount points
908 902 cleanup
909 903
910 904 # Create block map file(s) of image(s)
911 905 if [ "$ENABLE_SPLITFS" = true ] ; then
912 906 # Create block map files for "bmaptool"
913 907 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
914 908 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
915 909
916 910 # Image was successfully created
917 911 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
918 912 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
919 913 else
920 914 # Create block map file for "bmaptool"
921 915 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
922 916
923 917 # Image was successfully created
924 918 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
925 919
926 920 # Create qemu qcow2 image
927 921 if [ "$ENABLE_QEMU" = true ] ; then
928 922 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
929 923 QEMU_SIZE=16G
930 924
931 925 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
932 926 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
933 927
934 928 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
935 929 fi
936 930 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant