Skip to content

Instantly share code, notes, and snippets.

@sihorton
Last active November 15, 2020 22:07
Show Gist options
  • Save sihorton/0872126b2bcde7213278fe2f30d7a509 to your computer and use it in GitHub Desktop.
Save sihorton/0872126b2bcde7213278fe2f30d7a509 to your computer and use it in GitHub Desktop.
odroid u2 mainline kernel compilation
#!/bin/bash
if [ "$1" = "" ]; then
echo "$0: please specify $0 (kernelv) (optional kernel-config)"
echo "e.g. $0 4.18.5 or $0 4.18.5 u3_docker_config"
else
KERNELV="$1"
KERNEL_CONFIG="u3_docker_config"
BOARD_DRIVER="exynos4412-odroidu3"
TARGETD="/media/boot/"
SRCD="~"
if [ "$2" != "" ]; then
KERNEL_CONFIG="$2"
fi
MESS=`echo "Press any key to compile kernel ${KERNELV} into ~/kernel-${KERNELV}. Compilation takes 1 hr on the odroid. " `;
read -p "${MESS}";
#check if the source code does not exist
if [ ! -d "~/kernel-${KERNELV}" ]; then
#git clone from kernel repository just the branch we are interested in
git clone --depth 1 --single-branch --branch v${KERNELV} git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/kernel-${KERNELV}
fi
#move to kernel directory
cp "${KERNEL_CONFIG}" "~/kernel-${KERNELV}/.config"
cd ~/kernel-${KERNELV}
#make the config from provided file
#make olddefconfig
#prepare modules
#make prepare modules_prepare
#big compilation step, takes 1 hr on odroid
#make -j4 bzImage modules dtbs
#generate the modules
#make modules_install
RELEASE=`cat include/config/kernel.release`
echo "compiled ${RELEASE}, generating boot files"
#copy output files into boot partition
cp arch/arm/boot/dts/${BOARD_DRIVER}.dtb /media/boot/${BOARD_DRIVER}_${KERNELV}.dtb
echo "copied ${BOARD_DRIVER}_${KERNELV}.dtb to boot"
cp arch/arm/boot/zImage /media/boot/zImage_${KERNELV}
echo "copied zImage_${KERNELV} to boot"
#cp .config /boot/config-${RELEASE}
cp .config /media/boot/config-${KERNELV}
#update-initramfs -c -k ${RELEASE}
#mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d /boot/initrd.img-${RELEASE} /boot/uInitrd-${KERNELV}
cp /boot/uInitrd-${KERNELV} /media/boot/
echo "copied uInitrd-${KERNELV} to boot"
echo "adding board_kernel ${KERNELV} to boot.ini"
echo "."
echo "."
#add new board_kernel into boot.ini
#sed -i -e '/#kernel bootcmd auto-generated/c\\'"#kernel bootcmd auto-generated\nif test \"\${board_kernel}\" = \"${KERNELV}\"; then setenv bootcmd \"fatload mmc 0:1 0x40008000 zImage_${KERNELV}; fatload mmc 0:1 0x42000000 uInitrd-${KERNELV}; fatload mmc 0:1 0x44000000 ${BOARD_DRIVER}_${KERNELV}.dtb; bootz 0x40008000 0x42000000 0x44000000\"; fi" /media/boot/boot.ini
#select the new board_kernel
#sed -i -e '/setenv board_kernel/c\\'"setenv board_kernel \"${KERNELV}\"" /media/boot/boot.ini
sed -i -e '/setenv board_kernel/c\\'"setenv board_kernel \"${KERNELV}\"\nif test \"\${board_kernel}\" = \"${KERNELV}\"; then setenv bootcmd \"fatload mmc 0:1 0x40008000 zImage_${KERNELV}; fatload mmc 0:1 0x42000000 uInitrd-${KERNELV}; fatload mmc 0:1 0x44000000 ${BOARD_DRIVER}_${KERNELV}.dtb; bootz 0x40008000 0x42000000 0x44000000\"; fi" ${TARGETD}/boot.ini
#remove duplicate lines in file (if added same board more than once)
gawk -i inplace '!seen[$0]++' /media/boot/boot.ini
#show to the user
cat /media/boot/boot.ini
echo "."
echo "."
mkimage -C none -A arm -T script -d /media/boot/boot.ini /media/boot/boot.scr
sync
echo "reboot now"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment