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