Build fail using MCUBOOT and SPI on ncs 1.7.1

Hi!

I'm working with the nrf52840 custom board, porting working project (tested on the ncs 1.4.1) to the ncs 1.7.1. As we are using several board variations for the same project, each board has a separate board_name_defconfig file, containing configs for that board, while all common configs are located in the main prj.conf file.

I have a problem building project with MCUBoot, resulting in error: 

[17/211] Performing build step for 'mcuboot_subimage'
[1/8] Linking C executable zephyr\zephyr_prebuilt.elf
FAILED: zephyr/zephyr_prebuilt.elf zephyr/zephyr_prebuilt.map C:/Repos/my_project/build/mcuboot/zephyr/zephyr_prebuilt.map
cmd.exe /C "cd . && C:\Users\Eva\ncs\v1.7.1\toolchain\opt\bin\arm-none-eabi-gcc.exe   zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj -o zephyr\zephyr_prebuilt.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -Wl,-T  zephyr/linker_zephyr_prebuilt.cmd  -Wl,-Map=C:/Repos/my_project/build/mcuboot/zephyr/zephyr_prebuilt.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/spi/libdrivers__spi.a  zephyr/drivers/flash/libdrivers__flash.a  zephyr/drivers/serial/libdrivers__serial.a  modules/nrf/lib/fprotect/lib..__nrf__lib__fprotect.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/mcuboot/boot/bootutil/zephyr/libmcuboot_util.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m+fp/hard"  -LC:/Repos/my_project/build/mcuboot/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  C:/Users/Eva/ncs/v1.7.1/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/hard-float/no-interrupts/libnrf_cc310_platform_0.9.11.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfpu=fpv4-sp-d16  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -no-pie  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  C:/Users/Eva/ncs/v1.7.1/nrfxlib/crypto/nrf_cc310_bl/lib/cortex-m4/hard-float/no-interrupts/libnrf_cc310_bl_0.9.12.a && cmd.exe /C "cd /D C:\Repos\my_project\build\mcuboot\zephyr && "C:\Program Files\CMake\bin\cmake.exe" -E echo ""
c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spi.c.obj): in function `k_sem_give':
C:/Repos/my_project/build/mcuboot/zephyr/include/generated/syscalls/kernel.h:841: undefined reference to `z_impl_k_sem_give'
c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:/Repos/my_project/build/mcuboot/zephyr/include/generated/syscalls/kernel.h:841: undefined reference to `z_impl_k_sem_give'
c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spi.c.obj): in function `k_sem_take':
C:/Repos/my_project/build/mcuboot/zephyr/include/generated/syscalls/kernel.h:826: undefined reference to `z_impl_k_sem_take'
c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spi.c.obj): in function `k_sem_give':
C:/Repos/my_project/build/mcuboot/zephyr/include/generated/syscalls/kernel.h:841: undefined reference to `z_impl_k_sem_give'
c:/users/eva/ncs/v1.7.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spi.c.obj): in function `k_sem_take':
C:/Repos/my_project/build/mcuboot/zephyr/include/generated/syscalls/kernel.h:826: undefined reference to `z_impl_k_sem_take'
collect2.exe: error: ld returned 1 exit status

However, if I remove CONFIG_SPI from board_name_defconfig file and just have it in the prj.conf file the problem disappears.

Why is CONFIG_SPI causing problems when placed in that folder? Am I missing something?

Thank you for your help in advance!

  • Hi,

     

    Looks like it is mcuboot that fails to build on your side.

    the "spi" driver depends on a multithreaded system, and the errors in linking indicate that your mcuboot config does not have "CONFIG_MULTITHREADING=y" set?

     

    Kind regards,

    Håkon

  • Adding CONFIG_MULTITHREADING=y did indeed solve this error, thank you!

    However, now I get a similar error in the lis2dw12 driver, again when using MCUBoot:

    In file included from C:/Users/Eva/ncs/v1.7.1/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:25:
    C:/Users/Eva/ncs/v1.7.1/zephyr/drivers/sensor/lis2dw12/lis2dw12.h:63:32: error: field 'i2c' has incomplete type
       63 |   const struct stmemsc_cfg_i2c i2c;
          |                                ^~~
    In file included from C:/Users/Eva/ncs/v1.7.1/zephyr/include/sys/util_macro.h:34,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/include/sys/util.h:17,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/include/kernel/sched_priq.h:9,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/include/kernel_includes.h:23,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/include/kernel.h:17,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/include/init.h:11,
                     from C:/Users/Eva/ncs/v1.7.1/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:13:
    C:/Users/Eva/ncs/v1.7.1/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:380:25: error: 'stmemsc_i2c_read' undeclared here (not in a function); did you mean 'stmemsc_spi_read'?
      380 |       (stmdev_read_ptr) stmemsc_i2c_read,  \
          |                         ^~~~~~~~~~~~~~~~

    I use the following config options for lis2dw sensor:

    CONFIG_I2C=y
    CONFIG_SENSOR=y
    CONFIG_LIS2DW12=y

    And the sensor is added in the devicetree as:

    &i2c0 {
    	compatible = "nordic,nrf-twi";
        status = "okay";
    	sda-pin = <6>;
    	scl-pin = <7>;
        lis2dw12_accel: lis2dw12-accel@19 {
            compatible = "st,lis2dw12";
            label = "LIS2DW12-ACCEL";
            reg = <0x19>;
        };
    };

    Am I again missing some config?

  • Hi,

     

    Do you need i2c in mcuboot? ie. should mcuboot be able to interface over i2c/spi?

    If not, I would recommend that you n-select the peripherals in mcuboot.

    This can be done by creating the folder, in your application:

    child_image/mcuboot.conf

    And place your override configuration in the above file.

     

    Kind regards,

    Håkon

  • Unselecting spi and i2c configs in mcuboot.conf solves the problem, thank you!

    If I understand correctly, configs in the prj.conf affect only application, while configs in defconfig files are applied to both application and MCUBoot. Due to nature of this project with several board configurations, we have many configs placed in defconfig files. Is it possible to have defconfig file that does not affects MCUBoot?

    Best,

    Eva

  • Hi Eva,

     

    eva_c said:
    Unselecting spi and i2c configs in mcuboot.conf solves the problem, thank you!

    I'm glad to hear!

     

    eva_c said:
    If I understand correctly, configs in the prj.conf affect only application, while configs in defconfig files are applied to both application and MCUBoot. Due to nature of this project with several board configurations, we have many configs placed in defconfig files. Is it possible to have defconfig file that does not affects MCUBoot?

    You can add a conditional on "depends on !MCUBOOT" for the specific sensor, and set this up in your board in a similar fashion as done in the nrf9160dk:

    https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig#L58-L59

     

    Kind regards,

    Håkon

Related