rockchip: fit_spl_optee: get text and optee base from build
[oweals/u-boot.git] / arch / arm / mach-rockchip / fit_spl_optee.sh
1 #!/bin/sh
2 # SPDX-License-Identifier:      GPL-2.0+
3 #
4 # Copyright (C) 2019 Rockchip Electronic Co.,Ltd
5 #
6 # Script to generate FIT image source for 32-bit Rockchip SoCs with
7 # U-Boot proper, OPTEE, and devicetree.
8 #
9 # usage: $0 <dt_name>
10
11 [ -z "$TEE" ] && TEE="tee.bin"
12
13 if [ ! -f $TEE ]; then
14         echo "WARNING: TEE file $TEE NOT found, U-Boot.itb is non-functional" >&2
15         echo "Please export path for TEE or copy tee.bin to U-Boot folder" >&2
16         TEE=/dev/null
17 fi
18
19 dtname=$1
20 text_base=`sed -n "/SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" .config \
21            |tr -d '\r'`
22 dram_base=`sed -n "/SYS_SDRAM_BASE=/s/CONFIG_SYS_SDRAM_BASE=//p" \
23            include/autoconf.mk|tr -d '\r'`
24 tee_base=`echo "obase=16;$(($dram_base+0x8400000))"|bc`
25 tee_base='0x'$tee_base
26
27 cat << __HEADER_EOF
28 /*
29  * Copyright (C) 2017-2019 Rockchip Electronic Co.,Ltd
30  *
31  * Simple U-boot FIT source file containing U-Boot, dtb and optee
32  */
33
34 /dts-v1/;
35
36 / {
37         description = "FIT image with OP-TEE support";
38         #address-cells = <1>;
39
40         images {
41                 uboot {
42                         description = "U-Boot";
43                         data = /incbin/("u-boot-nodtb.bin");
44                         type = "standalone";
45                         os = "U-Boot";
46                         arch = "arm";
47                         compression = "none";
48                         load = <$text_base>;
49                 };
50                 optee {
51                         description = "OP-TEE";
52                         data = /incbin/("$TEE");
53                         type = "firmware";
54                         arch = "arm";
55                         os = "tee";
56                         compression = "none";
57                         load = <$tee_base>;
58                         entry = <$tee_base>;
59                 };
60                 fdt {
61                         description = "$(basename $dtname .dtb)";
62                         data = /incbin/("$dtname");
63                         type = "flat_dt";
64                         compression = "none";
65                 };
66 __HEADER_EOF
67
68 cat << __CONF_HEADER_EOF
69         };
70
71         configurations {
72                 default = "conf";
73                 conf {
74                         description = "$(basename $dtname .dtb)";
75                         firmware = "optee";
76                         loadables = "uboot";
77                         fdt = "fdt";
78                 };
79 __CONF_HEADER_EOF
80
81 cat << __ITS_EOF
82         };
83 };
84 __ITS_EOF