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