Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

414 Commits   2 Branches   1 Tag

COMPONENT_TARGETS  = $(HARDWARE_REPKA_PI3)

NEED_ABS_PATH      = true

COMPONENT_IS_3PP   = true


include ../../../../build-system/constants.mk


SOURCE_REQUIRES    = sources/U-Boot/ATF
SOURCE_REQUIRES   += sources/U-Boot/denx

REQUIRES           = boot/kernel/repka-pi3/6.1.53

# ======= __END_OF_REQUIRES__ =======


version            = 2023.04
tar_bz2_archive    = $(SRC_PACKAGE_PATH)/U-Boot/denx/u-boot-$(version).tar.bz2
SRC_ARCHIVE        = $(tar_bz2_archive)
SRC_DIR            = $(TARGET_BUILD_DIR)/u-boot-$(version)
src_done           = $(TARGET_BUILD_DIR)/.source_done

atf_version        = 2.9.0
atf_archive        = $(SRC_PACKAGE_PATH)/U-Boot/ATF/arm-trusted-firmware-$(atf_version).tar.xz
ATF_SRC_DIR        = $(TARGET_BUILD_DIR)/arm-trusted-firmware-$(atf_version)
atf_src_done       = $(TARGET_BUILD_DIR)/.atf-source-done


PATCHES = PATCHES


bl31               = $(TARGET_DEST_DIR)/bootfs/bl31.bin

u_boot             = $(TARGET_BUILD_DIR)/.u_boot_done
u_boot_config      = repka-pi3_defconfig

#
# Image, zImage from Linux kernel package:
#
kernel_version     = 6.1.53
linux_Image        = $(TARGET_DEST_DIR)/bootfs/Image
linux_zImage       = $(TARGET_DEST_DIR)/bootfs/vmlinuz

#
# uImage, uzImage for U-Boot (see u-boot-2023.04/include/configs/sunxi-common.h):
#
kernel_addr        = 0x40080000
entry_point        = $(kernel_addr)
uImage             = $(TARGET_BUILD_DIR)/uImage
uzImage            = $(TARGET_BUILD_DIR)/uzImage

fdt_addr           = 0x4fa00000
kernel_comp_addr   = 0x44000000
ramdisk_addr       = 0x4ff00000

#
# Boot Scripts:
#
boot_sdhc_script    = $(TARGET_BUILD_DIR)/boot.sdhc.script
boot_sdhc_scr       = $(TARGET_BUILD_DIR)/boot.sdhc.scr


boot_records         = $(TARGET_BUILD_DIR)/$(HARDWARE).boot-records
install_boot_records = $(TARGET_BUILD_DIR)/.boot_records_done


ifneq ($(filter $(TOOLCHAIN),$(TOOLCHAIN_H5_GLIBC)),)
ARCH = arm64
endif

USE_TARGET_DEST_DIR_SYSROOT = no


####### Targets

PKG_GROUP = boot


UBOOT_BIN_PKG_NAME                = u-boot
UBOOT_BIN_PKG_VERSION             = 2023.04
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   = Denx mainline 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      = $(bl31)
BUILD_TARGETS     += $(u_boot)
BUILD_TARGETS     += $(uImage)
BUILD_TARGETS     += $(uzImage)
BUILD_TARGETS     += $(boot_sdhc_script)
BUILD_TARGETS     += $(boot_sdhc_scr)
BUILD_TARGETS     += $(build_uboot_pkg)
BUILD_TARGETS     += $(install_boot_records)

PRODUCT_TARGETS    = $(products)

ROOTFS_TARGETS     = $(pkg_archive)


include ../../../../build-system/core.mk

#
# 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=sun50i_a64 bl31

HOST_TOOLS_SETTINGS = PYTHON3=/usr/bin/python3 HOSTLDFLAGS='-L/usr/lib64' HOSTCFLAGS='-I/usr/include'

device_dtb = sun50i-h5-repka-pi3.dtb

#
# Extra kernel boot arguments:
#
extra  = consoleblank=0
extra += no_console_suspend


####### Dependencies


$(atf_src_done): $(atf_archive)
	@echo "Expanding $(atf_archive)"
	@tar xJf $(atf_archive) -C $(TARGET_BUILD_DIR)
	@touch $@

