NCS Uses wrong python version when built with bootloader

Across several NRF Connect SDK versions, I have noticed that when built with the bootloader, the child image is built with the wrong environment and does not use the vendored installation. Here are some logs that the show that the bootloader and child image are built with different python versions when built in VS Code. The build fails because it uses a version of python that does not have the zephyr requirements installed when building the application child image.

My expected behavior would be that both images (mcuboot and b0 image) are built with the python installation under /opt/nordic/ncs/toolchains and the build succeeds regardless of the number of the other python installations.


The workaround I use is to either disable the bootloader or to remove python from my path (editing my shell environment and restarting VS Code).

This happens for sure with the NRF Connect for Desktop Toolchain Manager installation for versions v1.9.1 and v2.1.0. 

```

west build --build-dir /Users/jwtrueb/Desktop/workspace/nirs-monitor/build /Users/jwtrueb/Desktop/workspace/nirs-monitor --pristine --board nrf52840dk_nrf52840 -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DBOARD_ROOT:STRING="/Users/jwtrueb/Desktop/workspace/nirs-monitor;/Users/jwtrueb/Desktop/workspace/nirs-monitor/" -DDTC_OVERLAY_FILE:STRING="/Users/jwtrueb/Desktop/workspace/nirs-monitor/boards/nrf52840dk_nrf52840.overlay" -DCONF_FILE:STRING="/Users/jwtrueb/Desktop/workspace/nirs-monitor/prj.conf"

-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /Users/jwtrueb/Desktop/workspace/nirs-monitor
-- Found Python3: /opt/nordic/ncs/toolchains/v2.1.0/bin/python3.9 (found suitable exact version "3.9.6") found components: Interpreter
-- Cache files will be written to: /Users/jwtrueb/Library/Caches/zephyr
-- Zephyr version: 3.1.99 (/opt/nordic/ncs/v2.1.0/zephyr)
-- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
-- Board: nrf52840dk_nrf52840
-- Found host-tools: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
-- Found dtc: /opt/nordic/ncs/toolchains/v2.1.0/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
-- Found toolchain: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
-- Found BOARD.dts: /opt/nordic/ncs/v2.1.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: /Users/jwtrueb/Desktop/workspace/nirs-monitor/boards/nrf52840dk_nrf52840.overlay
-- Generated zephyr.dts: /Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: /Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: /Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/dts.cmake
Parsing /Users/jwtrueb/Desktop/workspace/nirs-monitor/Kconfig
Loaded configuration '/opt/nordic/ncs/v2.1.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
Merged configuration '/Users/jwtrueb/Desktop/workspace/nirs-monitor/prj.conf'
Configuration saved to '/Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/.config'
Kconfig header saved to '/Users/jwtrueb/Desktop/workspace/nirs-monitor/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Found Python3: /opt/nordic/ncs/toolchains/v2.1.0/bin/python3.9 (found version "3.9.6") found components: Interpreter

=== child image mcuboot - begin ===
loading initial cache file /Users/jwtrueb/Desktop/workspace/nirs-monitor/build/mcuboot/child_image_preload.cmake
Loading Zephyr default modules (Zephyr base).
-- Application: /opt/nordic/ncs/v2.1.0/bootloader/mcuboot/boot/zephyr
-- Found Python3: /Users/jwtrueb/miniforge3/bin/python3.10 (found suitable exact version "3.10.6") found components: Interpreter
-- Cache files will be written to: /Users/jwtrueb/Library/Caches/zephyr
-- Zephyr version: 3.1.99 (/opt/nordic/ncs/v2.1.0/zephyr)
-- Board: nrf52840dk_nrf52840
-- Found host-tools: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
-- Found dtc: /opt/nordic/ncs/toolchains/v2.1.0/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
-- Found toolchain: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
-- Found BOARD.dts: /opt/nordic/ncs/v2.1.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: /opt/nordic/ncs/v2.1.0/bootloader/mcuboot/boot/zephyr/dts.overlay
Traceback (most recent call last):
File "/opt/nordic/ncs/v2.1.0/zephyr/scripts/dts/gen_defines.py", line 33, in <module>
from devicetree import edtlib
File "/opt/nordic/ncs/v2.1.0/zephyr/scripts/dts/python-devicetree/src/devicetree/edtlib.py", line 77, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'

```

I have a mac with the required python installation to use tensorflow, which installs via the Apple script that adds this to the end of ~/.zshrc. https://developer.apple.com/metal/tensorflow-plugin/

```

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/jwtrueb/miniforge3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/jwtrueb/miniforge3/etc/profile.d/conda.sh" ]; then
. "/Users/jwtrueb/miniforge3/etc/profile.d/conda.sh"
else
export PATH="/Users/jwtrueb/miniforge3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

```

To enable the bootloader, there is a zephyr sample. The key flags used to enable the bootloader build:

