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