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