#!/bin/sh
# Generate a boot.img for the Razer Forge TV from an unpacked one
set -e

bootimgfile=${1:-my-boot.img}
outdir=${2:-mybootimg}

cd "$outdir/ramdisk"
find \
    | grep -v '^.$'\
    | sort\
    | pax -w -x sv4cpio -M mtime -M uidgid -s '#^./##' -d -f ../myinitrd.cpio

cd ..
cat myinitrd.cpio | gzip > myinitrd.img

cd ..

echo "Generating new boot image: $bootimgfile"
../mkbootimg.py\
    --kernel "$outdir/zImage"\
    --ramdisk "$outdir/myinitrd.img"\
    --cmdline "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x3b7 dwc3_msm.cpu_to_affin=1"\
    --pagesize 0x1000\
    --kernel_offset 0x8000\
    --ramdisk_offset 0x1000000\
    --tags_offset 0x100\
    -o "$bootimgfile"
