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