zephyr.bbclass: support for image configuration

New class to support commands such as:

$ MACHINE=xxx bitbake yyy -c menuconfig
$ MACHINE=xxx bitbake yyy -c devshell

Kernel options are typically configured via menuconfig.
The file "prj.conf" must be edited manually, hence the need for devshell.
Once in devshell, user can use their favorite editor to edit the file.

For proper operation, these two variables need to be set in
recipes:

ZEPHYR_SRC_DIR : path to the source, typically place with prj.conf
ZEPHYR_BASE: Zephyr kernel tree location

[YOCTO#10657]

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
This commit is contained in:
Juro Bystricky
2017-01-18 11:09:50 -08:00
parent 159b06b6c5
commit 56fbee01e8
5 changed files with 72 additions and 22 deletions

53
classes/zephyr.bbclass Normal file
View File

@@ -0,0 +1,53 @@
inherit terminal
OE_TERMINAL_EXPORTS += "HOST_EXTRACFLAGS HOSTLDFLAGS TERMINFO CROSS_CURSES_LIB CROSS_CURSES_INC"
HOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS}"
HOSTLDFLAGS = "${BUILD_LDFLAGS}"
CROSS_CURSES_LIB = "-lncurses -ltinfo"
CROSS_CURSES_INC = '-DCURSES_LOC="<curses.h>"'
TERMINFO = "${STAGING_DATADIR_NATIVE}/terminfo"
KCONFIG_CONFIG_COMMAND ??= "menuconfig"
python () {
# Translate MACHINE into Zephyr BOARD
# Zephyr BOARD is basically our MACHINE, except we must use "-" instead of "_"
board = d.getVar('MACHINE',True)
board = board.replace('-', '_')
d.setVar('BOARD',board)
}
python do_menuconfig() {
os.chdir(d.getVar('ZEPHYR_SRC_DIR', True))
configdir = d.getVar('ZEPHYR_SRC_DIR', True) + '/outdir/' + d.getVar('BOARD', True)
try:
mtime = os.path.getmtime(configdir +"/.config")
except OSError:
mtime = 0
oe_terminal("${SHELL} -c \"ZEPHYR_BASE=%s make BOARD=%s %s; if [ \$? -ne 0 ]; then echo 'Command failed.'; \
printf 'Press any key to continue... '; \
read r; fi\"" % (d.getVar('ZEPHYR_BASE', True), d.getVar('BOARD', True),d.getVar('KCONFIG_CONFIG_COMMAND', True)),
d.getVar('PN', True) + ' Configuration', d)
try:
newmtime = os.path.getmtime(configdir +"/.config")
except OSError:
newmtime = 0
if newmtime > mtime:
bb.warn("Configuration changed, recompile will be forced")
bb.build.write_taint('do_compile', d)
}
do_menuconfig[depends] += "ncurses-native:do_populate_sysroot"
do_menuconfig[nostamp] = "1"
do_menuconfig[dirs] = "${B}"
addtask menuconfig after do_configure
python do_devshell_prepend () {
# Most likely we need to manually edit prj.conf...
os.chdir(d.getVar('ZEPHYR_SRC_DIR', True))
}

View File

@@ -6,15 +6,11 @@ inherit deploy
QEMU_BIN_PATH = "${STAGING_BINDIR_NATIVE}"
OE_TERMINAL_EXPORTS += "CROSS_COMPILE"
OE_TERMINAL_EXPORTS += "BOARD"
ZEPHYR_BASE = "${S}"
do_compile () {
cd ${S}
export ZEPHYR_BASE=${S}
export ZEPHYR_GCC_VARIANT="yocto"
${MAKE_COMMAND} -C ${ZEPHYR_IMAGE_SRCDIR} pristine
${MAKE_COMMAND} -C ${ZEPHYR_IMAGE_SRCDIR}
oe_runmake ${ZEPHYR_MAKE_ARGS} -C ${ZEPHYR_IMAGE_SRCDIR}
}
do_deploy () {

View File

@@ -1,15 +1,12 @@
# Common settings for all Zephyr recipes
inherit zephyr
# There shouldn't be a manifest for zephyr kernels since there is no root
# filesystem.
IMAGE_NO_MANIFEST = "1"
# Zephyr BOARD is basically our MACHINE, except we must use "-" instead of "_"
BOARD="$(echo ${MACHINE} | tr - _)"
# oe_runmake isn't used because of the make -e causing issues with some
# make variables.
MAKE_COMMAND = "make -j V=1 BOARD=${BOARD} CROSS_COMPILE=${CROSS_COMPILE}"
ZEPHYR_MAKE_ARGS = " V=1 BOARD=${BOARD} CROSS_COMPILE=${CROSS_COMPILE} ZEPHYR_GCC_VARIANT="yocto" ZEPHYR_BASE=${ZEPHYR_BASE} SYSROOT=${STAGING_DIR_TARGET}"
# We always need a toolchain to cross-compile.
INHIBIT_DEFAULT_DEPS = "1"
@@ -28,3 +25,7 @@ python () {
d.delVar('CXXFLAGS')
d.delVar('LDFLAGS')
}
OE_TERMINAL_EXPORTS += "CROSS_COMPILE"
OE_TERMINAL_EXPORTS += "BOARD"
OE_TERMINAL_EXPORTS += "ZEPHYR_SRC_DIR"
OE_TERMINAL_EXPORTS += "ZEPHYR_BASE"

View File

@@ -2,12 +2,12 @@ require zephyr-kernel.inc
require zephyr-kernel-common.inc
inherit deploy
ZEPHYR_SRC_DIR = "${S}/samples/philosophers"
ZEPHYR_BASE = "${S}"
do_compile () {
cd ${S}
export ZEPHYR_BASE=${S}
export ZEPHYR_GCC_VARIANT="yocto"
${MAKE_COMMAND} -C samples/philosophers pristine
${MAKE_COMMAND} -C samples/philosophers
cd ${ZEPHYR_SRC_DIR}
oe_runmake ${ZEPHYR_MAKE_ARGS}
}
do_deploy () {

View File

@@ -9,14 +9,14 @@ SRCREV="b8d511be4d2b9e05c6adb413a33d6ea510aa0c6a"
SRC_URI = "git://github.com/pfalcon/zephyr_console_helpers.git;protocol=https"
S = "${WORKDIR}/git/zephyr_getchar"
ZEPHYR_SRC_DIR = "${S}"
ZEPHYR_BASE="${STAGING_DIR_TARGET}/usr/src/zephyr"
DEPENDS += " zephyr-kernel-src"
do_compile () {
cd ${S}
export ZEPHYR_GCC_VARIANT="yocto"
export CROSS_COMPILE=${CROSS_COMPILE}
export ZEPHYR_BASE=${STAGING_DIR_TARGET}/usr/src/zephyr
make -j V=1 BOARD=${BOARD}
cd ${ZEPHYR_SRC_DIR}
oe_runmake ${ZEPHYR_MAKE_ARGS}
}
do_deploy () {