Skip to content

Instantly share code, notes, and snippets.

@Geofferey
Last active March 22, 2024 22:25
Show Gist options
  • Save Geofferey/e33a978b889dff199dc650aa9491564e to your computer and use it in GitHub Desktop.
Save Geofferey/e33a978b889dff199dc650aa9491564e to your computer and use it in GitHub Desktop.
#!/bin/sh
export ARCH=arm64
if [ $(whoami) != root ]; then
echo "You should probably be running me as root!"
export RUN_AS_ROOT=sudo
echo "You now are:" $(${RUN_AS_ROOT} whoami)
echo
fi
## Cleanup if set
if [ ! -z ${CLEAN_BUILD} ]; then
rm -f Image Image.lz4 bootloader.bin kernel.itb vmlinux.kpart
make clean
make mrproper
cd tools/perf
make clean
cd ../power/cpupower
make clean
cd ../../..
fi
## Update the .config
if [ ! -e .config ]; then
echo ".config not present... exiting."
exit 0
fi
if [ ! -e cmdline ]; then
echo "cmdline not present... exiting."
exit 0
fi
make olddefconfig
## Set our device tree blobs
DT_BLOBS="-b arch/arm64/boot/dts/qcom/sc7180-trogdor-coachz-r1-lte.dtb -b arch/arm64/boot/dts/qcom/sc7180-trogdor-coachz-r1.dtb -b arch/arm64/boot/dts/qcom/sc7180-trogdor-coachz-r3.dtb -b arch/arm64/boot/dts/qcom/sc7180-trogdor-coachz-r3-lte.dtb -b arch/arm64/boot/dts/qcom/sc7180-trogdor-r1.dtb -b arch/arm64/boot/dts/qcom/sc7180-trogdor-r1-lte.dtb"
## Build Image dtbs and modules
make -j 8 Image dtbs modules
## Build misc components
cd tools/perf
make -j 8
cd ../power/cpupower
make -j 8
cd ../../..
## Get the kernel version
export kver=`make kernelrelease`
echo ${kver}
## Install kernel modules and components to disk
${RUN_AS_ROOT} make modules_install
${RUN_AS_ROOT} mkdir -p /lib/modules/${kver}/tools
${RUN_AS_ROOT} cp -v tools/perf/perf /lib/modules/${kver}/tools
${RUN_AS_ROOT} cp -v tools/power/cpupower/cpupower /lib/modules/${kver}/tools
${RUN_AS_ROOT} cp -v tools/power/cpupower/libcpupower.so.0.0.1 /lib/modules/${kver}/tools/libcpupower.so.0
## Update /boot components
${RUN_AS_ROOT} cp -v .config /boot/config-${kver}
${RUN_AS_ROOT} cp -v arch/arm64/boot/Image /boot/Image-${kver}
${RUN_AS_ROOT} mkdir -p /boot/dtb-${kver}
${RUN_AS_ROOT} cp -v arch/arm64/boot/dts/qcom/sc7180-trogdor*.dtb /boot/dtb-${kver}
${RUN_AS_ROOT} cp -v System.map /boot/System.map-${kver}
## Build chromebook compatible image
cp arch/arm64/boot/Image Image
lz4 -f Image Image.lz4
dd if=/dev/zero of=bootloader.bin bs=512 count=1
mkimage -D "-I dts -O dtb -p 2048" -f auto -A arm64 -O linux -T kernel -C lz4 -a 0 -d Image.lz4 ${DT_BLOBS} kernel.itb kernel.itb
vbutil_kernel --pack vmlinux.kpart --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --version 1 --config cmdline --bootloader bootloader.bin --vmlinuz kernel.itb --arch arm
${RUN_AS_ROOT} cp -v vmlinux.kpart /boot/vmlinux.kpart-${kver}
## Write vmlinux to kernel partition
${RUN_AS_ROOT} dd if=vmlinux.kpart of=/dev/mmcblk1p1
## Update initramfs
cd /boot
${RUN_AS_ROOT} update-initramfs -c -k ${kver}
cd -
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment