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