pdn: Failed to configure CID 0, err, -1 after upgrading the SPI flash memory

Hi,

I would like to carry the full modem update.

Based on nordic website I need at least 4MBytes of flash for doing a full modem update on the nRF9160:

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/nrf9160/http_update/full_modem_update/README.html

Currently i am using the Winbond W25Q64JV 8MBytes flash memory.

www.digikey.com/.../5803999

My Environment

Device: nRF9160
SDK vesion: v1.9.1

prj.conf

CONFIG_TRUSTED_EXECUTION_NONSECURE=y

# General config
CONFIG_REBOOT=y
CONFIG_RING_BUFFER=y

# LOGGNG
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=2048
CONFIG_LOG2_MODE_DEFERRED=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_LOG_DEFAULT_LEVEL=4

# Console
CONFIG_PRINTK=y
CONFIG_UART_CONSOLE=n
CONFIG_SHELL=y
CONFIG_KERNEL_SHELL=y
CONFIG_DEVICE_SHELL=y
CONFIG_POSIX_CLOCK=y
CONFIG_DATE_SHELL=y
CONFIG_SHELL_STACK_SIZE=1024
CONFIG_SHELL_BACKEND_SERIAL=n
CONFIG_SHELL_LOG_BACKEND=y
CONFIG_SHELL_RTT_LOG_LEVEL_DBG=y
CONFIG_SHELL_RTT_INIT_LOG_LEVEL_WRN=y

CONFIG_THREAD_MONITOR=y
CONFIG_INIT_STACKS=y
CONFIG_BOOT_BANNER=n
CONFIG_THREAD_NAME=y

#enable RTT shell
CONFIG_USE_SEGGER_RTT=y
CONFIG_SHELL_BACKEND_RTT=y
CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN=32

# UART
CONFIG_UART_ASYNC_API=y

# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_MODEM_INFO=y

CONFIG_MODEM_KEY_MGMT=y
CONFIG_DOWNLOAD_CLIENT=y


CONFIG_NEWLIB_LIBC=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

CONFIG_LTE_LOCK_BANDS=y
CONFIG_LTE_LOCK_BAND_MASK="0000000001000000000000000001"

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y

# PDN library
CONFIG_PDN=y
CONFIG_PDN_SYS_INIT=y
CONFIG_PDN_DEFAULTS_OVERRIDE=y
CONFIG_PDN_DEFAULT_APN="my apn here"
CONFIG_PDN_DEFAULT_FAM_IPV4=y
CONFIG_PDN_DEFAULT_AUTH_CHAP=y
CONFIG_PDN_DEFAULT_USERNAME="my username"
CONFIG_PDN_DEFAULT_PASSWORD="my password"


# Stacks and heaps
CONFIG_HEAP_MEM_POOL_SIZE=16384

# for debug
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG_THREAD_INFO=y

CONFIG_OPENOCD_SUPPORT=y
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_PRIVILEGED_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096


# Flash
CONFIG_SPI=y
CONFIG_FLASH=y
CONFIG_SPI_NOR=y

# I2C
CONFIG_I2C_NRFX=y
CONFIG_I2C=y

#IMU
CONFIG_SENSOR=y
CONFIG_ICM42605=y
CONFIG_ICM42605_TRIGGER_NONE=y

# json
CONFIG_JSON_LIBRARY=y

CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# for Zmod library
CONFIG_FPU=y
CONFIG_FPU_SHARING=y
CONFIG_FP_HARDABI=y

CONFIG_CPU_LOAD=y
CONFIG_CPU_LOAD_LOG_INTERVAL=2000
CONFIG_CPU_LOAD_LOG_PERIODIC=y

CONFIG_DATE_TIME=y

CONFIG_APP_VERSION="v0.0.4"

CONFIG_WARNING_BUZZER=n

CONFIG_DEVELOP_MODE=n

CONFIG_STAGING_FLG=n

# appication fota update configuration
CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_SOCKET_RETRIES=5

CONFIG_DOWNLOAD_HOST="stg-domain.com"
CONFIG_DOWNLOAD_FILE="https://stg-domain.com/app_update.bin"
CONFIG_DOWNLOAD_HOST_PROD="prd-domain.com"
CONFIG_DOWNLOAD_FILE_PROD="https://prd-domain.com/app_update.bin"


