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