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