#DFU 
CONFIG_DFU_TARGET=y

# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# Download client
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2048
CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS=n
CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y
CONFIG_DOWNLOAD_CLIENT_LOG_HEADERS=y


#modem delta update configuartion 

CONFIG_MODEM_DELTA_UPDATE_VERSION="mfw_nrf9160_1.3.2"
CONFIG_DOWNLOAD_DELTA_MODEM_FILE="https://stg-domain.com/mfw_nrf9160_update_from_1.3.1_to_1.3.2.bin"
CONFIG_DOWNLOAD_DELTA_MODEM_FILE_PROD="https://prd-domain.com/mfw_nrf9160_update_from_1.3.1_to_1.3.2.bin"


nrf9160_common.dts

/*
 * Copyright (c) 2018-2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	model = "modelname";
	compatible = "modelname";


	/* These aliases are provided for compatibility with samples */
	aliases {
		led-pwm = &pwm0;
		buzzer-pwm = &pwm1;
	};
};

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

/* PWM0 is intended for LED(PWM Serial) control */
&pwm0 {
	status = "okay";
	ch0-pin = <12>;
};

/* PWM1 is intended for buzzer control */
&pwm1 {
	status = "okay";
	ch0-pin = <1>;
	ch1-pin = <0>;
	ch1-inverted;
};


&uart0 {
	current-speed = <9600>;
	compatible = "nordic,nrf-uarte";
	status = "okay";
	tx-pin = <15>;
	rx-pin = <16>;
};


&i2c1 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <4>;
	scl-pin = <3>;
	clock-frequency = <100000>;
};


&spi2 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <8>;
	mosi-pin = <10>;
	miso-pin = <9>;
	miso-pull-up;
	cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
	icm42605@0 {
		compatible = "invensense,icm42605";
		label = "ICM-42605";
		spi-max-frequency = <1000000>;
		accel-hz = <100>;
		gyro-hz = <100>;
		accel-fs = <2>;
		reg = <0>;
		int-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>;
	};
};


&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <27>;
	mosi-pin = <28>;
	miso-pin = <30>;
	cs-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
	w25q64jv: w25q64jv@0 {
		compatible = "jedec,spi-nor";
		label = "w25q64jv";
		size = <0x4000000>; // 32MBit
		spi-max-frequency = <40000000>;
		reg = <0>;
		jedec-id = [ ef 40 17 ]; // 64MBit
		wp-gpios = <&gpio0 29 0>;
		hold-gpios = <&gpio0 26 0>;
	};
};

&timer0 {
	status = "okay";
};

&timer1 {
	status = "okay";
};

&timer2 {
	status = "okay";
};

&flash0 {

	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
		};
		slot0_ns_partition: partition@50000 {
			label = "image-0-nonsecure";
		};
		slot1_partition: partition@80000 {
			label = "image-1";
		};
		slot1_ns_partition: partition@c0000 {
			label = "image-1-nonsecure";
		};
		scratch_partition: partition@f0000 {
			label = "image-scratch";
			reg = <0x000f0000 0xa000>;
		};
		storage_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00006000>;
		};
	};
};

/ {

	reserved-memory {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		sram0_s: image_s@20000000 {
			/* Secure image memory */
		};

		sram0_modem: image_modem@20016000 {
			/* Modem (shared) memory */
		};

		sram0_ns: image_ns@20020000 {
			/* Non-Secure image memory */
		};
	};
};

/* Include partition configuration file */
#include "nrf9160_partition_conf.dts"


nrf1960_partition_conf.dts

&slot0_partition {
	reg = <0x00010000 0x40000>;
};

&slot0_ns_partition {
	reg = <0x00050000 0x30000>;
};

&slot1_partition {
	reg = <0x00080000 0x40000>;
};

&slot1_ns_partition {
	reg = <0x000c0000 0x30000>;
};

&sram0_s {
	reg = <0x20000000 DT_SIZE_K(88)>;
};

&sram0_modem {
	reg = <0x20016000 DT_SIZE_K(40)>;
};

&sram0_ns {
	reg = <0x20020000 DT_SIZE_K(128)>;
};


device_get_binding for w25q64jv flash memory

