From dce1256be47163751696ad93237a0aa5155c03ef 2016-03-11 11:08:36 From: Filip Pytloun Date: 2016-03-11 11:08:36 Subject: [PATCH] Enhance kernel build by headers install, parallelism and cleanup --- diff --git a/README.md b/README.md index 6c2627e..3733d49 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,9 @@ Path to a directory with scripts that should be run in the chroot before the ima ##### `BUILD_KERNEL`=false Build and install the latest RPi2 linux kernel. Currently only the default RPi2 kernel configuration is used. Detailed configuration parameters for customizing the kernel and minor bug fixes still need to get implemented. feel free to help. +##### `KERNEL_HEADERS`=true +If true, also install kernel headers with built kernel. + ## Logging of the bootstrapping process All information related to the bootstrapping process and the commands executed by the `rpi2-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose: diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index 633d993..508d070 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -7,26 +7,31 @@ # Fetch and build latest raspberry kernel if [ "$BUILD_KERNEL" = true ] ; then # Fetch current raspberrypi kernel sources - git -C $R/tmp clone --depth=1 https://github.com/raspberrypi/linux + git -C $R/usr/local/src clone --depth=1 https://github.com/raspberrypi/linux # Load default raspberry kernel configuration - make -C $R/tmp/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig + make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig # Cross compile kernel and modules - make -C $R/tmp/linux -j 8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs + make -C $R/usr/local/src/linux -j$(grep -c processor /proc/cpuinfo) ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs # Install kernel modules - make -C $R/tmp/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../.. modules_install + make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../.. modules_install + + # Install kernel headers + if [ "$KERNEL_HEADERS" = true ]; then + make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_HDR_PATH=../../usr headers_install + fi # Copy and rename compiled kernel to boot directory mkdir $R/boot/firmware/ - $R/tmp/linux/scripts/mkknlimg $R/tmp/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img + $R/usr/local/src/linux/scripts/mkknlimg $R/usr/local/src/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img # Copy dts and dtb device definitions mkdir $R/boot/firmware/overlays/ - cp $R/tmp/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/ - cp $R/tmp/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/ - cp $R/tmp/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/ + cp $R/usr/local/src/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/ + cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/ + cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/ # Install raspberry bootloader and flash-kernel chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel diff --git a/rpi2-gen-image.sh b/rpi2-gen-image.sh index a1ff548..709ab04 100755 --- a/rpi2-gen-image.sh +++ b/rpi2-gen-image.sh @@ -79,6 +79,7 @@ ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} # Kernel compilation settings BUILD_KERNEL=${BUILD_KERNEL:=false} +KERNEL_HEADERS=${KERNEL_HEADERS:=true} # Image chroot path R=${BUILDDIR}/chroot