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