flash_dev = DEVICE_DT_GET(DT_NODELABEL(w25q64jv));


the above device binding information got from this ticket link

SPI flash driver w25q64jv was found successfully.

I am getting below error

RTT Error log

rtt:~$ Found SPI flash driver w25q64jv 
[00:02:30.951,354] <err> pdn: Failed to configure CID 0, err, -1
[00:02:30.951,385] <err> pdn: Failed to configure default CID, err -1


NOTE:

PDN error won't occur in other device with w25q32jv 4Mbytes flash memory.

It is occurring only in device with w25q64jv 8Mbytes flash memory.

am i missing anything in spi3 configuration of device tree? 

Please guide to overcome this problem.



Best Regards



Praveen Deshmane

Parents
  • Hi,

     

    The error returned (-1) from pdn_init() indicates that the modem lib is not yet initialized.

    I would recommend that you initalize the pdn connection in your application by setting :

    CONFIG_PDN_SYS_INIT=n

    And initialize PDN prior to executing AT+CFUN=1 (ie. before lte_lc_init()), similar to what is done in the lwm2m sample:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/samples/nrf9160/lwm2m_client/src/main.c#L407-L413

     

    Could you try this and see if this works better?

     

    Kind regards,

    Håkon

  • Hi Hakon,

    Thank you for your reply and time.

    As you recommended, I set pdn connection in prj.conf

    CONFIG_PDN_SYS_INIT=n


    lte.c

    #if !defined(CONFIG_NRF_MODEM_LIB_SYS_INIT)
    	ret = nrf_modem_lib_init(NORMAL_MODE);
    	LOG_DBG("inside normal mode\n");
    #else
    	/* If nrf_modem_lib is initialized on post-kernel we should
    	* fetch the returned error code instead of nrf_modem_lib_init
    	*/
    	ret = nrf_modem_lib_get_init_ret();
    	LOG_DBG("nrf_modem_lib_get_init_ret\n");
    #endif
    	switch (ret) {
    	case MODEM_DFU_RESULT_OK:
    		LOG_DBG("Modem firmware update successful!\n");
    		LOG_DBG("Modem will run the new firmware after reboot\n");
    		sys_reboot(0);
    		break;
    	case MODEM_DFU_RESULT_UUID_ERROR:
    	case MODEM_DFU_RESULT_AUTH_ERROR:
    		LOG_DBG("Modem firmware update failed\n");
    		LOG_DBG("Modem will run non-updated firmware on reboot.\n");
    		sys_reboot(0);
    		break;
    	case MODEM_DFU_RESULT_HARDWARE_ERROR:
    	case MODEM_DFU_RESULT_INTERNAL_ERROR:
    		LOG_DBG("Modem firmware update failed\n");
    		LOG_DBG("Fatal error.\n");
    		break;
    	case -1:
    		LOG_DBG("Could not initialize momdem library.\n");
    		LOG_DBG("Fatal error.\n");
    	default:
    		break;
    	}
    #if defined (SDK_UPDATE_1_9_1)
    #else	// #if defined (SDK_UPDATE_1_9_1)
    	/* Initialize AT comms in order to provision the certificate */
    	ret = at_comms_init();
    	if (ret) {
    		LOG_ERROR("Faild to at_comms_init(): %d", ret);
    		return ret;
    	}
    #endif	// #if defined (SDK_UPDATE_1_9_1)
    
    	LOG_DEBUG("%s", "write certificates");
    	/* Provision certificates before connecting to the LTE network */
    
    	ret = carrier_certs_provision();
    	if (ret) {
    		LOG_ERROR("%s", "write certificates error");
    		return ret;
    	}
    
    	LOG_DEBUG("%s", "PDN connection start");
    
    	if(gl_cid != 0)
    	{
    		int ret2 = pdn_ctx_destroy(gl_cid);
    		LOG_INFO("pdn_ctx_destroy() ret2=%d", ret2);
    		gl_cid = 0;
    	}
    
    	/* Register to the necessary packet domain AT notifications */
    #if defined (SDK_UPDATE_1_9_1)
    	ret = nrf_modem_at_printf("AT+CNEC=16");
    #else	// #if defined (SDK_UPDATE_1_9_1)
    	ret = at_cmd_write("AT+CNEC=16", NULL, 0, NULL);
    #endif	// #if defined (SDK_UPDATE_1_9_1)
    	if (ret)
    	{
    		LOG_ERROR("AT+CNEC=16 failed, err %d", ret);
    		return ret;
    	}
    
    #if defined (SDK_UPDATE_1_9_1)
    	ret = nrf_modem_at_printf("AT+CGEREP=1");
    #else	// #if defined (SDK_UPDATE_1_9_1)
    	ret = at_cmd_write("AT+CGEREP=1", NULL, 0, NULL);
    #endif	// #if defined (SDK_UPDATE_1_9_1)
    	if (ret)
    	{
    		LOG_ERROR("AT+CGEREP=1 failed, err %d", ret);
    		return ret;
    	}
    
    	ret = pdn_init();
    	if (ret)
    	{
    		LOG_ERROR("pdn_init, err %d", ret);
    		return ret;
    	}
    
    	ret = pdn_default_apn_get(apn, sizeof(apn));
    	if (ret)
    	{
    		LOG_ERROR("pdn_default_apn_get() failed, err %d", ret);
    		return ret;
    	}
    
    	LOG_INFO("APN is %s", apn);
    
    	/* Setup a callback for the default PDP context (zero).
    	 * Do this before switching to function mode 1 (CFUN=1)
    	 * to receive the first activation event.
    	 */
    	ret = pdn_default_callback_set(pdn_event_handler);
    	if (ret)
    	{
    		LOG_ERROR("pdn_default_callback_set() failed, err %d", ret);
    		return ret;
    	}
    
    	LOG_DEBUG("pdn_default_callback_set() passed, ret %d", ret);
    
    	ret = lte_lc_init_and_connect();
    	if (ret && ret != -EALREADY)
    	{
    		LOG_ERROR("lte_lc_init_and_connect() failed, err %d", ret);
    		return ret;
    	}
    
    	/* Create a PDP context and assign an event handler to receive events */
    	ret = pdn_ctx_create(&gl_cid, pdn_event_handler);
    	if (ret)
    	{
    		LOG_ERROR("pdn_ctx_create() failed, err %d", ret);
    		return ret;
    	}
    	/* Configure a PDP context with APN and Family */
    	ret = pdn_ctx_configure(gl_cid, apn, PDN_FAM_IPV4, NULL);
    	if (ret)
    	{
    		LOG_ERROR("pdn_ctx_configure() failed, err %d", ret);
    		return ret;
    	}
    	/* Configure a PDP context with AUTH */
    	ret = pdn_ctx_auth_set(gl_cid, PDN_AUTH_CHAP, "mobile@iij", "iij");
    	if (ret)
    	{
    		LOG_ERROR("pdn_ctx_configure() failed, err %d", ret);
    		return ret;
    	}
    
    	/* Activate a PDN connection */
    #if defined (SDK_UPDATE_1_9_1)
    	ret = pdn_activate(gl_cid, &esm, &fam);
    #else	// #if defined (SDK_UPDATE_1_9_1)
    	ret = pdn_activate(gl_cid, &esm);
    #endif	// #if defined (SDK_UPDATE_1_9_1)
    	if (ret)
    	{
    		LOG_ERROR("pdn_activate() failed, err %d esm %d %s",
    				ret, esm, esm_strerr(esm));
    		return ret;
    	}


    I am getting below warning now

    modem_key_mgmt: Failed to retrieve CMEE status, err -77


    Please tell me what is wrong.

    Best Regards

    Praveen Deshmane


  • Hi,

     

    The pdn_ctx_destroy is potentially called before pdn_init. is this intentional?

    Could you share a larger log to see where you get this warning returned?

    Does everything else work as intended?

     

    Kind regards,

    Håkon

  • Hello Hakon,

    Thank you for your reply and also sorry for replying late.

    As you asked here it is the larger log

    rtt:~$ Found SPI flash driver w25q64jv 
    [00:00:00.288,024] <wrn> date_time: Valid time not currently available
    [00:00:00.294,281] <wrn> modem_key_mgmt: Failed to retrieve CMEE status, err -77
    [00:00:00.295,471] <err> LTE: write certificates error
    [00:00:00.295,562] <wrn> date_time: Valid time not currently available
    [00:00:00.295,593] <wrn> LTE_TH: lte_init error ret=-1
    [00:00:00.295,684] <wrn> date_time: Valid time not currently available
    [00:00:00.302,520] <wrn> LOGGER_TH: erase! boot_info initial
    [00:00:00.302,612] <wrn> date_time: Valid time not currently available


    carrier_certs.c

    #include <stdint.h>
    #include <string.h>
    #include <toolchain.h>
    #include <sys/util.h>
    #include <modem/modem_key_mgmt.h>
    #include <logging/log.h>
    
    #include "carrier_certs.h"
    
    #if (CONFIG_DEVELOP_MODE == 1)
    LOG_MODULE_REGISTER(carrier_certs, CONFIG_LOG_MAX_LEVEL);
    #else	//#if (CONFIG_DEVELOP_MODE == 1)
    LOG_MODULE_REGISTER(carrier_certs, CONFIG_LOG_OVERRIDE_LEVEL);
    #endif	//#if (CONFIG_DEVELOP_MODE == 1)
    
    #define TLS_MC_API_SEC_TAG	42
    #if 0
    #define TLS_FOTA_SEC_TAG	43
    #endif //end if 0
    
    /* The order of the tags in this array specifies which tag is used first */
    #if 0
    static int tags[] = { TLS_MC_API_SEC_TAG, TLS_FOTA_SEC_TAG };
    #endif //end if 0
    
    static int tags[] = { TLS_MC_API_SEC_TAG };
    
    
    static const char ca42[] = {
    	#include "./certs/mc_api.cer"
    };
    #if 0
    static const char ca43[] = {
    	/* FOTA server certificate */
    	#include "./certs/fota.cer"
    };
    #endif //end if 0
    
    BUILD_ASSERT(sizeof(ca42) < KB(4), "Cert is too large");
    #if 0
    BUILD_ASSERT(sizeof(ca43) < KB(4), "Cert is too large");
    #endif //end if 0
    
    static const struct {
    	uint16_t tag;
    	const char *data;
    } certs[] = {
    	{
    		.tag = TLS_MC_API_SEC_TAG,
    		.data = ca42,
    	},
    	#if 0
    	{
    		.tag = TLS_FOTA_SEC_TAG,
    		.data = ca43,
    	}
    	#endif //end if 0
    };
    
    int carrier_certs_provision()
    {
    	int err;
    	bool mismatch = 0;
    	bool provisioned;
    
    	for (int i = 0; i < ARRAY_SIZE(certs); i++) {
    		err = modem_key_mgmt_exists(
    			certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN, &provisioned);
    		if (err) {
    			goto cert_exit_empty;
    		}
    
    		if (provisioned) {
    			err = modem_key_mgmt_cmp(
    				certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    				certs[i].data, strlen(certs[i].data));
    
    			/* 0 on match, 1 otherwise; like memcmp() */
    			mismatch = err;
    
    			LOG_DBG("Certificate found, tag %d: %s", certs[i].tag,
    				mismatch ? "mismatch" : "match");
    		} else {
    			LOG_DBG("Certificate tag %d not found", certs[i].tag);
    		}
    
    		if (mismatch || !provisioned) {
    			/* overwrite the certificate */
    			err = modem_key_mgmt_write(
    				certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    				certs[i].data, strlen(certs[i].data));
    			if (err) {
    				LOG_ERR("Unable to provision certificate, error: %d", err);
    				goto cert_exit_empty;
    			}
    
    			LOG_DBG("Certificate provisioned, tag %d", certs[i].tag);
    		}
    	}
    
    	return 0;
    
    cert_exit_empty:
    	return -1;
    	
    }

    The pdn_ctx_destroy is potentially called before pdn_init. is this intentional?

    It has written by some other developer. I commented that code, i still getting the problem

    <err> LTE: write certificates error


    we have increased flash memory to 8Mbytes does it affecting? 

    Best Reagrds

    Praveen Deshmane

