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