Lukas Auer | e9fbc71 | 2019-08-21 21:14:47 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0+ |
| 3 | # |
| 4 | # script to generate FIT image source for RISC-V boards with OpenSBI |
| 5 | # and, optionally, multiple device trees (given on the command line). |
| 6 | # |
| 7 | # usage: $0 [<dt_name> [<dt_name] ...] |
| 8 | |
| 9 | [ -z "$OPENSBI" ] && OPENSBI="fw_dynamic.bin" |
| 10 | |
| 11 | if [ -z "$UBOOT_LOAD_ADDR" ]; then |
| 12 | UBOOT_LOAD_ADDR="$(grep "^CONFIG_SYS_TEXT_BASE=" .config | awk 'BEGIN{FS="="} {print $2}')" |
| 13 | fi |
| 14 | |
| 15 | if [ -z "$OPENSBI_LOAD_ADDR" ]; then |
| 16 | OPENSBI_LOAD_ADDR="$(grep "^CONFIG_SPL_OPENSBI_LOAD_ADDR=" .config | awk 'BEGIN{FS="="} {print $2}')" |
| 17 | fi |
| 18 | |
| 19 | if [ ! -f $OPENSBI ]; then |
| 20 | echo "WARNING: OpenSBI binary \"$OPENSBI\" not found, resulting binary is not functional." >&2 |
| 21 | OPENSBI=/dev/null |
| 22 | fi |
| 23 | |
| 24 | cat << __HEADER_EOF |
| 25 | /dts-v1/; |
| 26 | |
| 27 | / { |
| 28 | description = "Configuration to load OpenSBI before U-Boot"; |
| 29 | |
| 30 | images { |
| 31 | uboot { |
| 32 | description = "U-Boot"; |
| 33 | data = /incbin/("u-boot-nodtb.bin"); |
| 34 | type = "standalone"; |
| 35 | os = "U-Boot"; |
| 36 | arch = "riscv"; |
| 37 | compression = "none"; |
| 38 | load = <$UBOOT_LOAD_ADDR>; |
| 39 | }; |
| 40 | opensbi { |
| 41 | description = "RISC-V OpenSBI"; |
| 42 | data = /incbin/("$OPENSBI"); |
| 43 | type = "firmware"; |
| 44 | os = "opensbi"; |
| 45 | arch = "riscv"; |
| 46 | compression = "none"; |
| 47 | load = <$OPENSBI_LOAD_ADDR>; |
| 48 | entry = <$OPENSBI_LOAD_ADDR>; |
| 49 | }; |
| 50 | __HEADER_EOF |
| 51 | |
| 52 | cnt=1 |
| 53 | for dtname in $* |
| 54 | do |
| 55 | cat << __FDT_IMAGE_EOF |
| 56 | fdt_$cnt { |
| 57 | description = "$(basename $dtname .dtb)"; |
| 58 | data = /incbin/("$dtname"); |
| 59 | type = "flat_dt"; |
| 60 | compression = "none"; |
| 61 | }; |
| 62 | __FDT_IMAGE_EOF |
| 63 | cnt=$((cnt+1)) |
| 64 | done |
| 65 | |
| 66 | cat << __CONF_HEADER_EOF |
| 67 | }; |
| 68 | configurations { |
| 69 | default = "config_1"; |
| 70 | |
| 71 | __CONF_HEADER_EOF |
| 72 | |
| 73 | if [ $# -eq 0 ]; then |
| 74 | cat << __CONF_SECTION_EOF |
| 75 | config_1 { |
| 76 | description = "U-Boot FIT"; |
| 77 | firmware = "opensbi"; |
| 78 | loadables = "uboot"; |
| 79 | }; |
| 80 | __CONF_SECTION_EOF |
| 81 | else |
| 82 | cnt=1 |
| 83 | for dtname in $* |
| 84 | do |
| 85 | cat << __CONF_SECTION_EOF |
| 86 | config_$cnt { |
| 87 | description = "$(basename $dtname .dtb)"; |
| 88 | firmware = "opensbi"; |
| 89 | loadables = "uboot"; |
| 90 | fdt = "fdt_$cnt"; |
| 91 | }; |
| 92 | __CONF_SECTION_EOF |
| 93 | cnt=$((cnt+1)) |
| 94 | done |
| 95 | fi |
| 96 | |
| 97 | cat << __ITS_EOF |
| 98 | }; |
| 99 | }; |
| 100 | __ITS_EOF |