COMPONENT_TARGETS = $(HARDWARE_VISIONFIVE2)
NEED_ABS_PATH = true
COMPONENT_IS_3PP = true
include ../../../../build-system/constants.mk
SOURCE_REQUIRES = sources/U-Boot/StarFive
REQUIRES = boot/kernel/visionfive2/6.1.31-3.8.2
# ======= __END_OF_REQUIRES__ =======
version = 2021.10-3.8.2
tar_xz_archive = $(SRC_PACKAGE_PATH)/U-Boot/StarFive/u-boot/u-boot-$(version).tar.xz
SRC_ARCHIVE = $(tar_xz_archive)
SRC_DIR = $(TARGET_BUILD_DIR)/u-boot-$(version)
src_done = $(TARGET_BUILD_DIR)/.source_done
opensbi_version = 1.2-3.8.2
opensbi_archive = $(SRC_PACKAGE_PATH)/U-Boot/StarFive/opensbi/opensbi-$(opensbi_version).tar.xz
OPENSBI_SRC_DIR = $(TARGET_BUILD_DIR)/opensbi-$(opensbi_version)
opensbi_src_done = $(TARGET_BUILD_DIR)/.opensbi-source-done
tools_version = 20231107
tools_archive = $(SRC_PACKAGE_PATH)/U-Boot/StarFive/Tools/tools-$(tools_version).tar.xz
TOOLS_SRC_DIR = $(TARGET_BUILD_DIR)/tools-$(tools_version)
tools_src_done = $(TARGET_BUILD_DIR)/.tools-source-done
PATCHES = PATCHES
u_boot = $(TARGET_BUILD_DIR)/.u_boot_done
u_boot_config = starfive_visionfive2_defconfig
spl_tool = $(TARGET_BUILD_DIR)/.spl_tool_done
opensbi = $(TARGET_BUILD_DIR)/.opensbi_done
u_boot_spl = $(TARGET_BUILD_DIR)/u-boot-spl.bin
fw_payload = $(TARGET_BUILD_DIR)/fw_payload.img
#
# Image, zImage from Linux kernel package:
#
kernel_version = 6.1.31
linux_Image = $(TARGET_DEST_DIR)/bootfs/Image
linux_zImage = $(TARGET_DEST_DIR)/bootfs/vmlinuz
#
# uImage, uzImage for U-Boot (see u-boot-2021.10-3.8.2/include/configs/starfive-visionfive2.h):
#
kernel_addr = 0x40200000
entry_point = $(kernel_addr)
uImage = $(TARGET_BUILD_DIR)/uImage
uzImage = $(TARGET_BUILD_DIR)/uzImage
fdt_addr = 0x46000000
kernel_comp_addr = 0x5a000000
ramdisk_addr = 0x46100000
#
# Boot Scripts:
#
boot_emmc_script = $(TARGET_BUILD_DIR)/boot.emmc.script
boot_emmc_scr = $(TARGET_BUILD_DIR)/boot.emmc.scr
boot_sdhc_script = $(TARGET_BUILD_DIR)/boot.sdhc.script
boot_sdhc_scr = $(TARGET_BUILD_DIR)/boot.sdhc.scr
boot_nvme_script = $(TARGET_BUILD_DIR)/boot.nvme.script
boot_nvme_scr = $(TARGET_BUILD_DIR)/boot.nvme.scr
spi_flash_image = $(TARGET_BUILD_DIR)/$(HARDWARE).spi-flash.image
install_spi_flash_image = $(TARGET_BUILD_DIR)/.spi_flash_image_done
spi_flash_image_sum = $(TARGET_BUILD_DIR)/$(HARDWARE).spi-flash.image.md5
install_spi_flash_image_sum = $(TARGET_BUILD_DIR)/.spi_flash_image_sum_done
ifneq ($(filter $(TOOLCHAIN),$(TOOLCHAIN_RISCV64_GLIBC)),)
ARCH = riscv
endif
USE_TARGET_DEST_DIR_SYSROOT = no
####### Targets
PKG_GROUP = boot
UBOOT_BIN_PKG_NAME = u-boot
UBOOT_BIN_PKG_VERSION = 2022.10
UBOOT_BIN_PKG_ARCH = $(PKGARCH)
UBOOT_BIN_PKG_DISTRO_NAME = $(DISTRO_NAME)
UBOOT_BIN_PKG_DISTRO_VERSION = $(DISTRO_VERSION)
UBOOT_BIN_PKG_GROUP = $(PKG_GROUP)
### |---handy-ruler-------------------------------|
UBOOT_BIN_PKG_SHORT_DESCRIPTION = StarFive VisionFive U-Boot
UBOOT_BIN_PKG_URL = $(BUG_URL)
UBOOT_BIN_PKG_LICENSE = custom
UBOOT_BIN_PKG_DESCRIPTION_FILE = $(TARGET_BUILD_DIR)/$(UBOOT_BIN_PKG_NAME)-pkg-description
UBOOT_BIN_PKG_DESCRIPTION_FILE_IN = $(UBOOT_BIN_PKG_NAME)-pkg-description.in
UBOOT_BIN_PKG_INSTALL_SCRIPT = $(UBOOT_BIN_PKG_NAME)-pkg-install.sh
UBOOT_BIN_PKG = $(CURDIR)/$(TARGET_BUILD_DIR)/$(UBOOT_BIN_PKG_NAME)-package
build_uboot_pkg = $(TARGET_BUILD_DIR)/.u_boot_pkg_done
pkg_basename = $(UBOOT_BIN_PKG_NAME)-$(UBOOT_BIN_PKG_VERSION)-$(UBOOT_BIN_PKG_ARCH)-$(UBOOT_BIN_PKG_DISTRO_NAME)-$(UBOOT_BIN_PKG_DISTRO_VERSION)
pkg_archive = $(TARGET_BUILD_DIR)/$(PKG_GROUP)/$(pkg_basename).$(pkg_arch_suffix)
pkg_certificate = $(call cert-name,$(pkg_archive))
pkg_signature = $(call sign-name,$(pkg_archive))
pkg_description = $(call desc-name,$(pkg_archive))
products = $(call pkg-files,$(pkg_archive))
BUILD_TARGETS = $(u_boot)
BUILD_TARGETS += $(spl_tool)
BUILD_TARGETS += $(opensbi)
BUILD_TARGETS += $(u_boot_spl)
BUILD_TARGETS += $(fw_payload)
BUILD_TARGETS += $(uImage)
BUILD_TARGETS += $(uzImage)
BUILD_TARGETS += $(boot_emmc_script)
BUILD_TARGETS += $(boot_sdhc_script)
BUILD_TARGETS += $(boot_nvme_script)
BUILD_TARGETS += $(boot_emmc_scr)
BUILD_TARGETS += $(boot_sdhc_scr)
BUILD_TARGETS += $(boot_nvme_scr)
BUILD_TARGETS += $(build_uboot_pkg)
BUILD_TARGETS += $(install_spi_flash_image)
BUILD_TARGETS += $(install_spi_flash_image_sum)
PRODUCT_TARGETS = $(products)
ROOTFS_TARGETS = $(pkg_archive)
include ../../../../build-system/core.mk
#
# U-Boot options:
#
suppress-host-warnings = -Wno-stringop-truncation
suppress-target-warnings = -Wno-unused-variable -Wno-int-conversion -Wno-cpp -Wno-implicit-function-declaration
HOST_TOOLS_SETTINGS = PKG_CONFIG_PATH= PYTHON3=/usr/bin/python3
HOST_TOOLS_SETTINGS += HOSTLDFLAGS='-L/usr/lib64'
HOST_TOOLS_SETTINGS += HOSTCFLAGS='-isystem/usr/include $(suppress-host-warnings)'
TARGET_TOOLS_SETTINGS = KCFLAGS='$(suppress-target-warnings)'
#
# OpenSBI options:
#
U_BOOT_PATH = ../u-boot-$(version)
OPENSBI_SETTINGS = PLATFORM=generic FW_PAYLOAD_PATH=$(U_BOOT_PATH)/u-boot.bin
OPENSBI_SETTINGS += FW_FDT_PATH=$(U_BOOT_PATH)/arch/riscv/dts/starfive_visionfive2.dtb
OPENSBI_SETTINGS += FW_TEXT_START=0x40000000
##
## armv7-m (cortex-m0) toolchain:
##
#M0_TOOLCHAIN_PATH = /opt/toolchains/arm-NONE-eabi-newlib/1.9.8
#CORTEX_M0_SETTINGS = M0_CROSS_COMPILE=$(M0_TOOLCHAIN_PATH)/bin/arm-none-eabi- PLAT=rk3399 bl31
#
#suppress-warnings = -Wno-maybe-uninitialized -Wno-stringop-truncation
#
#HOST_TOOLS_SETTINGS = PYTHON3=/usr/bin/python3 HOSTLDFLAGS='-L/usr/lib64' HOSTCFLAGS='-I/usr/include $(suppress-warnings)'
device_dtb = jh7110-visionfive-v2.dtb
#
# Extra kernel boot arguments:
#
extra = consoleblank=0
extra += no_console_suspend
####### Dependencies
$(opensbi_src_done): $(opensbi_archive)
@echo "Expanding $(opensbi_archive)"
@tar xJf $(opensbi_archive) -C $(TARGET_BUILD_DIR)
@touch $@
$(tools_src_done): $(tools_archive)
@echo "Expanding $(tools_archive)"
@tar xJf $(tools_archive) -C $(TARGET_BUILD_DIR)
@touch $@
$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP) $(opensbi_src_done) $(tools_src_done)
$(UNPACK_SRC_ARCHIVE)
$(APPLY_PATCHES)
@( cd $(SRC_DIR)/configs ; \
echo '# Set BOOTDELAY options:' >> $(u_boot_config) ; \
echo 'CONFIG_BOOTDELAY=3' >> $(u_boot_config) ; \
echo 'CONFIG_AUTOBOOT_KEYED=y' >> $(u_boot_config) ; \
echo 'CONFIG_AUTOBOOT_PROMPT="Hit SPACE in %d seconds to stop autoboot.\n"' >> $(u_boot_config) ; \
echo 'CONFIG_AUTOBOOT_STOP_STR=" "' >> $(u_boot_config) ; \
)
@touch $@
$(spl_tool): $(src_done)
# ======= Build spl_tool: =======
@$(MAKE) -C $(TOOLS_SRC_DIR)/spl_tool
@touch $@
UMAKE := $(HOST_TOOLS_SETTINGS) $(TARGET_TOOLS_SETTINGS) $(MAKE) -C $(SRC_DIR) ARCH=$(ARCH) CROSS_COMPILE='$(CROSS_PREFIX)'
$(u_boot): $(spl_tool)
# ======= Build U-Boot: =======
+$(UMAKE) $(u_boot_config)
+$(UMAKE)
@touch $@
OMAKE := $(MAKE) -C $(OPENSBI_SRC_DIR) ARCH=$(ARCH) CROSS_COMPILE='$(CROSS_PREFIX)' $(OPENSBI_SETTINGS)
$(opensbi): $(u_boot)
# ======= Build OpenSBI: =======
+$(OMAKE)
@touch $@
$(u_boot_spl): $(spl_tool) $(u_boot)
# ======= Create U-Boot SPL: =======
@$(TOOLS_SRC_DIR)/spl_tool/spl_tool -c -f $(SRC_DIR)/spl/u-boot-spl.bin
@cp -a $(SRC_DIR)/spl/u-boot-spl.bin.normal.out $@
$(fw_payload): $(opensbi)
# ======= Create fw_payload image: =======
@( cd $(TOOLS_SRC_DIR)/uboot_its ; \
cp ../../opensbi-$(opensbi_version)/build/platform/generic/firmware/fw_payload.bin ./ ; \
../../u-boot-$(version)/tools/mkimage -f visionfive2-uboot-fit-image.its \
-A $(ARCH) -O u-boot -T firmware visionfive2_fw_payload.img ; \
)
@cp -a $(TOOLS_SRC_DIR)/uboot_its/visionfive2_fw_payload.img $@
$(uImage): $(u_boot_spl) $(fw_payload)
$(CURDIR)/$(SRC_DIR)/tools/mkimage \
-A $(ARCH) -O linux -T kernel -C none -a $(kernel_addr) -e $(entry_point) \
-n $(kernel_version) -d $(linux_Image) $@
$(uzImage): $(u_boot_spl) $(fw_payload)
$(CURDIR)/$(SRC_DIR)/tools/mkimage \
-A $(ARCH) -O linux -T kernel -C lzma -a $(kernel_addr) -e $(entry_point) \
-n $(kernel_version) -d $(linux_zImage) $@
#
# NOTE:
# ====
# eMMC is always mmc 0 in u-boot and mmcblk0 in kernel
# sdhc is always mmc 1 in u-boot and mmcblk1 in kernel
# nvme is always nvme 0 in u-boot and nvme0n1 in kernel
#
$(boot_emmc_script): $(uImage) $(uzImage)
@( echo "" > $(boot_emmc_script) && \
echo "mmc dev 0" >> $(boot_emmc_script) && \
echo "mmcinfo" >> $(boot_emmc_script) && \
echo "ext4load mmc 0:2 \$${kernel_comp_addr_r} /boot/uzImage" >> $(boot_emmc_script) && \
echo "ext4load mmc 0:2 \$${fdt_addr_r} /boot/starfive/$(device_dtb)" >> $(boot_emmc_script) && \
echo "setenv bootargs 'earlycon=sbi console=ttyS0,115200n8 console=tty1 ro root=/dev/mmcblk0p2 rootwait rootfstype=ext4 $(extra)'" >> $(boot_emmc_script) && \
echo "bootm \$${kernel_comp_addr_r} - \$${fdt_addr_r}" >> $(boot_emmc_script) \
)
$(boot_emmc_scr): $(boot_emmc_script)
$(CURDIR)/$(SRC_DIR)/tools/mkimage -A $(ARCH) -T script -C none -n "Boot Script" -d $< $@
$(boot_sdhc_script): $(uImage) $(uzImage)
@( echo "" > $(boot_sdhc_script) && \
echo "mmc dev 1" >> $(boot_sdhc_script) && \
echo "mmcinfo" >> $(boot_sdhc_script) && \
echo "ext4load mmc 1:2 \$${kernel_comp_addr_r} /boot/uzImage" >> $(boot_sdhc_script) && \
echo "ext4load mmc 1:2 \$${fdt_addr_r} /boot/starfive/$(device_dtb)" >> $(boot_sdhc_script) && \
echo "setenv bootargs 'earlycon=sbi console=ttyS0,115200n8 console=tty1 ro root=/dev/mmcblk1p2 rootwait rootfstype=ext4 $(extra)'" >> $(boot_sdhc_script) && \
echo "bootm \$${kernel_comp_addr_r} - \$${fdt_addr_r}" >> $(boot_sdhc_script) \
)
$(boot_sdhc_scr): $(boot_sdhc_script)
$(CURDIR)/$(SRC_DIR)/tools/mkimage -A $(ARCH) -T script -C none -n "Boot Script" -d $< $@
$(boot_nvme_script): $(uImage) $(uzImage)
@( echo "" > $(boot_nvme_script) && \
echo "nvme device 0" >> $(boot_nvme_script) && \
echo "nvme info" >> $(boot_nvme_script) && \
echo "ext4load nvme 0:2 \$${kernel_comp_addr_r} /boot/uzImage" >> $(boot_nvme_script) && \
echo "ext4load nvme 0:2 \$${fdt_addr_r} /boot/starfive/$(device_dtb)" >> $(boot_nvme_script) && \
echo "setenv bootargs 'earlycon=sbi console=ttyS0,115200n8 console=tty1 ro root=/dev/nvme0n1p2 rootwait rootfstype=ext4 $(extra)'" >> $(boot_nvme_script) && \
echo "bootm \$${kernel_comp_addr_r} - \$${fdt_addr_r}" >> $(boot_nvme_script) \
)
$(boot_nvme_scr): $(boot_nvme_script)
$(CURDIR)/$(SRC_DIR)/tools/mkimage -A $(ARCH) -T script -C none -n "Boot Script" -d $< $@
$(build_uboot_pkg): $(boot_emmc_scr) $(boot_sdhc_scr) $(boot_nvme_scr)
@mkdir -p $(TARGET_DEST_DIR)/bootfs/u-boot
@mkdir -p $(UBOOT_BIN_PKG)/boot/u-boot
# ======= install U-Boot images =======
@cp -a $(u_boot_spl) $(fw_payload) $(UBOOT_BIN_PKG)/boot/u-boot
# ======= install signed kernel and script images =======
@cp -a $(uImage) $(uzImage) $(boot_emmc_scr) $(boot_sdhc_scr) $(boot_nvme_scr) $(UBOOT_BIN_PKG)/boot
@( cd $(UBOOT_BIN_PKG)/boot ; \
ln -sf boot.sdhc.scr boot.scr ; \
)
# ======= copy U-Boot images and binaries into devenv =======
@cp -a $(uImage) $(uzImage) $(boot_emmc_scr) $(boot_sdhc_scr) $(boot_nvme_scr) $(TARGET_DEST_DIR)/bootfs
@cp -a $(u_boot_spl) $(fw_payload) $(TARGET_DEST_DIR)/bootfs/u-boot
# ======= install Documentation =======
@mkdir -p $(UBOOT_BIN_PKG)/usr/doc/u-boot-$(UBOOT_BIN_PKG_VERSION)
@cp -a $(SRC_DIR)/Licenses $(SRC_DIR)/MAINTAINERS $(SRC_DIR)/README \
$(UBOOT_BIN_PKG)/usr/doc/u-boot-$(UBOOT_BIN_PKG_VERSION)
@touch $@
#
# In jh7110-visionfive-v2.dtsi defined:
#
# Offset | Length | Size | Part Name | Description
# ----------+-----------+-------+-----------+-----------------
# 0x0 0x40000 256k spl SPL
# 0xf0000 0x10000 64k uboot-env U-Boot environment variables
# 0x100000 0x300000 3072k uboot fw_payload.img (OpenSBI + U-Boot)
# 0xf00000 0x100000 1024k data Reseved
#
$(spi_flash_image): $(build_uboot_pkg)
# ======= Create SPI flash image: =======
@$(DD) if=/dev/zero bs=1k count=16384 | tr '\000' '\377' > $@
# ------- Clean U-Boot environment: -------
@$(DD) if=/dev/zero of=$@ bs=1k count=64 seek=960 conv=notrunc
# ------- Write u-boot-spl and fw_payload into flash image: -------
@$(DD) if=$(u_boot_spl) of=$@ bs=1k conv=notrunc
@$(DD) if=$(fw_payload) of=$@ bs=1k seek=1024 conv=notrunc
@cp -a $(spi_flash_image) $(UBOOT_BIN_PKG)/boot/u-boot/spi-flash.image
@( cd $(UBOOT_BIN_PKG)/boot/u-boot/ ; \
md5sum -b spi-flash.image > spi-flash.image.md5 ; \
)
@touch $@
$(install_spi_flash_image): $(spi_flash_image)
@$(BUILDSYSTEM)/install_targets \
--destination=$(PRODUCTS_DEST_DIR) \
--toolchain=$(TOOLCHAIN) \
--hardware=$(HARDWARE) \
--flavour=$(FLAVOUR) \
$^
@touch $@
$(spi_flash_image_sum): $(spi_flash_image)
@( cd $(TARGET_BUILD_DIR) ; \
md5sum -b $(HARDWARE).spi-flash.image > $(HARDWARE).spi-flash.image.md5 ; \
)
@touch $@
$(install_spi_flash_image_sum): $(spi_flash_image_sum)
@$(BUILDSYSTEM)/install_targets \
--destination=$(PRODUCTS_DEST_DIR) \
--toolchain=$(TOOLCHAIN) \
--hardware=$(HARDWARE) \
--flavour=$(FLAVOUR) \
$^
@touch $@
$(UBOOT_BIN_PKG_DESCRIPTION_FILE): $(UBOOT_BIN_PKG_DESCRIPTION_FILE_IN)
@cat $< | $(SED) -e "s/@VERSION@/$(UBOOT_BIN_PKG_VERSION)/g" | \
$(SED) -e "s/@HARDWARE_SPEC@/$(HW_SPEC)/g"> $@
$(pkg_certificate) : $(pkg_archive) ;
$(pkg_signature) : $(pkg_archive) ;
$(pkg_description) : $(pkg_archive) ;
$(pkg_archive): $(install_boot_records) $(UBOOT_BIN_PKG_DESCRIPTION_FILE) $(UBOOT_BIN_PKG_INSTALL_SCRIPT)
@cp $(UBOOT_BIN_PKG_DESCRIPTION_FILE) $(UBOOT_BIN_PKG)/.DESCRIPTION
@cp $(UBOOT_BIN_PKG_INSTALL_SCRIPT) $(UBOOT_BIN_PKG)/.INSTALL
@chmod a+x $(UBOOT_BIN_PKG)/.INSTALL
@$(BUILD_PKG_REQUIRES) $(UBOOT_BIN_PKG)/.REQUIRES
@echo "pkgname=$(UBOOT_BIN_PKG_NAME)" > $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "pkgver=$(UBOOT_BIN_PKG_VERSION)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "arch=$(UBOOT_BIN_PKG_ARCH)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "distroname=$(UBOOT_BIN_PKG_DISTRO_NAME)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "distrover=$(UBOOT_BIN_PKG_DISTRO_VERSION)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "group=$(UBOOT_BIN_PKG_GROUP)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "short_description=\"$(UBOOT_BIN_PKG_SHORT_DESCRIPTION)\"" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "url=$(UBOOT_BIN_PKG_URL)" >> $(UBOOT_BIN_PKG)/.PKGINFO ; \
echo "license=$(UBOOT_BIN_PKG_LICENSE)" >> $(UBOOT_BIN_PKG)/.PKGINFO
@$(PSEUDO) sh -c "cd $(UBOOT_BIN_PKG) && \
chown -R root:root . && \
$(MAKE_PACKAGE) -J --linkadd=yes $(GNUPG_OPTIONS) -m -d .. ."