Follow i.MX, Sunxi, RISC-V and Rockchip to generate u-boot.itb which
includes U-Boot proper, ATF and DTBs in FIT format. ZynqMP supports FIT for
quite a long time but with using out of tree solution. The patch is filling
this gap.

Tested on zcu102, zcu104 and zcu100/Ultra96.

zcu100/Ultra96 v2.2 ATF build by:
make DEBUG=0 ZYNQMP_CONSOLE=cadence1 RESET_TO_BL31=1 PLAT=zynqmp bl31

Signed-off-by: Michal Simek <michal.si...@xilinx.com>
---

Changes in v3:
- remove bl31 size report
- detect u-boot address based on text base
- enable build without ATF
- add license to its
- setup default option based on DEVICE_TREE variable
- add note about readelf
- add entry field to uboot
- call only awk instead of grep and awk
- add support for filling load DTB address based on 
CONFIG_XILINX_OF_BOARD_DTB_ADDR

Changes in v2:
- Exchange u-boot/atf in config section
- Use default ATF baseaddr from mainline
- Update commit message

Based on my discussion with Tom this should be converted to common shell
script which will contain ITB generation. To enable this generation for
ZynqMP make sense to include this script to let distribution like Fedora to
use and conversion can be done on the top of this.
For more information please take a look at
https://lists.denx.de/pipermail/u-boot/2019-December/393556.html

---
 Kconfig                                 |   3 +-
 arch/arm/mach-zynqmp/mkimage_fit_atf.sh | 123 ++++++++++++++++++++++++
 include/configs/xilinx_zynqmp.h         |   6 +-
 3 files changed, 130 insertions(+), 2 deletions(-)
 create mode 100755 arch/arm/mach-zynqmp/mkimage_fit_atf.sh

diff --git a/Kconfig b/Kconfig
index 92fc4fc135a4..526a5a2e2bde 100644
--- a/Kconfig
+++ b/Kconfig
@@ -254,7 +254,7 @@ config BUILD_TARGET
        default "u-boot-spl.kwb" if ARCH_MVEBU && SPL
        default "u-boot-elf.srec" if RCAR_GEN3
        default "u-boot.itb" if SPL_LOAD_FIT && (ARCH_ROCKCHIP || \
-                               ARCH_SUNXI || RISCV)
+                               ARCH_SUNXI || RISCV || ARCH_ZYNQMP)
        default "u-boot.kwb" if KIRKWOOD
        default "u-boot-with-spl.bin" if ARCH_AT91 && SPL_NAND_SUPPORT
        default "u-boot-with-spl.imx" if ARCH_MX6 && SPL
@@ -482,6 +482,7 @@ config SPL_FIT_GENERATOR
        depends on SPL_FIT
        default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
        default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
ARCH_ROCKCHIP
+       default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
ARCH_ZYNQMP
        default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && RISCV
        help
          Specifies a (platform specific) script file to generate the FIT
