Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0+ |
| 3 | # |
| 4 | # script to generate FIT image source for Xilinx ZynqMP boards with |
| 5 | # ARM Trusted Firmware and multiple device trees (given on the command line) |
| 6 | # |
| 7 | # usage: $0 <dt_name> [<dt_name> [<dt_name] ...] |
| 8 | |
| 9 | BL33="u-boot-nodtb.bin" |
| 10 | [ -z "$BL31" ] && BL31="bl31.bin" |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 11 | BL31_ELF="${BL31%.*}.elf" |
| 12 | [ -f ${BL31_ELF} ] && ATF_LOAD_ADDR=`${CROSS_COMPILE}readelf -l "${BL31_ELF}" | \ |
| 13 | awk '/Entry point/ { print $3 }'` |
| 14 | |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 15 | [ -z "$ATF_LOAD_ADDR" ] && ATF_LOAD_ADDR="0xfffea000" |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 16 | ATF_LOAD_ADDR_LOW=`printf 0x%x $((ATF_LOAD_ADDR & 0xffffffff))` |
| 17 | ATF_LOAD_ADDR_HIGH=`printf 0x%x $((ATF_LOAD_ADDR >> 32))` |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 18 | |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 19 | [ -z "$BL32" ] && BL32="tee.bin" |
| 20 | BL32_ELF="${BL32%.*}.elf" |
| 21 | [ -f ${BL32_ELF} ] && TEE_LOAD_ADDR=`${CROSS_COMPILE}readelf -l "${BL32_ELF}" | \ |
| 22 | awk '/Entry point/ { print $3 }'` |
| 23 | |
| 24 | [ -z "$TEE_LOAD_ADDR" ] && TEE_LOAD_ADDR="0x60000000" |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 25 | TEE_LOAD_ADDR_LOW=`printf 0x%x $((TEE_LOAD_ADDR & 0xffffffff))` |
| 26 | TEE_LOAD_ADDR_HIGH=`printf 0x%x $((TEE_LOAD_ADDR >> 32))` |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 27 | |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 28 | if [ -z "$BL33_LOAD_ADDR" ];then |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 29 | BL33_LOAD_ADDR=`awk '/CONFIG_TEXT_BASE/ { print $3 }' include/generated/autoconf.h` |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 30 | fi |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 31 | BL33_LOAD_ADDR_LOW=`printf 0x%x $((BL33_LOAD_ADDR & 0xffffffff))` |
| 32 | BL33_LOAD_ADDR_HIGH=`printf 0x%x $((BL33_LOAD_ADDR >> 32))` |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 33 | |
| 34 | DTB_LOAD_ADDR=`awk '/CONFIG_XILINX_OF_BOARD_DTB_ADDR/ { print $3 }' include/generated/autoconf.h` |
| 35 | if [ ! -z "$DTB_LOAD_ADDR" ]; then |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 36 | DTB_LOAD_ADDR_LOW=`printf 0x%x $((DTB_LOAD_ADDR & 0xffffffff))` |
| 37 | DTB_LOAD_ADDR_HIGH=`printf 0x%x $((DTB_LOAD_ADDR >> 32))` |
| 38 | DTB_LOAD="load = <$DTB_LOAD_ADDR_HIGH $DTB_LOAD_ADDR_LOW>;" |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 39 | else |
| 40 | DTB_LOAD="" |
| 41 | fi |
| 42 | |
| 43 | if [ -z "$*" ]; then |
| 44 | DT=arch/arm/dts/${DEVICE_TREE}.dtb |
| 45 | else |
| 46 | DT=$* |
| 47 | fi |
| 48 | |
| 49 | if [ ! -f $BL31 ]; then |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 50 | echo "WARNING: BL31 file $BL31 NOT found, U-Boot will run in EL3" >&2 |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 51 | BL31=/dev/null |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 52 | fi |
| 53 | |
| 54 | cat << __HEADER_EOF |
| 55 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
| 56 | |
| 57 | /dts-v1/; |
| 58 | |
| 59 | / { |
Michal Simek | 367eb80 | 2021-08-19 14:17:37 +0200 | [diff] [blame] | 60 | description = "Configuration for Xilinx ZynqMP SoC"; |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 61 | |
| 62 | images { |
| 63 | uboot { |
| 64 | description = "U-Boot (64-bit)"; |
| 65 | data = /incbin/("$BL33"); |
| 66 | type = "firmware"; |
| 67 | os = "u-boot"; |
| 68 | arch = "arm64"; |
| 69 | compression = "none"; |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 70 | load = <$BL33_LOAD_ADDR_HIGH $BL33_LOAD_ADDR_LOW>; |
| 71 | entry = <$BL33_LOAD_ADDR_HIGH $BL33_LOAD_ADDR_LOW>; |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 72 | hash { |
| 73 | algo = "md5"; |
| 74 | }; |
| 75 | }; |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 76 | __HEADER_EOF |
| 77 | |
| 78 | if [ -f $BL31 ]; then |
| 79 | cat << __ATF |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 80 | atf { |
Michal Simek | 367eb80 | 2021-08-19 14:17:37 +0200 | [diff] [blame] | 81 | description = "Trusted Firmware-A"; |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 82 | data = /incbin/("$BL31"); |
| 83 | type = "firmware"; |
| 84 | os = "arm-trusted-firmware"; |
| 85 | arch = "arm64"; |
| 86 | compression = "none"; |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 87 | load = <$ATF_LOAD_ADDR_HIGH $ATF_LOAD_ADDR_LOW>; |
| 88 | entry = <$ATF_LOAD_ADDR_HIGH $ATF_LOAD_ADDR_LOW>; |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 89 | hash { |
| 90 | algo = "md5"; |
| 91 | }; |
| 92 | }; |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 93 | __ATF |
| 94 | fi |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 95 | |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 96 | if [ -f $BL32 ]; then |
| 97 | cat << __TEE |
| 98 | tee { |
| 99 | description = "TEE firmware"; |
| 100 | data = /incbin/("$BL32"); |
| 101 | type = "firmware"; |
| 102 | os = "tee"; |
| 103 | arch = "arm64"; |
| 104 | compression = "none"; |
Michal Simek | 48bd9ba | 2021-06-07 12:37:32 +0200 | [diff] [blame] | 105 | load = <$TEE_LOAD_ADDR_HIGH $TEE_LOAD_ADDR_LOW>; |
| 106 | entry = <$TEE_LOAD_ADDR_HIGH $TEE_LOAD_ADDR_LOW>; |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 107 | hash { |
| 108 | algo = "md5"; |
| 109 | }; |
| 110 | }; |
| 111 | __TEE |
| 112 | fi |
| 113 | |
Michal Simek | 3c99ab5 | 2021-08-19 12:02:57 +0200 | [diff] [blame] | 114 | MULTI_DTB=`awk '/CONFIG_MULTI_DTB_FIT / { print $3 }' include/generated/autoconf.h` |
| 115 | |
| 116 | if [ 1"$MULTI_DTB" -eq 11 ]; then |
| 117 | cat << __FDT_IMAGE_EOF |
| 118 | fdt_1 { |
| 119 | description = "Multi DTB fit image"; |
| 120 | data = /incbin/("fit-dtb.blob"); |
| 121 | type = "flat_dt"; |
| 122 | arch = "arm64"; |
| 123 | compression = "none"; |
| 124 | $DTB_LOAD |
| 125 | hash { |
| 126 | algo = "md5"; |
| 127 | }; |
| 128 | }; |
| 129 | }; |
| 130 | configurations { |
| 131 | default = "config_1"; |
| 132 | __FDT_IMAGE_EOF |
| 133 | |
| 134 | if [ ! -f $BL31 ]; then |
| 135 | cat << __CONF_SECTION1_EOF |
| 136 | config_1 { |
| 137 | description = "Multi DTB without TF-A"; |
| 138 | firmware = "uboot"; |
| 139 | loadables = "fdt_1"; |
| 140 | }; |
| 141 | __CONF_SECTION1_EOF |
| 142 | else |
Michal Simek | 7029ea8 | 2022-05-18 13:41:31 +0200 | [diff] [blame] | 143 | if [ -f $BL32 ]; then |
Michal Simek | 3c99ab5 | 2021-08-19 12:02:57 +0200 | [diff] [blame] | 144 | cat << __CONF_SECTION1_EOF |
| 145 | config_1 { |
Michal Simek | 7029ea8 | 2022-05-18 13:41:31 +0200 | [diff] [blame] | 146 | description = "Multi DTB with TF-A and TEE"; |
| 147 | firmware = "atf"; |
| 148 | loadables = "uboot", "tee", "fdt_1"; |
| 149 | }; |
| 150 | __CONF_SECTION1_EOF |
| 151 | else |
| 152 | cat << __CONF_SECTION1_EOF |
| 153 | config_1 { |
Michal Simek | 3c99ab5 | 2021-08-19 12:02:57 +0200 | [diff] [blame] | 154 | description = "Multi DTB with TF-A"; |
| 155 | firmware = "atf"; |
| 156 | loadables = "uboot", "fdt_1"; |
| 157 | }; |
| 158 | __CONF_SECTION1_EOF |
| 159 | fi |
Michal Simek | 7029ea8 | 2022-05-18 13:41:31 +0200 | [diff] [blame] | 160 | fi |
Michal Simek | 3c99ab5 | 2021-08-19 12:02:57 +0200 | [diff] [blame] | 161 | |
| 162 | cat << __ITS_EOF |
| 163 | }; |
| 164 | }; |
| 165 | __ITS_EOF |
| 166 | |
| 167 | else |
| 168 | |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 169 | DEFAULT=1 |
| 170 | cnt=1 |
| 171 | for dtname in $DT |
| 172 | do |
| 173 | cat << __FDT_IMAGE_EOF |
| 174 | fdt_$cnt { |
| 175 | description = "$(basename $dtname .dtb)"; |
| 176 | data = /incbin/("$dtname"); |
| 177 | type = "flat_dt"; |
| 178 | arch = "arm64"; |
| 179 | compression = "none"; |
| 180 | $DTB_LOAD |
| 181 | hash { |
| 182 | algo = "md5"; |
| 183 | }; |
| 184 | }; |
| 185 | __FDT_IMAGE_EOF |
| 186 | |
| 187 | [ "x$(basename $dtname .dtb)" = "x${DEVICE_TREE}" ] && DEFAULT=$cnt |
| 188 | |
| 189 | cnt=$((cnt+1)) |
| 190 | done |
| 191 | |
| 192 | cat << __CONF_HEADER_EOF |
| 193 | }; |
| 194 | configurations { |
| 195 | default = "config_$DEFAULT"; |
| 196 | |
| 197 | __CONF_HEADER_EOF |
| 198 | |
| 199 | cnt=1 |
| 200 | for dtname in $DT |
| 201 | do |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 202 | if [ ! -f $BL31 ]; then |
| 203 | cat << __CONF_SECTION1_EOF |
| 204 | config_$cnt { |
| 205 | description = "$(basename $dtname .dtb)"; |
| 206 | firmware = "uboot"; |
| 207 | fdt = "fdt_$cnt"; |
| 208 | }; |
| 209 | __CONF_SECTION1_EOF |
| 210 | else |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 211 | if [ -f $BL32 ]; then |
| 212 | cat << __CONF_SECTION1_EOF |
| 213 | config_$cnt { |
| 214 | description = "$(basename $dtname .dtb)"; |
| 215 | firmware = "atf"; |
| 216 | loadables = "uboot", "tee"; |
| 217 | fdt = "fdt_$cnt"; |
| 218 | }; |
| 219 | __CONF_SECTION1_EOF |
| 220 | else |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 221 | cat << __CONF_SECTION1_EOF |
| 222 | config_$cnt { |
| 223 | description = "$(basename $dtname .dtb)"; |
| 224 | firmware = "atf"; |
| 225 | loadables = "uboot"; |
| 226 | fdt = "fdt_$cnt"; |
| 227 | }; |
| 228 | __CONF_SECTION1_EOF |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 229 | fi |
Michal Simek | f088750 | 2021-05-31 11:13:45 +0200 | [diff] [blame] | 230 | fi |
Michal Simek | cf73de1 | 2020-03-23 14:40:52 +0100 | [diff] [blame] | 231 | |
Michal Simek | a7178b7 | 2019-10-02 15:55:57 +0200 | [diff] [blame] | 232 | cnt=$((cnt+1)) |
| 233 | done |
| 234 | |
| 235 | cat << __ITS_EOF |
| 236 | }; |
| 237 | }; |
| 238 | __ITS_EOF |
Michal Simek | 3c99ab5 | 2021-08-19 12:02:57 +0200 | [diff] [blame] | 239 | |
| 240 | fi |