```
# Enable mcumgr.
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n

```

  • Hi  ,

    I have the same problem mentioned above but in my case, the issue is present both in VS and Terminal opened by the Toolchain manager.

    The log is (I have just opened a ticket):

    Building prova_multicore
    west build --build-dir /Users/warcomeb/Projects/x/prova_multicore/build_nonna /Users/warcomeb/Projects/x/prova_multicore --pristine --board nrf5340dk_nrf5340_cpuapp -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DDTC_OVERLAY_FILE:STRING="/Users/warcomeb/Projects/x/prova_multicore/nrf5340dk_nrf5340_cpuapp.overlay" -DCONF_FILE:STRING="/Users/warcomeb/Projects/x/prova_multicore/prj.conf"
    
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /Users/warcomeb/Projects/x/prova_multicore
    -- Found Python3: /opt/nordic/ncs/toolchains/v2.1.0/bin/python3.9 (found suitable exact version "3.9.6") found components: Interpreter 
    -- Cache files will be written to: /Users/warcomeb/Library/Caches/zephyr
    -- Zephyr version: 3.1.99 (/opt/nordic/ncs/v2.1.0/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
    -- Found dtc: /opt/nordic/ncs/toolchains/v2.1.0/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
    -- Found toolchain: zephyr 0.14.1 (/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk)
    -- Found BOARD.dts: /opt/nordic/ncs/v2.1.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: /Users/warcomeb/Projects/x/prova_multicore/nrf5340dk_nrf5340_cpuapp.overlay
    -- Generated zephyr.dts: /Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/dts.cmake
    Parsing /Users/warcomeb/Projects/x/prova_multicore/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.1.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/Users/warcomeb/Projects/x/prova_multicore/prj.conf'
    Configuration saved to '/Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/.config'
    Kconfig header saved to '/Users/warcomeb/Projects/x/prova_multicore/build_nonna/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 10.3.0
    -- The CXX compiler identification is GNU 10.3.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    
    === child image b0 -  begin ===
    loading initial cache file /Users/warcomeb/Projects/x/prova_multicore/build_nonna/b0/child_image_preload.cmake
    Loading Zephyr default modules (Zephyr base).
    -- Application: /opt/nordic/ncs/v2.1.0/nrf/samples/bootloader
    CMake Error at /opt/nordic/ncs/toolchains/v2.1.0/Cellar/cmake/3.20.5/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
      Could NOT find Python3: Found unsuitable version "3.9.7", but required is
      exact version "3.7" (found /usr/local/bin/python3, found components:
      Interpreter)
    Call Stack (most recent call first):
      /opt/nordic/ncs/toolchains/v2.1.0/Cellar/cmake/3.20.5/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:592 (_FPHSA_FAILURE_MESSAGE)
      /opt/nordic/ncs/toolchains/v2.1.0/Cellar/cmake/3.20.5/share/cmake/Modules/FindPython/Support.cmake:3165 (find_package_handle_standard_args)
      /opt/nordic/ncs/toolchains/v2.1.0/Cellar/cmake/3.20.5/share/cmake/Modules/FindPython3.cmake:485 (include)
      /opt/nordic/ncs/v2.1.0/zephyr/cmake/modules/python.cmake:46 (find_package)
      /opt/nordic/ncs/v2.1.0/zephyr/cmake/modules/zephyr_default.cmake:121 (include)
      /opt/nordic/ncs/v2.1.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /opt/nordic/ncs/v2.1.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:9 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    CMake Error at /opt/nordic/ncs/v2.1.0/nrf/cmake/multi_image.cmake:409 (message):
      CMake generation for b0 failed, aborting.  Command: 1
    Call Stack (most recent call first):
      /opt/nordic/ncs/v2.1.0/nrf/cmake/multi_image.cmake:150 (add_child_image_from_source)
      /opt/nordic/ncs/v2.1.0/nrf/samples/CMakeLists.txt:68 (add_child_image)
    
    
    -- Configuring incomplete, errors occurred!
    See also "/Users/warcomeb/Projects/x/prova_multicore/build_nonna/CMakeFiles/CMakeOutput.log".
    See also "/Users/warcomeb/Projects/x/prova_multicore/build_nonna/CMakeFiles/CMakeError.log".
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/v2.1.0/bin/cmake -DWEST_PYTHON=/opt/nordic/ncs/toolchains/v2.1.0/bin/python3 -B/Users/warcomeb/Projects/x/prova_multicore/build_nonna -GNinja -DBOARD=nrf5340dk_nrf5340_cpuapp -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DDTC_OVERLAY_FILE:STRING=/Users/warcomeb/Projects/x/prova_multicore/nrf5340dk_nrf5340_cpuapp.overlay -DCONF_FILE:STRING=/Users/warcomeb/Projects/x/prova_multicore/prj.conf -S/Users/warcomeb/Projects/x/prova_multicore

    Any ideas?

    Best

    Marco

Related