From 322e23dc213d51a12345ca705b3776f189dc413f Mon Sep 17 00:00:00 2001 From: Mark Hatle Date: Wed, 15 Dec 2021 13:52:16 -0800 Subject: Initial restructure/split of meta-xilinx-bsp Create a new meta-xilinx-core, move core functionality to the core, keeping board specific files in the bsp layer. zynqmp-generic changed from require to include, so if meta-xilinx-bsp is not available it will not fail. Signed-off-by: Mark Hatle --- .../classes/fpgamanager_custom.bbclass | 85 ++++++++++++++++++++++ .../classes/image-types-xilinx-qemu.bbclass | 10 +++ meta-xilinx-core/classes/image-wic-utils.bbclass | 51 +++++++++++++ .../classes/kernel-simpleimage.bbclass | 35 +++++++++ meta-xilinx-core/classes/qemuboot-xilinx.bbclass | 27 +++++++ .../classes/xilinx-fetch-restricted.bbclass | 35 +++++++++ .../classes/xilinx-platform-init.bbclass | 14 ++++ meta-xilinx-core/classes/xilinx-testimage.bbclass | 11 +++ meta-xilinx-core/classes/xlnx-standalone.bbclass | 16 ++++ 9 files changed, 284 insertions(+) create mode 100644 meta-xilinx-core/classes/fpgamanager_custom.bbclass create mode 100644 meta-xilinx-core/classes/image-types-xilinx-qemu.bbclass create mode 100644 meta-xilinx-core/classes/image-wic-utils.bbclass create mode 100644 meta-xilinx-core/classes/kernel-simpleimage.bbclass create mode 100644 meta-xilinx-core/classes/qemuboot-xilinx.bbclass create mode 100644 meta-xilinx-core/classes/xilinx-fetch-restricted.bbclass create mode 100644 meta-xilinx-core/classes/xilinx-platform-init.bbclass create mode 100644 meta-xilinx-core/classes/xilinx-testimage.bbclass create mode 100644 meta-xilinx-core/classes/xlnx-standalone.bbclass (limited to 'meta-xilinx-core/classes') 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 @@ +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +inherit devicetree + +DEPENDS = "dtc-native bootgen-native" + +COMPATIBLE_MACHINE ?= "^$" +COMPATIBLE_MACHINE:zynqmp = ".*" +COMPATIBLE_MACHINE:zynq = ".*" + +PROVIDES = "" + +do_fetch[cleandirs] = "${B}" + +DT_PADDING_SIZE = "0x1000" +BOOTGEN_FLAGS ?= " -arch ${SOC_FAMILY} ${@bb.utils.contains('SOC_FAMILY','zynqmp','-w','-process_bitstream bin',d)}" + +S ?= "${WORKDIR}" +FW_DIR ?= "" +DTSI_PATH ?= "" +DT_FILES_PATH = "${S}/${DTSI_PATH}" + +python (){ + + if "git://" in d.getVar("SRC_URI") or "https://" in d.getVar("SRC_URI"): + d.setVar("S",'${WORKDIR}/git/'+d.getVar("FW_DIR")) + else: + if d.getVar("SRC_URI").count(".dtsi") != 1 or d.getVar("SRC_URI").count(".bit") != 1 \ + or d.getVar("SRC_URI").count("shell.json") != 1: + raise bb.parse.SkipRecipe("Need one '.dtsi', one '.bit' and one 'shell.json' file added to SRC_URI") + + d.setVar("DTSI_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.dtsi' in a][0])) + d.setVar("BIT_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.bit' in a][0])) + d.setVar("JSON_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if 'shell.json' in a][0])) + + #optional input + if '.xclbin' in d.getVar("SRC_URI"): + d.setVar("XCL_PATH",os.path.dirname([a for a in d.getVar('SRC_URI').split('file://') if '.xclbin' in a][0])) +} +python do_configure() { + import glob, re, shutil + + if bb.utils.contains('MACHINE_FEATURES', 'fpga-overlay', False, True, d): + bb.warn("Using fpga-manager.bbclass requires fpga-overlay MACHINE_FEATURE to be enabled") + + #renaming firmware-name using $PN as bitstream will be renamed using $PN when generating the bin file + orig_dtsi = glob.glob(d.getVar('S')+ (d.getVar('DTSI_PATH') or '') + '/*.dtsi')[0] + new_dtsi = d.getVar('S') + '/pl.dtsi_firmwarename' + with open(new_dtsi, 'w') as newdtsi: + with open(orig_dtsi) as olddtsi: + for line in olddtsi: + newdtsi.write(re.sub('firmware-name.*\".*\"','firmware-name = \"'+d.getVar('PN')+'.bit.bin\"',line)) + shutil.move(new_dtsi,orig_dtsi) +} + +python devicetree_do_compile:append() { + import glob, subprocess + pn = d.getVar('PN') + biffile = pn + '.bif' + + with open(biffile, 'w') as f: + f.write('all:\n{\n\t' + glob.glob(d.getVar('S')+(d.getVar('BIT_PATH') or '') + '/*.bit')[0] + '\n}') + + bootgenargs = ["bootgen"] + (d.getVar("BOOTGEN_FLAGS") or "").split() + bootgenargs += ["-image", biffile, "-o", pn + ".bit.bin"] + subprocess.run(bootgenargs, check = True) + + if not os.path.isfile(pn + ".bit.bin"): + bb.fatal("bootgen failed. Enable -log debug with bootgen and check logs") +} + +do_install() { + install -d ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/ + install -Dm 0644 *.dtbo ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.dtbo + install -Dm 0644 ${PN}.bit.bin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.bit.bin + if ls ${S}/${XCL_PATH}/*.xclbin >/dev/null 2>&1; then + install -Dm 0644 ${S}/${XCL_PATH}/*.xclbin ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/${PN}.xclbin + fi + install -Dm 0644 ${S}/${JSON_PATH}/shell.json ${D}/${nonarch_base_libdir}/firmware/xilinx/${PN}/shell.json +} + +do_deploy[noexec] = "1" + +FILES:${PN} += "${nonarch_base_libdir}/firmware/xilinx/${PN}" diff --git a/meta-xilinx-core/classes/image-types-xilinx-qemu.bbclass b/meta-xilinx-core/classes/image-types-xilinx-qemu.bbclass new file mode 100644 index 00000000..63318087 --- /dev/null +++ b/meta-xilinx-core/classes/image-types-xilinx-qemu.bbclass @@ -0,0 +1,10 @@ +# Define the 'qemu-sd' conversion type +# +# This conversion type pads any image to the 512K boundary to ensure that the +# image file can be used directly with QEMU's SD emulation which requires the +# block device to match that of valid SD card sizes (which are multiples of +# 512K). + +CONVERSIONTYPES:append = " qemu-sd" +CONVERSION_CMD:qemu-sd = "cp ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd; truncate -s %256M ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd" +CONVERSION_DEPENDS_qemu-sd = "coreutils-native" diff --git a/meta-xilinx-core/classes/image-wic-utils.bbclass b/meta-xilinx-core/classes/image-wic-utils.bbclass new file mode 100644 index 00000000..562f3263 --- /dev/null +++ b/meta-xilinx-core/classes/image-wic-utils.bbclass @@ -0,0 +1,51 @@ +# Helper/utility functions to work with the IMAGE_BOOT_FILES variable and its +# expected behvaior with regards to the contents of the DEPLOY_DIR_IMAGE. +# +# The use of these functions assume that the deploy directory is populated with +# any dependent files/etc. Such that the recipe using these functions depends +# on the recipe that provides the files being used/queried. + +def boot_files_split_expand(d): + # IMAGE_BOOT_FILES has extra renaming info in the format ';' + for f in (d.getVar("IMAGE_BOOT_FILES") or "").split(" "): + parts = f.split(";", 1) + sources = [parts[0].strip()] + if "*" in parts[0]: + # has glob part + import glob + deployroot = d.getVar("DEPLOY_DIR_IMAGE") + sources = [] + for i in glob.glob(os.path.join(deployroot, parts[0])): + sources.append(os.path.basename(i)) + + # for all sources, yield an entry + for s in sources: + if len(parts) == 2: + yield s, parts[1].strip() + yield s, s + +def boot_files_bitstream(d): + expectedfiles = [("bitstream", True)] + expectedexts = [(".bit", True), (".bin", False)] + # search for bitstream paths, use the renamed file. First matching is used + for source, target in boot_files_split_expand(d): + # skip boot.bin and u-boot.bin, it is not a bitstream + skip = ["boot.bin", "u-boot.bin"] + if source in skip or target in skip: + continue + + for e, t in expectedfiles: + if source == e or target == e: + return target, t + for e, t in expectedexts: + if source.endswith(e) or target.endswith(e): + return target, t + return "", False + +def boot_files_dtb_filepath(d): + dtbs = (d.getVar("IMAGE_BOOT_FILES") or "").split(" ") + for source, target in boot_files_split_expand(d): + if target.endswith(".dtb"): + return target + return "" + diff --git a/meta-xilinx-core/classes/kernel-simpleimage.bbclass b/meta-xilinx-core/classes/kernel-simpleimage.bbclass new file mode 100644 index 00000000..110ee254 --- /dev/null +++ b/meta-xilinx-core/classes/kernel-simpleimage.bbclass @@ -0,0 +1,35 @@ +python __anonymous () { + kerneltypes = set((d.getVar("KERNEL_IMAGETYPE") or "").split()) + kerneltypes |= set((d.getVar("KERNEL_IMAGETYPES") or "").split()) + if any(t.startswith("simpleImage.") for t in kerneltypes): + # Enable building of simpleImage + bb.build.addtask('do_prep_simpleimage', 'do_compile', 'do_configure', d) + uarch = d.getVar("UBOOT_ARCH") + if uarch == "microblaze": + d.appendVarFlag('do_prep_simpleimage', 'depends', ' virtual/dtb:do_populate_sysroot') +} + +do_prep_simpleimage[dirs] += "${B}" +do_prep_simpleimage () { + install -d ${B}/arch/${ARCH}/boot/dts + for type in ${KERNEL_IMAGETYPES} ; do + if [ -z "${type##*simpleImage*}" ] && [ ${ARCH} = "microblaze" ]; then + ext="${type##*.}" + # Microblaze simpleImage only works with dts file + cp ${RECIPE_SYSROOT}/boot/devicetree/${ext}.dts ${B}/arch/${ARCH}/boot/dts/ + fi + done +} + +do_deploy:append () { + for type in ${KERNEL_IMAGETYPES} ; do + if [ -z "${type##*simpleImage*}" ] && [ ${ARCH} = "microblaze" ]; then + base_name=${type}-${KERNEL_IMAGE_NAME} + install -m 0644 ${KERNEL_OUTPUT_DIR}/${type}.strip $deployDir/${base_name}.strip + install -m 0644 ${KERNEL_OUTPUT_DIR}/${type}.unstrip $deployDir/${base_name}.unstrip + symlink_name=${type}-${KERNEL_IMAGE_LINK_NAME} + ln -sf ${base_name}.strip $deployDir/${symlink_name}.strip + ln -sf ${base_name}.unstrip $deployDir/${symlink_name}.unstrip + fi + done +} diff --git a/meta-xilinx-core/classes/qemuboot-xilinx.bbclass b/meta-xilinx-core/classes/qemuboot-xilinx.bbclass new file mode 100644 index 00000000..48dfa6e2 --- /dev/null +++ b/meta-xilinx-core/classes/qemuboot-xilinx.bbclass @@ -0,0 +1,27 @@ + +# enable the overrides for the context of the conf only +OVERRIDES .= ":qemuboot-xilinx" + +# Default machine targets for Xilinx QEMU (FDT Generic) +# Allow QB_MACHINE to be overridden by a BSP config +QB_MACHINE ?= "${QB_MACHINE_XILINX}" +QB_RNG="" +QB_MACHINE_XILINX:aarch64 = "-machine arm-generic-fdt" +QB_MACHINE_XILINX:arm = "-M arm-generic-fdt-7series" +QB_MACHINE_XILINX:microblaze = "-M microblaze-fdt-plnx" + +# defaults +QB_DEFAULT_KERNEL ?= "none" + +inherit qemuboot + +# rewrite the qemuboot with the custom sysroot bindir +python do_write_qemuboot_conf:append() { + val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'), 'qemu-xilinx-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/') + cf.set('config_bsp', 'STAGING_BINDIR_NATIVE', '%s' % val) + + # write out the updated version from this append + with open(qemuboot, 'w') as f: + cf.write(f) +} + diff --git a/meta-xilinx-core/classes/xilinx-fetch-restricted.bbclass b/meta-xilinx-core/classes/xilinx-fetch-restricted.bbclass new file mode 100644 index 00000000..a778ec7d --- /dev/null +++ b/meta-xilinx-core/classes/xilinx-fetch-restricted.bbclass @@ -0,0 +1,35 @@ +# This class is setup to override the default fetching for the target recipe. +# When fetching it forces PREMIRROR only fetching so that no attempts are made +# to fetch the Xilinx downloads that are restricted to authenticated users only. +# +# The purpose of this class is to allow for automatation with pre-downloaded +# content or content that is available with curated/user defined pre-mirrors +# and or pre-populated downloads/ directories. + +python do_fetch() { + xilinx_restricted_url = "xilinx.com/member/forms/download" + + src_uri = (d.getVar('SRC_URI') or "").split() + if len(src_uri) == 0: + return + + for i in src_uri: + if xilinx_restricted_url in i: + # force the use of premirrors only, do not attempt download from xilinx.com + d.setVar("BB_FETCH_PREMIRRORONLY", "1") + break + + try: + fetcher = bb.fetch2.Fetch(src_uri, d) + fetcher.download() + except bb.fetch2.NetworkAccess as e: + if xilinx_restricted_url in e.url: + # fatal on access to xilinx.com restricted downloads, print the url for manual download + bb.fatal("The following download cannot be fetched automatically. " \ + "Please manually download the file and place it in the 'downloads' directory (or on an available PREMIRROR).\n" \ + " %s" % (e.url.split(";")[0])) + else: + bb.fatal(str(e)) + except bb.fetch2.BBFetchException as e: + bb.fatal(str(e)) +} diff --git a/meta-xilinx-core/classes/xilinx-platform-init.bbclass b/meta-xilinx-core/classes/xilinx-platform-init.bbclass new file mode 100644 index 00000000..99f7863a --- /dev/null +++ b/meta-xilinx-core/classes/xilinx-platform-init.bbclass @@ -0,0 +1,14 @@ +# This class should be included by any recipe that wants to access or provide +# the platform init source files which are used to initialize a Zynq or ZynqMP +# SoC. + +# Define the path to the xilinx platform init code/headers +PLATFORM_INIT_DIR ?= "/usr/src/xilinx-platform-init" + +PLATFORM_INIT_STAGE_DIR = "${STAGING_DIR_HOST}${PLATFORM_INIT_DIR}" + +# Target files use for platform init +PLATFORM_INIT_FILES ?= "" +PLATFORM_INIT_FILES:zynq = "ps7_init_gpl.c ps7_init_gpl.h" +PLATFORM_INIT_FILES:zynqmp = "psu_init_gpl.c psu_init_gpl.h" + diff --git a/meta-xilinx-core/classes/xilinx-testimage.bbclass b/meta-xilinx-core/classes/xilinx-testimage.bbclass new file mode 100644 index 00000000..99519637 --- /dev/null +++ b/meta-xilinx-core/classes/xilinx-testimage.bbclass @@ -0,0 +1,11 @@ +inherit testimage + +HOSTTOOLS += 'ip ping ps scp ssh stty' + +python do_testimage:prepend () { + from oeqa.core.target.qemu import supported_fstypes + supported_fstypes.append('wic.qemu-sd') +} + +IMAGE_AUTOLOGIN = "0" +IMAGE_FSTYPES = "wic.qemu-sd" diff --git a/meta-xilinx-core/classes/xlnx-standalone.bbclass b/meta-xilinx-core/classes/xlnx-standalone.bbclass new file mode 100644 index 00000000..9232b1ef --- /dev/null +++ b/meta-xilinx-core/classes/xlnx-standalone.bbclass @@ -0,0 +1,16 @@ +# Only enabled when ilp32 is enabled. +def xlnx_ilp32_dict(machdata, d): + machdata["elf"] = { + "aarch64" : (183, 0, 0, True, 32), + "aarch64_be" :(183, 0, 0, False, 32), + } + return machdata + +# Only enabled when microblaze64 is enabled. +def xlnx_mb64_dict(machdata, d): + machdata["elf"] = { + "microblaze": (189, 0, 0, False, 64), + "microblazeeb":(189, 0, 0, False, 64), + "microblazeel":(189, 0, 0, True, 64), + } + return machdata -- cgit v1.2.3-54-g00ecf