1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0+
3#
4# script to generate FIT image source for K3 Family boards with
5# ATF, OPTEE, SPL and multiple device trees (given on the command line).
6# Inspired from board/sunxi/mksunxi_fit_atf.sh
7#
8# usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
9
10[ -z "$ATF" ] && ATF="bl31.bin"
11
12if [ ! -f $ATF ]; then
13	echo "WARNING ATF file $ATF NOT found, resulting binary is non-functional" >&2
14	ATF=/dev/null
15fi
16
17[ -z "$TEE" ] && TEE="bl32.bin"
18
19if [ ! -f $TEE ]; then
20	echo "WARNING OPTEE file $TEE NOT found, resulting might be non-functional" >&2
21	TEE=/dev/null
22fi
23
24if [ ! -z "$IS_HS" ]; then
25	HS_APPEND=_HS
26fi
27
28cat << __HEADER_EOF
29/dts-v1/;
30
31/ {
32	description = "Configuration to load ATF and SPL";
33	#address-cells = <1>;
34
35	images {
36		atf {
37			description = "ARM Trusted Firmware";
38			data = /incbin/("$ATF");
39			type = "firmware";
40			arch = "arm64";
41			compression = "none";
42			os = "arm-trusted-firmware";
43			load = <0x70000000>;
44			entry = <0x70000000>;
45		};
46		tee {
47			description = "OPTEE";
48			data = /incbin/("$TEE");
49			type = "tee";
50			arch = "arm64";
51			compression = "none";
52			os = "tee";
53			load = <0x9e800000>;
54			entry = <0x9e800000>;
55		};
56		spl {
57			description = "SPL (64-bit)";
58			data = /incbin/("spl/u-boot-spl-nodtb.bin$HS_APPEND");
59			type = "standalone";
60			os = "U-Boot";
61			arch = "arm64";
62			compression = "none";
63			load = <0x80080000>;
64			entry = <0x80080000>;
65		};
66__HEADER_EOF
67
68for dtname in $*
69do
70	cat << __FDT_IMAGE_EOF
71		$(basename $dtname) {
72			description = "$(basename $dtname .dtb)";
73			data = /incbin/("$dtname$HS_APPEND");
74			type = "flat_dt";
75			arch = "arm";
76			compression = "none";
77		};
78__FDT_IMAGE_EOF
79done
80
81cat << __CONF_HEADER_EOF
82	};
83	configurations {
84		default = "$(basename $1)";
85
86__CONF_HEADER_EOF
87
88for dtname in $*
89do
90	cat << __CONF_SECTION_EOF
91		$(basename $dtname) {
92			description = "$(basename $dtname .dtb)";
93			firmware = "atf";
94			loadables = "tee", "spl";
95			fdt = "$(basename $dtname)";
96		};
97__CONF_SECTION_EOF
98done
99
100cat << __ITS_EOF
101	};
102};
103__ITS_EOF
104