This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to set TOOLCHAIN_HOME in command line, Ubuntu based Zephyr SDK?

Hello Nordic DevZone,

My name is Ted, and I'm having some difficulty with a recently installed Nordic / Zephyr SDK and toolchain.  On 2021-07-24 I downloaded and installed the Zephyr project and Nordics's SDK that's linked from the nRF9160 product overview page.  The specific instructions I used are at Nordic site's page "">developer.nordicsemi.com/.../index.html

My need is work related.  At present I'm tasked to bring up our nRF9160 dev board and begin writing drivers for additional sensors and memory devices not on this board.

I followed instructions for the "Ubuntu" installation steps, as that's my development environment.  I am using the command line, no IDE.

When attempting to build an ARM based blinky demo, the `west` driven build process fails early with the message:

    CMake Error at /home/ted/zephyrproject/zephyr/cmake/compiler/gcc/generic.cmake:8 (message):
      Zephyr was unable to find the toolchain.  Is the environment misconfigured?

I am including full build messages below.

In terms of preparing my workstation and installing dependencies, steps 1 through 4 of "Getting Started" succeed without errors.  In particular for step 4, "Install Toolchain" I am able to download and to run the ".run" file for Zephyr SDK version 0.12.4.  I first installed this SDK in /opt/zephyr-sdk-0.12.4.  Next I attempt to build the ARM based blinky application for the nRF9160 dev board with this command:

    $ west build -b [email protected] ./samples/basic/blinky

To this command the following messages appear:


ted@localhost:~/zephyrproject/zephyr$ west build -b [email protected] ./samples/basic/blinky
-- west build: generating a build system
Including boilerplate (Zephyr base (cached)): /home/ted/zephyrproject/zephyr/cmake/app/boilerplate.cmake
-- Application: /home/ted/zephyrproject/zephyr/samples/basic/blinky
-- Zephyr version: 2.6.99 (/home/ted/zephyrproject/zephyr), build: zephyr-v2.6.0-1460-g17d2e9d084b2
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf9160dk_nrf9160, Revision: 1.0.0 (Active: 0.14.0)
-- Cache files will be written to: /home/ted/.cache/zephyr
-- Using toolchain: zephyr 0.12.4 (/opt/zephyr-sdk-0.12.4)
-- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found toolchain: cross-compile (arm-unknown-linux-gnueabi-)
CMake Error at /home/ted/zephyrproject/zephyr/cmake/compiler/gcc/generic.cmake:8 (message):
  Zephyr was unable to find the toolchain.  Is the environment misconfigured?

  User-configuration:

  ZEPHYR_TOOLCHAIN_VARIANT: cross-compile

  Internal variables:

  CROSS_COMPILE: arm-unknown-linux-gnueabi-

  TOOLCHAIN_HOME:

Call Stack (most recent call first):
  /home/ted/zephyrproject/zephyr/cmake/generic_toolchain.cmake:42 (include)
  /home/ted/zephyrproject/zephyr/cmake/app/boilerplate.cmake:570 (include)
  /home/ted/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
  /home/ted/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/zephyrproject/zephyr/build -S/home/ted/zephyrproject/zephyr/samples/basic/blinky -GNinja

From these messages it looks like there is a variable that's internal to `west` or some other facet of this SDK, namely the variable TOOLCHAIN_HOME.  I confirm also that the cmake file indicated above is the source of the fatal error message:


    ~/zephyrproject/zephyr/cmake/compiler/gcc/generic.cmake


The first few lines of this file are:


  1 # SPDX-License-Identifier: Apache-2.0
  2
  3 set_ifndef(CC gcc)
  4
  5 find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC}   PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
  6
  7 if(CMAKE_C_COMPILER STREQUAL CMAKE_C_COMPILER-NOTFOUND)
  8   message(FATAL_ERROR "Zephyr was unable to find the toolchain. Is the environment misconfigured?
  9 User-configuration:
 10 ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT}
 11 Internal variables:
 12 CROSS_COMPILE: ${CROSS_COMPILE}
 13 TOOLCHAIN_HOME: ${TOOLCHAIN_HOME}
 14 ")
 15 endif()
   .
   .
   .

Line 13 plus the build messages tell me that variable $TOOLCHAIN_HOME is unset.  But I don't find any mention of how to set this variable, either semi-permanently as an environment variable (that's not working) or each time manually when invoking the build process.

The nRF9160 SDK / Zephyr Ubuntu set up instructions state that the Zephyr project tools, or meta-tool, can automatically find a given example project's toolchain when the toolchain is installed in /opt or ~, among a few other conventional places.  I've installed Zephyr's tools in both these locations, per Nordic's "getting started".   Yet the internal variable $TOOLCHAIN_HOME is unset and seems to be the reason that the simplest of demos is failing to start compiling.

