packages/boot: add arm-trusted-firmware-airoha
Add support for compiling Airoha ATF, based on a modified version of the TF-A based on 2.10. The package will clone the base TF-A and apply the modified source and pre-compiled objects (DDR calibration, eFUSE handling, TX/RX path...) to correctly compile. An helper script is added to implement the same format used for special BL2 handling. BL2 is composed of 3 sub-phase with a initial BL21, a BL22 that loads a LZMA decompressor and BL23 that actually calibrate and loads BL31 ATF. Also a special flash_table is used to handle SPI-NAND externally to the BL2, a special Host target is added for that. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Link: https://github.com/openwrt/openwrt/pull/24257 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
parent
652b2e90b3
commit
c249552ea5
2 changed files with 267 additions and 0 deletions
198
package/boot/arm-trusted-firmware-airoha/Makefile
Normal file
198
package/boot/arm-trusted-firmware-airoha/Makefile
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_VERSION:=2.10
|
||||
PKG_RELEASE:=1
|
||||
PKG_HASH:=88215a62291b9ba87da8e50b077741103cdc08fb6c9e1ebd34dfaace746d3201
|
||||
|
||||
PKG_MAINTAINER:=Christian Marangi <ansuelsmth@gmail.com>
|
||||
|
||||
PKG_BUILD_DEPENDS:=arm-trusted-firmware-tools/host arm-trusted-firmware-airoha/host
|
||||
|
||||
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/trusted-firmware-a-airoha-$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/trusted-firmware-a.mk
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Trusted-Firmware-A/Default
|
||||
BUILD_TARGET:=airoha
|
||||
PLAT:=en7523
|
||||
HIDDEN:=y
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/bl2/Default
|
||||
NAME:=Airoha an7581 bl2
|
||||
ARCH:=aarch32
|
||||
ATF_STAGE:=bl2
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/an7581-bl2
|
||||
$(call Trusted-Firmware-A/bl2/Default)
|
||||
BUILD_SUBTARGET:=an7581
|
||||
SOC:=EN7581
|
||||
BUILD_DEVICES:=airoha_an7581-evb airoha_an7581-evb-emmc-eagle airoha_an7581-evb-emmc-kite nokia_valyrian nokia_xg-040g-md-ubi
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/an7583-bl2
|
||||
$(call Trusted-Firmware-A/bl2/Default)
|
||||
BUILD_SUBTARGET:=an7583
|
||||
SOC:=AN7583
|
||||
BUILD_DEVICES:=airoha_an7583-evb airoha_an7583-evb-emmc
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/bl31/Default
|
||||
NAME:=Airoha an7581 bl31
|
||||
ARCH:=aarch64
|
||||
ATF_STAGE:=bl31
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/an7581-bl31
|
||||
$(call Trusted-Firmware-A/bl31/Default)
|
||||
BUILD_SUBTARGET:=an7581
|
||||
SOC:=EN7581
|
||||
BUILD_DEVICES:=airoha_an7581-evb airoha_an7581-evb-emmc
|
||||
endef
|
||||
|
||||
define Trusted-Firmware-A/an7583-bl31
|
||||
$(call Trusted-Firmware-A/bl31/Default)
|
||||
BUILD_SUBTARGET:=an7583
|
||||
SOC:=AN7583
|
||||
BUILD_DEVICES:=airoha_an7583-evb airoha_an7583-evb-emmc
|
||||
endef
|
||||
|
||||
TFA_TARGETS:= \
|
||||
an7581-bl2 an7581-bl31 \
|
||||
an7583-bl2 an7583-bl31
|
||||
|
||||
TFA_MAKE_FLAGS= \
|
||||
ARM32TOOLCHAIN_BASE=$(PKG_BUILD_DIR)/$(BL2_GCC_SOURCE)/bin/arm-none-eabi- \
|
||||
MBEDTLS_DIR=$(PKG_BUILD_DIR)/$(MBEDTLS_SOURCE) \
|
||||
ARCH=$(ARCH) CONFIG_ECNT=1 \
|
||||
TCSUPPORT_OPENWRT=1 TCSUPPORT_ATF_UNOPEN=0 \
|
||||
TCSUPPORT_CPU_$(SOC)=1 TCSUPPORT_CPU_EN7523=1 \
|
||||
TCSUPPORT_CPU_ARMV8=1 TCSUPPORT_UBOOT_64BIT=1 \
|
||||
TCSUPPORT_EMMC=1 TCSUPPORT_UBOOT=1 TCSUPPORT_BL2_OPTIMIZATION=1 \
|
||||
TOOLS_DIR=$(STAGING_DIR_HOST)/bin
|
||||
|
||||
BL2_GCC_NAME:=arm-gnu-toolchain
|
||||
BL2_GCC_RELEASE:=15.3.rel1
|
||||
BL2_GCC_VERSION:=$(HOST_ARCH)-arm-none-eabi
|
||||
BL2_GCC_SOURCE=$(BL2_GCC_NAME)-$(BL2_GCC_RELEASE)-$(BL2_GCC_VERSION)
|
||||
|
||||
define Download/bl2-toolchain
|
||||
FILE:=$(BL2_GCC_SOURCE).tar.xz
|
||||
URL:=https://gitlab.arm.com/api/v4/projects/tooling%2Fgnu-toolchains-for-arm/packages/generic/gnu-toolchain/$(BL2_GCC_RELEASE)/
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
HASH:=06979e0c8171de58e5dc2a2b2019330a290f30930f27728af98a83e1a7369b3a
|
||||
else
|
||||
HASH:=563bebb2b97d53382b956d6ee1fe61e2cae26699901417234a37df505ef9b5fa
|
||||
endif
|
||||
endef
|
||||
|
||||
define Download/atf-airoha
|
||||
SOURCE_DATE:=2026-07-17
|
||||
SOURCE_VERSION:=80519beaea5298bbc660cd8f345e08aba9bd9547
|
||||
URL:=https://github.com/Ansuel/atf-airoha.git
|
||||
MIRROR_HASH:=242d055db6d2af449ca084fb742cca6f546e40453d99b903068da7152db2f0af
|
||||
PROTO:=git
|
||||
FILE:=atf-airoha-$$$$(subst -,.,$$$$(SOURCE_DATE))~$$$$(call version_abbrev,$$$$(SOURCE_VERSION)).tar.zst
|
||||
SUBDIR:=atf-airoha
|
||||
endef
|
||||
|
||||
define Download/atf-airoha-host
|
||||
$(call Download/atf-airoha)
|
||||
FILE:=atf-airoha-host-$$$$(subst -,.,$$$$(SOURCE_DATE))~$$$$(call version_abbrev,$$$$(SOURCE_VERSION)).tar.zst
|
||||
endef
|
||||
|
||||
MBEDTLS_NAME:=mbedtls
|
||||
MBEDTLS_RELEASE:=3.4.1
|
||||
MBEDTLS_SOURCE:=$(MBEDTLS_NAME)-$(MBEDTLS_RELEASE)
|
||||
|
||||
define Download/mbedtls
|
||||
FILE:=$(MBEDTLS_SOURCE).tar.zst
|
||||
PROTO:=git
|
||||
URL:=https://github.com/Mbed-TLS/mbedtls.git
|
||||
SOURCE_VERSION:=72718dd87e087215ce9155a826ee5a66cfbe9631
|
||||
MIRROR_HASH:=482e699edb915f8530c99f680ac69783036d96d461eebc95382d19a6064e906b
|
||||
SUBDIR:=$(MBEDTLS_SOURCE)
|
||||
endef
|
||||
|
||||
define Host/Prepare
|
||||
$(eval $(call Download,atf-airoha-host))
|
||||
$(TAR) -C $(HOST_BUILD_DIR) --strip-components=1 -xf $(DL_DIR)/$(FILE)
|
||||
endef
|
||||
|
||||
HOST_CFLAGS += \
|
||||
-DFLASH_TABLE_OPEN \
|
||||
-DTCSUPPORT_BL2_OPTIMIZATION \
|
||||
-I$(HOST_BUILD_DIR)/plat/ecnt/en7523/include
|
||||
define Host/Compile
|
||||
$(HOSTCC) $(HOST_CFLAGS) -o $(HOST_BUILD_DIR)/spi_nand_flash_table \
|
||||
$(HOST_BUILD_DIR)/plat/ecnt/common/drivers/flash/spi_nand_flash_table.c
|
||||
endef
|
||||
|
||||
define Host/Install
|
||||
$(INSTALL_BIN) $(HOST_BUILD_DIR)/spi_nand_flash_table $(STAGING_DIR_HOST)/bin/airoha-atf-gen-flash-table
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(if $(filter bl2,$(ATF_STAGE)),
|
||||
$(eval $(call Download,bl2-toolchain))
|
||||
$(TAR) -C $(PKG_BUILD_DIR) -xf $(DL_DIR)/$(FILE)
|
||||
)
|
||||
|
||||
$(call Build/Prepare/Default,)
|
||||
|
||||
$(eval $(call Download,mbedtls))
|
||||
$(TAR) -C $(PKG_BUILD_DIR) -xf $(DL_DIR)/$(FILE)
|
||||
|
||||
$(eval $(call Download,atf-airoha))
|
||||
$(TAR) -C $(PKG_BUILD_DIR) --strip-components=1 -xf $(DL_DIR)/$(FILE)
|
||||
endef
|
||||
|
||||
define Build/Compile/bl2
|
||||
$(Build/Compile/Trusted-Firmware-A) IMAGE_BL21=1 bl2
|
||||
$(Build/Compile/Trusted-Firmware-A) clean
|
||||
$(Build/Compile/Trusted-Firmware-A) IMAGE_BL22=1 bl2
|
||||
$(Build/Compile/Trusted-Firmware-A) clean
|
||||
$(Build/Compile/Trusted-Firmware-A) IMAGE_BL23=1 bl2
|
||||
endef
|
||||
|
||||
define Build/Compile/bl31
|
||||
$(Build/Compile/Trusted-Firmware-A) bl31
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(call Build/Compile/$(ATF_STAGE))
|
||||
endef
|
||||
|
||||
define Package/trusted-firmware-a/bl2/install
|
||||
dd if=/dev/null of=$(PKG_BUILD_DIR)/bl21.bin bs=1 count=0 seek=14336
|
||||
|
||||
(cd $(PKG_BUILD_DIR); $(STAGING_DIR_HOST)/bin/airoha-atf-gen-flash-table)
|
||||
$(STAGING_DIR_HOST)/bin/lzma e \
|
||||
$(PKG_BUILD_DIR)/flash_table.bin \
|
||||
$(PKG_BUILD_DIR)/flash_table.lzma
|
||||
|
||||
$(INSTALL_DIR) $(STAGING_DIR_IMAGE)
|
||||
./scripts/airoha_pack_bl2.sh \
|
||||
$(PKG_BUILD_DIR)/bl21.bin \
|
||||
$(PKG_BUILD_DIR)/bl22.lzma \
|
||||
$(PKG_BUILD_DIR)/bl23.lzma \
|
||||
$(PKG_BUILD_DIR)/flash_table.lzma \
|
||||
$(STAGING_DIR_IMAGE)/$(BUILD_SUBTARGET)-bl2.bin
|
||||
endef
|
||||
|
||||
define Package/trusted-firmware-a/bl31/install
|
||||
$(INSTALL_DIR) $(STAGING_DIR_IMAGE)
|
||||
$(STAGING_DIR_HOST)/bin/lzma e \
|
||||
$(PKG_BUILD_DIR)/build/$(PLAT)/release/bl31.bin \
|
||||
$(STAGING_DIR_IMAGE)/$(BUILD_SUBTARGET)-bl31.lzma
|
||||
endef
|
||||
|
||||
define Package/trusted-firmware-a/install
|
||||
$(call Package/trusted-firmware-a/$(ATF_STAGE)/install)
|
||||
endef
|
||||
|
||||
$(eval $(call HostBuild))
|
||||
$(eval $(call BuildPackage/Trusted-Firmware-A))
|
||||
69
package/boot/arm-trusted-firmware-airoha/scripts/airoha_pack_bl2.sh
Executable file
69
package/boot/arm-trusted-firmware-airoha/scripts/airoha_pack_bl2.sh
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Airoha implement a complex logic for BL2
|
||||
# BL21 is a minimal BL2 that gets loaded to NPU SRAM
|
||||
# and is just a LZMA decompressor
|
||||
# BL21 use the specific struct with all the info
|
||||
# and decompresso/load the images.
|
||||
# BL22 is what execute RAM calibration and first init setup
|
||||
# BL23 is what prepares and load BL31
|
||||
#
|
||||
# BL2 is a concatenation of all these middle files and
|
||||
# is organized as follow:
|
||||
# 1. BL21
|
||||
# 2. f_header_t struct
|
||||
# 3. BL22
|
||||
# 4. BL23
|
||||
# 5. Special flash table (LZMA packed with NAND info table)
|
||||
|
||||
BL21=$1
|
||||
BL22=$2
|
||||
BL23=$3
|
||||
FLASH_TABLE=$4
|
||||
BL2=$5
|
||||
|
||||
cat $BL21 > $BL2
|
||||
|
||||
bl22_length=$(stat -c %s $BL22)
|
||||
bl23_length=$(stat -c %s $BL23)
|
||||
flash_table_length=$(stat -c %s $FLASH_TABLE)
|
||||
lzma_src=$((0x1e843c00 + 36))
|
||||
lzma_des=0x08004000
|
||||
lzma_length=$bl22_length
|
||||
lzma_cmd=0x0
|
||||
fw_ver=0x0
|
||||
reserved=0x0
|
||||
|
||||
write_le32()
|
||||
{
|
||||
local v=$1
|
||||
printf "\\$(printf '%03o' $(( v & 0xff)))"
|
||||
printf "\\$(printf '%03o' $(((v >> 8) & 0xff)))"
|
||||
printf "\\$(printf '%03o' $(((v >> 16) & 0xff)))"
|
||||
printf "\\$(printf '%03o' $(((v >> 24) & 0xff)))"
|
||||
}
|
||||
|
||||
# Write struct as little-endian unsigned ints
|
||||
{
|
||||
write_le32 "$bl22_length"
|
||||
write_le32 "$bl23_length"
|
||||
write_le32 "$flash_table_length"
|
||||
write_le32 "$lzma_src"
|
||||
write_le32 "$lzma_des"
|
||||
write_le32 "$lzma_length"
|
||||
write_le32 "$lzma_cmd"
|
||||
write_le32 "$fw_ver"
|
||||
write_le32 "$reserved"
|
||||
} >> $BL2
|
||||
|
||||
cat $BL22 >> $BL2
|
||||
cat $BL23 >> $BL2
|
||||
cat $FLASH_TABLE >> $BL2
|
||||
|
||||
crc=$(cksum -a crc32b $BL2 | cut -d' ' -f1)
|
||||
|
||||
# XOR with 0xffffffff
|
||||
crc=$((0xffffffff ^ $crc))
|
||||
|
||||
# append little endian
|
||||
write_le32 "$crc" >> "$BL2"
|
||||
Loading…
Reference in a new issue