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