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" |
| 11 | # Can be also done as ${CROSS_COMPILE}readelf -l bl31.elf | awk '/Entry point/ { print $3 }' |
| 12 | [ -z "$ATF_LOAD_ADDR" ] && ATF_LOAD_ADDR="0xfffea000" |
| 13 | |
| 14 | if [ -z "$BL33_LOAD_ADDR" ];then |
| 15 | BL33_LOAD_ADDR=`awk '/CONFIG_SYS_TEXT_BASE/ { print $3 }' include/generated/autoconf.h` |
| 16 | fi |
| 17 | |
| 18 | DTB_LOAD_ADDR=`awk '/CONFIG_XILINX_OF_BOARD_DTB_ADDR/ { print $3 }' include/generated/autoconf.h` |
| 19 | if [ ! -z "$DTB_LOAD_ADDR" ]; then |
| 20 | DTB_LOAD="load = <$DTB_LOAD_ADDR>;" |
| 21 | else |
| 22 | DTB_LOAD="" |
| 23 | fi |
| 24 | |
| 25 | if [ -z "$*" ]; then |
| 26 | DT=arch/arm/dts/${DEVICE_TREE}.dtb |
| 27 | else |
| 28 | DT=$* |
| 29 | fi |
| 30 | |
| 31 | if [ ! -f $BL31 ]; then |
| 32 | echo "WARNING: BL31 file $BL31 NOT found, resulting binary is non-functional" >&2 |
| 33 | BL31=/dev/null |
| 34 | # But U-Boot proper could be loaded in EL3 by specifying |
| 35 | # firmware = "uboot"; |
| 36 | # instead of "atf" in config node |
| 37 | fi |
| 38 | |
| 39 | cat << __HEADER_EOF |
| 40 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
| 41 | |
| 42 | /dts-v1/; |
| 43 | |
| 44 | / { |
| 45 | description = "Configuration to load ATF before U-Boot"; |
| 46 | |
| 47 | images { |
| 48 | uboot { |
| 49 | description = "U-Boot (64-bit)"; |
| 50 | data = /incbin/("$BL33"); |
| 51 | type = "firmware"; |
| 52 | os = "u-boot"; |
| 53 | arch = "arm64"; |
| 54 | compression = "none"; |
| 55 | load = <$BL33_LOAD_ADDR>; |
| 56 | entry = <$BL33_LOAD_ADDR>; |
| 57 | hash { |
| 58 | algo = "md5"; |
| 59 | }; |
| 60 | }; |
| 61 | atf { |
| 62 | description = "ARM Trusted Firmware"; |
| 63 | data = /incbin/("$BL31"); |
| 64 | type = "firmware"; |
| 65 | os = "arm-trusted-firmware"; |
| 66 | arch = "arm64"; |
| 67 | compression = "none"; |
| 68 | load = <$ATF_LOAD_ADDR>; |
| 69 | entry = <$ATF_LOAD_ADDR>; |
| 70 | hash { |
| 71 | algo = "md5"; |
| 72 | }; |
| 73 | }; |
| 74 | __HEADER_EOF |
| 75 | |
| 76 | DEFAULT=1 |
| 77 | cnt=1 |
| 78 | for dtname in $DT |
| 79 | do |
| 80 | cat << __FDT_IMAGE_EOF |
| 81 | fdt_$cnt { |
| 82 | description = "$(basename $dtname .dtb)"; |
| 83 | data = /incbin/("$dtname"); |
| 84 | type = "flat_dt"; |
| 85 | arch = "arm64"; |
| 86 | compression = "none"; |
| 87 | $DTB_LOAD |
| 88 | hash { |
| 89 | algo = "md5"; |
| 90 | }; |
| 91 | }; |
| 92 | __FDT_IMAGE_EOF |
| 93 | |
| 94 | [ "x$(basename $dtname .dtb)" = "x${DEVICE_TREE}" ] && DEFAULT=$cnt |
| 95 | |
| 96 | cnt=$((cnt+1)) |
| 97 | done |
| 98 | |
| 99 | cat << __CONF_HEADER_EOF |
| 100 | }; |
| 101 | configurations { |
| 102 | default = "config_$DEFAULT"; |
| 103 | |
| 104 | __CONF_HEADER_EOF |
| 105 | |
| 106 | cnt=1 |
| 107 | for dtname in $DT |
| 108 | do |
| 109 | cat << __CONF_SECTION1_EOF |
| 110 | config_$cnt { |
| 111 | description = "$(basename $dtname .dtb)"; |
| 112 | firmware = "atf"; |
| 113 | loadables = "uboot"; |
| 114 | fdt = "fdt_$cnt"; |
| 115 | }; |
| 116 | __CONF_SECTION1_EOF |
| 117 | cnt=$((cnt+1)) |
| 118 | done |
| 119 | |
| 120 | cat << __ITS_EOF |
| 121 | }; |
| 122 | }; |
| 123 | __ITS_EOF |