qts-filter-a10.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. #
  3. # helper function to convert from DOS to Unix, if necessary, and handle
  4. # lines ending in '\'.
  5. #
  6. fix_newlines_in_macros() {
  7. sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' $1
  8. }
  9. #filter out only what we need from a10 hps.xml
  10. grep_a10_hps_config() {
  11. egrep "clk_hz|i_clk_mgr|i_io48_pin_mux|AXI_SLAVE|AXI_MASTER"
  12. }
  13. #
  14. # Process hps.xml
  15. # $1: hps.xml
  16. # $2: Output File
  17. #
  18. process_a10_hps_config() {
  19. hps_xml="$1"
  20. outfile="$2"
  21. (cat << EOF
  22. // SPDX-License-Identifier: BSD-3-Clause
  23. /*
  24. * Intel Arria 10 SoCFPGA configuration
  25. */
  26. #ifndef __SOCFPGA_ARRIA10_CONFIG_H__
  27. #define __SOCFPGA_ARRIA10_CONFIG_H__
  28. EOF
  29. echo "/* Clocks */"
  30. fix_newlines_in_macros \
  31. ${hps_xml} | egrep "clk_hz" |
  32. awk -F"'" '{ gsub("\\.","_",$2) ; \
  33. print "#define" " " toupper($2) " " $4}' |
  34. sed 's/\.[0-9]//' |
  35. sed 's/I_CLK_MGR_//' |
  36. sort
  37. fix_newlines_in_macros \
  38. ${hps_xml} | egrep "i_clk_mgr_mainpll" |
  39. awk -F"'" '{ gsub("\\.","_",$2) ; \
  40. print "#define" " " toupper($2) " " $4}' |
  41. sed 's/\.[0-9]//' |
  42. sed 's/I_CLK_MGR_//' |
  43. sort
  44. fix_newlines_in_macros \
  45. ${hps_xml} | egrep "i_clk_mgr_perpll" |
  46. awk -F"'" '{ gsub("\\.","_",$2) ; \
  47. print "#define" " " toupper($2) " " $4}' |
  48. sed 's/\.[0-9]//' |
  49. sed 's/I_CLK_MGR_//' |
  50. sort
  51. fix_newlines_in_macros \
  52. ${hps_xml} | egrep "i_clk_mgr_clkmgr" |
  53. awk -F"'" '{ gsub("\\.","_",$2) ; \
  54. print "#define" " " toupper($2) " " $4}' |
  55. sed 's/\.[0-9]//' |
  56. sed 's/I_CLK_MGR_//' |
  57. sort
  58. fix_newlines_in_macros \
  59. ${hps_xml} | egrep "i_clk_mgr_alteragrp" |
  60. awk -F"'" '{ gsub("\\.","_",$2) ; \
  61. print "#define" " " toupper($2) " " $4}' |
  62. sed 's/\.[0-9]//' |
  63. sed 's/I_CLK_MGR_//' |
  64. sort
  65. echo "#define ALTERAGRP_MPUCLK ((ALTERAGRP_MPUCLK_PERICNT << 16) | \\"
  66. echo " (ALTERAGRP_MPUCLK_MAINCNT))"
  67. echo "#define ALTERAGRP_NOCCLK ((ALTERAGRP_NOCCLK_PERICNT << 16) | \\"
  68. echo " (ALTERAGRP_NOCCLK_MAINCNT))"
  69. echo
  70. echo "/* Pin Mux Configuration */"
  71. fix_newlines_in_macros \
  72. ${hps_xml} | egrep "i_io48_pin_mux" |
  73. awk -F"'" '{ gsub("\\.","_",$2) ; \
  74. print "#define" " " toupper($2) " " $4}' |
  75. sed 's/I_IO48_PIN_MUX_//' |
  76. sed 's/SHARED_3V_IO_GRP_//' |
  77. sed 's/FPGA_INTERFACE_GRP_//' |
  78. sed 's/DEDICATED_IO_GRP_//' |
  79. sed 's/CONFIGURATION_DEDICATED/CONFIG/' |
  80. sort
  81. echo
  82. echo "/* Bridge Configuration */"
  83. fix_newlines_in_macros \
  84. ${hps_xml} | egrep "AXI_SLAVE|AXI_MASTER" |
  85. awk -F"'" '{ gsub("\\.","_",$2) ; \
  86. print "#define" " " toupper($2) " " $4}' |
  87. sed 's/true/1/' |
  88. sed 's/false/0/' |
  89. sort
  90. echo
  91. echo "/* Voltage Select for Config IO */"
  92. echo "#define CONFIG_IO_BANK_VSEL \\"
  93. echo " (((CONFIG_IO_BANK_VOLTAGE_SEL_CLKRST_IO & 0x3) << 8) | \\"
  94. echo " (CONFIG_IO_BANK_VOLTAGE_SEL_PERI_IO & 0x3))"
  95. echo
  96. echo "/* Macro for Config IO bit mapping */"
  97. echo -n "#define CONFIG_IO_MACRO(NAME) "
  98. echo "(((NAME ## _RTRIM & 0xff) << 19) | \\"
  99. echo " ((NAME ## _INPUT_BUF_EN & 0x3) << 17) | \\"
  100. echo " ((NAME ## _WK_PU_EN & 0x1) << 16) | \\"
  101. echo " ((NAME ## _PU_SLW_RT & 0x1) << 13) | \\"
  102. echo " ((NAME ## _PU_DRV_STRG & 0xf) << 8) | \\"
  103. echo " ((NAME ## _PD_SLW_RT & 0x1) << 5) | \\"
  104. echo " (NAME ## _PD_DRV_STRG & 0x1f))"
  105. cat << EOF
  106. #endif /* __SOCFPGA_ARRIA10_CONFIG_H__ */
  107. EOF
  108. ) > "${outfile}"
  109. }
  110. usage() {
  111. echo "$0 [hps_xml] [output_file]"
  112. echo "Process QTS-generated hps.xml into devicetree header."
  113. echo ""
  114. echo " hps_xml - hps.xml file from hps_isw_handoff"
  115. echo " output_file - Output header file for dtsi include"
  116. echo ""
  117. }
  118. hps_xml="$1"
  119. outfile="$2"
  120. if [ "$#" -ne 2 ] ; then
  121. usage
  122. exit 1
  123. fi
  124. process_a10_hps_config "${hps_xml}" "${outfile}"