#!/bin/bash echo -e "If you have some errors when trying to rebuild, delete ./out dir" echo "" FIRE_VERSION="1.0" set -e if [ -z "$1" ]; then echo "Please exec from root directory" exit 1 fi cd "$1" if [ "$(uname -m)" != "x86_64" ]; then echo "This script requires an x86_64 (64-bit) machine." exit 1 fi export PATH="$(pwd)/kernel_build/bin:$PATH" echo -e "Check in btop, htop, top (whatever you use) if its building." # Configs OUTDIR="$(pwd)/out" MODULES_OUTDIR="$(pwd)/modules_out" TMPDIR="$(pwd)/kernel_build/tmp" IN_PLATFORM="$(pwd)/kernel_build/vboot_platform" IN_DLKM="$(pwd)/kernel_build/vboot_dlkm" IN_DTB="$OUTDIR/arch/arm64/boot/dts/exynos/s5e8825.dtb" PLATFORM_RAMDISK_DIR="$TMPDIR/ramdisk_platform" DLKM_RAMDISK_DIR="$TMPDIR/ramdisk_dlkm" PREBUILT_RAMDISK="$(pwd)/kernel_build/boot/ramdisk" MODULES_DIR="$DLKM_RAMDISK_DIR/lib/modules" MKBOOTIMG="$(pwd)/kernel_build/mkbootimg/mkbootimg.py" MKDTBOIMG="$(pwd)/kernel_build/dtb/mkdtboimg.py" OUT_KERNELZIP="$(pwd)/kernel_build/FireAsf-${FIRE_VERSION}_a53x.zip" OUT_KERNELTAR="$(pwd)/kernel_build/FireAsf-${FIRE_VERSION}_a53x.tar" OUT_KERNEL="$OUTDIR/arch/arm64/boot/Image" OUT_BOOTIMG="$(pwd)/kernel_build/zip/boot.img" OUT_VENDORBOOTIMG="$(pwd)/kernel_build/zip/vendor_boot.img" OUT_DTBIMAGE="$TMPDIR/dtb.img" # Kernel-side BUILD_ARGS="LOCALVERSION=-FireAsf-${FIRE_VERSION} KBUILD_BUILD_USER=Ksawlii KBUILD_BUILD_HOST=FireAsFuck" kfinish() { rm -rf "$TMPDIR" rm -rf "$MODULES_OUTDIR" } kfinish DIR="$(readlink -f .)" PARENT_DIR="$(readlink -f ${DIR}/..)" export CROSS_COMPILE="$PARENT_DIR/clang-r416183b/bin/aarch64-linux-gnu-" export CC="$PARENT_DIR/clang-r416183b/bin/clang" export PLATFORM_VERSION=12 export ANDROID_MAJOR_VERSION=s export PATH="$PARENT_DIR/build-tools/path/linux-x86:$PARENT_DIR/clang-r416183b/bin:$PATH" export TARGET_SOC=s5e8825 export LLVM=1 LLVM_IAS=1 export ARCH=arm64 if [ ! -d "$PARENT_DIR/clang-r416183b" ]; then git clone https://github.com/crdroidandroid/android_prebuilts_clang_host_linux-x86_clang-r416183b "$PARENT_DIR/clang-r416183b" --depth=1 fi if [ ! -d "$PARENT_DIR/build-tools" ]; then git clone https://android.googlesource.com/platform/prebuilts/build-tools "$PARENT_DIR/build-tools" --depth=1 fi make -j$(nproc --all) -C $(pwd) O=out $BUILD_ARGS a53x_defconfig >/dev/null make -j$(nproc --all) -C $(pwd) O=out $BUILD_ARGS dtbs >/dev/null make -j$(nproc --all) -C $(pwd) O=out $BUILD_ARGS >/dev/null make -j$(nproc --all) -C $(pwd) O=out INSTALL_MOD_STRIP="--strip-debug --keep-section=.ARM.attributes" INSTALL_MOD_PATH="$MODULES_OUTDIR" modules_install >/dev/null rm -rf "$TMPDIR" rm -f "$OUT_BOOTIMG" rm -f "$OUT_VENDORBOOTIMG" mkdir "$TMPDIR" mkdir -p "$MODULES_DIR/0.0" mkdir "$PLATFORM_RAMDISK_DIR" cp -rf "$IN_PLATFORM"/* "$PLATFORM_RAMDISK_DIR/" mkdir "$PLATFORM_RAMDISK_DIR/first_stage_ramdisk" cp -f "$PLATFORM_RAMDISK_DIR/fstab.s5e8825" "$PLATFORM_RAMDISK_DIR/first_stage_ramdisk/fstab.s5e8825" if ! find "$MODULES_OUTDIR/lib/modules" -mindepth 1 -type d | read; then echo "Unknown error!" exit 1 fi missing_modules="" for module in $(cat "$IN_DLKM/modules.load"); do i=$(find "$MODULES_OUTDIR/lib/modules" -name $module); if [ -f "$i" ]; then cp -f "$i" "$MODULES_DIR/0.0/$module" else missing_modules="$missing_modules $module" fi done if [ "$missing_modules" != "" ]; then echo "ERROR: the following modules were not found: $missing_modules" exit 1 fi depmod 0.0 -b "$DLKM_RAMDISK_DIR" sed -i 's/\([^ ]\+\)/\/lib\/modules\/\1/g' "$MODULES_DIR/0.0/modules.dep" cd "$MODULES_DIR/0.0" for i in $(find . -name "modules.*" -type f); do if [ $(basename "$i") != "modules.dep" ] && [ $(basename "$i") != "modules.softdep" ] && [ $(basename "$i") != "modules.alias" ]; then rm -f "$i" fi done cd "$DIR" cp -f "$IN_DLKM/modules.load" "$MODULES_DIR/0.0/modules.load" mv "$MODULES_DIR/0.0"/* "$MODULES_DIR/" rm -rf "$MODULES_DIR/0.0" echo "Building dtb image..." python2 "$MKDTBOIMG" create "$OUT_DTBIMAGE" --custom0=0x00000000 --custom1=0xff000000 --version=0 --page_size=2048 "$IN_DTB" || exit 1 echo "Building boot image..." $MKBOOTIMG --header_version 4 \ --kernel "$OUT_KERNEL" \ --output "$OUT_BOOTIMG" \ --ramdisk "$PREBUILT_RAMDISK" \ --os_version 12.0.0 \ --os_patch_level 2024-09 || exit 1 echo "Done!" echo "Building vendor_boot image..." cd "$DLKM_RAMDISK_DIR" find . | cpio --quiet -o -H newc -R root:root | lz4 -9cl > ../ramdisk_dlkm.lz4 cd ../ramdisk_platform find . | cpio --quiet -o -H newc -R root:root | lz4 -9cl > ../ramdisk_platform.lz4 cd .. echo "buildtime_bootconfig=enable" > bootconfig $MKBOOTIMG --header_version 4 \ --vendor_boot "$OUT_VENDORBOOTIMG" \ --vendor_bootconfig "$(pwd)/bootconfig" \ --dtb "$OUT_DTBIMAGE" \ --vendor_ramdisk "$(pwd)/ramdisk_platform.lz4" \ --ramdisk_type dlkm \ --ramdisk_name dlkm \ --vendor_ramdisk_fragment "$(pwd)/ramdisk_dlkm.lz4" \ --os_version 12.0.0 \ --os_patch_level 2024-09 || exit 1 cd "$DIR" echo "Done!" echo "Building zip..." cd "$(pwd)/kernel_build/zip" rm -f "$OUT_KERNELZIP" brotli --quality=11 -c boot.img > boot.br brotli --quality=11 -c vendor_boot.img > vendor_boot.br zip -r9 -q "$OUT_KERNELZIP" META-INF boot.br vendor_boot.br rm -f boot.br vendor_boot.br cd "$DIR" echo "Done! Output: $OUT_KERNELZIP" echo "Building tar..." cd "$(pwd)/kernel_build" rm -f "$OUT_KERNELTAR" lz4 -c -12 -B6 --content-size "$OUT_BOOTIMG" > boot.img.lz4 lz4 -c -12 -B6 --content-size "$OUT_VENDORBOOTIMG" > vendor_boot.img.lz4 tar -cf "$OUT_KERNELTAR" boot.img.lz4 vendor_boot.img.lz4 cd "$DIR" rm -f boot.img.lz4 vendor_boot.img.lz4 echo "Done! Output: $OUT_KERNELTAR" echo "Cleaning..." rm -f "${OUT_VENDORBOOTIMG}" "${OUT_BOOTIMG}" kfinish