DESCRIPTION = "Linux Kernel for Orange Pi Zero"
SECTION = "kernel"
LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRCREV_machine = "3495b5ee0594566c9fed930b96b1cae90600412e"
# SRCREV_meta = "1a97a82e62ebf4ef3787768a1f5937e2d2f280ce"

# COMPATIBLE_MACHINE ?= "^orange-pi-zero2w$"
COMPATIBLE_MACHINE = "(sun4i|sun5i|sun7i|sun8i|sun50i)"

KERNEL_DEVICETREE = "allwinner/sun50i-h616-orangepi-zero2w.dtb \
    allwinner/overlay/sun50i-h616-disable-leds.dtbo \
    allwinner/overlay/sun50i-h616-disable-uart0.dtbo \
    allwinner/overlay/sun50i-h616-gpu.dtbo \
    allwinner/overlay/sun50i-h616-ir.dtbo \
    allwinner/overlay/sun50i-h616-ph-i2c1.dtbo \
    allwinner/overlay/sun50i-h616-ph-i2c2.dtbo \
    allwinner/overlay/sun50i-h616-ph-i2c3.dtbo \
    allwinner/overlay/sun50i-h616-ph-i2c4.dtbo \
    allwinner/overlay/sun50i-h616-ph-pwm12.dtbo \
    allwinner/overlay/sun50i-h616-ph-pwm34.dtbo \
    allwinner/overlay/sun50i-h616-ph-uart2.dtbo \
    allwinner/overlay/sun50i-h616-ph-uart5.dtbo \
    allwinner/overlay/sun50i-h616-pi-i2c0.dtbo \
    allwinner/overlay/sun50i-h616-pi-i2c1.dtbo \
    allwinner/overlay/sun50i-h616-pi-i2c2.dtbo \
    allwinner/overlay/sun50i-h616-pi-pwm1.dtbo \
    allwinner/overlay/sun50i-h616-pi-pwm2.dtbo \
    allwinner/overlay/sun50i-h616-pi-pwm3.dtbo \
    allwinner/overlay/sun50i-h616-pi-pwm4.dtbo \
    allwinner/overlay/sun50i-h616-pi-uart2.dtbo \
    allwinner/overlay/sun50i-h616-pi-uart3.dtbo \
    allwinner/overlay/sun50i-h616-pi-uart4.dtbo \
    allwinner/overlay/sun50i-h616-spi0-spidev.dtbo \
    allwinner/overlay/sun50i-h616-spi1-cs0-cs1-spidev.dtbo \
    allwinner/overlay/sun50i-h616-spi1-cs0-spidev.dtbo \
    allwinner/overlay/sun50i-h616-spi1-cs1-spidev.dtbo \
    allwinner/overlay/sun50i-h616-usb0-host.dtbo \
    allwinner/overlay/sun50i-h616-zero2w-disable-led.dtbo \
"

LINUX_OPI_BRANCH ?= "orange-pi-6.1-sun50iw9"

SRC_URI = " \
    git://github.com/orangepi-xunlong/linux-orangepi.git;name=machine;branch=${LINUX_OPI_BRANCH};protocol=https \
    file://defconfig \ 
    file://0003-enable-mali-gpu.patch \
    file://0004-fix-unisocwcn-include-path.patch \
    "
# file://0002-fix-rtl8822c-compi-error.patch 
# file://0005-fix-rtl8xxx-include-path.patch

# Pull in the devicetree files into the rootfs
RDEPENDS_${KERNEL_PACKAGE_NAME}-base += "kernel-devicetree"

KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT}"

inherit kernel

require linux.inc

LINUX_VERSION ?= "${PV}"
S = "${UNPACKDIR}/git"

do_deploy:append() {
    install -d ${DEPLOY_DIR_IMAGE}
    install -d ${DEPLOY_DIR_IMAGE}/allwinner
    install -d ${DEPLOY_DIR_IMAGE}/allwinner/overlay
    for file in ${KERNEL_DEVICETREE}; do
        name=$(basename $file)
        ext="${name##*.}"
        if [ "$ext" = "dtb" ]; then
            ln -sf ${DEPLOY_DIR_IMAGE}/${name} ${DEPLOY_DIR_IMAGE}/allwinner/${name}
        else
            ln -sf ${DEPLOY_DIR_IMAGE}/${name} ${DEPLOY_DIR_IMAGE}/allwinner/overlay/${name}
        fi
    done
    install -m 0755 ${S}/arch/arm64/boot/dts/allwinner/overlay/sun50i-h616-fixup.scr ${DEPLOY_DIR_IMAGE}/allwinner/overlay/

}

# allwinner/overlay/sun50i-h616-fixup.scr

FILES_${KERNEL_PACKAGE_NAME}-base:append = " ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin.modinfo"
