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