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

  • Thanks for suggestion. I will back with outcome in next week Slight smile

  • Is this a simple thing for people to get working?  On a project which builds properly for me on the command line, adding the command

     -- -DZEPHYR_SCA_VARIANT=sparse

    Causes errors similar to what others have observed.

    D:\SDK\ncs\v2.4.0>west build --board example1_cpuapp --build-dir "d:/Software/Projects/Example1/build" "d:/Software/Projects/Example1" -- -DZEPHYR_SCA_VARIANT=sparse
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: D:/Software/Projects/Example1
    -- CMake version: 3.20.5
    -- Found Python3: D:/SDK/ncs/toolchains/31f4403e35/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: D:/SDK/ncs/v2.4.0/zephyr/.cache
    -- Zephyr version: 3.3.99 (D:/SDK/ncs/v2.4.0/zephyr)
    -- Found west (found suitable version "1.0.0", minimum required is "0.7.1")
    -- Board: example1_cpuapp
    -- Found host-tools: zephyr 0.16.0 (D:/SDK/ncs/toolchains/31f4403e35/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.0 (D:/SDK/ncs/toolchains/31f4403e35/opt/zephyr-sdk)
    -- Found BOARD.dts: D:/Software/Projects/Example1/boards/arm/example1/example1_cpuapp.dts
    -- Found devicetree overlay: example1_cpuapp.overlay
    -- Generated zephyr.dts: D:/Software/Projects/Example1/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: D:/Software/Projects/Example1/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: D:/Software/Projects/Example1/build/zephyr/dts.cmake
    
    warning: Deprecated symbol BT_DEBUG_LOG is enabled.
    
    
    warning: Deprecated symbol BT_DEBUG_LOG is enabled.
    
    
    warning: Experimental symbol BT_ISO_PERIPHERAL is enabled.
    
    
    warning: Experimental symbol BT_ISO_CENTRAL is enabled.
    
    Parsing D:/SDK/ncs/v2.4.0/zephyr/Kconfig
    Loaded configuration 'D:/Software/Projects/Example1/build/zephyr/.config'
    No change to configuration in 'D:/Software/Projects/Example1/build/zephyr/.config'
    No change to Kconfig header in 'D:/Software/Projects/Example1/build/zephyr/include/generated/autoconf.h'
    CMake Error at D:/SDK/ncs/v2.4.0/zephyr/cmake/sca/sparse/sca.cmake:5 (find_program):
      Could not find SPARSE_COMPILER using the following names: cgcc
    Call Stack (most recent call first):
      D:/SDK/ncs/v2.4.0/zephyr/cmake/modules/FindScaTools.cmake:23 (include)
      D:/SDK/ncs/v2.4.0/zephyr/cmake/modules/kernel.cmake:26 (find_package)
      D:/SDK/ncs/v2.4.0/zephyr/cmake/modules/zephyr_default.cmake:124 (include)
      D:/SDK/ncs/v2.4.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      D:/SDK/ncs/v2.4.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
      CMakeLists.txt:8 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    See also "D:/Software/Projects/Example1/build/CMakeFiles/CMakeOutput.log".
    See also "D:/Software/Projects/Example1/build/CMakeFiles/CMakeError.log".
    ?[91mFATAL ERROR: command exited with status 1: 'D:\SDK\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE' '-DWEST_PYTHON=D:\SDK\ncs\toolchains\31f4403e35\opt\bin\python.exe' '-Bd:\Software\Projects\Example1\build' -GNinja -DZEPHYR_SCA_VARIANT=sparse '-Sd:\Software\Projects\Example1'
    ?[0m
    D:\SDK\ncs\v2.4.0>
    

    The issue looks to be

    Could not find SPARSE_COMPILER using the following names: cgcc

    The command project is started using the Toolchain Manager then open command prompt option with the V2.4.0.SDK which is what we are using.  Does an alternative compiler need to be installed other then what the tool chain manger installs?  Does the command to build need to be changed?

    Thank you for any help.

  • The problem is that the toolchain does not include the 'cgcc' executable, which is used by sparse. If you were using Debian or Ubuntu, you could simply install 'cgcc' using the command: $ sudo apt install sparse. However, the executable doesn't seem to be available on Windows. A possible workaround is to make a copy of the /ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe file. Rename this copy to cgcc.exe and place it in the same directory. This workaround produces fewer warnings when I tried it here, though.

    I will ask internally if it would be possible to have sparse support included in our toolchain.

Related