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