$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP) $(atf_src_done)
	$(UNPACK_SRC_ARCHIVE)
	$(APPLY_PATCHES)
	@( cd $(SRC_DIR)/configs ; \
	   echo '# Set BOOTDELAY options:'          >> $(u_boot_config) ; \
	   echo 'CONFIG_SYS_PROMPT="$(HARDWARE)# "' >> $(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) ; \
	 )
	# ======= Suppress '_elf.so has a LOAD segment with RWX permissions' warnings =======
	@( cd $(SRC_DIR) ; \
	   sed -i 's,^\(KBUILD_LDFLAGS[ \t]*:=\).*,\1 --no-warn-rwx-segments,' Makefile ; \
	   sed -i 's,^\(cmd_efi_ld = $$(LD)\),\1 --no-warn-rwx-segments,'      scripts/Makefile.lib ; \
	   dd if=/dev/zero of=scp.bin bs=1024 count=1 ; \
	 )
	@touch $@

AMAKE := LDFLAGS='--no-warn-rwx-segments' \
         $(MAKE) -C $(ATF_SRC_DIR) CROSS_COMPILE='$(CROSS_PREFIX)' $(CORTEX_M0_SETTINGS)

$(bl31): $(src_done)
	+$(AMAKE)
	@cp -a $(ATF_SRC_DIR)/build/sun50i_a64/release/bl31.bin $@

UMAKE := $(HOST_TOOLS_SETTINGS) $(MAKE) -C $(SRC_DIR) BL31=$(bl31) CROSS_COMPILE='$(CROSS_PREFIX)'

$(u_boot): $(bl31)
	+$(UMAKE) $(u_boot_config)
	+$(UMAKE)
	@touch $@

$(uImage): $(u_boot)
	$(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)
	$(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:
# ====
#   sdhc is always mmc0 in u-boot and mmcblk0 in kernel
#

$(boot_sdhc_script): $(uzImage)
	@( echo ""                                                                 > $(boot_sdhc_script) && \
	   echo "mmc dev 0"                                                       >> $(boot_sdhc_script) && \
	   echo "mmcinfo"                                                         >> $(boot_sdhc_script) && \
	   echo "ext4load mmc 0:1 \$${kernel_comp_addr_r} /boot/Image"            >> $(boot_sdhc_script) && \
	   echo "ext4load mmc 0:1 \$${fdt_addr_r} /boot/allwinner/$(device_dtb)"  >> $(boot_sdhc_script) && \
	   echo "setenv bootargs 'earlyprintk console=ttyS0,115200n8 console=tty1 ro root=/dev/mmcblk0p1 rootwait rootfstype=ext4 $(extra)'" >> $(boot_sdhc_script) && \
	   echo "booti \$${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 $< $@

$(build_uboot_pkg): $(boot_sdhc_scr)
	@mkdir -p $(TARGET_DEST_DIR)/bootfs/u-boot
	@mkdir -p $(UBOOT_BIN_PKG)/boot/u-boot
	# ======= install U-Boot images =======
	@cp -a $(SRC_DIR)/u-boot-sunxi-with-spl.bin $(UBOOT_BIN_PKG)/boot/u-boot
	# ======= install signed kernel and script images =======
	@cp -a $(uImage) $(uzImage) $(boot_sdhc_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_sdhc_scr) $(TARGET_DEST_DIR)/bootfs
	@cp -a $(SRC_DIR)/u-boot-sunxi-with-spl.bin  $(TARGET_DEST_DIR)/bootfs/u-boot
	# ======= install Documentation =======
	@mkdir -p $(UBOOT_BIN_PKG)/usr/doc/u-boot-$(version)
	@cp -a $(SRC_DIR)/Licenses $(SRC_DIR)/MAINTAINERS $(SRC_DIR)/README \
	       $(UBOOT_BIN_PKG)/usr/doc/u-boot-$(version)
	@touch $@

$(boot_records): $(build_uboot_pkg)
	@$(DD) if=/dev/zero of=$@ bs=512 count=2048 conv=notrunc
	# ======= Setup u-boot into unallocated space of disk image =======
	@$(DD) if=$(UBOOT_BIN_PKG)/boot/u-boot/u-boot-sunxi-with-spl.bin of=$@ bs=1024 seek=8 conv=notrunc
	@touch $@

$(install_boot_records): $(boot_records)
	@$(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 .. ."