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