Skip to content

Instantly share code, notes, and snippets.

@sihorton
Created September 1, 2018 23:41
Show Gist options
  • Save sihorton/d8e583c91c1ae1711fad9b68bf6c241f to your computer and use it in GitHub Desktop.
Save sihorton/d8e583c91c1ae1711fad9b68bf6c241f to your computer and use it in GitHub Desktop.
compile odroid u2
#!/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=`echo ~`
if [ "$2" != "" ]; then
KERNEL_CONFIG="$2"
fi
MESS=`echo "Press any key to compile kernel ${KERNELV} into ${SRCD}/kernel-${KERNELV}. Compilation takes 1 hr on the odroid. " `;
read -p "${MESS}";
#check if the source code does not exist
if [ ! -d "${SRCD}/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 ${SRCD}/kernel-${KERNELV}
fi
#move to kernel directory
cp "${KERNEL_CONFIG}" "${SRCD}/kernel-${KERNELV}/.config"
cd ${SRCD}/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 ${TARGETD}/${BOARD_DRIVER}_${KERNELV}.dtb
echo "copied ${BOARD_DRIVER}_${KERNELV}.dtb to boot"
cp arch/arm/boot/zImage ${TARGETD}/zImage_${KERNELV}
echo "copied zImage_${KERNELV} to boot"
#cp .config /boot/config-${RELEASE}
cp .config ${TARGETD}/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} ${TARGETD}/
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 ${$
#select the new board_kernel
#sed -i -e '/setenv board_kernel/c\\'"setenv board_kernel \"${KERNELV}\"" ${TARGETD}/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]++' ${TARGETD}/boot.ini
#show to the user
cat ${TARGETD}/boot.ini
echo "."
echo "."
mkimage -C none -A arm -T script -d ${TARGETD}/boot.ini ${TARGETD}/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