diff options
Diffstat (limited to 'meta-xilinx-core/classes/fpgamanager_custom.bbclass')
| -rw-r--r-- | meta-xilinx-core/classes/fpgamanager_custom.bbclass | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/meta-xilinx-core/classes/fpgamanager_custom.bbclass b/meta-xilinx-core/classes/fpgamanager_custom.bbclass new file mode 100644 index 00000000..0b5fa249 --- /dev/null +++ b/meta-xilinx-core/classes/fpgamanager_custom.bbclass | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | LICENSE = "MIT" | ||
| 2 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
| 3 | |||
| 4 | inherit devicetree | ||
| 5 | |||
| 6 | DEPENDS = "dtc-native bootgen-native" | ||
| 7 | |||
| 8 | COMPATIBLE_MACHINE ?= "^$" | ||
| 9 | COMPATIBLE_MACHINE:zynqmp = ".*" | ||
| 10 | COMPATIBLE_MACHINE:zynq = ".*" | ||
| 11 | |||
| 12 | PROVIDES = "" | ||
| 13 | |||
| 14 | do_fetch[cleandirs] = "${B}" | ||
| 15 | |||
| 16 | DT_PADDING_SIZE = "0x1000" | ||
| 17 | BOOTGEN_FLAGS ?= " -arch ${SOC_FAMILY} ${@bb.utils.contains('SOC_FAMILY','zynqmp','-w','-process_bitstream bin',d)}" | ||
| 18 | |||
| 19 | S ?= "${WORKDIR}" | ||
| 20 | FW_DIR ?= "" | ||
| 21 | DTSI_PATH ?= "" | ||
| 22 | DT_FILES_PATH = "${S}/${DTSI_PATH}" | ||
| 23 | |||
| 24 | python (){ | ||
| 25 | |||
| 26 | if "git://" in d.getVar("SRC_URI") or "https://" in d.getVar("SRC_URI"): | ||
| 27 | d.setVar("S",'${WORKDIR}/git/'+d.getVar("FW_DIR")) | ||
| 28 | else: | ||
| 29 | if d.getVar("SRC_URI").count(".dtsi") != 1 or d.getVar("SRC_URI").count(".bit") != 1 \ | ||
| 30 | or d.getVar("SRC_URI").count("shell.json") != 1: | ||
| 31 | raise bb.parse.SkipRecipe("Need one '.dtsi', one '.bit' and one 'shell.json' file added to SRC_URI") | ||
| 32 | |||
| 33 | d.setVar("DTSI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.dtsi' in a][0])) | ||
| 34 | d.setVar("BIT_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.bit' in a][0])) | ||
| 35 | d.setVar("JSON_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if 'shell.json' in a][0])) | ||
| 36 | |||
| 37 | #optional input | ||
| 38 | if '.xclbin' in d.getVar("SRC_URI"): | ||
| 39 | d.setVar("XCL_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.xclbin' in a][0])) | ||
| 40 | } | ||
| 41 | python do_configure() { | ||
| 42 | import glob, re, shutil | ||
| 43 | |||
| 44 | if bb.utils.contains('MACHINE_FEATURES', 'fpga-overlay', False, True, d): | ||
| 45 | bb.warn("Using fpga-manager.bbclass requires fpga-overlay MACHINE_FEATURE to be enabled") | ||
| 46 | |||
| 47 | #renaming firmware-name using $PN as bitstream will be renamed using $PN when generating the bin file | ||
| 48 | orig_dtsi = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0] | ||
| 49 | new_dtsi = d.getVar('S') + '/pl.dtsi_firmwarename' | ||
| 50 | with open(new_dtsi, 'w') as newdtsi: | ||
| 51 | with open(orig_dtsi) as olddtsi: | ||
| 52 | for line in olddtsi: | ||
| 53 | newdtsi.write(re.sub('firmware-name.*\".*\"','firmware-name = \"'+d.getVar('PN')+'.bit.bin\"',line)) | ||
| 54 | shutil.move(new_dtsi,orig_dtsi) | ||
| 55 | } | ||
| 56 | |||
| 57 | python devicetree_do_compile:append() { | ||
| 58 | import glob, subprocess | ||
| 59 | pn = d.getVar('PN') | ||
| 60 | biffile = pn + '.bif' | ||
| 61 | |||
| 62 | with open(biffile, 'w') as f: | ||
| 63 | f.write('all:\n{\n\t' + glob.glob(d.getVar('S')+(d.getVar('BIT_PATH') or '') + '/*.bit')[0] + '\n}') | ||
| 64 | |||
| 65 | bootgenargs = ["bootgen"] + (d.getVar("BOOTGEN_FLAGS") or "").split() | ||
| 66 | bootgenargs += ["-image", biffile, "-o", pn + ".bit.bin"] | ||
| 67 | subprocess.run(bootgenargs, check = True) | ||
| 68 | |||
| 69 | if not os.path.isfile(pn + ".bit.bin"): | ||
| 70 | bb.fatal("bootgen failed. Enable -log debug with bootgen and check logs") | ||
| 71 | } | ||
| 72 | |||
| 73 | do_install() { | ||
| 74 | install -d ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ | ||
| 75 | install -Dm 0644 *.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.dtbo | ||
| 76 | install -Dm 0644 ${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin | ||
| 77 | if ls ${S}/${XCL_PATH}/*.xclbin >/dev/null 2>&1; then | ||
| 78 | install -Dm 0644 ${S}/${XCL_PATH}/*.xclbin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.xclbin | ||
| 79 | fi | ||
| 80 | install -Dm 0644 ${S}/${JSON_PATH}/shell.json ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/shell.json | ||
| 81 | } | ||
| 82 | |||
| 83 | do_deploy[noexec] = "1" | ||
| 84 | |||
| 85 | FILES:${PN} += "${nonarch_base_libdir}/firmware/xilinx/${PN}" | ||
