diff options
Diffstat (limited to 'meta-xilinx-standalone-sdt/classes-recipe/esw.bbclass')
| -rw-r--r-- | meta-xilinx-standalone-sdt/classes-recipe/esw.bbclass | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/meta-xilinx-standalone-sdt/classes-recipe/esw.bbclass b/meta-xilinx-standalone-sdt/classes-recipe/esw.bbclass new file mode 100644 index 00000000..7d0a2e5d --- /dev/null +++ b/meta-xilinx-standalone-sdt/classes-recipe/esw.bbclass | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | inherit python3native xlnx-embeddedsw pkgconfig cmake | ||
| 2 | |||
| 3 | # Poky always tries to enable EXPORT_COMPILE_COMMANDS, but ESW changes | ||
| 4 | # behavior when this is enabled and will generate: | ||
| 5 | # -isystem /usr/include | ||
| 6 | # which will cause a build failures. | ||
| 7 | OECMAKE_ARGS:remove = "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON" | ||
| 8 | |||
| 9 | SRCREV_FORMAT = "src_decouple" | ||
| 10 | |||
| 11 | S = "${UNPACKDIR}/git" | ||
| 12 | B = "${UNPACKDIR}/build" | ||
| 13 | OECMAKE_SOURCEPATH = "${S}/${ESW_COMPONENT_SRC}" | ||
| 14 | LICFILENAME = "license.txt" | ||
| 15 | |||
| 16 | SPECFILE_PATH:arm = "${S}/scripts/specs/arm/Xilinx.spec" | ||
| 17 | SPECFILE_PATH:aarch64 = "${S}/scripts/specs/arm/Xilinx.spec" | ||
| 18 | SPECFILE_PATH:microblaze = "${S}/scripts/specs/microblaze/Xilinx.spec" | ||
| 19 | |||
| 20 | ESW_MACHINE ?= "${MACHINE}" | ||
| 21 | |||
| 22 | ESW_CFLAGS += "-specs=${SPECFILE_PATH}" | ||
| 23 | |||
| 24 | inherit ccmake | ||
| 25 | |||
| 26 | COMPATIBLE_HOST = ".*-elf" | ||
| 27 | COMPATIBLE_HOST:arm = "[^-]*-[^-]*-eabi" | ||
| 28 | |||
| 29 | CONFIG_DTFILE ??= "" | ||
| 30 | DTS_FILE = "${DEPLOY_DIR_IMAGE}/devicetree/${@os.path.basename(d.getVar('CONFIG_DTFILE').replace('.dts','.dtb'))}" | ||
| 31 | |||
| 32 | DEPENDS += "python3-pyyaml-native lopper-native device-tree python3-dtc-native" | ||
| 33 | |||
| 34 | # We need the deployed output | ||
| 35 | do_configure[depends] += "device-tree:do_deploy" | ||
| 36 | do_compile[depends] += "device-tree:do_deploy" | ||
| 37 | do_install[depends] += "device-tree:do_deploy" | ||
| 38 | |||
| 39 | def get_xlnx_cmake_machine(fam, variant, d): | ||
| 40 | cmake_machine = fam | ||
| 41 | if (fam == 'zynqmp'): | ||
| 42 | cmake_machine = 'ZynqMP' | ||
| 43 | elif (fam == 'versal'): | ||
| 44 | cmake_machine = 'Versal' | ||
| 45 | if (variant == 'net'): | ||
| 46 | cmake_machine = 'VersalNet' | ||
| 47 | elif (fam == 'zynq'): | ||
| 48 | cmake_machine = 'Zynq' | ||
| 49 | return cmake_machine | ||
| 50 | |||
| 51 | def get_xlnx_cmake_processor(tune, machine, variant, d): | ||
| 52 | cmake_processor = tune | ||
| 53 | if tune.startswith('microblaze'): | ||
| 54 | if (machine == 'psu_pmu_0'): | ||
| 55 | cmake_processor = 'pmu_microblaze' | ||
| 56 | elif (machine in [ 'psv_pmc_0', 'psx_pmc_0' ]): | ||
| 57 | cmake_processor = 'plm_microblaze' | ||
| 58 | else: | ||
| 59 | cmake_processor = 'microblaze' | ||
| 60 | elif (tune in [ 'cortexr5', 'cortexr5hf' ]): | ||
| 61 | cmake_processor = 'cortexr5' | ||
| 62 | elif (tune in [ 'cortexr52', 'cortexr52hf' ]): | ||
| 63 | cmake_processor = 'cortexr52' | ||
| 64 | elif tune.startswith('cortexa9'): | ||
| 65 | cmake_processor = 'cortexa9' | ||
| 66 | elif (tune in [ 'cortexa53', 'cortexa72-cortexa53' ]): | ||
| 67 | cmake_processor = 'cortexa53' | ||
| 68 | elif tune == 'cortexa72': | ||
| 69 | cmake_processor = 'cortexa72' | ||
| 70 | if (variant == 'net'): | ||
| 71 | cmake_processor = 'cortexa78' | ||
| 72 | return cmake_processor | ||
| 73 | |||
| 74 | XLNX_CMAKE_MACHINE = "${@get_xlnx_cmake_machine(d.getVar('SOC_FAMILY'), d.getVar('SOC_VARIANT'), d)}" | ||
| 75 | XLNX_CMAKE_PROCESSOR = "${@get_xlnx_cmake_processor(d.getVar('DEFAULTTUNE'), d.getVar('ESW_MACHINE'), d.getVar('SOC_VARIANT'), d)}" | ||
| 76 | XLNX_CMAKE_SYSTEM_NAME ?= "Generic" | ||
| 77 | XLNX_CMAKE_BSP_VARS ?= "" | ||
| 78 | |||
| 79 | cmake_do_generate_toolchain_file:append() { | ||
| 80 | cat >> ${UNPACKDIR}/toolchain.cmake <<EOF | ||
| 81 | include(CMakeForceCompiler) | ||
| 82 | CMAKE_FORCE_C_COMPILER("${OECMAKE_C_COMPILER}" GNU) | ||
| 83 | CMAKE_FORCE_CXX_COMPILER("${OECMAKE_CXX_COMPILER}" GNU) | ||
| 84 | set( CMAKE_SYSTEM_PROCESSOR "${XLNX_CMAKE_PROCESSOR}" ) | ||
| 85 | set( CMAKE_MACHINE "${XLNX_CMAKE_MACHINE}" ) | ||
| 86 | # Will need this in the future to make cmake understand esw variables | ||
| 87 | # set( CMAKE_SYSTEM_NAME `echo elf | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` ) | ||
| 88 | set( CMAKE_SYSTEM_NAME "${XLNX_CMAKE_SYSTEM_NAME}" ) | ||
| 89 | set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${S}/cmake) | ||
| 90 | set( CMAKE_LIBRARY_PATH ${B}) | ||
| 91 | if ("${XLNX_CMAKE_PROCESSOR}" STREQUAL "plm_microblaze") | ||
| 92 | set( CMAKE_BUILD_TYPE Release) | ||
| 93 | endif() | ||
| 94 | add_definitions( "${XLNX_CMAKE_BSP_VARS} -DSDT" ) | ||
| 95 | EOF | ||
| 96 | } | ||
| 97 | |||
| 98 | do_install() { | ||
| 99 | install -d ${D}${libdir} | ||
| 100 | install -d ${D}${includedir} | ||
| 101 | install -m 0755 ${B}/${ESW_COMPONENT_NAME} ${D}${libdir} | ||
| 102 | install -m 0644 ${B}/include/*.h ${D}${includedir} | ||
| 103 | } | ||
| 104 | |||
| 105 | CFLAGS:append = " ${ESW_CFLAGS}" | ||
| 106 | EXTRA_OECMAKE += "-DYOCTO=ON" | ||
| 107 | |||
| 108 | do_configure:prepend() { | ||
| 109 | ( | ||
| 110 | cd ${S} | ||
| 111 | lopper ${DTS_FILE} -- bmcmake_metadata_xlnx ${ESW_MACHINE} ${S}/lib/bsp/standalone/src/ hwcmake_metadata ${S} | ||
| 112 | install -m 0755 StandaloneExample.cmake ${S}/cmake/Findcommonmeta.cmake | ||
| 113 | ) | ||
| 114 | } | ||
| 115 | |||
| 116 | # We need to find the license file, which vaires depending on the component | ||
| 117 | # recurse a maximum of x times, could be fancier but it gets complicated since | ||
| 118 | # we dont know for certain we are running devtool or just externalsrc | ||
| 119 | python(){ | ||
| 120 | import os.path | ||
| 121 | if bb.data.inherits_class('externalsrc', d) and d.getVar('EXTERNALSRC'): | ||
| 122 | externalsrc = d.getVar('EXTERNALSRC') | ||
| 123 | lic_file = d.getVar('LIC_FILES_CHKSUM', False) | ||
| 124 | licpath=externalsrc | ||
| 125 | for i in range(5): | ||
| 126 | if os.path.isfile(licpath + '/' + d.getVar('LICFILENAME',True)): | ||
| 127 | lic_file = lic_file.replace('${S}',licpath) | ||
| 128 | d.setVar('LIC_FILES_CHKSUM', lic_file) | ||
| 129 | return | ||
| 130 | licpath=os.path.dirname(licpath) | ||
| 131 | bb.error("Couldn't find license file: %s, within directory %s or his parent directories" % (d.getVar('LICFILENAME',True), externalsrc)) | ||
| 132 | } | ||
| 133 | |||
| 134 | do_generate_driver_data[dirs] = "${B}" | ||
| 135 | do_generate_driver_data[depends] += "device-tree:do_deploy" | ||
| 136 | python do_generate_driver_data() { | ||
| 137 | import glob, subprocess, os | ||
| 138 | |||
| 139 | system_dt = glob.glob(d.getVar('DTS_FILE')) | ||
| 140 | src_dir = glob.glob(d.getVar('OECMAKE_SOURCEPATH')) | ||
| 141 | machine = d.getVar('ESW_MACHINE') | ||
| 142 | |||
| 143 | driver_name = d.getVar('REQUIRED_MACHINE_FEATURES') | ||
| 144 | |||
| 145 | if len(system_dt) == 0: | ||
| 146 | bb.error("Couldn't find device tree %s" % d.getVar('DTS_FILE')) | ||
| 147 | |||
| 148 | if len(src_dir) == 0: | ||
| 149 | bb.error("Couldn't find source dir %s" % d.getVar('OECMAKE_SOURCEPATH')) | ||
| 150 | |||
| 151 | os.chdir(d.getVar('B')) | ||
| 152 | command = ["lopper"] + ["-f"] + [system_dt[0]] + ["--"] + ["baremetalconfig_xlnx.py"] + [machine] + [src_dir[0]] | ||
| 153 | subprocess.run(command, check = True) | ||
| 154 | src_file = glob.glob('*_g.c') | ||
| 155 | if os.path.exists(src_file[0]): | ||
| 156 | bb.note("Generated config file for driver %s" % driver_name) | ||
| 157 | command = ["install"] + ["-m"] + ["0755"] + [src_file[0]] + [src_dir[0]] | ||
| 158 | subprocess.run(command, check = True) | ||
| 159 | } | ||
