summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com>2023-08-14 08:59:23 -0600
committerMark Hatle <mark.hatle@amd.com>2023-08-17 09:55:43 -0500
commit89daaf083b4d4f3e6e5875545dd2387d2e05b468 (patch)
treeb7de59a30245cbb2676b69278e7a8a94939f2f0b
parent517ea2b99abdd164bd6a4d18c67a97dbaded6f6e (diff)
downloadmeta-xilinx-89daaf083b4d4f3e6e5875545dd2387d2e05b468.tar.gz
dfx_user_dts: Add support for bin and dts use case
1. Add support for bin and single dts use case. 2. Skip reciep when both .bit and .bin files are used in SRC_URI. 3. Fix regular expression logic to handle .dts and .dtsi file search. For example if the file name is user-dts.dtsi then dts search count was set to one which results in build failures. 4. Skip devicetree do_compile task if input file is dtbo in SRC_URI for ZynqMP and Zynq-7000. 5. Using bootgen tool "-o" option user can specify output file name. Hence fix logic for .bin install as .bin file name doesn't have to be <filename>.bit.bin always. 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.bbclass96
1 files changed, 56 insertions, 40 deletions
diff --git a/meta-xilinx-core/classes/dfx_user_dts.bbclass b/meta-xilinx-core/classes/dfx_user_dts.bbclass
index 2525a38e..4404aa05 100644
--- a/meta-xilinx-core/classes/dfx_user_dts.bbclass
+++ b/meta-xilinx-core/classes/dfx_user_dts.bbclass
@@ -41,6 +41,7 @@ python() {
41 dtsi_found = False 41 dtsi_found = False
42 dtbo_found = False 42 dtbo_found = False
43 bit_found = False 43 bit_found = False
44 bin_found = False
44 pdi_found = False 45 pdi_found = False
45 46
46 # Required Inputs 47 # Required Inputs
@@ -56,6 +57,10 @@ python() {
56 bit_found = True 57 bit_found = True
57 d.setVar("BIT_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.bit' in a][0].lstrip('file://'))) 58 d.setVar("BIT_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.bit' in a][0].lstrip('file://')))
58 59
60 if '.bin' in d.getVar("SRC_URI") and soc_family != "versal":
61 bin_found = True
62 d.setVar("BIT_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.bin' in a][0].lstrip('file://')))
63
59 if '.pdi' in d.getVar("SRC_URI") and soc_family == "versal": 64 if '.pdi' in d.getVar("SRC_URI") and soc_family == "versal":
60 pdi_found = True 65 pdi_found = True
61 d.setVar("PDI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.pdi' in a][0].lstrip('file://'))) 66 d.setVar("PDI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split() if '.pdi' in a][0].lstrip('file://')))
@@ -63,8 +68,10 @@ python() {
63 # Check for valid combination of input files in SRC_URI 68 # Check for valid combination of input files in SRC_URI
64 if dtsi_found or dtbo_found: 69 if dtsi_found or dtbo_found:
65 bb.debug(2, "dtsi or dtbo found in SRC_URI") 70 bb.debug(2, "dtsi or dtbo found in SRC_URI")
66 if bit_found or pdi_found: 71 if bit_found or pdi_found or bin_found:
67 bb.debug(2, "bitstream or pdi found in SRC_URI") 72 bb.debug(2, "bitstream or pdi found in SRC_URI")
73 elif bit_found and bin_found:
74 raise bb.parse.SkipRecipe("Both '.bit' and '.bin' file found in SRC_URI, either .bit or .bin file is supported but not both.")
68 else: 75 else:
69 raise bb.parse.SkipRecipe("Need one '.bit' or one '.pdi' file added to SRC_URI ") 76 raise bb.parse.SkipRecipe("Need one '.bit' or one '.pdi' file added to SRC_URI ")
70 else: 77 else:
@@ -74,8 +81,8 @@ python() {
74 # Following file combinations are not supported use case. 81 # Following file combinations are not supported use case.
75 # 1. More than one '.dtsi' and zero '.dts' file. 82 # 1. More than one '.dtsi' and zero '.dts' file.
76 # 2. More than one '.dts' and zero or more than one '.dtsi'file . 83 # 2. More than one '.dts' and zero or more than one '.dtsi'file .
77 pattern_dts = re.compile(r'.dts\b') 84 pattern_dts = re.compile(r'[.]+dts\b')
78 pattern_dtsi = re.compile(r'.dtsi\b') 85 pattern_dtsi = re.compile(r'[.]+dtsi\b')
79 dts_count = len([*re.finditer(pattern_dts, d.getVar('SRC_URI'))]) 86 dts_count = len([*re.finditer(pattern_dts, d.getVar('SRC_URI'))])
80 dtsi_count = len([*re.finditer(pattern_dtsi, d.getVar("SRC_URI"))]) 87 dtsi_count = len([*re.finditer(pattern_dtsi, d.getVar("SRC_URI"))])
81 88
@@ -145,35 +152,39 @@ python devicetree_do_compile:append() {
145 import glob, subprocess, shutil 152 import glob, subprocess, shutil
146 soc_family = d.getVar("SOC_FAMILY") 153 soc_family = d.getVar("SOC_FAMILY")
147 154
148 # Convert .bit to bit.bin format only if dtsi is input. 155 dtbo_count = sum(1 for f in glob.iglob((d.getVar('S') + '/*.dtbo'),recursive=True) if os.path.isfile(f))
149 # In case of dtbo as input, bbclass doesn't know if firmware-name is .bit or 156
150 # .bit.bin format and corresponding file name. Hence we are not doing 157 # Skip devicetree do_compile task if input file is dtbo in SRC_URI
151 # bit.bin conversion. 158 if not dtbo_count:
152 if soc_family != 'versal' and glob.glob(d.getVar('S') + '/' + d.getVar('FIRMWARE_NAME_DT_FILE')): 159 # Convert .bit to bit.bin format only if dtsi is input.
153 pn = d.getVar('PN') 160 # In case of dtbo as input, bbclass doesn't know if firmware-name is .bit or
154 biffile = pn + '.bif' 161 # .bit.bin format and corresponding file name. Hence we are not doing
155 162 # bit.bin conversion.
156 with open(biffile, 'w') as f: 163 if soc_family != 'versal' and glob.glob(d.getVar('S') + '/' + d.getVar('FIRMWARE_NAME_DT_FILE')):
157 f.write('all:\n{\n\t' + glob.glob(d.getVar('S')+(d.getVar('BIT_PATH') or '') + '/*.bit')[0] + '\n}') 164 pn = d.getVar('PN')
158 165 biffile = pn + '.bif'
159 bootgenargs = ["bootgen"] + (d.getVar("BOOTGEN_FLAGS") or "").split() 166
160 bootgenargs += ["-image", biffile, "-o", pn + ".bit.bin"] 167 with open(biffile, 'w') as f:
161 subprocess.run(bootgenargs, check = True) 168 f.write('all:\n{\n\t' + glob.glob(d.getVar('S')+(d.getVar('BIT_PATH') or '') + '/*.bit')[0] + '\n}')
162 169
163 # In Zynq7k using both "-process_bitstream bin" and "-o" in bootgen flag, 170 bootgenargs = ["bootgen"] + (d.getVar("BOOTGEN_FLAGS") or "").split()
164 # to convert bit file to bin format, "-o" option will not be effective 171 bootgenargs += ["-image", biffile, "-o", pn + ".bit.bin"]
165 # and generated output file name is ${S}+${BIT_PATH}/<bit_file_name>.bit.bin 172 subprocess.run(bootgenargs, check = True)
166 # file, Hence we need to rename this file from <bit_file_name>.bit.bin to 173
167 # ${PN}.bit.bin which matches the firmware name in dtbo and move 174 # In Zynq7k using both "-process_bitstream bin" and "-o" in bootgen flag,
168 # ${PN}.bit.bin to ${B} directory. 175 # to convert bit file to bin format, "-o" option will not be effective
169 if soc_family == 'zynq': 176 # and generated output file name is ${S}+${BIT_PATH}/<bit_file_name>.bit.bin
170 src_bitbin_file = glob.glob(d.getVar('S') + (d.getVar('BIT_PATH') or '') + '/*.bit.bin')[0] 177 # file, Hence we need to rename this file from <bit_file_name>.bit.bin to
171 dst_bitbin_file = d.getVar('B') + '/' + pn + '.bit.bin' 178 # ${PN}.bit.bin which matches the firmware name in dtbo and move
172 shutil.move(src_bitbin_file, dst_bitbin_file) 179 # ${PN}.bit.bin to ${B} directory.
173 180 if soc_family == 'zynq':
174 if not os.path.isfile(pn + ".bit.bin"): 181 src_bitbin_file = glob.glob(d.getVar('S') + (d.getVar('BIT_PATH') or '') + '/*.bit.bin')[0]
175 bb.fatal("Couldn't find %s file, Enable '-log trace' in BOOTGEN_FLAGS" \ 182 dst_bitbin_file = d.getVar('B') + '/' + pn + '.bit.bin'
176 "and check bootgen_log.txt" % (d.getVar('B') + '/' + pn + '.bit.bin')) 183 shutil.move(src_bitbin_file, dst_bitbin_file)
184
185 if not os.path.isfile(pn + ".bit.bin"):
186 bb.fatal("Couldn't find %s file, Enable '-log trace' in BOOTGEN_FLAGS" \
187 "and check bootgen_log.txt" % (d.getVar('B') + '/' + pn + '.bit.bin'))
177} 188}
178 189
179# If user inputs both dtsi and dts files then device-tree will generate dtbo 190# If user inputs both dtsi and dts files then device-tree will generate dtbo
@@ -188,7 +199,7 @@ python find_user_dts_overlay_file() {
188 dtsi_count = get_dt_count(d, 'dtsi') 199 dtsi_count = get_dt_count(d, 'dtsi')
189 if dtsi_count == 1 and dts_count == 0: 200 if dtsi_count == 1 and dts_count == 0:
190 dts_file =glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0] 201 dts_file =glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0]
191 elif dtsi_count > 1 and dts_count == 1: 202 elif dtsi_count >=0 and dts_count == 1:
192 dts_file = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dts')[0] 203 dts_file = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dts')[0]
193 204
194 d.setVar('USER_DTS_FILE', os.path.splitext(os.path.basename(dts_file))[0]) 205 d.setVar('USER_DTS_FILE', os.path.splitext(os.path.basename(dts_file))[0])
@@ -224,16 +235,21 @@ do_install() {
224 bbfatal "A PDI file with '.pdi' expected but not found" 235 bbfatal "A PDI file with '.pdi' expected but not found"
225 fi 236 fi
226 else 237 else
227 # In case of dtbo as input, .bit or .bit.bin will be copied from directly 238 # In case of dtbo as input, .bit or .bin will be copied from directly
228 # from ${S} without renaming the .bit name to ${PN}.bit.bin 239 # from ${S} without renaming the .bit/.bin name to ${PN}.bit/${PN}.bin
229 if [ `ls ${S}/*.bit* | wc -l` -eq 1 ] && [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then 240 # if more than one .bit/.bin file is found then fail the task.
230 install -Dm 0644 ${S}/*.bit* ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ 241 if [ `ls ${S}/*.bit | wc -l` -gt 1 ]; then
231 elif [ `ls ${S}/*.bit* | wc -l` -gt 1 ]; then 242 bbfatal "Multiple .bit found, use the right .bit in SRC_URI from the following:\n$(basename -a ${S}/*.bit)"
232 bbfatal "Multiple bit/bit.bin found, use the right bit/bit.bin in SRC_URI from the following:\n$(basename -a ${S}/*.bit*)" 243 elif [ `ls ${S}/*.bin | wc -l` -gt 1 ]; then
244 bbfatal "Multiple .bin found, use the right .bin in SRC_URI from the following:\n$(basename -a ${S}/*.bin)"
245 elif [ `ls ${S}/*.bit | wc -l` -eq 1 ] && [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then
246 install -Dm 0644 ${S}/*.bit ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/
247 elif [ `ls ${S}/*.bin | wc -l` -eq 1 ] && [ `ls ${S}/*.dtbo | wc -l` -eq 1 ]; then
248 install -Dm 0644 ${S}/*.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/
233 elif [ -f ${B}/${PN}.bit.bin ] && [ -f ${B}/${USER_DTS_FILE}.dtbo ]; then 249 elif [ -f ${B}/${PN}.bit.bin ] && [ -f ${B}/${USER_DTS_FILE}.dtbo ]; then
234 install -Dm 0644 ${B}/${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin 250 install -Dm 0644 ${B}/${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin
235 else 251 else
236 bbfatal "A bitstream file with '.bit' or '.bit.bin' expected but not found" 252 bbfatal "A bitstream file with '.bit' or '.bin' expected but not found"
237 fi 253 fi
238 fi 254 fi
239 255