Reply
  • Hello Hakon,

    Thank you for your reply and also sorry for replying late.

    As you asked here it is the larger log

    rtt:~$ Found SPI flash driver w25q64jv 
    [00:00:00.288,024] <wrn> date_time: Valid time not currently available
    [00:00:00.294,281] <wrn> modem_key_mgmt: Failed to retrieve CMEE status, err -77
    [00:00:00.295,471] <err> LTE: write certificates error
    [00:00:00.295,562] <wrn> date_time: Valid time not currently available
    [00:00:00.295,593] <wrn> LTE_TH: lte_init error ret=-1
    [00:00:00.295,684] <wrn> date_time: Valid time not currently available
    [00:00:00.302,520] <wrn> LOGGER_TH: erase! boot_info initial
    [00:00:00.302,612] <wrn> date_time: Valid time not currently available


    carrier_certs.c

    #include <stdint.h>
    #include <string.h>
    #include <toolchain.h>
    #include <sys/util.h>
    #include <modem/modem_key_mgmt.h>
    #include <logging/log.h>
    
    #include "carrier_certs.h"
    
    #if (CONFIG_DEVELOP_MODE == 1)
    LOG_MODULE_REGISTER(carrier_certs, CONFIG_LOG_MAX_LEVEL);
    #else	//#if (CONFIG_DEVELOP_MODE == 1)
    LOG_MODULE_REGISTER(carrier_certs, CONFIG_LOG_OVERRIDE_LEVEL);
    #endif	//#if (CONFIG_DEVELOP_MODE == 1)
    
    #define TLS_MC_API_SEC_TAG	42
    #if 0
    #define TLS_FOTA_SEC_TAG	43
    #endif //end if 0
    
    /* The order of the tags in this array specifies which tag is used first */
    #if 0
    static int tags[] = { TLS_MC_API_SEC_TAG, TLS_FOTA_SEC_TAG };
    #endif //end if 0
    
    static int tags[] = { TLS_MC_API_SEC_TAG };
    
    
    static const char ca42[] = {
    	#include "./certs/mc_api.cer"
    };
    #if 0
    static const char ca43[] = {
    	/* FOTA server certificate */
    	#include "./certs/fota.cer"
    };
    #endif //end if 0
    
    BUILD_ASSERT(sizeof(ca42) < KB(4), "Cert is too large");
    #if 0
    BUILD_ASSERT(sizeof(ca43) < KB(4), "Cert is too large");
    #endif //end if 0
    
    static const struct {
    	uint16_t tag;
    	const char *data;
    } certs[] = {
    	{
    		.tag = TLS_MC_API_SEC_TAG,
    		.data = ca42,
    	},
    	#if 0
    	{
    		.tag = TLS_FOTA_SEC_TAG,
    		.data = ca43,
    	}
    	#endif //end if 0
    };
    
    int carrier_certs_provision()
    {
    	int err;
    	bool mismatch = 0;
    	bool provisioned;
    
    	for (int i = 0; i < ARRAY_SIZE(certs); i++) {
    		err = modem_key_mgmt_exists(
    			certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN, &provisioned);
    		if (err) {
    			goto cert_exit_empty;
    		}
    
    		if (provisioned) {
    			err = modem_key_mgmt_cmp(
    				certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    				certs[i].data, strlen(certs[i].data));
    
    			/* 0 on match, 1 otherwise; like memcmp() */
    			mismatch = err;
    
    			LOG_DBG("Certificate found, tag %d: %s", certs[i].tag,
    				mismatch ? "mismatch" : "match");
    		} else {
    			LOG_DBG("Certificate tag %d not found", certs[i].tag);
    		}
    
    		if (mismatch || !provisioned) {
    			/* overwrite the certificate */
    			err = modem_key_mgmt_write(
    				certs[i].tag, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    				certs[i].data, strlen(certs[i].data));
    			if (err) {
    				LOG_ERR("Unable to provision certificate, error: %d", err);
    				goto cert_exit_empty;
    			}
    
    			LOG_DBG("Certificate provisioned, tag %d", certs[i].tag);
    		}
    	}
    
    	return 0;
    
    cert_exit_empty:
    	return -1;
    	
    }

    The pdn_ctx_destroy is potentially called before pdn_init. is this intentional?

    It has written by some other developer. I commented that code, i still getting the problem

    <err> LTE: write certificates error


    we have increased flash memory to 8Mbytes does it affecting? 

    Best Reagrds

    Praveen Deshmane

Children
Related