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