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