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