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