From: Eilís Ní Fhlannagáin <[email protected]> This commit removes the need for calling out ZEPHYR_MODULES via MACHINEOVERRIDES. It uses west list to figure out what ZEPHYR_MODULES are available and attaches them to -DZEPHYR_MODULES. Additional out of tree modules may be added via ZEPHYR_EXTRA_MODULES.
Signed-off-by: Eilís Ní Fhlannagáin <[email protected]> --- .../conf/machine/include/nrf52.inc | 2 - .../machine/include/stm32mp1-cortex-m4.inc | 3 - ...xport-an-OpenEmbedded-machine-config.patch | 201 ++++++++++++++++++ .../meta/generate-zephyr-machines.bb | 48 +++++ meta-zephyr-core/classes/zephyr.bbclass | 42 ++++ meta-zephyr-core/conf/layer.conf | 2 + .../zephyr-kernel/zephyr-kernel-common.inc | 13 +- 7 files changed, 298 insertions(+), 13 deletions(-) create mode 100644 meta-zephyr-bsp/recipes-meta/meta/files/0001-zephyr-Export-an-OpenEmbedded-machine-config.patch create mode 100644 meta-zephyr-bsp/recipes-meta/meta/generate-zephyr-machines.bb diff --git a/meta-zephyr-bsp/conf/machine/include/nrf52.inc b/meta-zephyr-bsp/conf/machine/include/nrf52.inc index d22f8bc..4162d3e 100644 --- a/meta-zephyr-bsp/conf/machine/include/nrf52.inc +++ b/meta-zephyr-bsp/conf/machine/include/nrf52.inc @@ -5,8 +5,6 @@ require conf/machine/include/tune-cortexm4.inc -MACHINEOVERRIDES =. "nordic:" - TUNE_FEATURES = "armv7m cortexm4" # Target type for this machine used by Pyocd diff --git a/meta-zephyr-bsp/conf/machine/include/stm32mp1-cortex-m4.inc b/meta-zephyr-bsp/conf/machine/include/stm32mp1-cortex-m4.inc index b82b02d..0d46620 100644 --- a/meta-zephyr-bsp/conf/machine/include/stm32mp1-cortex-m4.inc +++ b/meta-zephyr-bsp/conf/machine/include/stm32mp1-cortex-m4.inc @@ -5,7 +5,4 @@ require conf/machine/include/tune-cortexm4.inc -# Include OpenAMP for communication with Cortex-A7 core of the SoC -MACHINEOVERRIDES =. "stm32:openamp:" - TUNE_FEATURES = "armv7m cortexm4" diff --git a/meta-zephyr-bsp/recipes-meta/meta/files/0001-zephyr-Export-an-OpenEmbedded-machine-config.patch b/meta-zephyr-bsp/recipes-meta/meta/files/0001-zephyr-Export-an-OpenEmbedded-machine-config.patch new file mode 100644 index 0000000..207237e --- /dev/null +++ b/meta-zephyr-bsp/recipes-meta/meta/files/0001-zephyr-Export-an-OpenEmbedded-machine-config.patch @@ -0,0 +1,201 @@ +From 412f998467633ab9e8ff0c7cb2ceff1c76c0435c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Eil=C3=ADs=20N=C3=AD=20Fhlannag=C3=A1in?= + <[email protected]> +Date: Mon, 18 Oct 2021 13:17:38 +0100 +Subject: [PATCH] zephyr: Export an OpenEmbedded machine config +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This commit abuses cmake to attempt to figure out the OE tune file +required and automatically generates an OpenEmbedded machine definition. + +We're basically abusing the same mechanism zephyr uses to export +Makefile build information. When using this, you will need to point +to a layer with a conf/machine in it (most likely oe-core). + +For testing purposes, I generate the machine confs like so: + +rm -rf build/*; +for x in `west boards`; +do +west build -d build/$x --cmake-only -b $x samples/hello_world -- \ + -DCONFIG_OEMACHINE_EXPORTS=y \ + -DMETA_OE_BASE:STRING="/home/pidge/poky/meta/"; +done + +Upstream-Status: Pending + +Signed-off-by: Eilís Ní Fhlannagáin <[email protected]> +--- + CMakeLists.txt | 6 + + Kconfig.zephyr | 5 + + cmake/oemachine_exports/CMakeLists.txt | 234 +++++++++++++++++++++++++ + 3 files changed, 245 insertions(+) + create mode 100644 cmake/oemachine_exports/CMakeLists.txt + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 242e30cd2e..b19a908f03 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1647,3 +1647,9 @@ add_subdirectory_ifdef( + CONFIG_MAKEFILE_EXPORTS + cmake/makefile_exports + ) ++ ++# Finally export all build flags from Zephyr ++add_subdirectory_ifdef( ++ CONFIG_OEMACHINE_EXPORTS ++ cmake/oemachine_exports ++ ) +diff --git a/Kconfig.zephyr b/Kconfig.zephyr +index 42d2d163cf..16eacb4382 100644 +--- a/Kconfig.zephyr ++++ b/Kconfig.zephyr +@@ -455,6 +455,11 @@ config MAKEFILE_EXPORTS + Generates a file with build information that can be read by + third party Makefile-based build systems. + ++config OEMACHINE_EXPORTS ++ bool "Generate machine configs to be used by OpenEmbedded and the Yocto Project" ++ help ++ Generates a machine configureation for OpenEmbedded and the Yocto Project. ++ + endmenu + endmenu + +diff --git a/cmake/oemachine_exports/CMakeLists.txt b/cmake/oemachine_exports/CMakeLists.txt +new file mode 100644 +index 0000000000..aaf0ced5e8 +--- /dev/null ++++ b/cmake/oemachine_exports/CMakeLists.txt +@@ -0,0 +1,126 @@ ++# Copyright (c) 2021 Huawei Inc. ++# SPDX-License-Identifier: Apache-2.0 ++ ++string(REPLACE _ - OE_BOARD ${BOARD}) ++if(GCC_M_CPU) ++ string(REPLACE _ - OE_M_CPU ${GCC_M_CPU}) ++endif() ++ ++zephyr_get_compile_options_for_lang_as_string(C C_compile_options) ++ ++if("${ARCH}" STREQUAL "arm") ++ if(CONFIG_CPU_CORTEX_M0) ++ set(OE_TUNE tune-cortexm0) ++ elseif(CONFIG_CPU_CORTEX_M0PLUS) ++ set(OE_TUNE tune-cortexm0plus) ++ elseif(CONFIG_CPU_CORTEX_M1) ++ set(OE_TUNE tune-cortexm1) ++ elseif(CONFIG_CPU_CORTEX_M3) ++ set(OE_TUNE tune-cortexm3) ++ elseif(CONFIG_CPU_CORTEX_M4) ++ set(OE_TUNE tune-cortexm4) ++ elseif(CONFIG_CPU_CORTEX_M7) ++ set(OE_TUNE tune-cortexm7) ++ elseif(CONFIG_CPU_CORTEX_M23) ++ set(OE_TUNE tune-cortexm23) ++ elseif(CONFIG_CPU_CORTEX_M33 OR CONFIG_CPU_CORTEX_M35 OR CONFIG_CPU_CORTEX_M23) ++ set(OE_TUNE tune-cortexm33) ++ if(CONFIG_ARMV8_M_DSP AND NOT CPU_HAS_FPU) ++ set(DEFAULT_TUNE armv8m-maine) ++ elseif(CONFIG_ARMV8_M_DSP AND CPU_HAS_FPU) ++ set(DEFAULT_TUNE armv8m-maine-vfpv5spd16) ++ elseif(NOT CONFIG_ARMV8_M_DSP AND CPU_HAS_FPU) ++ set(DEFAULT_TUNE armv8m-main-fpv5-spd16) ++ elseif(NOT CONFIG_ARMV8_M_DSP AND NOT CPU_HAS_FPU) ++ set(DEFAULT_TUNE armv8m-main) ++ endif() ++ elseif(CONFIG_CPU_CORTEX_M55) ++ set(OE_TUNE tune-cortexm55) ++ elseif(CONFIG_CPU_CORTEX_R4) ++ set(OE_TUNE tune-cortexr4) ++ elseif(CONFIG_CPU_CORTEX_R5) ++ set(OE_TUNE tune-cortexr5) ++ elseif(CONFIG_CPU_CORTEX_R7) ++ set(OE_TUNE tune-cortexr7) ++ else() ++ set(OE_TUNE tune-${OE_M_CPU}) ++ endif() ++elseif("${ARCH}" STREQUAL "arm64") ++ if(CONFIG_CPU_CORTEX_A53) ++ set(OE_TUNE tune-cortexa53) ++ elseif(CONFIG_CPU_CORTEX_A72) ++ set(OE_TUNE tune-cortexa72) ++ elseif(CONFIG_CPU_CORTEX_R82) ++ set(OE_TUNE arch-armv8a) ++ endif() ++elseif("${ARCH}" STREQUAL "arc") ++ set(OE_TUNE tune-arc) ++elseif("${ARCH}" STREQUAL "x86") ++ if(CONFIG_X86_64) ++ set(OE_TUNE tune-core2) ++ set(DEFAULT_TUNE core2-64) ++ else() ++ set(OE_TUNE tune-corei7) ++ set(DEFAULT_TUNE core2-32) ++ endif() ++elseif("${ARCH}" STREQUAL "nios2") ++ set(OE_TUNE tune-nios2) ++else() ++ message(FATAL_ERRORO "We currently do not support outputting build configuration for ${ARCH}" ) ++endif() ++ ++if("${ARCH}" STREQUAL "arm") ++ if (NOT DEFAULT_TUNE) ++ string(REPLACE "tune-" "" DEFAULT_TUNE ${OE_TUNE}) ++ endif() ++endif() ++ ++string (REPLACE ";" "\n" MACHINE_OVERRIDES "${MACHINE_OVERRIDES}") ++ ++execute_process( ++ COMMAND bash "-c" "cd ${META_OE_BASE}; find . -name ${OE_TUNE}.inc" ++ OUTPUT_VARIABLE OE_REQUIRES ++ OUTPUT_STRIP_TRAILING_WHITESPACE) ++ ++if(OE_REQUIRES) ++ string(REPLACE "./" "require " OE_REQUIRES ${OE_REQUIRES}) ++else() ++ set(OE_REQUIRES "# We were unable to find a tuning for this board. # GCC_M_CPU: ${GCC_M_CPU}\n# ARCH: ${ARCH}\n# BOARD: ${BOARD}\n") ++endif() ++ ++if(DEFAULT_TUNE) ++ set(DEFAULT_TUNE_STR "DEFAULTUNE ?= \"${DEFAULT_TUNE}\"") ++endif() ++ ++#get_target_property(INCLUDES zephyr_interface INTERFACE_INCLUDE_DIRECTORIES) ++#string(REPLACE ${ZEPHYR_BASE}/ " -I" INCLUDES ${INCLUDES}) ++ ++set(exports ++"#@TYPE: Machine ++#@NAME: ${OE_BOARD} ++#@DESCRIPTION: Machine configuration for ${OE_BOARD} ${BUILD_VERSION_STR} ++# ++# This file is autogenerated. ++ ++ARCH_${OE_BOARD} = \"${ARCH}\" ++ ++${DEFAULT_TUNE_STR} ++ ++${OE_REQUIRES} ++ ++# MACHINE_OVERRIDES based on default kconfig in zephyr ++${MACHINE_OVERRIDES} ++ ++#ZEPHYR_EXTRA_OECMAKE +=\"${INCLUDES} ${SYSINCLUDES} -D$<JOIN:$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>, -D>\" ++ ++ZEPHYR_BOARD = \"${BOARD}\" ++ ++" ++ ) ++ ++file(GENERATE ++ OUTPUT ${CMAKE_BINARY_DIR}/${OE_BOARD}.conf ++ CONTENT "${exports}" ++) ++ ++ +-- +2.25.1 + diff --git a/meta-zephyr-bsp/recipes-meta/meta/generate-zephyr-machines.bb b/meta-zephyr-bsp/recipes-meta/meta/generate-zephyr-machines.bb new file mode 100644 index 0000000..f3159df --- /dev/null +++ b/meta-zephyr-bsp/recipes-meta/meta/generate-zephyr-machines.bb @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: Huawei Inc. +# SPDX-License-Identifier: Apache-2.0 +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" + +ZEPHYR_INHERIT_CLASSES += "zephyr cmake" + +inherit ${ZEPHYR_INHERIT_CLASSES} + +require recipes-kernel/zephyr-kernel/zephyr-sample.inc + +SRC_URI:append = "file://0001-zephyr-Export-an-OpenEmbedded-machine-config.patch" + +ZEPHYR_SRC_DIR = "${S}/samples/hello_world" + +OECMAKE_SOURCEPATH = "${ZEPHYR_SRC_DIR}" + +OECMAKE_GENERATOR_ARGS += "-c" + +EXTRA_OECMAKE += "\ + -DCONFIG_OEMACHINE_EXPORTS=y \ + -DMETA_OE_BASE:STRING=\"${ZEPHYR_BSP_TOPDIR}\" \ + " + +MACHINE_TUNINGS ?= "${COREBASE}/conf/machines" + +EXTRA_WEST += "-DCONFIG_OEMACHINE_EXPORTS=y -DMETA_OE_BASE:STRING=\"${MACHINE_TUNINGS}\"" + +DEPENDS += "west-native" + +do_compile() { + cd ${S} + for machine in $(west boards); + do + bbnote "Generating $machine" + west build -d ${B}/$machine --cmake-only -b $machine samples/hello_world -- \ + ${EXTRA_WEST}|| bbwarn "$machine machine def failed"; + done +} + +do_deploy () { + cd ${S} + for machine in $(west boards); + do + oe_board_name=$(echo $machine|sed 's/_/-/g') + bbnote "Copying ${machine} to ${DEPLOY_DIR}" + install -D ${B}/$machine/$oe_board_name.conf ${DEPLOYDIR}/$oe_board_name.conf || bbwarn "No $oe_board_name.conf found. Skipping."; + done +} diff --git a/meta-zephyr-core/classes/zephyr.bbclass b/meta-zephyr-core/classes/zephyr.bbclass index e1d3185..f3d16b7 100644 --- a/meta-zephyr-core/classes/zephyr.bbclass +++ b/meta-zephyr-core/classes/zephyr.bbclass @@ -1,4 +1,7 @@ inherit terminal +inherit python3native + +PYTHONPATH="${STAGING_DIR_HOST}${libdir}/${PYTHON_DIR}/site-packages" OE_TERMINAL_EXPORTS += "HOST_EXTRACFLAGS HOSTLDFLAGS TERMINFO CROSS_CURSES_LIB CROSS_CURSES_INC" HOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS}" @@ -21,6 +24,45 @@ python () { d.setVar('BOARD',board) } +do_get_zmods() { + + export PYTHONPATH="${RECIPE_SYSROOT_NATIVE}/${libdir}/${PYTHON_DIR}/site-packages:${RECIPE_SYSROOT_NATIVE}/${libdir}/${PYTHON_DIR}" + cd ${S} + + # I really dislike how tied in this is to west, but without reimplementing their script, this seems to be the + # easiest way to do this + rm -rf .west; mkdir .west + cat << EOF >> ${S}/.west/config +[manifest] +path = . +file = west.yml +EOF + + # Because of how we structure things, we need to either structure this more like a west workspace or just tweak + # the manifest in order to get access to the west extentions like build and whatnot. Tweaking the manifest is the + # easier path here and minimizes the amount of breakage that might occur. + + sed -i 's/path: zephyr/path: ./' west.yml + + # Get all available modules and add them to ZEPHYR_MODULES + for i in $(west list|awk 'NR>1 {print $2}'); do + ZEPHYR_MODULES="${S}/$i\;${ZEPHYR_MODULES}" + done + export ZEPHYR_MODULES +} + +do_get_zmods[nostamp] = "1" +do_get_zmods[dirs] = "${B}" + +EXTRA_OECMAKE:append = " -DZEPHYR_MODULES=${ZEPHYR_MODULES}" + +addtask get_zmods after do_patch before do_configure +do_get_zmods[depends] += "west-native:do_populate_sysroot" +do_get_zmods[depends] += "python3-pyyaml-native:do_populate_sysroot" +do_get_zmods[depends] += "python3-pykwalify-native:do_populate_sysroot" +do_get_zmods[depends] += "python3-colorama-native:do_populate_sysroot" +do_get_zmods[depends] += "python3-pyelftools-native:do_populate_sysroot" + python do_menuconfig() { os.chdir(d.getVar('ZEPHYR_SRC_DIR', True)) configdir = d.getVar('ZEPHYR_SRC_DIR', True) + '/outdir/' + d.getVar('BOARD', True) diff --git a/meta-zephyr-core/conf/layer.conf b/meta-zephyr-core/conf/layer.conf index 4b1bf91..d3ac10e 100644 --- a/meta-zephyr-core/conf/layer.conf +++ b/meta-zephyr-core/conf/layer.conf @@ -18,3 +18,5 @@ LAYERDEPENDS_zephyrcore = "core meta-python" LAYERSERIES_COMPAT_zephyrcore = "dunfell gatesgarth hardknott honister" X86_TUNE_DIR = "${@bb.utils.contains('LAYERSERIES_CORENAMES', 'honister', 'include/x86', 'include', d)}" + +PYTHON3_NATIVE_SITEPACKAGES_DIR = "${libdir_native}/${PYTHON3_DIR}/site-packages" diff --git a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc index 5ae7504..e69ba3c 100644 --- a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc +++ b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc @@ -2,7 +2,6 @@ ZEPHYR_INHERIT_CLASSES += "zephyr cmake" inherit ${ZEPHYR_INHERIT_CLASSES} -inherit python3native # There shouldn't be a manifest for zephyr kernels since there is no root # filesystem. @@ -24,19 +23,17 @@ EXTRA_OECMAKE = "\ -DZEPHYR_SYSROOT=${ZEPHYR_SYSROOT} \ -DZEPHYR_TOOLCHAIN_VARIANT=yocto \ -DEXTRA_CPPFLAGS=${CPPFLAGS} \ + -DZEPHYR_MODULES=${ZEPHYR_MODULES} \ " -ZEPHYR_MODULES = "" -ZEPHYR_MODULES:append:arm = "\;${S}/modules/cmsis" -ZEPHYR_MODULES:append:nordic = "\;${S}/modules/hal/nordic" -ZEPHYR_MODULES:append:stm32 = "\;${S}/modules/hal/stm32" -ZEPHYR_MODULES:append:openamp = "\;${S}/modules/lib/open-amp\;${S}/modules/hal/libmetal" +ZEPHYR_EXTRA_MODULES = "" -EXTRA_OECMAKE:append = " -DZEPHYR_MODULES=${ZEPHYR_MODULES}" +EXTRA_OECMAKE:append = " -DZEPHYR_EXTRA_MODULES=${ZEPHYR_EXTRA_MODULES}" export ZEPHYR_BASE="${S}" -DEPENDS += "gperf-native python3-pyelftools-native python3-pyyaml-native python3-pykwalify-native" +DEPENDS += "gperf-native" + CROSS_COMPILE = "${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}" DEPENDS:append:qemuall = " qemu-native qemu-helper-native" -- 2.25.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#55780): https://lists.yoctoproject.org/g/yocto/message/55780 Mute This Topic: https://lists.yoctoproject.org/mt/88330107/21656 Group Owner: [email protected] Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
