You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.1 KiB
104 lines
3.1 KiB
#!/bin/bash -e
|
|
#
|
|
# Build ARM kernel 4.x.y for QEMU Raspberry Pi Emulation
|
|
#
|
|
#######################################################
|
|
|
|
TOOLCHAIN=arm-linux-gnueabihf
|
|
COMMIT=raspberrypi-kernel_1.20190620-1
|
|
INSTALL_PACKAGES=""
|
|
USE_GIT=1
|
|
USB_WEBCAM_MODULES="" # add USB & V4L modules for USB webcam support (didn't work as static)
|
|
|
|
SOURCE_DIR=$(pwd)
|
|
BUILD_DIR=$SOURCE_DIR
|
|
TARGET_DIR=$SOURCE_DIR
|
|
|
|
if [ -f build-kernel-qemu.conf ] ; then
|
|
. build-kernel-qemu.conf
|
|
fi
|
|
|
|
if [ "$INSTALL_PACKAGES" ] ; then
|
|
sudo apt-get update
|
|
sudo apt-get install git libncurses5-dev gcc-arm-linux-gnueabihf
|
|
fi
|
|
|
|
mkdir -p $BUILD_DIR $TARGET_DIR
|
|
CUR_DIR=$(pwd)
|
|
cd $BUILD_DIR
|
|
|
|
if [ "$USE_GIT" ] ; then
|
|
# checking out 4.x.y tag - change it if you want to change kernel version
|
|
# for a specific hash, have a look at: https://github.com/raspberrypi/linux/tags
|
|
# To check the effective kernel version, click on a tag in that list;
|
|
# the branch and tag name are under the commit message.
|
|
if [ ! -d linux ] ; then
|
|
git clone https://github.com/raspberrypi/linux.git
|
|
else
|
|
echo "Using existing Linux sources!"
|
|
fi
|
|
cd linux
|
|
if [ "$COMMIT" ] ; then
|
|
git reset --hard
|
|
git clean -xdf
|
|
git checkout "$COMMIT"
|
|
fi
|
|
else
|
|
if [ -z "$COMMIT" ] ; then echo "COMMIT missing!" >&2 ; exit 1 ; fi
|
|
wget -c https://github.com/raspberrypi/linux/archive/${COMMIT}.zip -O linux-${COMMIT}.zip
|
|
rm -rf linux-${COMMIT}
|
|
unzip linux-${COMMIT}.zip
|
|
cd linux-${COMMIT}
|
|
fi
|
|
|
|
# Use all available cores for compilation
|
|
export MAKEFLAGS="$MAKEFLAGS -j$(nproc)"
|
|
|
|
KERNEL_VERSION=$(make kernelversion)
|
|
KERNEL_TARGET_FILE_NAME=$TARGET_DIR/qemu-kernel-$KERNEL_VERSION
|
|
MODULES_INSTALL_PATH=$TARGET_DIR/qemu-kernel-$KERNEL_VERSION-modules
|
|
if [ -e "../linux-arm-$KERNEL_VERSION.patch" ]; then
|
|
patch -p1 < $SOURCE_DIR/linux-arm-$KERNEL_VERSION.patch
|
|
else
|
|
patch -p1 < $SOURCE_DIR/linux-arm.patch
|
|
fi
|
|
make ARCH=arm versatile_defconfig
|
|
echo "Building Qemu Raspberry Pi kernel qemu-kernel-$KERNEL_VERSION"
|
|
|
|
cat >> .config << EOF
|
|
CONFIG_CROSS_COMPILE="$TOOLCHAIN"
|
|
EOF
|
|
|
|
if [ -e "$SOURCE_DIR/config_file_$KERNEL_VERSION" ]; then
|
|
cat "$SOURCE_DIR/config_file_$KERNEL_VERSION" >> .config
|
|
else
|
|
cat "$SOURCE_DIR/config_file" >> .config
|
|
fi
|
|
|
|
if [ $USB_WEBCAM_MODULES ] ; then
|
|
echo "Make sure you have drivers for your webcam selected in menuconfig"
|
|
cat $SOURCE_DIR/config_webcam >> .config
|
|
fi
|
|
|
|
cat $SOURCE_DIR/config_ip_tables >> .config
|
|
cat $SOURCE_DIR/config_loopdev >> .config
|
|
|
|
make -k ARCH=arm CROSS_COMPILE=${TOOLCHAIN}- menuconfig
|
|
make -k ARCH=arm CROSS_COMPILE=${TOOLCHAIN}- bzImage dtbs
|
|
cp arch/arm/boot/zImage $KERNEL_TARGET_FILE_NAME
|
|
if [ -e arch/arm/boot/dts/versatile-pb.dtb ] ; then
|
|
cp arch/arm/boot/dts/versatile-pb.dtb $TARGET_DIR
|
|
fi
|
|
|
|
if [ $USB_WEBCAM_MODULES ] ; then
|
|
mkdir -p $MODULES_INSTALL_PATH
|
|
if [ ! -d $MODULES_INSTALL_PATH ] ; then
|
|
echo "Couldn't create webcam modules install directory $MODULES_INSTALL_PATH"
|
|
fi
|
|
make -k ARCH=arm CROSS_COMPILE=${TOOLCHAIN}- modules
|
|
make -k ARCH=arm CROSS_COMPILE=${TOOLCHAIN}- \
|
|
INSTALL_MOD_PATH=$MODULES_INSTALL_PATH modules_install
|
|
echo "Copy modules to Raspberry to /lib/modules/$KERNEL_VERSION"
|
|
fi
|
|
|
|
cd $CUR_DIR
|
|
|