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