Why does application that builds using nRF Connect SDK v2.0.0 fail to build under SDK v2.1.0

Under Ubuntu 20.04 the udp sample application that we have modified that builds with no problem under nRF Connect SDK v2.0.0 fails to build when when its directory is copied to SDK v2.1.0. 

There appear to be two problem areas.

This uart code builds and runs under v2.0.0 but fails under v2.1.0

	baseuart= device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));

	if (baseuart == NULL) {
		printk("Could not find  %s!\n\r", DT_LABEL(DT_NODELABEL(uart2)));
		return;
	}

Errors as follows:

In file included from /media/sam/ncs21/zephyr/include/zephyr/arch/arm/aarch32/arch.h:20,
                 from /media/sam/ncs21/zephyr/include/zephyr/arch/cpu.h:19,
                 from /media/sam/ncs21/zephyr/include/zephyr/kernel_includes.h:33,
                 from /media/sam/ncs21/zephyr/include/zephyr/kernel.h:17,
                 from /media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c:8:
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c: In function 'main':
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/build/zephyr/include/generated/devicetree_unfixed.h:9216:38: error: 'DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_label' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_reg'?
 9216 | #define DT_N_NODELABEL_uart2         DT_N_S_soc_S_peripheral_40000000_S_uart_a000
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:3068:24: note: in definition of macro 'DT_CAT'
 3068 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:715:27: note: in expansion of macro 'DT_PROP'
  715 | #define DT_LABEL(node_id) DT_PROP(node_id, label)
      |                           ^~~~~~~
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c:918:31: note: in expansion of macro 'DT_LABEL'
  918 |  baseuart= device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));
      |                               ^~~~~~~~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:3068:24: note: in expansion of macro 'DT_N_NODELABEL_uart2'
 3068 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:177:29: note: in expansion of macro 'DT_CAT'
  177 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c:918:40: note: in expansion of macro 'DT_NODELABEL'
  918 |  baseuart= device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));
      |                                        ^~~~~~~~~~~~
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/build/zephyr/include/generated/devicetree_unfixed.h:9216:38: note: each undeclared identifier is reported only once for each function it appears in
 9216 | #define DT_N_NODELABEL_uart2         DT_N_S_soc_S_peripheral_40000000_S_uart_a000
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:3068:24: note: in definition of macro 'DT_CAT'
 3068 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:715:27: note: in expansion of macro 'DT_PROP'
  715 | #define DT_LABEL(node_id) DT_PROP(node_id, label)
      |                           ^~~~~~~
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c:918:31: note: in expansion of macro 'DT_LABEL'
  918 |  baseuart= device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));
      |                               ^~~~~~~~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:3068:24: note: in expansion of macro 'DT_N_NODELABEL_uart2'
 3068 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/media/sam/ncs21/zephyr/include/zephyr/devicetree.h:177:29: note: in expansion of macro 'DT_CAT'
  177 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
/media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/src/main.c:918:40: note: in expansion of macro 'DT_NODELABEL'
  918 |  baseuart= device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));
      |                                        ^~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/build

I think the uart aliases may have changed so that this initialisation needs coding differently but am unclear how to resolve.

There is also an overlay file with the following:

&uart2 {
	status = "okay";
    current-speed = <115200>;
	pinctrl-0 = <&uart2_default>;
	pinctrl-1 = <&uart2_sleep>;
    // rx-pin = <14>;
	// tx-pin = <15>;
};

This doesn't seem to be the only problem moving from v2.0.0 to v2.1.0

