##// END OF EJS Templates
bugs
Unknown -
r348:5eed4a04c472
parent child
Show More
@@ -1,310 +1,339
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 # GPL v2.0
86 # GPL v2.0
87 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
87 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
88 if [ "$KERNEL_ZSWAP" = true ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
88 if [ "$KERNEL_ZSWAP" = true ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
89 # enable ZSWAP support for better performance during large builds etc.
89 # enable ZSWAP support for better performance during large builds etc.
90 # requires activation via kernel parameter or sysfs
90 # requires activation via kernel parameter or sysfs
91 # see e.g. https://askubuntu.com/a/472227 for a summary of ZSWAP (vs ZRAM etc.)
91 # see e.g. https://askubuntu.com/a/472227 for a summary of ZSWAP (vs ZRAM etc.)
92 # and e.g. https://wiki.archlinux.org/index.php/zswap for parameters etc.
92 # and e.g. https://wiki.archlinux.org/index.php/zswap for parameters etc.
93
93
94 set_kernel_config ZPOOL y "${KERNEL_DIR}/.config"
94 set_kernel_config ZPOOL y "${KERNEL_DIR}"/.config
95 set_kernel_config ZSWAP y "${KERNEL_DIR}/.config"
95 set_kernel_config ZSWAP y "${KERNEL_DIR}"/.config
96 set_kernel_config ZBUD y "${KERNEL_DIR}/.config"
96 set_kernel_config ZBUD y "${KERNEL_DIR}"/.config
97 set_kernel_config Z3FOLD y "${KERNEL_DIR}/.config"
97 set_kernel_config Z3FOLD y "${KERNEL_DIR}"/.config
98 set_kernel_config ZSMALLOC y "${KERNEL_DIR}/.config"
98 set_kernel_config ZSMALLOC y "${KERNEL_DIR}"/.config
99 set_kernel_config PGTABLE_MAPPING y "${KERNEL_DIR}/.config"
99 set_kernel_config PGTABLE_MAPPING y "${KERNEL_DIR}"/.config
100 fi
100 fi
101
101
102 if [ "$KERNEL_VIRT" = true ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
102 if [ "$KERNEL_VIRT" = true ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
103 # Submit PRs with edits targeting the _bottom_ of this file
103 # Submit PRs with edits targeting the _bottom_ of this file
104 # Please set modules where possible, rather than building in, and
104 # Please set modules where possible, rather than building in, and
105 # provide a short rationale comment for the changes made
105 # provide a short rationale comment for the changes made
106
106
107 # enable basic KVM support; see e.g.
107 # enable basic KVM support; see e.g.
108 # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453
108 # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453
109
109
110 set_kernel_config VIRTUALIZATION y "${KERNEL_DIR}/.config"
110 set_kernel_config VIRTUALIZATION y "${KERNEL_DIR}"/.config
111 set_kernel_config KVM y "${KERNEL_DIR}/.config"
111 set_kernel_config KVM y "${KERNEL_DIR}"/.config
112 set_kernel_config VHOST_NET m "${KERNEL_DIR}/.config"
112 set_kernel_config VHOST_NET m "${KERNEL_DIR}"/.config
113 set_kernel_config VHOST_CROSS_ENDIAN_LEGACY y "${KERNEL_DIR}/.config"
113 set_kernel_config VHOST_CROSS_ENDIAN_LEGACY y "${KERNEL_DIR}"/.config
114 fi
114 fi
115
115
116 if [ "$KERNEL_NF" = true ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
117 # Netfilter Xtables support (required for ip_tables - should be enabled already)
118 set_kernel_config NETFILTER_XTABLES m "${KERNEL_DIR}"/.config"
119 # Netfilter nf_tables support
120 set_kernel_config NF_TABLES m "${KERNEL_DIR}"/.config"
121 set_kernel_config NFT_PAYLOAD m "${KERNEL_DIR}"/.config"
122 set_kernel_config NFT_EXTHDR m "${KERNEL_DIR}"/.config"
123 set_kernel_config NFT_META m "${KERNEL_DIR}"/.config"
124 set_kernel_config NFT_CT m "${KERNEL_DIR}"/.config"
125 set_kernel_config NFT_RBTREE m "${KERNEL_DIR}"/.config"
126 set_kernel_config NFT_HASH m "${KERNEL_DIR}"/.config"
127 set_kernel_config NFT_COUNTER m "${KERNEL_DIR}"/.config"
128 set_kernel_config NFT_LOG m "${KERNEL_DIR}"/.config"
129 set_kernel_config NFT_LIMIT m "${KERNEL_DIR}"/.config"
130 set_kernel_config NFT_NAT m "${KERNEL_DIR}"/.config"
131 set_kernel_config NFT_COMPAT m "${KERNEL_DIR}"/.config"
132 # IPv4 nf_tables support
133 set_kernel_config NF_TABLES_IPV4 m
134 set_kernel_config NFT_REJECT_IPV4 m
135 set_kernel_config NFT_CHAIN_ROUTE_IPV4 m
136 set_kernel_config NFT_CHAIN_NAT_IPV4 m
137 # IPv6 nf_tables support
138 set_kernel_config NF_TABLES_IPV6 m
139 set_kernel_config NFT_CHAIN_ROUTE_IPV6 m
140 set_kernel_config NFT_CHAIN_NAT_IPV6 m
141 # Ethernet Bridge nf_tables support
142 set_kernel_config NF_TABLES_BRIDGE m
143 fi
144
116 if [ "$KERNELSRC_CONFIG" = true ] ; then
145 if [ "$KERNELSRC_CONFIG" = true ] ; then
117 # Load default raspberry kernel configuration
146 # Load default raspberry kernel configuration
118 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
147 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
119
148
120 # Set kernel configuration parameters to enable qemu emulation
149 # Set kernel configuration parameters to enable qemu emulation
121 if [ "$ENABLE_QEMU" = true ] ; then
150 if [ "$ENABLE_QEMU" = true ] ; then
122 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
151 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
123 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
152 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
124
153
125 if [ "$ENABLE_CRYPTFS" = true ] ; then
154 if [ "$ENABLE_CRYPTFS" = true ] ; then
126 {
155 {
127 echo "CONFIG_EMBEDDED=y"
156 echo "CONFIG_EMBEDDED=y"
128 echo "CONFIG_EXPERT=y"
157 echo "CONFIG_EXPERT=y"
129 echo "CONFIG_DAX=y"
158 echo "CONFIG_DAX=y"
130 echo "CONFIG_MD=y"
159 echo "CONFIG_MD=y"
131 echo "CONFIG_BLK_DEV_MD=y"
160 echo "CONFIG_BLK_DEV_MD=y"
132 echo "CONFIG_MD_AUTODETECT=y"
161 echo "CONFIG_MD_AUTODETECT=y"
133 echo "CONFIG_BLK_DEV_DM=y"
162 echo "CONFIG_BLK_DEV_DM=y"
134 echo "CONFIG_BLK_DEV_DM_BUILTIN=y"
163 echo "CONFIG_BLK_DEV_DM_BUILTIN=y"
135 echo "CONFIG_DM_CRYPT=y"
164 echo "CONFIG_DM_CRYPT=y"
136 echo "CONFIG_CRYPTO_BLKCIPHER=y"
165 echo "CONFIG_CRYPTO_BLKCIPHER=y"
137 echo "CONFIG_CRYPTO_CBC=y"
166 echo "CONFIG_CRYPTO_CBC=y"
138 echo "CONFIG_CRYPTO_XTS=y"
167 echo "CONFIG_CRYPTO_XTS=y"
139 echo "CONFIG_CRYPTO_SHA512=y"
168 echo "CONFIG_CRYPTO_SHA512=y"
140 echo "CONFIG_CRYPTO_MANAGER=y"
169 echo "CONFIG_CRYPTO_MANAGER=y"
141 } >> ${KERNEL_DIR}/.config
170 } >> ${KERNEL_DIR}/.config
142 fi
171 fi
143 fi
172 fi
144
173
145 # Copy custom kernel configuration file
174 # Copy custom kernel configuration file
146 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
175 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
147 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
176 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
148 fi
177 fi
149
178
150 # Set kernel configuration parameters to their default values
179 # Set kernel configuration parameters to their default values
151 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
180 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
152 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
181 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
153 fi
182 fi
154
183
155 # Start menu-driven kernel configuration (interactive)
184 # Start menu-driven kernel configuration (interactive)
156 if [ "$KERNEL_MENUCONFIG" = true ] ; then
185 if [ "$KERNEL_MENUCONFIG" = true ] ; then
157 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
186 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
158 fi
187 fi
159 fi
188 fi
160
189
161 # Use ccache to cross compile the kernel
190 # Use ccache to cross compile the kernel
162 if [ "$KERNEL_CCACHE" = true ] ; then
191 if [ "$KERNEL_CCACHE" = true ] ; then
163 cc="ccache ${CROSS_COMPILE}gcc"
192 cc="ccache ${CROSS_COMPILE}gcc"
164 else
193 else
165 cc="${CROSS_COMPILE}gcc"
194 cc="${CROSS_COMPILE}gcc"
166 fi
195 fi
167
196
168 # Cross compile kernel and dtbs
197 # Cross compile kernel and dtbs
169 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
198 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
170
199
171 # Cross compile kernel modules
200 # Cross compile kernel modules
172 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
201 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
173 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
202 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
174 fi
203 fi
175 fi
204 fi
176
205
177 # Check if kernel compilation was successful
206 # Check if kernel compilation was successful
178 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
207 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
179 echo "error: kernel compilation failed! (kernel image not found)"
208 echo "error: kernel compilation failed! (kernel image not found)"
180 cleanup
209 cleanup
181 exit 1
210 exit 1
182 fi
211 fi
183
212
184 # Install kernel modules
213 # Install kernel modules
185 if [ "$ENABLE_REDUCE" = true ] ; then
214 if [ "$ENABLE_REDUCE" = true ] ; then
186 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
215 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
187 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
216 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
188 fi
217 fi
189 else
218 else
190 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
219 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
191 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
220 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
192 fi
221 fi
193
222
194 # Install kernel firmware
223 # Install kernel firmware
195 if [ "$(grep "^firmware_install:" "${KERNEL_DIR}/Makefile")" ] ; then
224 if [ "$(grep "^firmware_install:" "${KERNEL_DIR}/Makefile")" ] ; then
196 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
225 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
197 fi
226 fi
198 fi
227 fi
199
228
200 # Install kernel headers
229 # Install kernel headers
201 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
230 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
202 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
231 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
203 fi
232 fi
204 # make tar.gz kernel package - missing os bzw. modules
233 # make tar.gz kernel package - missing os bzw. modules
205 #** ** ** WARNING ** ** **
234 #** ** ** WARNING ** ** **
206 #Your architecture did not define any architecture-dependent files
235 #Your architecture did not define any architecture-dependent files
207 #to be placed into the tarball. Please add those to ./scripts/package/buildtar .
236 #to be placed into the tarball. Please add those to ./scripts/package/buildtar .
208 # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg
237 # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg
209
238
210 # Prepare boot (firmware) directory
239 # Prepare boot (firmware) directory
211 mkdir "${BOOT_DIR}"
240 mkdir "${BOOT_DIR}"
212
241
213 # Get kernel release version
242 # Get kernel release version
214 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
243 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
215
244
216 # Copy kernel configuration file to the boot directory
245 # Copy kernel configuration file to the boot directory
217 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
246 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
218
247
219 # Prepare device tree directory
248 # Prepare device tree directory
220 mkdir "${BOOT_DIR}/overlays"
249 mkdir "${BOOT_DIR}/overlays"
221
250
222 # Ensure the proper .dtb is located
251 # Ensure the proper .dtb is located
223 if [ "$KERNEL_ARCH" = "arm" ] ; then
252 if [ "$KERNEL_ARCH" = "arm" ] ; then
224 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
253 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
225 if [ -f "${dtb}" ] ; then
254 if [ -f "${dtb}" ] ; then
226 install_readonly "${dtb}" "${BOOT_DIR}/"
255 install_readonly "${dtb}" "${BOOT_DIR}/"
227 fi
256 fi
228 done
257 done
229 else
258 else
230 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
259 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
231 if [ -f "${dtb}" ] ; then
260 if [ -f "${dtb}" ] ; then
232 install_readonly "${dtb}" "${BOOT_DIR}/"
261 install_readonly "${dtb}" "${BOOT_DIR}/"
233 fi
262 fi
234 done
263 done
235 fi
264 fi
236
265
237 # Copy compiled dtb device tree files
266 # Copy compiled dtb device tree files
238 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
267 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
239 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do
268 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do
240 if [ -f "${dtb}" ] ; then
269 if [ -f "${dtb}" ] ; then
241 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
270 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
242 fi
271 fi
243 done
272 done
244
273
245 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
274 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
246 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
275 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
247 fi
276 fi
248 fi
277 fi
249
278
250 if [ "$ENABLE_UBOOT" = false ] ; then
279 if [ "$ENABLE_UBOOT" = false ] ; then
251 # Convert and copy kernel image to the boot directory
280 # Convert and copy kernel image to the boot directory
252 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
281 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
253 else
282 else
254 # Copy kernel image to the boot directory
283 # Copy kernel image to the boot directory
255 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
284 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
256 fi
285 fi
257
286
258 # Remove kernel sources
287 # Remove kernel sources
259 if [ "$KERNEL_REMOVESRC" = true ] ; then
288 if [ "$KERNEL_REMOVESRC" = true ] ; then
260 rm -fr "${KERNEL_DIR}"
289 rm -fr "${KERNEL_DIR}"
261 else
290 else
262 # Prepare compiled kernel modules
291 # Prepare compiled kernel modules
263 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
292 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
264 if [ "$(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile")" ] ; then
293 if [ "$(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile")" ] ; then
265 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
294 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
266 fi
295 fi
267
296
268 # Create symlinks for kernel modules
297 # Create symlinks for kernel modules
269 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
298 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
270 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
299 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
271 fi
300 fi
272 fi
301 fi
273
302
274 else # BUILD_KERNEL=false
303 else # BUILD_KERNEL=false
275 # echo " Install precompiled kernel..."
304 # echo " Install precompiled kernel..."
276 # echo "error: not implemented"
305 # echo "error: not implemented"
277 if [ "$KERNEL_ARCH" = arm64 ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
306 if [ "$KERNEL_ARCH" = arm64 ] && ( [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ) ; then
278 # Create temporary directory for dl
307 # Create temporary directory for dl
279 temp_dir=$(as_nobody mktemp -d)
308 temp_dir=$(as_nobody mktemp -d)
280
309
281 # Fetch kernel dl
310 # Fetch kernel dl
282 as_nobody wget -c "$RPI3_64_KERNEL_URL" "${temp_dir}"/kernel.tar.xz
311 as_nobody wget -c "$RPI3_64_KERNEL_URL" "${temp_dir}"/kernel.tar.xz
283 #extract download
312 #extract download
284 tar -xJf kernel.tar.xz -C "${R}"
313 tar -xJf kernel.tar.xz -C "${R}"
285
314
286 # Remove temporary directory for kernel sources
315 # Remove temporary directory for kernel sources
287 rm -fr "${temp_dir}"
316 rm -fr "${temp_dir}"
288
317
289 # Set permissions of the kernel sources
318 # Set permissions of the kernel sources
290 chown -R root:root "${R}/boot"
319 chown -R root:root "${R}/boot"
291 chown -R root:root "${R}/lib"
320 chown -R root:root "${R}/lib"
292 fi
321 fi
293
322
294 # Check if kernel installation was successful
323 # Check if kernel installation was successful
295 KERNEL="$(ls -1 "${R}"/boot/kernel* | sort | tail -n 1)"
324 KERNEL="$(ls -1 "${R}"/boot/kernel* | sort | tail -n 1)"
296 if [ -z "$KERNEL" ] ; then
325 if [ -z "$KERNEL" ] ; then
297 echo "error: kernel installation failed! (/boot/kernel* not found)"
326 echo "error: kernel installation failed! (/boot/kernel* not found)"
298 cleanup
327 cleanup
299 exit 1
328 exit 1
300 fi
329 fi
301
330
302 if [ "$SET_ARCH" = 64 ] ; then
331 if [ "$SET_ARCH" = 64 ] ; then
303 echo "Using precompiled arm64 kernel"
332 echo "Using precompiled arm64 kernel"
304 else
333 else
305 echo "error: no precompiled arm64 (bcmrpi3) kernel found"
334 echo "error: no precompiled arm64 (bcmrpi3) kernel found"
306 exit 1
335 exit 1
307 # inset precompiled 64 bit kernel code here
336 # inset precompiled 64 bit kernel code here
308 fi
337 fi
309 #fi build_kernel=true
338 #fi build_kernel=true
310 fi
339 fi
@@ -1,104 +1,104
1 # This file contains utility functions used by rpi23-gen-image.sh
1 # This file contains utility functions used by rpi23-gen-image.sh
2
2
3 cleanup (){
3 cleanup (){
4 set +x
4 set +x
5 set +e
5 set +e
6
6
7 # Identify and kill all processes still using files
7 # Identify and kill all processes still using files
8 echo "killing processes using mount point ..."
8 echo "killing processes using mount point ..."
9 fuser -k "${R}"
9 fuser -k "${R}"
10 sleep 3
10 sleep 3
11 fuser -9 -k -v "${R}"
11 fuser -9 -k -v "${R}"
12
12
13 # Clean up temporary .password file
13 # Clean up temporary .password file
14 if [ -r ".password" ] ; then
14 if [ -r ".password" ] ; then
15 shred -zu .password
15 shred -zu .password
16 fi
16 fi
17
17
18 # Clean up all temporary mount points
18 # Clean up all temporary mount points
19 echo "removing temporary mount points ..."
19 echo "removing temporary mount points ..."
20 umount -l "${R}/proc" 2> /dev/null
20 umount -l "${R}/proc" 2> /dev/null
21 umount -l "${R}/sys" 2> /dev/null
21 umount -l "${R}/sys" 2> /dev/null
22 umount -l "${R}/dev/pts" 2> /dev/null
22 umount -l "${R}/dev/pts" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
28 trap - 0 1 2 3 6
28 trap - 0 1 2 3 6
29 }
29 }
30
30
31 chroot_exec() {
31 chroot_exec() {
32 # Exec command in chroot
32 # Exec command in chroot
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $*
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $*
34 }
34 }
35
35
36 as_nobody() {
36 as_nobody() {
37 # Exec command as user nobody
37 # Exec command as user nobody
38 sudo -E -u nobody LANG=C LC_ALL=C $*
38 sudo -E -u nobody LANG=C LC_ALL=C $*
39 }
39 }
40
40
41 install_readonly() {
41 install_readonly() {
42 # Install file with user read-only permissions
42 # Install file with user read-only permissions
43 install -o root -g root -m 644 $*
43 install -o root -g root -m 644 $*
44 }
44 }
45
45
46 install_exec() {
46 install_exec() {
47 # Install file with root exec permissions
47 # Install file with root exec permissions
48 install -o root -g root -m 744 $*
48 install -o root -g root -m 744 $*
49 }
49 }
50
50
51 use_template () {
51 use_template () {
52 # Test if configuration template file exists
52 # Test if configuration template file exists
53 if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then
53 if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then
54 echo "error: configuration template ${CONFIG_TEMPLATE} not found"
54 echo "error: configuration template ${CONFIG_TEMPLATE} not found"
55 exit 1
55 exit 1
56 fi
56 fi
57
57
58 # Load template configuration parameters
58 # Load template configuration parameters
59 . "./templates/${CONFIG_TEMPLATE}"
59 . "./templates/${CONFIG_TEMPLATE}"
60 }
60 }
61
61
62 chroot_install_cc() {
62 chroot_install_cc() {
63 # Install c/c++ build environment inside the chroot
63 # Install c/c++ build environment inside the chroot
64 if [ -z "${COMPILER_PACKAGES}" ] ; then
64 if [ -z "${COMPILER_PACKAGES}" ] ; then
65 COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }')
65 COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }')
66
66
67 if [ "$RELEASE" = "jessie" ] ; then
67 if [ "$RELEASE" = "jessie" ] ; then
68 chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES}
68 chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES}
69 elif [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
69 elif [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
70 chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES}
70 chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES}
71 fi
71 fi
72 fi
72 fi
73 }
73 }
74
74
75 chroot_remove_cc() {
75 chroot_remove_cc() {
76 # Remove c/c++ build environment from the chroot
76 # Remove c/c++ build environment from the chroot
77 if [ ! -z "${COMPILER_PACKAGES}" ] ; then
77 if [ ! -z "${COMPILER_PACKAGES}" ] ; then
78 chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES}
78 chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES}
79 COMPILER_PACKAGES=""
79 COMPILER_PACKAGES=""
80 fi
80 fi
81 }
81 }
82 #GPL v2.0
82 #GPL v2.0
83 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
83 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
84 # edited with thir param
84 # edited with thir param
85 #start
85 #start
86 set_kernel_config() {
86 set_kernel_config() {
87 # flag as $1, value to set as $2, config must exist at "./.config"
87 # flag as $1, value to set as $2, config must exist at "./.config"
88 local TGT="CONFIG_${1}"
88 local TGT="CONFIG_${1}"
89 local REP="${2//\//\\/}"
89 local REP="${2//\//\\/}"
90 if grep -q "^${TGT}[^_]" .config; then
90 if grep -q "^${TGT}[^_]" "${3}"; then
91 sed -i "s/^\(${TGT}=.*\|# ${TGT} is not set\)/${TGT}=${REP}/" "${3}"
91 sed -i "s/^\(${TGT}=.*\|# ${TGT} is not set\)/${TGT}=${REP}/" "${3}"
92 else
92 else
93 echo "${TGT}=${2}" >> "${3}"
93 echo "${TGT}=${2}" >> "${3}"
94 fi
94 fi
95 }
95 }
96
96
97 unset_kernel_config() {
97 unset_kernel_config() {
98 # unsets flag with the value of $1, config must exist at "./.config"
98 # unsets flag with the value of $1, config must exist at "./.config"
99 local TGT="CONFIG_${1}"
99 local TGT="CONFIG_${1}"
100 sed -i "s/^${TGT}=.*/# ${TGT} is not set/" "${2}"
100 sed -i "s/^${TGT}=.*/# ${TGT} is not set/" "${2}"
101 }
101 }
102 #
102 #
103 #end
103 #end
104 #
104 #
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant