1#!/bin/sh
2#
3# script to generate FIT image source for 64-bit sunxi boards with
4# ARM Trusted Firmware and multiple device trees (given on the command line)
5#
6# usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
7
8[ -z "$BL31" ] && BL31="bl31.bin"
9
10if [ ! -f $BL31 ]; then
11	echo "WARNING: BL31 file $BL31 NOT found, resulting binary is non-functional" >&2
12	echo "Please read the section on ARM Trusted Firmware (ATF) in board/sunxi/README.sunxi64" >&2
13	BL31=/dev/null
14fi
15
16if grep -q "^CONFIG_MACH_SUN50I_H6=y" .config; then
17	BL31_ADDR=0x104000
18else
19	BL31_ADDR=0x44000
20fi
21
22cat << __HEADER_EOF
23/dts-v1/;
24
25/ {
26	description = "Configuration to load ATF before U-Boot";
27	#address-cells = <1>;
28
29	images {
30		uboot {
31			description = "U-Boot (64-bit)";
32			data = /incbin/("u-boot-nodtb.bin");
33			type = "standalone";
34			arch = "arm64";
35			compression = "none";
36			load = <0x4a000000>;
37		};
38		atf {
39			description = "ARM Trusted Firmware";
40			data = /incbin/("$BL31");
41			type = "firmware";
42			arch = "arm64";
43			compression = "none";
44			load = <$BL31_ADDR>;
45			entry = <$BL31_ADDR>;
46		};
47__HEADER_EOF
48
49cnt=1
50for dtname in $*
51do
52	cat << __FDT_IMAGE_EOF
53		fdt_$cnt {
54			description = "$(basename $dtname .dtb)";
55			data = /incbin/("$dtname");
56			type = "flat_dt";
57			compression = "none";
58		};
59__FDT_IMAGE_EOF
60	cnt=$((cnt+1))
61done
62
63cat << __CONF_HEADER_EOF
64	};
65	configurations {
66		default = "config_1";
67
68__CONF_HEADER_EOF
69
70cnt=1
71for dtname in $*
72do
73	cat << __CONF_SECTION_EOF
74		config_$cnt {
75			description = "$(basename $dtname .dtb)";
76			firmware = "uboot";
77			loadables = "atf";
78			fdt = "fdt_$cnt";
79		};
80__CONF_SECTION_EOF
81	cnt=$((cnt+1))
82done
83
84cat << __ITS_EOF
85	};
86};
87__ITS_EOF
88