diff --git a/arch/arm/mach-zynqmp/mkimage_fit_atf.sh 
b/arch/arm/mach-zynqmp/mkimage_fit_atf.sh
new file mode 100755
index 000000000000..9c6f973bfa70
--- /dev/null
+++ b/arch/arm/mach-zynqmp/mkimage_fit_atf.sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# script to generate FIT image source for Xilinx ZynqMP boards with
+# ARM Trusted Firmware and multiple device trees (given on the command line)
+#
+# usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
+
+BL33="u-boot-nodtb.bin"
+[ -z "$BL31" ] && BL31="bl31.bin"
+# Can be also done as ${CROSS_COMPILE}readelf -l bl31.elf | awk '/Entry point/ 
{ print $3 }'
+[ -z "$ATF_LOAD_ADDR" ] && ATF_LOAD_ADDR="0xfffea000"
+
+if [ -z "$BL33_LOAD_ADDR" ];then
+       BL33_LOAD_ADDR=`awk '/CONFIG_SYS_TEXT_BASE/ { print $3 }' 
include/generated/autoconf.h`
+fi
+
+DTB_LOAD_ADDR=`awk '/CONFIG_XILINX_OF_BOARD_DTB_ADDR/ { print $3 }' 
include/generated/autoconf.h`
+if [ ! -z "$DTB_LOAD_ADDR" ]; then
+       DTB_LOAD="load = <$DTB_LOAD_ADDR>;"
+else
+       DTB_LOAD=""
+fi
+
+if [ -z "$*" ]; then
+       DT=arch/arm/dts/${DEVICE_TREE}.dtb
+else
+       DT=$*
+fi
+
+if [ ! -f $BL31 ]; then
+       echo "WARNING: BL31 file $BL31 NOT found, resulting binary is 
non-functional" >&2
+       BL31=/dev/null
+       # But U-Boot proper could be loaded in EL3 by specifying
+       # firmware = "uboot";
+       # instead of "atf" in config node
+fi
+
+cat << __HEADER_EOF
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+/dts-v1/;
+
+/ {
+       description = "Configuration to load ATF before U-Boot";
+
+       images {
+               uboot {
+                       description = "U-Boot (64-bit)";
+                       data = /incbin/("$BL33");
+                       type = "firmware";
+                       os = "u-boot";
+                       arch = "arm64";
+                       compression = "none";
+                       load = <$BL33_LOAD_ADDR>;
+                       entry = <$BL33_LOAD_ADDR>;
+                       hash {
+                               algo = "md5";
+                       };
+               };
+               atf {
+                       description = "ARM Trusted Firmware";
+                       data = /incbin/("$BL31");
+                       type = "firmware";
+                       os = "arm-trusted-firmware";
+                       arch = "arm64";
+                       compression = "none";
+                       load = <$ATF_LOAD_ADDR>;
+                       entry = <$ATF_LOAD_ADDR>;
+                       hash {
+                               algo = "md5";
+                       };
+               };
+__HEADER_EOF
+
+DEFAULT=1
+cnt=1
+for dtname in $DT
+do
+       cat << __FDT_IMAGE_EOF
+               fdt_$cnt {
+                       description = "$(basename $dtname .dtb)";
+                       data = /incbin/("$dtname");
+                       type = "flat_dt";
+                       arch = "arm64";
+                       compression = "none";
+                       $DTB_LOAD
+                       hash {
+                               algo = "md5";
+                       };
+               };
+__FDT_IMAGE_EOF
+
+[ "$(basename $dtname .dtb)" == "${DEVICE_TREE}" ] && DEFAULT=$cnt
+
+cnt=$((cnt+1))
+done
+
+cat << __CONF_HEADER_EOF
+       };
+       configurations {
+               default = "config_$DEFAULT";
+
+__CONF_HEADER_EOF
+
+cnt=1
+for dtname in $DT
+do
+cat << __CONF_SECTION1_EOF
+               config_$cnt {
+                       description = "$(basename $dtname .dtb)";
+                       firmware = "atf";
+                       loadables = "uboot";
+                       fdt = "fdt_$cnt";
+               };
+__CONF_SECTION1_EOF
+cnt=$((cnt+1))
+done
+
+cat << __ITS_EOF
+       };
+};
+__ITS_EOF
diff --git a/include/configs/xilinx_zynqmp.h b/include/configs/xilinx_zynqmp.h
index 9e08ed510805..b094dce49afb 100644
--- a/include/configs/xilinx_zynqmp.h
+++ b/include/configs/xilinx_zynqmp.h
@@ -242,7 +242,11 @@
 # define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0 /* unused */
 # define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS        0 /* unused */
 # define CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR       0 /* unused */
-# define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME       "u-boot.img"
+# if defined(CONFIG_SPL_LOAD_FIT)
+#  define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME      "u-boot.itb"
+# else
+#  define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME      "u-boot.img"
+# endif
 #endif
 
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_DFU)
-- 
2.24.0

Reply via email to