I have found only a couple other posts on any forum with this error message, and the solutions in those were not related or did not solve the issue for me on my workstation.

Are there any further debugging steps I can take?  Or command line options I can pass to set $TOOLCHAIN_HOME and allow the nRF9160 Zephyr projects from NordicSemi to build?

Lastly am I correct to say that, in my scenario, $TOOLCHAIN_HOME can and should be set to /opt/zephyr-sdk-0.12.4?

Thank you in advance!

- Ted

Parents
  • Hi Ted,

    As mentions, the environment variables must be set in order to be able to build. If you are using Toolchain Manager to install the SDK, as in Raj's case, these are set automatically when you open the terminal or SES through there. If you install the SDK manually instead, you must set these manually as well.

    The toolchain west is mentioning here is the GNU Arm Embedded Toolchain. When installing the SDK manually, you should download it from here: GNU Arm Embedded Toolchain, and extract the contents of the root folder. We recommend extracting it into a folder such as ~/gnuarmemb on Linux. Please make sure to not have any spaces or special characters in the folder or path, as that might cause errors when building. Following this, you must define the environment variables ZEPHYR_TOOLCHAIN_VARIANT and GNUARMEMB_TOOLCHAIN_PATH. The value of the latter should be the folder you extracted the contents into. You can set this using the following commands in a terminal:

    export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
    export GNUARMEMB_TOOLCHAIN_PATH="~/gnuarmemb"
    source zephyr/zephyr-env.sh

    I see you mention following steps 1 through 4 in the guide in the Zephyr documentation. Did you follow this guide only when installing, or did you follow the guide in our documentation as well? Some of the steps differ, so if you want to use NCS, and not only the Zephyr SDK, i recommend following the guide in our documentation. You can found it at Installing the nRF Connect SDK manually.

    You must also set ZEPHYR_BASE. You can either set this in your system's environment variables, or you can do it by calling the command:

    source zephyr/zephyr-env.sh

    This command must be called from inside the ncs folder, and it must be called every time you open a new terminal window, unless you have set ZEPHYR_BASE in your system's environment variables. Please also see Set up the command-line build environment for more information. ZEPHYR_BASE should be where your zephyr folder is located, for example "~/ncs/zephyr" if you are using NCS. So if you want to set it manually you can do it using the following command in a terminal:

    export ZEPHYR_BASE="~/ncs/zephyr"

    I hope this solves your issue. If not, please let me know!

    Best regards,

    Marte

Reply
  • Hi Ted,

    As mentions, the environment variables must be set in order to be able to build. If you are using Toolchain Manager to install the SDK, as in Raj's case, these are set automatically when you open the terminal or SES through there. If you install the SDK manually instead, you must set these manually as well.

    The toolchain west is mentioning here is the GNU Arm Embedded Toolchain. When installing the SDK manually, you should download it from here: GNU Arm Embedded Toolchain, and extract the contents of the root folder. We recommend extracting it into a folder such as ~/gnuarmemb on Linux. Please make sure to not have any spaces or special characters in the folder or path, as that might cause errors when building. Following this, you must define the environment variables ZEPHYR_TOOLCHAIN_VARIANT and GNUARMEMB_TOOLCHAIN_PATH. The value of the latter should be the folder you extracted the contents into. You can set this using the following commands in a terminal:

    export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
    export GNUARMEMB_TOOLCHAIN_PATH="~/gnuarmemb"
    source zephyr/zephyr-env.sh

    I see you mention following steps 1 through 4 in the guide in the Zephyr documentation. Did you follow this guide only when installing, or did you follow the guide in our documentation as well? Some of the steps differ, so if you want to use NCS, and not only the Zephyr SDK, i recommend following the guide in our documentation. You can found it at Installing the nRF Connect SDK manually.

    You must also set ZEPHYR_BASE. You can either set this in your system's environment variables, or you can do it by calling the command:

    source zephyr/zephyr-env.sh

    This command must be called from inside the ncs folder, and it must be called every time you open a new terminal window, unless you have set ZEPHYR_BASE in your system's environment variables. Please also see Set up the command-line build environment for more information. ZEPHYR_BASE should be where your zephyr folder is located, for example "~/ncs/zephyr" if you are using NCS. So if you want to set it manually you can do it using the following command in a terminal:

    export ZEPHYR_BASE="~/ncs/zephyr"

    I hope this solves your issue. If not, please let me know!

    Best regards,

    Marte

Children
Related