Files
SimpleLinux/scripts/kernel.sh
T
2025-04-04 15:06:54 +07:00

76 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
. ./scripts/colors.sh
. ./scripts/funcs.sh
. ./scripts/config.sh
#--------------- Building Linux Kernel ---------------------
kernel() {
printf "$UGREEN** Building Linux Kernel\n$RESET"
rm -r $build/kernel # &>> $fulllogfile
mkdir -p $build/kernel # &>> $fulllogfile
cd $build/kernel
printf "$UGREEN** Extracting Linux Kernel\n$RESET"
tar -xvf $root/downloads/linux-$KERNEL_VERSION.tar.xz # &>> $fulllogfile
check $? "Extract Linux Kernel"
cd linux-$KERNEL_VERSION
printf "$UGREEN** Configuring Linux Kernel\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- mrproper # &>> $fulllogfile
cp -v $root/board/${BOARD_NAME}/linux-$KERNEL_VERSION.config .config # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- oldconfig # &>> $fulllogfile
check $? "Configure Linux Kernel"
printf "$UGREEN** Building Linux Kernel\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build Linux Kernel"
KIMAGE=zImage
[ "$ARCH" = "arm64" ] && KIMAGE=Image
ls -lh arch/$ARCH/boot/$KIMAGE
} # kernel
#-----------------------------------------------------------
#----------- Build and Install kernel modules --------------
kernel_modules() {
printf "$UGREEN** Building Linux Kernel modules\n$RESET"
cd $build/kernel/linux-$KERNEL_VERSION
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- modules # &>> fulllogfile
check $? "Build Linux Kernel modules"
printf "$UGREEN** Installing Linux Kernel modules into rootfs path\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- INSTALL_MOD_PATH=$rootfspath modules_install # &>> $fulllogfile
for i in $(find $rootfspath | grep .ko); do
gzip -9 $i;
done
check $? "Install Linux Kernel modules"
rm -v $rootfspath/usr/lib/modules/$KERNEL_VERSION/{source,build}
} # kernel_modules
#-----------------------------------------------------------
#--------------- Building Linux Kernel with rootfs ---------
kernel_with_rootfs() {
printf "$UGREEN** Building Linux Kernel with rootfs\n$RESET"
if [ ! -d $out ]; then
mkdir -pv $out
fi
cd $build/kernel/linux-$KERNEL_VERSION
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- CONFIG_INITRAMFS_SOURCE=$rootfspath $makeflags # &>> fulllogfile
check $? "Build Linux Kernel with rootfs"
printf "$UGREEN** Installing Linux Kernel into images path\n$RESET"
# make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$rootfspath modules_install # &>> $fulllogfile
# rm -v $rootfspath/usr/lib/modules/6.1.91/{source,build}
KIMAGE=zImage
[ "$ARCH" = "arm64" ] && KIMAGE=Image
cp -v arch/$ARCH/boot/$KIMAGE $sdroot/boot
check $? "Install Linux Kernel into images path"
}
#-----------------------------------------------------------
kernel_headers() {
printf "$UGREEN** Building Linux Kernel headers\n$RESET"
[ ! -d $build/kernel-headers ] && mkdir $build/kernel-headers
cd $build/kernel-headers
tar -xvf $root/downloads/linux-$KERNEL_VERSION.tar.xz
check $? "Extract Linux Kernel"
cd linux-$KERNEL_VERSION
make ARCH=$ARCH headers
check $? "Build kernel headers"
}