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