Skip to content

Commit

Permalink
[chef] fixes to Zephyr environment variables
Browse files Browse the repository at this point in the history
1. Use Zephyr SDK toolchain.
2. Use proper shell configuration.
  • Loading branch information
Damian-Nordic committed Jun 2, 2023
1 parent eff67ec commit eac4e73
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
3 changes: 3 additions & 0 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ matter_build(chip
)

set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip)
# Enable visibility of POSIX.1-2008 functions, such as strnlen
target_compile_definitions(chip INTERFACE _POSIX_C_SOURCE=200809)
# Make sure that kernel symbols that are only referenced by the Matter libraries are resolved.
target_link_libraries(chip INTERFACE $<TARGET_FILE:kernel>)

if (CONFIG_CHIP_MALLOC_SYS_HEAP_OVERRIDE)
target_link_options(chip INTERFACE
Expand Down
33 changes: 24 additions & 9 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def load_config() -> None:
"for the vendor's SDK")
configStream = open(configFile, 'w')
config["nrfconnect"]["ZEPHYR_BASE"] = os.environ.get('ZEPHYR_BASE')
config["nrfconnect"]["ZEPHYR_SDK_INSTALL_DIR"] = os.environ.get(
'ZEPHYR_SDK_INSTALL_DIR')
config["nrfconnect"]["TTY"] = None
config["esp32"]["IDF_PATH"] = os.environ.get('IDF_PATH')
config["esp32"]["TTY"] = None
Expand Down Expand Up @@ -374,9 +376,6 @@ def main() -> int:
flush_print(
f"{device_name} in CICD config but not {_DEVICE_FOLDER}!")
exit(1)
if options.build_target == "nrfconnect":
shell.run_cmd(
"export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"")
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
command = f"./chef.py -cbr -d {device_name} -t {options.build_target}"
flush_print(f"Building {command}", with_border=True)
Expand Down Expand Up @@ -412,8 +411,6 @@ def main() -> int:
command += " ".join(args)
flush_print(f"Building {command}", with_border=True)
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
shell.run_cmd(
"export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"")
try:
shell.run_cmd(command)
except RuntimeError as build_fail_error:
Expand Down Expand Up @@ -469,11 +466,29 @@ def main() -> int:
elif options.build_target == "nrfconnect":
if config['nrfconnect']['ZEPHYR_BASE'] is None:
flush_print(
'Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file')
'The path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file. This is typically <NCS INSTALL PATH>/ncs/vX.X.X/zephyr')
exit(1)
shell.run_cmd(
f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh')
shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb")
if config['nrfconnect']['ZEPHYR_SDK_INSTALL_DIR'] is None:
flush_print(
'The path for nrfconnect toolchain was not found. Make sure nrfconnect.ZEPHYR_SDK_INSTALL_DIR is set on your config.yaml file. This is typically <NCS INSTALL PATH>/ncs/toolchains/vX.X.X/opt/zephyr-sdk')
exit(1)
zephyr_sdk_dir = config['nrfconnect']['ZEPHYR_SDK_INSTALL_DIR']
shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=zephyr")
shell.run_cmd(f"export ZEPHYR_SDK_INSTALL_DIR={zephyr_sdk_dir}")
shell.run_cmd(f"export ZEPHYR_BASE={config['nrfconnect']['ZEPHYR_BASE']}")
shell.run_cmd(f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh')
# QUIRK:
# When the Zephyr SDK is installed as a part of the NCS toolchain, the build system will use
# build tools from the NCS toolchain, but it will not update the PATH and LD_LIBRARY_PATH
# and hence the build will fail. This ideally, should be handled automatically by the NCS
# build system but until it is fixed, set the variables manually.
ncs_toolchain_dir = os.path.abspath(f"{zephyr_sdk_dir}/../..")
if os.path.exists(os.path.join(ncs_toolchain_dir, 'manifest.json')):
shell.run_cmd(f"export PATH=$PATH:{ncs_toolchain_dir}/usr/bin")
shell.run_cmd(f"export PATH=$PATH:{ncs_toolchain_dir}/usr/local/bin")
shell.run_cmd(f"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{ncs_toolchain_dir}/usr/lib")
shell.run_cmd(
f"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{ncs_toolchain_dir}/usr/local/lib")
elif options.build_target == "linux":
pass
elif options.build_target == "silabs-thread":
Expand Down
5 changes: 2 additions & 3 deletions examples/chef/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_
if(NOT ${CONFIG_DEVICE_PRODUCT_NAME} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\"${CONFIG_DEVICE_PRODUCT_NAME}\"")
endif()
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_PLATFORM_NRFCONNECT=1")
if(NOT ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING}\"")
endif()
Expand Down Expand Up @@ -76,7 +75,7 @@ target_include_directories(app PRIVATE
${NRFCONNECT_COMMON}/app/include
)

if (CONFIG_ENABLE_CHIP_SHELL)
if (CONFIG_CHIP_LIB_SHELL)
target_sources(app PRIVATE
${CHEF}/shell_common/globals.cpp
${CHEF}/shell_common/cmd_misc.cpp
Expand All @@ -86,7 +85,7 @@ if (CONFIG_ENABLE_CHIP_SHELL)
target_include_directories(app PRIVATE
${CHEF}/shell_common/include
)
endif (CONFIG_ENABLE_CHIP_SHELL)
endif()

target_sources(app PRIVATE
${CHEF}/nrfconnect/main.cpp
Expand Down
4 changes: 2 additions & 2 deletions examples/chef/nrfconnect/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main()
ChipLogError(AppServer, "OpenBasicCommissioningWindow() failed");
}

#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL
#if CONFIG_CHIP_LIB_SHELL
int rc = Engine::Root().Init();
if (rc != 0)
{
Expand All @@ -154,7 +154,7 @@ int main()
cmd_app_server_init();
#endif

#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL
#if CONFIG_CHIP_LIB_SHELL
Engine::Root().RunMainLoop();
#endif

Expand Down

0 comments on commit eac4e73

Please sign in to comment.