mkimage_fit_opensbi.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. [ -z "$OPENSBI" ] && OPENSBI="fw_dynamic.bin"
  9. if [ -z "$UBOOT_LOAD_ADDR" ]; then
  10. UBOOT_LOAD_ADDR="$(grep "^CONFIG_SYS_TEXT_BASE=" .config | awk 'BEGIN{FS="="} {print $2}')"
  11. fi
  12. if [ -z "$OPENSBI_LOAD_ADDR" ]; then
  13. OPENSBI_LOAD_ADDR="$(grep "^CONFIG_SPL_OPENSBI_LOAD_ADDR=" .config | awk 'BEGIN{FS="="} {print $2}')"
  14. fi
  15. if [ ! -f $OPENSBI ]; then
  16. echo "WARNING: OpenSBI binary \"$OPENSBI\" not found, resulting binary is not functional." >&2
  17. OPENSBI=/dev/null
  18. fi
  19. cat << __HEADER_EOF
  20. /dts-v1/;
  21. / {
  22. description = "Configuration to load OpenSBI before U-Boot";
  23. images {
  24. uboot {
  25. description = "U-Boot";
  26. data = /incbin/("u-boot-nodtb.bin");
  27. type = "standalone";
  28. os = "U-Boot";
  29. arch = "riscv";
  30. compression = "none";
  31. load = <$UBOOT_LOAD_ADDR>;
  32. };
  33. opensbi {
  34. description = "RISC-V OpenSBI";
  35. data = /incbin/("$OPENSBI");
  36. type = "firmware";
  37. os = "opensbi";
  38. arch = "riscv";
  39. compression = "none";
  40. load = <$OPENSBI_LOAD_ADDR>;
  41. entry = <$OPENSBI_LOAD_ADDR>;
  42. };
  43. __HEADER_EOF
  44. cnt=1
  45. for dtname in $*
  46. do
  47. cat << __FDT_IMAGE_EOF
  48. fdt_$cnt {
  49. description = "$(basename $dtname .dtb)";
  50. data = /incbin/("$dtname");
  51. type = "flat_dt";
  52. compression = "none";
  53. };
  54. __FDT_IMAGE_EOF
  55. cnt=$((cnt+1))
  56. done
  57. cat << __CONF_HEADER_EOF
  58. };
  59. configurations {
  60. default = "config_1";
  61. __CONF_HEADER_EOF
  62. if [ $# -eq 0 ]; then
  63. cat << __CONF_SECTION_EOF
  64. config_1 {
  65. description = "U-Boot FIT";
  66. firmware = "opensbi";
  67. loadables = "uboot";
  68. };
  69. __CONF_SECTION_EOF
  70. else
  71. cnt=1
  72. for dtname in $*
  73. do
  74. cat << __CONF_SECTION_EOF
  75. config_$cnt {
  76. description = "$(basename $dtname .dtb)";
  77. firmware = "opensbi";
  78. loadables = "uboot";
  79. fdt = "fdt_$cnt";
  80. };
  81. __CONF_SECTION_EOF
  82. cnt=$((cnt+1))
  83. done
  84. fi
  85. cat << __ITS_EOF
  86. };
  87. };
  88. __ITS_EOF