Created
November 27, 2016 01:04
-
-
Save mypetyak/e5a3933ce1f59bd7febb75048b1d990d to your computer and use it in GitHub Desktop.
build a new kernel for ARM7 CHIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The first argument should be the path to the existing | |
# kernel .config file you'd like to use as a baseline. | |
# Inspired by http://www.raspibo.org/wiki/index.php/Compile_the_Linux_kernel_for_Chip:_my_personal_HOWTO | |
# practice safe bash | |
set -e | |
set -u | |
set -o pipefail | |
# show bash debug output | |
set -x | |
kernelver="4.4.13" | |
configpath="$1" | |
if [ -z "${configpath}" ]; then | |
echo "Specify the path to .config" | |
exit 1 | |
fi | |
workdir="/tmp/buildchip" | |
mkdir -p "${workdir}" | |
libdir=$(mktemp -d) | |
assemblydir=$(mktemp -d) | |
kerneldir="${workdir}/CHIP-linux" | |
wifidir="${workdir}/RTL8723BS" | |
function cleanup { | |
# remove temporarily directories | |
rm -r "${libdir}" "${assemblydir}" | |
} | |
trap cleanup EXIT | |
# retrieve the desired branch of CHIP kernel source | |
if [ ! -d "${kerneldir}" ]; then | |
git clone https://github.com/NextThingCo/CHIP-linux.git -b debian/4.4.13-ntc-mlc --single-branch $kerneldir | |
fi | |
# move .config into kernel path | |
cp "${configpath}" "${kerneldir}/.config" | |
# start interactive configuration | |
(cd "${kerneldir}" && make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- menuconfig) | |
# retrieve the kernel build suffix from config line similar to | |
# CONFIG_LOCALVERSION="bunn001" | |
suffix=$(grep -Po "(?<=CONFIG_LOCALVERSION=\")(\w+)" "${kerneldir}/.config") | |
# cross-compile kernel and modules | |
(cd "${kerneldir}" && make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -j 9) | |
# install kernel modules to $libdir | |
(cd $kerneldir && make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- INSTALL_MOD_PATH=$libdir modules_install) | |
# retrieve RTL8723BS kernel source, debian branch | |
if [ ! -d "${wifidir}" ]; then | |
git clone https://github.com/NextThingCo/RTL8723BS.git -b debian --single-branch $wifidir | |
# apply debian patches to RTL8723BS source | |
(cd "${wifidir}" && for i in debian/patches/0*; do echo $i; patch -p 1 <$i ; done) | |
fi | |
# cross-compile module | |
(cd "${wifidir}" && make -j 9 CONFIG_PLATFORM_ARM_SUNxI=y ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -C "${kerneldir}" M="${PWD}" CONFIG_RTL8723BS=m INSTALL_MOD_PATH="${libdir}") | |
# install module to $libdir | |
(cd "${wifidir}" && make -j 9 CONFIG_PLATFORM_ARM_SUNxI=y ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -C "${kerneldir}" M="${PWD}" CONFIG_RTL8723BS=m INSTALL_MOD_PATH=$libdir modules_install) | |
# set up package for transport | |
(cd "${assemblydir}" && mkdir -p boot lib/modules lib/firmware) | |
cp "${kerneldir}/arch/arm/boot/zImage" "${assemblydir}/boot/vmlinuz-${kernelver}${suffix}+" | |
cp "${kerneldir}/.config" "${assemblydir}/boot/config-${kernelver}${suffix}+" | |
cp "${kerneldir}/System.map" "${assemblydir}/boot/System.map-${kernelver}${suffix}+" | |
cp -r "${libdir}/lib/modules" "${assemblydir}/lib/" | |
if [ -d "${libdir}/firmware" ]; then | |
cp -r "${libdir}/firmware" "${assemblydir}/lib/" | |
fi | |
# create a tar that can be untarred on the CHIP with | |
# sudo tar -C / -xzvf "4.4.13${suffix}.tar.gz" | |
tar -C "${assemblydir}" -cvzf "${kernelver}${suffix}.tar.gz" boot lib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment