--- /dev/null
+#
+# Copyright (C) 2020 Zoltan HERPAI
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=opensbi
+PKG_RELEASE:=1
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL=https://github.com/riscv/opensbi
+PKG_SOURCE_DATE:=2019-11-11
+PKG_SOURCE_VERSION:=18897aaf5d0382017c05a5690d0bc8e0d044270f
+PKG_MIRROR_HASH:=8379cfbd1ce61788b4d715563375e6d6c21cd51133962a630628e6a607c370ee
+
+PKG_BUILD_DIR = $(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
+
+PKG_TARGETS:=bin
+PKG_FLAGS:=nonshared
+PKG_LICENSE:=BSD-2-Clause
+PKG_LICENSE_FILES:=COPYING.BSD
+PKG_BUILD_PARALLEL:=1
+
+PKG_MAINTAINER:=Zoltan HERPAI <wigyori@uid0.hu>
+
+export GCC_HONOUR_COPTS=s
+
+MAKE_VARS = \
+ CROSS_COMPILE="$(TARGET_CROSS)"
+
+include $(INCLUDE_DIR)/package.mk
+
+define OpenSBI/Default
+ BUILD_TARGET:=riscv64
+ OPENSBI_IMAGE:=fw_payload.bin
+ URL:=https://github.com/riscv/opensbi/blob/master/README.md
+# HIDDEN:=1
+endef
+
+define OpenSBI/sifive_fu540
+ $(OpenSBI/Default)
+ NAME:=SiFive Unleashed
+ OPENSBI_PLATFORM:=sifive/fu540
+ DTS:=hifive-unleashed-a00.dtb
+endef
+
+#OPENSBI_TARGETS := sifive_fu540
+
+#define Build/Compile
+# $(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) \
+# PLATFORM=sifive/fu540 \
+# FW_PAYLOAD_PATH=$(STAGING_DIR_IMAGE)/sifive_fu540-u-boot.bin \
+# FW_PAYLOAD_FDT_PATH=$(STAGING_DIR_IMAGE)/hifive-unleashed-a00.dtb
+#
+# $(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) \
+# PLATFORM=qemu/virt
+#endef
+
+define Package/opensbi/install/default
+endef
+
+#define Package/opensbi/install
+# #$(INSTALL_BIN) $(PKG_BUILD_DIR)/build/platform/qemu/sifive_u/firmware/fw_jump.elf $(BIN_DIR)/fw_jump.sifive_u.elf
+# $(INSTALL_BIN) $(PKG_BUILD_DIR)/build/platform/qemu/virt/firmware/fw_jump.elf $(BIN_DIR)/fw_jump.virt.elf
+#
+# $(INSTALL_BIN) $(PKG_BUILD_DIR)/build/platform/sifive/fu540/firmware/fw_payload.bin $(STAGING_DIR)/fw_payload.fu540.bin
+#endef
+
+
+define Package/opensbi/install/default
+ $(CP) $(patsubst %,$(PKG_BUILD_DIR)/%,$(OPENSBI_IMAGE)) $(1)/
+endef
+
+Package/opensbi/install = $(Package/opensbi/install/default)
+
+#define OpenSBI/Init
+# BUILD_TARGET:=
+# BUILD_SUBTARGET:=
+# BUILD_DEVICES:=
+# NAME:=
+# DEPENDS:=
+# HIDDEN:=
+# DEFAULT:=
+# VARIANT:=$(1)
+## OPENSBI_CONFIG:=$(1)
+# OPENSBI_IMAGE:=fw_payload.bin
+#endef
+
+#TARGET_DEP = TARGET_$(BUILD_TARGET)$(if $(BUILD_SUBTARGET),_$(BUILD_SUBTARGET))
+
+#UBOOT_MAKE_FLAGS = \
+# HOSTCC="$(HOSTCC)" \
+# HOSTCFLAGS="$(HOST_CFLAGS) $(HOST_CPPFLAGS) -std=gnu11" \
+# HOSTLDFLAGS="$(HOST_LDFLAGS)"
+
+define Build/OpenSBI/Target
+ $(eval $(call OpenSBI/Init,$(1)))
+ $(eval $(call OpenSBI/Default,$(1)))
+ $(eval $(call OpenSBI/$(1),$(1)))
+
+ define Package/opensbi-$(1)
+ SECTION:=boot
+ CATEGORY:=Boot Loaders
+ TITLE:=OpenSBI for $(NAME)
+ VARIANT:=$(VARIANT)
+# DEPENDS:=@!IN_SDK $(DEPENDS) +u-boot-$(1)
+# HIDDEN:=$(HIDDEN)
+ ifneq ($(BUILD_TARGET),)
+ DEPENDS += @$(TARGET_DEP)
+ ifneq ($(BUILD_DEVICES),)
+ DEFAULT := y if ($(TARGET_DEP)_Default \
+ $(patsubst %,|| $(TARGET_DEP)_DEVICE_%,$(BUILD_DEVICES)) \
+ $(patsubst %,|| $(patsubst TARGET_%,TARGET_DEVICE_%,$(TARGET_DEP))_DEVICE_%,$(BUILD_DEVICES)))
+ endif
+ endif
+ $(if $(DEFAULT),DEFAULT:=$(DEFAULT))
+ endef
+
+ define Package/opensbi-$(1)/install
+ $$(Package/opensbi/install)
+ endef
+endef
+
+define Build/Configure/OpenSBI
+# +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) $(OPENSBI_CONFIGURE_VARS) $(UBOOT_CONFIG)_config
+endef
+
+#DTC=$(wildcard $(LINUX_DIR)/scripts/dtc/dtc)
+
+define Build/Compile/OpenSBI
+ +$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) \
+ PLATFORM=$(OPENSBI_PLATFORM) \
+ FW_PAYLOAD_PATH=$(STAGING_DIR_IMAGE)/$(subst /,_/$(OPENSBI_PLATFORM)-u-boot.bin \
+ FW_FDT_PATH=$(STAGING_DIR_IMAGE)/$(DTS)
+endef
+
+define Build/Compile
+#<------>$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) \
+#<------><------>PLATFORM=sifive/fu540 \
+#<------><------>FW_PAYLOAD_PATH=$(STAGING_DIR_IMAGE)/sifive_fu540-u-boot.bin \
+#<------><------>FW_PAYLOAD_FDT_PATH=$(STAGING_DIR_IMAGE)/hifive-unleashed-a00.dtb
+
+
+# +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
+# CROSS_COMPILE=$(TARGET_CROSS) \
+# $(if $(DTC),DTC="$(DTC)") \
+# $(UBOOT_MAKE_FLAGS)
+endef
+
+#todo
+define BuildPackage/OpenSBI/Defaults
+ Build/Configure/Default = $$$$(Build/Configure/OpenSBI)
+ Build/Compile/Default = $$$$(Build/Compile/OpenSBI)
+endef
+
+define BuildPackage/OpenSBI
+ $(eval $(call BuildPackage/OpenSBI/Defaults))
+# $(foreach type,$(if $(DUMP),$(OPENSBI_TARGETS),$(BUILD_VARIANT)), \
+ $(foreach type,$(OPENSBI_TARGETS), \
+# $(foreach type,$(UBOOT_TARGETS), \
+ $(eval $(call Build/OpenSBI/Target,$(type)))
+ )
+
+ $(eval $(call Build/DefaultTargets))
+ $(foreach type,$(OPENSBI_TARGETS), \
+# $(foreach type,$(UBOOT_TARGETS), \
+# $(foreach type,$(if $(DUMP),$(OPENSBI_TARGETS),$(BUILD_VARIANT)), \
+ $(call BuildPackage,opensbi-$(type))
+ )
+endef
+
+$(eval $(call BuildPackage,OpenSBI))