If the modem initialisation code is modified so that it compiles (but won't run), there are additional errors:

[113/292] Building C object zephyr/CMakeFiles/zephyr.dir/media/sam/ncs21/nrf/subsys/nonsecure/soc_secure.c.obj
/media/sam/ncs21/nrf/subsys/nonsecure/soc_secure.c: In function 'soc_secure_mem_read':
/media/sam/ncs21/nrf/subsys/nonsecure/soc_secure.c:19:2: warning: 'spm_request_read' is deprecated [-Wdeprecated-declarations]
   19 |  return spm_request_read(dst, (uint32_t)src, len);
      |  ^~~~~~
In file included from /media/sam/ncs21/nrf/subsys/nonsecure/soc_secure.c:10:
/media/sam/ncs21/nrf/include/secure_services.h:88:18: note: declared here
   88 | __deprecated int spm_request_read(void *destination, uint32_t addr, size_t len);
      |                  ^~~~~~~~~~~~~~~~
[146/292] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/net/lib/sockets/sockets_tls.c.obj
/media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'dtls_rx':
/media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:804:11: warning: implicit declaration of function 'mbedtls_ssl_set_client_transport_id'; did you mean 'mbedtls_ssl_conf_transport'? [-Wimplicit-function-declaration]
  804 |     err = mbedtls_ssl_set_client_transport_id(
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |           mbedtls_ssl_conf_transport
/media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'tls_mbedtls_init':
/media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:1236:3: warning: implicit declaration of function 'mbedtls_ssl_conf_handshake_timeout'; did you mean 'mbedtls_ssl_conf_read_timeout'? [-Wimplicit-function-declaration]
 1236 |   mbedtls_ssl_conf_handshake_timeout(&context->config,
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_ssl_conf_read_timeout
/media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:1249:4: warning: implicit declaration of function 'mbedtls_ssl_conf_dtls_cookies'; did you mean 'mbedtls_ssl_conf_sig_hashes'? [-Wimplicit-function-declaration]
 1249 |    mbedtls_ssl_conf_dtls_cookies(&context->config,
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |    mbedtls_ssl_conf_sig_hashes
[210/292] Building C object zephyr/drivers/entropy/CMakeFiles/drivers__entropy.dir/media/sam/ncs21/nrf/drivers/entropy/entropy_cc3xx.c.obj
/media/sam/ncs21/nrf/drivers/entropy/entropy_cc3xx.c: In function 'entropy_cc3xx_rng_get_entropy':
/media/sam/ncs21/nrf/drivers/entropy/entropy_cc3xx.c:65:3: warning: 'spm_request_random_number' is deprecated [-Wdeprecated-declarations]
   65 |   ret = spm_request_random_number(buffer + offset,
      |   ^~~
In file included from /media/sam/ncs21/nrf/drivers/entropy/entropy_cc3xx.c:18:
/media/sam/ncs21/nrf/include/secure_services.h:75:18: note: declared here
   75 | __deprecated int spm_request_random_number(uint8_t *output, size_t len, size_t *olen);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~
[281/292] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/build/zephyr/zephyr_pre0.map 

Again these errors don't appear when building under v2.0.0

This looks like it could be some kind of new configuration option that needs asserting that affects conditional compilation of the functions not found (as they do exist), but have not been able to find anything new in the documentation, even though different version of sdk-mbedtls have been provided as appears in the two west.yaml files:

 v3.0.0-ncs2 in nrf connect v2.0.0 and  v3.1.0-ncs1 in nrf connect v2.1.0 

The applications are being built from VSC after SDK installation via toolchain manager.

Any assistance would be very much appreciated. Cheers Ron.

  • Hi,

    The label property has been removed in v2.1.0 (see this commit), so you cannot use DT_LABEL in this case. It is recommended to use node labels to get devices instead of using the label property, and to use DEVICE_DT_GET instead of device_get_binding. In your case, this would look something like the following:

    baseuart = DEVICE_DT_GET(DT_NODELABEL(uart2));
    
    if (!device_is_ready(baseuart)) {
        /* device exists, but it failed to initialize */
    }

    For more information about these changes, please see the Zephyr release notes: Zephyr release notes 3.2 - Devicetree.

    Best regards,

    Marte

  • Thanks Marte, that's very helpful, partially answering the question.

    Although I had some idea that there were no longer labels, having done a code comparison, for some reason the actual calls were proving elusive.

    The remaining, in some respects more pressing issue is the second set of related errors, with several related functions unable to be found, e.g. mbedtls_ssl_set_client_transport_id, or that were previously being built not now being built.  I've tried temporarily including some of the defines that should result in these functions building but although that removes some of the error messages, it creates or perhaps unmasks additional errors. So it's as though there is a new prj.conf or overlay configuration requirement of the newer version of the library (sdk-mbedtls) that is missing, but I haven't been able to track down any information that indicates what that might be.  Or perhaps this is on completely the wrong track!  In any case further assistance with this problem would be very much appreciated. Cheers Ron. 

  • Hi,

    Can you share the modem initialization code and prj.conf?

    Please use TF-M instead of SPM and see if that improves anything.

    Best regards,

    Marte

  • Hi Marte,

    Modem initialisation is based on the nRF9160 udp sample code, which has been modified to use dtls with psk.  Data is received via uart2 from an application mcu, sent via dtls (over NB-IoT) to a remote gateway, with responses being returned to the application mcu.

    You'll have gathered that I'm new to Zephyr and indeed Nordic. So still trying to find my way.  Modem init and associated code is here:

    #if defined(CONFIG_NRF_MODEM_LIB) // set to y in prj.conf
    
    static int configure_low_power(void)
    {
    	int err;
    
    #if defined(CONFIG_UDP_PSM_ENABLE)
    	/** Power Saving Mode */
    	err = lte_lc_psm_req(true);
    	if (err) {
    		printk("lte_lc_psm_req, error: %d\n", err);
    	}
    #else
    	err = lte_lc_psm_req(false);
    	if (err) {
    		printk("lte_lc_psm_req, error: %d\n", err);
    	}
    #endif
    
    #if defined(CONFIG_UDP_EDRX_ENABLE)
    	/** enhanced Discontinuous Reception */
    	err = lte_lc_edrx_req(true);
    	if (err) {
    		printk("lte_lc_edrx_req, error: %d\n", err);
    	}
    #else
    	err = lte_lc_edrx_req(false);
    	if (err) {
    		printk("lte_lc_edrx_req, error: %d\n", err);
    	}
    #endif
    
    #if defined(CONFIG_UDP_RAI_ENABLE)
    	/** Release Assistance Indication  */
    	err = lte_lc_rai_req(true);
    	if (err) {
    		printk("lte_lc_rai_req, error: %d\n", err);
    	}
    #endif
    
    	return err;
    }
    
    
    static int modem_init(void)
    {
    	int err = 0;
    
    	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
    		/* Do nothing, modem is already configured and LTE connected. */
    	} else {
    		err = lte_lc_init();
    		if (err) {
    			printk("LTE Modem initialization failed, error: %d\n", err);
    			return err;
    		}
    		else {
    			DBG_PRINTF("LTE modem initialised\r\n");
    		}
    	}
    	return err;
    }
    
    static int modem_connect(void)
    {
    	int err = 0;
    
    	DBG_PRINTF("Waiting for network.. ");
    	//## Note that timeout in seconds is set in prj.conf by CONFIG_LTE_NETWORK_TIMEOUT
    	err = lte_lc_init_and_connect();
    
    	if (err) {
    			DBG_PRINTF("Connecting to celluar network failed, error: %d\n",err);
    			return err;
    		}
    		else {
    			DBG_PRINTF(".Cellular modem connected\r\n");
    		}
    	
    	return err;
    }
    #endif
    
    
    static int dtls_init(void) {
    
    int err;
    
    // Check for existing credentials
    bool exists;
    err = modem_key_mgmt_exists(PSK_TAG, MODEM_KEY_MGMT_CRED_TYPE_PSK, &exists);
    if (err == 0) {
    	DBG_PRINTF("Modem PSK Credential %s\r\n", exists ? "psk exists" : "psk doesn't exist");
    }
    else {
    	printk("Modem psk credentials check failed!\r\n");
    }
    
    err = modem_key_mgmt_exists(PSK_TAG, MODEM_KEY_MGMT_CRED_TYPE_IDENTITY, &exists);
    if (err == 0) {
    	DBG_PRINTF("Modem PSK_ID Credential %s\r\n", exists ? "psk id exists" : "psk id doesn't exist");
    }
    else {
    	printk("Modem psk id credentials check failed!\r\n");
    }
    
    err = modem_key_mgmt_cmp(PSK_TAG, MODEM_KEY_MGMT_CRED_TYPE_IDENTITY, psk_id, (size_t) sizeof(psk_id)-1);
    if (err == 0) {
    	DBG_PRINTF("PSK ID matches modem\r\n");
    }
    else if (err == 1) {
    		DBG_PRINTF("PSK ID doesn't match modem\r\n");
    	}
    	else {
    		printk("PSK ID compare match error %d\r\n", err);
    	}
    
    // Write DTLS credentials to the modem store, i.e. psk and psk identity
    // modem_key_mgmt_write(nrf_sec_tag_t sec_tag, enum modem_key_mgmt_cred_type cred_type, const void *buf, size_t len)
    #if defined(CONFIG_NRF_MODEM_LIB) && defined(CONFIG_MODEM_KEY_MGMT) // set to y in prj.conf
    	err = modem_key_mgmt_write(PSK_TAG, MODEM_KEY_MGMT_CRED_TYPE_PSK, psk, (size_t) sizeof(psk));
    	if (err < 0) {
    		printk("Failed to register PSK: %d\r\n", err);
    	}
    	else {
    		DBG_PRINTF("PSK registered: %.*s\r\n", (size_t) sizeof(psk), psk);
    	}
    
    	err = modem_key_mgmt_write(PSK_TAG, MODEM_KEY_MGMT_CRED_TYPE_IDENTITY, psk_id,(size_t) sizeof(psk_id)-1);
    	if (err < 0) {
    		printk("Failed to register PSK ID: %d\r\n", err);
    	}
    	else {
    		DBG_PRINTF("PSK ID registered: %.*s\r\n", (size_t) sizeof(psk_id)-1, psk_id);
    	}
    
    #endif
    
    }
    
    static K_MUTEX_DEFINE(lte_mutex);
    static K_CONDVAR_DEFINE(lte_condvar);
    static volatile int lte_connected_state = 0;
    static k_timeout_t timeout;
    time_t time;
    
    static int lte_connection_wait(k_timeout_t timeout)
    {
       int res = 0;
       k_mutex_lock(&lte_mutex, timeout);
       res = lte_connected_state;
       if (!res) {
          k_condvar_wait(&lte_condvar, &lte_mutex, timeout);
          res = lte_connected_state;
       }
       k_mutex_unlock(&lte_mutex);
       return res;
    }
    
    static int modem_connection_wait(const k_timeout_t timeout)
    {
       int err = 0;
       k_timeout_t time = K_MSEC(0);
       k_timeout_t interval = K_MSEC(1500);
       while (!lte_connection_wait(interval)) {
          time.ticks += interval.ticks;
          if ((time.ticks - timeout.ticks) > 0) {
             err = 1;
             break;
          }
       }
       return err;
    }
    
    
    
    main () {
    .
    .
    .
    
    #if defined(CONFIG_NRF_MODEM_LIB) // set to y in prj.conf
    
    	// Initialize the modem before calling configure_low_power(). This is
    	// because the enabling of RAI is dependent on the
    	// configured network mode which is set during modem initialization.
    	
    	err = modem_init();
    	if (err) goto err_exit;
    
    	err = configure_low_power();
    	if (err) {
    		printk("Unable to set low power configuration, error: %d\n", err);
    		goto err_exit;
    	}
    
    // all set to y in prj.conf
    #if defined(CONFIG_NRF_MODEM_LIB) && defined(CONFIG_MODEM_KEY_MGMT) &&  defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
    	dtls_init( );
    #endif
    	err = modem_connect();
    	if (err) 
    		goto err_exit;
    
    	if (!err) {
          time = k_uptime_get();
          err = modem_connection_wait(timeout);
          time = k_uptime_get() - time;
          if (!err) 
            printk("LTE connected in %ld [ms]", (long)time);
    	}
    
    #endif
    
    ...
    }
    

    As said, the application is working well with nRF Connect 2.0.0, end-to-end communications working as needed (builds from VSC and from the command line using West) but obviously we would prefer not to be 'stuck' using an older version.

    Tried building with TF-M:

    i.e. in prj.conf changed:

    CONFIG_BUILD_WITH_TFM=y
    CONFIG_SPM=n

    but am getting the same errors, including "implcit declarations" of the same functions such as mbedtls_ssl_conf_dtls_cookies

    Reproducing those errors again here:

    [113/267] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/net/lib/sockets/sockets_tls.c.obj
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'tls_session_store':
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:638:8: warning: implicit declaration of function 'mbedtls_ssl_get_session'; did you mean 'mbedtls_ssl_get_version'? [-Wimplicit-function-declaration]
      638 |  ret = mbedtls_ssl_get_session(&context->ssl, &session);
          |        ^~~~~~~~~~~~~~~~~~~~~~~
          |        mbedtls_ssl_get_version
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'tls_session_restore':
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:674:8: warning: implicit declaration of function 'mbedtls_ssl_set_session'; did you mean 'mbedtls_ssl_get_version'? [-Wimplicit-function-declaration]
      674 |  ret = mbedtls_ssl_set_session(&context->ssl, &session);
          |        ^~~~~~~~~~~~~~~~~~~~~~~
          |        mbedtls_ssl_get_version
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'dtls_rx':
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:804:11: warning: implicit declaration of function 'mbedtls_ssl_set_client_transport_id'; did you mean 'mbedtls_ssl_conf_transport'? [-Wimplicit-function-declaration]
      804 |     err = mbedtls_ssl_set_client_transport_id(
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |           mbedtls_ssl_conf_transport
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c: In function 'tls_mbedtls_init':
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:1236:3: warning: implicit declaration of function 'mbedtls_ssl_conf_handshake_timeout'; did you mean 'mbedtls_ssl_conf_read_timeout'? [-Wimplicit-function-declaration]
     1236 |   mbedtls_ssl_conf_handshake_timeout(&context->config,
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |   mbedtls_ssl_conf_read_timeout
    /media/sam/ncs21/zephyr/subsys/net/lib/sockets/sockets_tls.c:1249:4: warning: implicit declaration of function 'mbedtls_ssl_conf_dtls_cookies'; did you mean 'mbedtls_ssl_conf_curves'? [-Wimplicit-function-declaration]
     1249 |    mbedtls_ssl_conf_dtls_cookies(&context->config,
          |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |    mbedtls_ssl_conf_curves
    [255/267] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /media/sam/ncs21/nrf/samples/nrf9160/dtlsnbiot/build/zephyr/zephyr_pre0.map 
    

    Further suggestions very much appreciated.

    Cheers Ron

  • Hi Ron,

    Can you please share your prj.conf as well?

    Best regards,

    Marte

Related