#!/bin/sh
set -e

PREREQS=""

prereqs() {
    echo "$PREREQS"
}

case "$1" in
prereqs)
    prereqs
    exit 0
    ;;
esac

. /usr/share/initramfs-tools/hook-functions

machine=`uname -m`
if [ "x$machine" = "xloongarch64" ];then
     if [ -f /lib/firmware/loongson/lg100_cp.bin ];then
        # Try to copy the firmware file and log if it fails
        if ! copy_exec /lib/firmware/loongson/lg100_cp.bin; then
            echo "Warning: Failed to copy firmware file /lib/firmware/loongson/lg100_cp.bin to initramfs" >&2
        fi
     else
        echo "Warning: Firmware file /lib/firmware/loongson/lg100_cp.bin not found" >&2
     fi

     # Try to add the gsgpu module and log if it fails
     if ! manual_add_modules gsgpu; then
        echo "Warning: Failed to add gsgpu module to initramfs" >&2
     fi
fi
