##// END OF EJS Templates
fix: kernel compilation, add ccache support
drtyhlpr -
r248:9054cc788a22
parent child
Show More
@@ -295,6 +295,12 Install kernel headers with built kernel.
295 ##### `KERNEL_MENUCONFIG`=false
295 ##### `KERNEL_MENUCONFIG`=false
296 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
296 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
297
297
298 ##### `KERNEL_OLDDEFCONFIG`=false
299 Run `make olddefconfig` to automatically set all new kernel configuration options to their recommended default values.
300
301 ##### `KERNEL_CCACHE`=false
302 Compile the kernel using ccache. This speeds up kernel recompilation by caching previous compilations and detecting when the same compilation is being done again.
303
298 ##### `KERNEL_REMOVESRC`=true
304 ##### `KERNEL_REMOVESRC`=true
299 Remove all kernel sources from the generated OS image after it was built and installed.
305 Remove all kernel sources from the generated OS image after it was built and installed.
300
306
@@ -25,9 +25,9 if [ "$BUILD_KERNEL" = true ] ; then
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 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 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
@@ -87,18 +87,36 if [ "$BUILD_KERNEL" = 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 # Copy custom kernel configuration file
90 if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then
91 if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then
91 cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config
92 cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config
92 fi
93 fi
93
94
95 # Set kernel configuration parameters to their default values
96 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
97 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
98 fi
99
94 # Start menu-driven kernel configuration (interactive)
100 # Start menu-driven kernel configuration (interactive)
95 if [ "$KERNEL_MENUCONFIG" = true ] ; then
101 if [ "$KERNEL_MENUCONFIG" = true ] ; then
96 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
102 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
97 fi
103 fi
98 fi
104 fi
99
105
100 # Cross compile kernel and modules
106 # Use ccache to cross compile the kernel
101 make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_BIN_IMAGE}" modules dtbs
107 if [ "$KERNEL_CCACHE" = true ] ; then
108 cc="ccache ${CROSS_COMPILE}gcc"
109 else
110 cc="${CROSS_COMPILE}gcc"
111 fi
112
113 # 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
115
116 # Cross compile kernel modules
117 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
119 fi
102 fi
120 fi
103
121
104 # Check if kernel compilation was successful
122 # Check if kernel compilation was successful
@@ -110,12 +128,16 if [ "$BUILD_KERNEL" = true ] ; then
110
128
111 # Install kernel modules
129 # Install kernel modules
112 if [ "$ENABLE_REDUCE" = true ] ; then
130 if [ "$ENABLE_REDUCE" = true ] ; then
131 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
113 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
132 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
133 fi
114 else
134 else
135 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
115 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
136 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
137 fi
116
138
117 # Install kernel firmware
139 # Install kernel firmware
118 if [ $(cat ./Makefile | grep "^firmware_install:") ] ; then
140 if [ $(grep "^firmware_install:" "${KERNEL_DIR}/Makefile") ] ; then
119 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
141 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
120 fi
142 fi
121 fi
143 fi
@@ -134,18 +156,36 if [ "$BUILD_KERNEL" = true ] ; then
134 # Copy kernel configuration file to the boot directory
156 # Copy kernel configuration file to the boot directory
135 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
157 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
136
158
137 # Copy dts and dtb device tree sources and binaries
159 # Prepare device tree directory
138 mkdir "${BOOT_DIR}/overlays"
160 mkdir "${BOOT_DIR}/overlays"
139
161
140 # Ensure the proper .dtb is located
162 # Ensure the proper .dtb is located
141 if [ "$KERNEL_ARCH" = "arm" ] ; then
163 if [ "$KERNEL_ARCH" = "arm" ] ; then
142 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOT_DIR}/"
164 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
165 if [ -f "${dtb}" ] ; then
166 install_readonly "${dtb}" "${BOOT_DIR}/"
167 fi
168 done
143 else
169 else
144 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb "${BOOT_DIR}/"
170 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
171 if [ -f "${dtb}" ] ; then
172 install_readonly "${dtb}" "${BOOT_DIR}/"
173 fi
174 done
175 fi
176
177 # Copy compiled dtb device tree files
178 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
180 if [ -f "${dtb}" ] ; then
181 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
145 fi
182 fi
183 done
146
184
147 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOT_DIR}/overlays/"
185 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
148 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
186 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
187 fi
188 fi
149
189
150 if [ "$ENABLE_UBOOT" = false ] ; then
190 if [ "$ENABLE_UBOOT" = false ] ; then
151 # Convert and copy kernel image to the boot directory
191 # Convert and copy kernel image to the boot directory
@@ -159,12 +199,17 if [ "$BUILD_KERNEL" = true ] ; then
159 if [ "$KERNEL_REMOVESRC" = true ] ; then
199 if [ "$KERNEL_REMOVESRC" = true ] ; then
160 rm -fr "${KERNEL_DIR}"
200 rm -fr "${KERNEL_DIR}"
161 else
201 else
202 # Prepare compiled kernel modules
203 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
204 if [ $(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile") ] ; then
162 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
205 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
206 fi
163
207
164 # Create symlinks for kernel modules
208 # Create symlinks for kernel modules
165 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
209 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
166 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
210 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
167 fi
211 fi
212 fi
168
213
169 else # BUILD_KERNEL=false
214 else # BUILD_KERNEL=false
170 # Kernel installation
215 # Kernel installation
@@ -175,6 +175,9 KERNEL_THREADS=${KERNEL_THREADS:=1}
175 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
175 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
176 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
176 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
177 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
177 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
178 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
179 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
180
178 if [ "$KERNEL_ARCH" = "arm64" ] ; then
181 if [ "$KERNEL_ARCH" = "arm64" ] ; then
179 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
182 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
180 else
183 else
@@ -269,6 +272,11 if [ "$KERNEL_MENUCONFIG" = true ] ; then
269 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
272 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
270 fi
273 fi
271
274
275 # Add ccache compiler cache for (faster) kernel cross (re)compilation
276 if [ "$KERNEL_CCACHE" = true ] ; then
277 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
278 fi
279
272 # Stop the Crypto Wars
280 # Stop the Crypto Wars
273 if [ "$DISABLE_FBI" = true ] ; then
281 if [ "$DISABLE_FBI" = true ] ; then
274 ENABLE_CRYPTFS=true
282 ENABLE_CRYPTFS=true
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant