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