diff options
author | Sandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com> | 2023-07-11 15:39:16 -0600 |
---|---|---|
committer | Mark Hatle <mark.hatle@amd.com> | 2023-07-12 15:00:55 -0500 |
commit | e51efc5983dcc119296f8e55cd5737a733e3f459 (patch) | |
tree | a0b4705295279e0eaa8fe5b3019e0858d1d96f6c | |
parent | 85ef223f5670cb2f48856b1e069d92e252f51fd3 (diff) | |
download | meta-xilinx-e51efc5983dcc119296f8e55cd5737a733e3f459.tar.gz |
dfx_user_dts: Add support for single dts input
Add support for single dts and multiple dtsi use case.
Also check for valid combination of dtsi and dts files in SRC_URI and
following file combinations are not supported use case.
1. More than one '.dtsi' and zero '.dts' file.
2. More than one '.dts' and zero or more than one '.dtsi' file.
Signed-off-by: Sandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com>
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
-rw-r--r-- | meta-xilinx-core/classes/dfx_user_dts.bbclass | 100 |
1 files changed, 87 insertions, 13 deletions
diff --git a/meta-xilinx-core/classes/dfx_user_dts.bbclass b/meta-xilinx-core/classes/dfx_user_dts.bbclass index 1f45cf12..2525a38e 100644 --- a/meta-xilinx-core/classes/dfx_user_dts.bbclass +++ b/meta-xilinx-core/classes/dfx_user_dts.bbclass | |||
@@ -26,8 +26,14 @@ FW_DIR ?= "" | |||
26 | DTSI_PATH ?= "" | 26 | DTSI_PATH ?= "" |
27 | DTBO_PATH ?= "" | 27 | DTBO_PATH ?= "" |
28 | DT_FILES_PATH = "${S}/${DTSI_PATH}" | 28 | DT_FILES_PATH = "${S}/${DTSI_PATH}" |
29 | FIRMWARE_NAME_DT_FILE ?= "" | ||
30 | USER_DTS_FILE ?= "" | ||
31 | |||
32 | FIRMWARE_NAME_DT_FILE[doc] = "DT file which has firmware-name device-tree property" | ||
33 | USER_DTS_FILE[doc] = "Final DTSI or DTS file which is used for packaging final DT overlay" | ||
29 | 34 | ||
30 | python() { | 35 | python() { |
36 | import re | ||
31 | soc_family = d.getVar("SOC_FAMILY") | 37 | soc_family = d.getVar("SOC_FAMILY") |
32 | if "git://" in d.getVar("SRC_URI") or "https://" in d.getVar("SRC_URI"): | 38 | if "git://" in d.getVar("SRC_URI") or "https://" in d.getVar("SRC_URI"): |
33 | d.setVar("S",'${WORKDIR}/git/'+d.getVar("FW_DIR")) | 39 | d.setVar("S",'${WORKDIR}/git/'+d.getVar("FW_DIR")) |
@@ -38,9 +44,9 @@ python() { | |||
38 | pdi_found = False | 44 | pdi_found = False |
39 | 45 | ||
40 | # Required Inputs | 46 | # Required Inputs |
41 | if '.dtsi' in d.getVar("SRC_URI"): | 47 | if '.dtsi' in d.getVar("SRC_URI") or '.dts' in d.getVar("SRC_URI"): |
42 | dtsi_found = True | 48 | dtsi_found = True |
43 | d.setVar("DTSI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.dtsi' in a][0].lstrip('file://'))) | 49 | d.setVar("DTSI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.dtsi' in a or '.dts' in a][0].lstrip('file://'))) |
44 | 50 | ||
45 | if '.dtbo' in d.getVar("SRC_URI"): | 51 | if '.dtbo' in d.getVar("SRC_URI"): |
46 | dtbo_found = True | 52 | dtbo_found = True |
@@ -64,6 +70,20 @@ python() { | |||
64 | else: | 70 | else: |
65 | raise bb.parse.SkipRecipe("Need one '.dtsi' or one '.dtbo' file added to SRC_URI ") | 71 | raise bb.parse.SkipRecipe("Need one '.dtsi' or one '.dtbo' file added to SRC_URI ") |
66 | 72 | ||
73 | # Check for valid combination of dtsi and dts files in SRC_URI | ||
74 | # Following file combinations are not supported use case. | ||
75 | # 1. More than one '.dtsi' and zero '.dts' file. | ||
76 | # 2. More than one '.dts' and zero or more than one '.dtsi'file . | ||
77 | pattern_dts = re.compile(r'.dts\b') | ||
78 | pattern_dtsi = re.compile(r'.dtsi\b') | ||
79 | dts_count = len([*re.finditer(pattern_dts, d.getVar('SRC_URI'))]) | ||
80 | dtsi_count = len([*re.finditer(pattern_dtsi, d.getVar("SRC_URI"))]) | ||
81 | |||
82 | if dtsi_count > 1 and dts_count == 0: | ||
83 | raise bb.parse.SkipRecipe("Recipe has more than one '.dtsi' and zero '.dts' found, this is an unsupported use case") | ||
84 | elif dts_count > 1: | ||
85 | raise bb.parse.SkipRecipe("Recipe has more than one '.dts' and zero or more than one '.dtsi' found, this is an unsupported use case") | ||
86 | |||
67 | # Optional input | 87 | # Optional input |
68 | if '.json' in d.getVar("SRC_URI"): | 88 | if '.json' in d.getVar("SRC_URI"): |
69 | d.setVar("JSON_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.json' in a][0].lstrip('file://'))) | 89 | d.setVar("JSON_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.json' in a][0].lstrip('file://'))) |
@@ -71,6 +91,32 @@ python() { | |||
71 | if '.xclbin' in d.getVar("SRC_URI"): | 91 | if '.xclbin' in d.getVar("SRC_URI"): |
72 | d.setVar("XCL_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.xclbin' in a][0].lstrip('file://'))) | 92 | d.setVar("XCL_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.xclbin' in a][0].lstrip('file://'))) |
73 | } | 93 | } |
94 | |||
95 | # Function to get dts or dtsi file count. | ||
96 | def get_dt_count(d, dt_ext): | ||
97 | import glob | ||
98 | dt_count = sum(1 for f in glob.iglob((d.getVar('S') + (d.getVar('DTSI_PATH')) + '/*.' + dt_ext),recursive=True) if os.path.isfile(f)) | ||
99 | return dt_count | ||
100 | |||
101 | # Function to search for dt firmware-name property in dts or dtsi file. | ||
102 | python find_firmware_file() { | ||
103 | import glob | ||
104 | pattern_fw = 'firmware-name' | ||
105 | search_count = 0 | ||
106 | for dt_files in glob.iglob((d.getVar('S') + (d.getVar('DTSI_PATH')) + '/*.dts*'),recursive=True): | ||
107 | with open(dt_files, "r") as f: | ||
108 | current_fd = f.read() | ||
109 | if pattern_fw in current_fd: | ||
110 | search_count += 1 | ||
111 | if search_count > 1: | ||
112 | bb.error("firmware-name dt property found in more than one dt files! Please fix the dts or dtsi file.") | ||
113 | break | ||
114 | else: | ||
115 | d.setVar('FIRMWARE_NAME_DT_FILE', os.path.basename(dt_files)) | ||
116 | } | ||
117 | |||
118 | do_configure[prefuncs] += "find_firmware_file" | ||
119 | |||
74 | python do_configure() { | 120 | python do_configure() { |
75 | import glob, re, shutil | 121 | import glob, re, shutil |
76 | soc_family = d.getVar("SOC_FAMILY") | 122 | soc_family = d.getVar("SOC_FAMILY") |
@@ -80,8 +126,8 @@ python do_configure() { | |||
80 | 126 | ||
81 | # Renaming firmware-name using $PN as bitstream/PDI will be renamed using | 127 | # Renaming firmware-name using $PN as bitstream/PDI will be renamed using |
82 | # $PN when generating the bin/pdi file. | 128 | # $PN when generating the bin/pdi file. |
83 | if '.dtsi' in d.getVar("SRC_URI"): | 129 | if os.path.isfile(d.getVar('S') + (d.getVar('DTSI_PATH') or '') + '/' + d.getVar('FIRMWARE_NAME_DT_FILE')): |
84 | orig_dtsi = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0] | 130 | orig_dtsi = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/' + d.getVar('FIRMWARE_NAME_DT_FILE'))[0] |
85 | new_dtsi = d.getVar('S') + '/pl.dtsi_firmwarename' | 131 | new_dtsi = d.getVar('S') + '/pl.dtsi_firmwarename' |
86 | with open(new_dtsi, 'w') as newdtsi: | 132 | with open(new_dtsi, 'w') as newdtsi: |
87 | with open(orig_dtsi) as olddtsi: | 133 | with open(orig_dtsi) as olddtsi: |
@@ -93,6 +139,8 @@ python do_configure() { | |||
93 | shutil.move(new_dtsi,orig_dtsi) | 139 | shutil.move(new_dtsi,orig_dtsi) |
94 | } | 140 | } |
95 | 141 | ||
142 | do_compile[prefuncs] += "find_firmware_file" | ||
143 | |||
96 | python devicetree_do_compile:append() { | 144 | python devicetree_do_compile:append() { |
97 | import glob, subprocess, shutil | 145 | import glob, subprocess, shutil |
98 | soc_family = d.getVar("SOC_FAMILY") | 146 | soc_family = d.getVar("SOC_FAMILY") |
@@ -101,7 +149,7 @@ python devicetree_do_compile:append() { | |||
101 | # In case of dtbo as input, bbclass doesn't know if firmware-name is .bit or | 149 | # In case of dtbo as input, bbclass doesn't know if firmware-name is .bit or |
102 | # .bit.bin format and corresponding file name. Hence we are not doing | 150 | # .bit.bin format and corresponding file name. Hence we are not doing |
103 | # bit.bin conversion. | 151 | # bit.bin conversion. |
104 | if soc_family != 'versal' and glob.glob(d.getVar('S') + '/*.dtsi'): | 152 | if soc_family != 'versal' and glob.glob(d.getVar('S') + '/' + d.getVar('FIRMWARE_NAME_DT_FILE')): |
105 | pn = d.getVar('PN') | 153 | pn = d.getVar('PN') |
106 | biffile = pn + '.bif' | 154 | biffile = pn + '.bif' |
107 | 155 | ||
@@ -128,15 +176,37 @@ python devicetree_do_compile:append() { | |||
128 | "and check bootgen_log.txt" % (d.getVar('B') + '/' + pn + '.bit.bin')) | 176 | "and check bootgen_log.txt" % (d.getVar('B') + '/' + pn + '.bit.bin')) |
129 | } | 177 | } |
130 | 178 | ||
179 | # If user inputs both dtsi and dts files then device-tree will generate dtbo | ||
180 | # files for each dt file, Hence to package the firmware pick the right user dt | ||
181 | # overlay file. | ||
182 | python find_user_dts_overlay_file() { | ||
183 | import glob | ||
184 | dtbo_count = sum(1 for f in glob.iglob((d.getVar('S') + '/*.dtbo'),recursive=True) if os.path.isfile(f)) | ||
185 | # Skip if input file is dtbo in SRC_URI | ||
186 | if not dtbo_count: | ||
187 | dts_count = get_dt_count(d, 'dts') | ||
188 | dtsi_count = get_dt_count(d, 'dtsi') | ||
189 | if dtsi_count == 1 and dts_count == 0: | ||
190 | dts_file =glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0] | ||
191 | elif dtsi_count > 1 and dts_count == 1: | ||
192 | dts_file = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dts')[0] | ||
193 | |||
194 | d.setVar('USER_DTS_FILE', os.path.splitext(os.path.basename(dts_file))[0]) | ||
195 | } | ||
196 | |||
197 | do_install[prefuncs] += "find_user_dts_overlay_file" | ||
198 | |||
131 | do_install() { | 199 | do_install() { |
132 | install -d ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ | 200 | install -d ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ |
133 | 201 | ||
134 | # In case of dtbo as input, dtbo will be copied from directly from ${S} | 202 | # In case of dtbo as input, dtbo will be copied from directly from ${S} |
135 | # In case of dtsi as input, dtbo will be copied from directly from ${B} | 203 | # In case of dtsi as input, dtbo will be copied from directly from ${B} |
136 | if [ -f ${S}/*.dtbo ]; then | 204 | if [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then |
137 | install -Dm 0644 ${S}/*.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ | 205 | install -Dm 0644 ${S}/*.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ |
138 | elif [ -f ${B}/*.dtbo ]; then | 206 | elif [ `ls ${S}/*.dtbo | wc -l` -gt 1 ]; then |
139 | install -Dm 0644 ${B}/*.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.dtbo | 207 | bbfatal "Multiple DTBO found, use the right DTBO in SRC_URI from the following:\n$(basename -a ${S}/*.dtbo)" |
208 | elif [ -f ${B}/${USER_DTS_FILE}.dtbo ]; then | ||
209 | install -Dm 0644 ${B}/${USER_DTS_FILE}.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.dtbo | ||
140 | else | 210 | else |
141 | bbfatal "A dtbo ending '.dtbo' expected but not found" | 211 | bbfatal "A dtbo ending '.dtbo' expected but not found" |
142 | fi | 212 | fi |
@@ -144,19 +214,23 @@ do_install() { | |||
144 | if [ "${SOC_FAMILY}" == "versal" ]; then | 214 | if [ "${SOC_FAMILY}" == "versal" ]; then |
145 | # In case of dtbo as input, pdi will be copied from directly from ${S} | 215 | # In case of dtbo as input, pdi will be copied from directly from ${S} |
146 | # without renaming the pdi name to ${PN}.pdi | 216 | # without renaming the pdi name to ${PN}.pdi |
147 | if [ -f ${S}/*.pdi ] && [ -f ${S}/*.dtbo ]; then | 217 | if [ `ls ${S}/*.pdi | wc -l` -eq 1 ] && [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then |
148 | install -Dm 0644 ${S}/*.pdi ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ | 218 | install -Dm 0644 ${S}/*.pdi ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ |
149 | elif [ -f ${S}/*.pdi ] && [ -f ${B}/*.dtbo ]; then | 219 | elif [ `ls ${S}/*.pdi | wc -l` -gt 1 ]; then |
220 | bbfatal "Multiple PDI found, use the right PDI in SRC_URI from the following:\n$(basename -a ${S}/*.pdi)" | ||
221 | elif [ `ls ${S}/*.pdi | wc -l` -eq 1 ] && [ -f ${B}/${USER_DTS_FILE}.dtbo ]; then | ||
150 | install -Dm 0644 ${S}/*.pdi ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.pdi | 222 | install -Dm 0644 ${S}/*.pdi ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.pdi |
151 | else | 223 | else |
152 | bbfatal "A PDI file with '.pdi' expected but not found" | 224 | bbfatal "A PDI file with '.pdi' expected but not found" |
153 | fi | 225 | fi |
154 | else | 226 | else |
155 | # In case of dtbo as input, .bit or .bit.in will be copied from directly | 227 | # In case of dtbo as input, .bit or .bit.bin will be copied from directly |
156 | # from ${S} without renaming the .bit name to ${PN}.bit.bin | 228 | # from ${S} without renaming the .bit name to ${PN}.bit.bin |
157 | if [ -f ${S}/*.bit* ] && [ -f ${S}/*.dtbo ]; then | 229 | if [ `ls ${S}/*.bit* | wc -l` -eq 1 ] && [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then |
158 | install -Dm 0644 ${S}/*.bit* ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ | 230 | install -Dm 0644 ${S}/*.bit* ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ |
159 | elif [ -f ${B}/${PN}.bit.bin ] && [ -f ${B}/*.dtbo ]; then | 231 | elif [ `ls ${S}/*.bit* | wc -l` -gt 1 ]; then |
232 | bbfatal "Multiple bit/bit.bin found, use the right bit/bit.bin in SRC_URI from the following:\n$(basename -a ${S}/*.bit*)" | ||
233 | elif [ -f ${B}/${PN}.bit.bin ] && [ -f ${B}/${USER_DTS_FILE}.dtbo ]; then | ||
160 | install -Dm 0644 ${B}/${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin | 234 | install -Dm 0644 ${B}/${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin |
161 | else | 235 | else |
162 | bbfatal "A bitstream file with '.bit' or '.bit.bin' expected but not found" | 236 | bbfatal "A bitstream file with '.bit' or '.bit.bin' expected but not found" |