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