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