Created
May 25, 2020 00:48
-
-
Save calebccff/7c0db05726b4ea8ec86b3ef695e7a044 to your computer and use it in GitHub Desktop.
Run in a kernel source tree to make a boot image from a mainline kernel (assume $HOME/pmos exists be default)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OUT="$HOME/pmos/mainline-boot.img" | |
DTB="$PWD/.output/arch/arm64/boot/dts/qcom/sdm845-oneplus-enchilada.dtb" | |
IMAGE="$PWD/.output/arch/arm64/boot/Image.gz" | |
THIS="$(basename $0)" | |
die() { | |
echo $1 1>&2 | |
exit | |
} | |
usage() { | |
echo "$THIS [ -d DTB(=$DTB) ] [ -r RAMDISK] [ -o OUT(=$OUT) ] [ -k KERNEL_IMAGE ] " 1>&2 | |
exit 1 | |
} | |
while getopts "r:o:d:" options; do | |
case "${options}" in | |
r) | |
RAMDISK=${OPTARG} | |
;; | |
o) | |
OUT=${OPTARG} | |
;; | |
d) | |
DTB=${OPTARG} | |
;; | |
k) | |
IMAGE=${OPTARG} | |
;; | |
:) | |
die "-${OPTARG} requires an argument" | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
[[ -f "$IMAGE" ]] || die "Kernel image \"$IMAGE\" doesn't exist" | |
[[ -f "$DTB" ]] || die "Device Tree Blob \"$DTB\" doesn't exist" | |
echo -e "$THIS: Appending dtb \"$(basename $DTB)\" to image \"$IMAGE\"" | |
cat $IMAGE $DTB > /tmp/kernel-dtb || die "Failed to append dtb" | |
CMD="mkbootimg \ | |
--base 0x0 \ | |
--kernel_offset 0x8000 \ | |
--ramdisk_offset 0x1000000 \ | |
--tags_offset 0x100 \ | |
--pagesize 4096 \ | |
--second_offset 0xf00000 \ | |
--kernel /tmp/kernel-dtb -o $OUT" | |
if [ ! -z $RAMDISK ]; then | |
CMD="$CMD --ramdisk $RAMDISK" | |
fi | |
$CMD || echo "Failed to make $OUT" | |
echo "$THIS: Boot image at $OUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment