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