Static code analyze tools for NRF Connect SDK

Hello,

I'm doing reasearch in static code analyze tools for my projects. At link below I saw that since version ncs 2.1.0 there is possible to use "Sparse" tool to static code analyze but some configs are required... I can't find what kind of configs...

 nrf Connect 1.6.1 SDK : Static Code Analysis 

 I also saw this:

https://docs.zephyrproject.org/3.1.0/develop/test/sparse.html

I've tried to build some example with "-- -DSPARSE=y".

west build -p always -b nrf52dk_nrf52832 samples/basic/blinky -- -DSPARSE=y

As a result I've got...

es2@es2-hpprobook450g1:~/ncs/zephyr$ west build -p always -b nrf52dk_nrf52832 samples/basic/blinky -- -DSPARSE=y
-- west build: making build dir /home/es2/ncs/zephyr/build pristine
-- west build: generating a build system                                                                                                                                                      
Loading Zephyr default modules (Zephyr base).                                                                                                                                                 
-- Application: /home/es2/ncs/zephyr/samples/basic/blinky
-- Found Python3: /usr/bin/python3.10 (found suitable exact version "3.10.6") found components: Interpreter
-- Cache files will be written to: /home/es2/.cache//zephyr
-- Zephyr version: 3.1.99 (/home/es2/ncs/zephyr)
-- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
-- Board: nrf52dk_nrf52832
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.14.1 (/home/es2/zephyr-sdk-0.14.1)
-- Found dtc: /home/es2/zephyr-sdk-0.14.1/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6")
-- Found toolchain: zephyr 0.14.1 (/home/es2/zephyr-sdk-0.14.1)
-- Found BOARD.dts: /home/es2/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
-- Generated zephyr.dts: /home/es2/ncs/zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /home/es2/ncs/zephyr/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: /home/es2/ncs/zephyr/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: /home/es2/ncs/zephyr/build/zephyr/dts.cmake
Parsing /home/es2/ncs/zephyr/Kconfig
Loaded configuration '/home/es2/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig'
Merged configuration '/home/es2/ncs/zephyr/samples/basic/blinky/prj.conf'
Configuration saved to '/home/es2/ncs/zephyr/build/zephyr/.config'
Kconfig header saved to '/home/es2/ncs/zephyr/build/zephyr/include/generated/autoconf.h'
CMake Error at /home/es2/ncs/zephyr/cmake/compiler/gcc/target.cmake:17 (message):
  C compiler                                                                                                                                                                                  
  /home/es2/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc not                                                                                                                     
  found - Please check your toolchain installation                                                                                                                                            
Call Stack (most recent call first):                                                                                                                                                          
  /home/es2/ncs/zephyr/cmake/modules/target_toolchain.cmake:63 (include)                                                                                                                      
  /home/es2/ncs/zephyr/cmake/modules/zephyr_default.cmake:121 (include)                                                                                                                       
  /home/es2/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)                                                                                                             
  /home/es2/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (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/es2/ncs/zephyr/build -GNinja -DBOARD=nrf52dk_nrf52832 -DSPARSE=y -S/home/es2/ncs/zephyr/samples/basic/blinky

If this is still in progress or something, what kind of tool You recommend for static code analyzing...?

Best regards,

Kamil

  • There is no difference.. There is complete set of commands that I've run on completely clear ubuntu 22.04 image using Podman...

    podman run -dit --name ncs ubuntu
    podman attach ncs
    
    apt-get update
    apt-get install sudo
    adduser ncs
    usermod -aG sudo ncs
    login ncs
    sudo apt install --no-install-recommends git cmake ninja-build gperf ccache dfu-util device-tree-compiler wget python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
    mkdir ${HOME}/gn && cd ${HOME}/gn
    wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
    sudo apt-get install unzip
    unzip gn.zip
    rm gn.zip
    echo 'export PATH=${HOME}/gn:"$PATH"' >> ${HOME}/.bashrc
    cd ~
    source ${HOME}/.bashrc
    pip3 install --user west
    echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
    source ~/.bashrc
    mkdir ncs
    cd ncs/
    west init -m https://github.com/nrfconnect/sdk-nrf --mr v2.2.0
    west update
    west zephyr-export
    pip3 install --user -r zephyr/scripts/requirements.txt
    pip3 install --user -r nrf/scripts/requirements.txt
    pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt
    cd ~
    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.1/zephyr-sdk-0.15.1_linux-x86_64.tar.gz
    wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.1/sha256.sum | shasum --check --ignore-missing
    tar xvf zephyr-sdk-0.15.1_linux-x86_64.tar.gz
    cd zephyr-sdk-0.15.1
    ./setup.sh
    cd ../ncs/
    source zephyr/zephyr-env.sh
    ln -s /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/cgcc
    ls -la /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/cgcc
    export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
    export REAL_CC="/home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc"
    cd zephyr/samples/basic/blinky 
    west build -p always -b nrf52dk_nrf52832  -- -DSPARSE=y
    
    
    

    ncs@7b954ae51633:~/ncs/zephyr/samples/basic/blinky$ ls -la /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/cgcc                                
    lrwxrwxrwx 1 ncs ncs 67 Dec 20 13:59 /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/cgcc -> /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc                                                                                                                              
    ncs@7b954ae51633:~/ncs/zephyr/samples/basic/blinky$

    ncs@7b954ae51633:~/ncs/zephyr/samples/basic/blinky$ echo $REAL_CC
    /home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    ncs@7b954ae51633:~/ncs/zephyr/samples/basic/blinky$

    ncs@7b954ae51633:~/ncs/zephyr/samples/basic/blinky$ west build -p always -b nrf52dk_nrf52832  -- -DSPARSE=y
    -- west build: making build dir /home/ncs/ncs/zephyr/samples/basic/blinky/build pristine
    -- west build: generating a build system                                                                                                       
    Loading Zephyr default modules (Zephyr base).                                                                                                  
    -- Application: /home/ncs/ncs/zephyr/samples/basic/blinky
    -- Found Python3: /usr/bin/python3.10 (found suitable exact version "3.10.6") found components: Interpreter 
    -- Cache files will be written to: /home/ncs/.cache/zephyr
    -- Zephyr version: 3.2.99 (/home/ncs/ncs/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf52dk_nrf52832
    -- Found host-tools: zephyr 0.15.1 (/home/ncs/zephyr-sdk-0.15.1)
    -- Found toolchain: zephyr 0.15.1 (/home/ncs/zephyr-sdk-0.15.1)
    -- Found Dtc: /home/ncs/zephyr-sdk-0.15.1/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
    -- Found BOARD.dts: /home/ncs/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
    -- Generated zephyr.dts: /home/ncs/ncs/zephyr/samples/basic/blinky/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/ncs/ncs/zephyr/samples/basic/blinky/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/ncs/ncs/zephyr/samples/basic/blinky/build/zephyr/dts.cmake
    Parsing /home/ncs/ncs/zephyr/Kconfig
    Loaded configuration '/home/ncs/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig'
    Merged configuration '/home/ncs/ncs/zephyr/samples/basic/blinky/prj.conf'
    Configuration saved to '/home/ncs/ncs/zephyr/samples/basic/blinky/build/zephyr/.config'
    Kconfig header saved to '/home/ncs/ncs/zephyr/samples/basic/blinky/build/zephyr/include/generated/autoconf.h'
    CMake Error at /home/ncs/ncs/zephyr/cmake/compiler/gcc/target.cmake:10 (find_program):
      Could not find CMAKE_C_COMPILER using the following names: cgcc                                                                              
    Call Stack (most recent call first):                                                                                                           
      /home/ncs/ncs/zephyr/cmake/modules/FindTargetTools.cmake:102 (include)                                                                       
      /home/ncs/ncs/zephyr/cmake/modules/kernel.cmake:25 (find_package)                                                                            
      /home/ncs/ncs/zephyr/cmake/modules/zephyr_default.cmake:117 (include)                                                                        
      /home/ncs/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)                                                              
      /home/ncs/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (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/ncs/ncs/zephyr/samples/basic/blinky/build -GNinja -DBOARD=nrf52dk_nrf52832 -DSPARSE=y -S/home/ncs/ncs/zephyr/samples/basic/blinky

  • It looks like we are doing the same, so I'm not sure why we end up with different results. Would you mind testing the same with the NCS toolchain (installed via the app mentioned here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html)? 

    Just remember to open the terminal via the toolchain manager app:

    Vidar Berg said:
    The easiest way to use this toolchain is to open the terminal via the toolchain manager app. This will update your env. variable with the paths defined in /ncs/toolchains/v2.2.0/environment.json
  • My goal is to integrate static code analyse with bitbucket's pipline. I can't imagine how to do that in different than command line way... So even it will work with nRF Connect SDK for desktop, that won't be siutable solution for me... Whole process has to be scripted.

    If it is possible, can You try the same as I did with podman ubuntu image...? It takes 20 minutes... In diffrent way I think we can spend next three monts here... Or maybe should I try some other way of technical support...? Can You give me some other options?

  • As the NCS toolchain worked for me and the others in this thread, I thought it was worth a try. It can be installed via the terminal too (with nRF Util). Anyway, if we take a step back and look at the actual error message, we can see that the build is failing because CMake is unable to locate the "cgcc" executable: 

    CMake Error at /home/ncs/ncs/zephyr/cmake/compiler/gcc/target.cmake:10 (find_program):
    Could not find CMAKE_C_COMPILER using the following names: cgcc
    Call Stack (most recent call first):
    /home/ncs/ncs/zephyr/cmake/modules/FindTargetTools.cmake:102 (include)

    Have you tried to add "/home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/" to your PATH?

    $ export PATH=/home/ncs/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/:"$PATH"

  • Uff... Works!  Vidar Berg (vibe) thanks a lot...

    Next few questions... 

    * Is it possible to set build directory when we build with vs code extension?

    * Is it possible to include SPARSE when we build with vs code extension?

Related