Azure FOTA w/o Partition Manager (NCS v2.9.3)

Hi,

 I would like to know if its possible to run Azure FOTA functionality w/o using Partition Manager (aka `SB_CONFIG_PARTITION_MANAGER=n`) ?

 Trying to build this gets the following errors:

1. 

nrf/subsys/dfu/dfu_target/src/dfu_target_mcuboot.c:20:10: fatal error: pm_config.h: No such file or directory
   20 | #include <pm_config.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

2. 

nrf/subsys/net/lib/fota_download/src/fota_download.c:12:10: fatal error: pm_config.h: No such file or directory
   12 | #include <pm_config.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

Trying to remove the include, creates these other issues:

3. 

nrf/subsys/dfu/dfu_target/src/dfu_target_mcuboot.c:60:41: error: 'PM_MCUBOOT_SECONDARY_SIZE' undeclared here (not in a function); did you mean 'PM_MCUBOOT_SECONDARY_0_SIZE'?
   60 | #define PM_MCUBOOT_SECONDARY_0_SIZE     PM_MCUBOOT_SECONDARY_SIZE
      |                                         

4. 

nrf/subsys/dfu/dfu_target/src/dfu_target_mcuboot.c:61:41: error: 'PM_MCUBOOT_SECONDARY_ADDRESS' undeclared here (not in a function); did you mean 'PM_MCUBOOT_SECONDARY_0_ADDRESS'?
   61 | #define PM_MCUBOOT_SECONDARY_0_ADDRESS  PM_MCUBOOT_SECONDARY_ADDRESS
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Trying to hack these further you get:

ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe:zephyr/linker_zephyr_pre0.cmd:61 cannot move location counter backwards (from 000000000000c300 to 000000000000c200)
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Best regards.

  • Hi,
    Could you please share the full application log, configuration and how the socket related code?

  • Hey Benjamin,

    1. This is the application log:

    *** Booting My Application v3.0.0-dev-4399cc554b34 ***
    *** Using nRF Connect SDK v2.9.3-6961c01f95c2 ***
    *** Using Zephyr OS v3.7.99-aa34a5632971 ***
    Powering on modem
    Bring up network interface
    Waiting for L4 connected
    [00:00:00.008,331] <inf> usb_cdc_acm: Device suspended
    [00:00:00.107,238] <inf> usb_cdc_acm: Device resumed
    [00:00:00.107,269] <inf> usb_cdc_acm: from suspend
    [00:00:00.235,382] <inf> usb_cdc_acm: Device configured
    [00:00:14.996,246] <wrn> usb_device: USB device support already enabled
    [00:00:14.996,307] <inf> app: Bringing network interface up and connecting to the network
    [00:00:14.996,368] <inf> app: Device ID: DEVICE_NO_10
    [00:00:14.996,368] <inf> wdt: WDT init
    [00:00:14.996,459] <inf> app: Connected to network
    [00:00:14.997,009] <err> app: Failed to acquire SNTP, code -11
    
    [00:00:14.997,009] <inf> app: Starting DPS
    [00:00:15.014,801] <inf> app: DPS registration status: AZURE_IOT_HUB_DPS_REG_STATUS_NOT_STARTED
    [00:00:15.014,831] <inf> app: Already assigned to an IoT hub, skipping DPS
    [00:00:15.014,923] <inf> app: Device ID "DEVICE_NO_10" assigned to IoT hub with hostname "REDACTED.azure-devices.net"[0m
    [00:00:15.018,890] <inf> app: Network connectivity established and IP address assigned
    [00:00:15.033,813] <inf> app: settings init and loaded: 0
    [00:00:15.034,515] <dbg> azure_fota: state_set: State transition: STATE_UNINIT --> STATE_INIT
    [00:00:15.034,576] <inf> azure_fota: Current firmware version: 0.0.0-dev
    [00:00:15.034,576] <inf> app: IoT Hub library initialized
    [00:00:15.034,606] <inf> app: AZURE_IOT_HUB_EVT_CONNECTING
    [00:00:17.112,854] <inf> app: Connection request sent to IoT Hub
    [00:00:17.208,129] <inf> app: AZURE_IOT_HUB_EVT_CONNECTED
    [00:00:17.284,515] <inf> app: AZURE_IOT_HUB_EVT_READY
    [00:00:17.475,189] <wrn> azure_fota: No job ID found
    [00:00:17.475,250] <dbg> azure_fota: parse_reported_status: Currently reported 'fwUpdateStatus' in device twin: error
    [00:00:17.475,311] <dbg> azure_fota: parse_reported_status: Currently reported 'currentFwVersion' in device twin: 0.0.0-dev
    [00:00:17.475,341] <dbg> azure_fota: parse_reported_status: No pendingFwVersion object found
    [00:00:17.477,294] <dbg> azure_fota: create_report: Created FOTA report: {"firmware":{"fwUpdateStatus":"current","currentFwVersion":"0.0.0-dev"}}
    [00:00:17.485,687] <dbg> azure_fota: extract_fw_details: Incoming firmware version: v1.0.1
    [00:00:17.485,687] <wrn> azure_fota: No job ID found
    [00:00:17.487,670] <dbg> azure_fota: state_set: State transition: STATE_INIT --> STATE_DOWNLOADING
    [00:00:17.487,792] <inf> azure_fota: Attempting to download firmware (version 'v1.0.1') from https://www.example.com//
    [00:00:17.487,823] <dbg> fota_download: set_host_and_file: URI checksums 577544763,0,0,0
    
    [00:00:17.487,884] <inf> download_client: Downloading:  [0]
    [00:00:17.488,037] <dbg> azure_fota: create_report: Created FOTA report: {"firmware":{"fwUpdateStatus":"downloading","currentFwVersion":"0.0.0-dev"}}
    [00:00:17.490,142] <inf> app: AZURE_IOT_HUB_EVT_FOTA_START
    [00:00:17.490,173] <inf> app: AZURE_IOT_HUB_EVT_TWIN_RECEIVED
    [00:00:17.594,299] <err> download_client: Failed to create socket, errno 12
    [00:00:17.594,329] <err> fota_download: Download client error
    [00:00:17.594,329] <dbg> fota_download: download_client_callback: No DFU target was initialized
    [00:00:17.594,390] <err> azure_fota: FOTA download failed
    [00:00:17.594,421] <dbg> azure_fota: state_set: State transition: STATE_DOWNLOADING --> STATE_INIT
    [00:00:17.594,543] <dbg> azure_fota: create_report: Created FOTA report: {"firmware":{"fwUpdateStatus":"error","currentFwVersion":"0.0.0-dev"}}
    [00:00:17.594,573] <err> azure_iot_hub: AZURE_FOTA_EVT_ERROR
    [00:00:17.596,679] <err> app: AZURE_IOT_HUB_EVT_FOTA_ERROR: FOTA failed
    [00:00:17.907,745] <inf> app: AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 174
    [00:00:17.915,893] <inf> app: AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 174
    [00:00:17.925,354] <inf> app: AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 175

    2. The FOTA overlay config:

    CONFIG_AZURE_FOTA=y
    CONFIG_FOTA_DOWNLOAD=y
    CONFIG_DFU_TARGET=y
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    CONFIG_NRF_CLOUD_SEC_TAG=10
    CONFIG_AZURE_FOTA_SEC_TAG=10
    CONFIG_NET_IPV6=n
    
    CONFIG_MBEDTLS_HEAP_SIZE=34816
    CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=4096
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
    
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2048
    CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE=2048
    CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_2048=y
    
    CONFIG_ZVFS_OPEN_MAX=15
    CONFIG_POSIX_MAX_FDS=15
    CONFIG_TLS_MAX_CREDENTIALS_NUMBER=5
    
    CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
    CONFIG_AZURE_FOTA_LOG_LEVEL_DBG=y
    CONFIG_FOTA_DOWNLOAD_LOG_LEVEL_DBG=y
    CONFIG_AZURE_FOTA_TLS=n

    Not sure about socket related code is what the OS already provides?

    Best regards.

  • Hi Benjamin,

     I've tried to debug this and this is what I found:

    1. while connecting to azure the modem interface is used, which works fine:

    (gdb) bt
    #0  z_impl_zsock_socket (family=1, type=2, proto=17) at C:/ws/fw/project/zephyr/subsys/net/lib/sockets/sockets.c:109
    #1  0x00024a3c in t (type=2, proto=17, family=1)
        at C:/ws/fw/project/app/build/app/zephyr/include/generated/zephyr/syscalls/socket.h:60
    #2  dns_resolve_init_locked (ctx=ctx@entry=0x2000d558 <dns_default_ctx>, servers=servers@entry=0x0,
        servers_sa=servers_sa@entry=0x20024944 <rx_stack+1412>) at C:/ws/fw/project/zephyr/subsys/net/lib/dns/resolve.c:432
    #3  0x0004d258 in dns_resolve_reconfigure (ctx=0x2000d558 <dns_default_ctx>, servers=servers@entry=0x0,
        servers_sa=servers_sa@entry=0x20024944 <rx_stack+1412>) at C:/ws/fw/project/zephyr/subsys/net/lib/dns/resolve.c:1617
    #4  0x0001e578 in ipcp_set_dns_servers (fsm=0x2000d970 <_net_l2_data_ppp_net_dev_ppp_quectel_bg9500+264>)
        at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/ipcp.c:341
    #5  ipcp_config_info_nack (pkt=<optimized out>, length=<optimized out>, rejected=<optimized out>,
        fsm=0x2000d970 <_net_l2_data_ppp_net_dev_ppp_quectel_bg9500+264>) at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/ipcp.c:367
    #6  ipcp_config_info_nack (fsm=0x2000d970 <_net_l2_data_ppp_net_dev_ppp_quectel_bg9500+264>, pkt=<optimized out>, length=<optimized out>,
        rejected=<optimized out>) at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/ipcp.c:349
    #7  0x00049528 in fsm_recv_configure_nack_rej (fsm=fsm@entry=0x2000d970 <_net_l2_data_ppp_net_dev_ppp_quectel_bg9500+264>, code=<optimized out>,
        id=<optimized out>, pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>, length=18) at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/fsm.c:775
    #8  0x0001dd0a in ppp_fsm_input (fsm=0x2000d970 <_net_l2_data_ppp_net_dev_ppp_quectel_bg9500+264>, proto=<optimized out>,
        pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>) at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/fsm.c:1089
    #9  0x0001d6d6 in process_ppp_msg (pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>, iface=0x200064c8 <__net_if_ppp_net_dev_ppp_quectel_bg950_0>)
        at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/ppp_l2.c:103
    #10 ppp_recv (iface=0x200064c8 <__net_if_ppp_net_dev_ppp_quectel_bg950_0>, pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>)
        at C:/ws/fw/project/zephyr/subsys/net/l2/ppp/ppp_l2.c:150
    #11 0x00049d0c in process_data (is_loopback=<optimized out>, pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>)
        at C:/ws/fw/project/zephyr/subsys/net/ip/net_core.c:94
    #12 processing_data (pkt=0x2003143c <_k_mem_slab_buf_rx_pkts+64>, is_loopback=<optimized out>)
        at C:/ws/fw/project/zephyr/subsys/net/ip/net_core.c:158
    #13 0x00049e70 in net_rx (iface=<optimized out>, pkt=<optimized out>) at C:/ws/fw/project/zephyr/subsys/net/ip/net_core.c:451
    #14 0x0004b16e in tc_rx_handler (p1=0x2000d3f0 <rx_classes>, p2=<optimized out>, p3=<optimized out>)
        at C:/ws/fw/project/zephyr/subsys/net/ip/net_tc.c:257
    

    2. while download_client uses different API's to create the connection, which fails:

    (gdb) bt
    #0  z_impl_zsock_socket (family=1, type=1, proto=258) at C:/ws/fw/project/zephyr/subsys/net/lib/sockets/sockets.c:109
    #1  0x0002b6dc in zsock_socket (proto=<optimized out>, type=<optimized out>, family=<optimized out>)
        at C:/ws/fw/project/app/build/app/zephyr/include/generated/zephyr/syscalls/socket.h:60
    #2  socket (proto=<optimized out>, type=<optimized out>, family=<optimized out>) at C:/ws/fw/project/zephyr/include/zephyr/net/socket.h:818
    #3  client_socket_connect (dl=dl@entry=0x20006600 <dlc>, type=<optimized out>, port=<optimized out>)
        at C:/ws/fw/project/nrf/subsys/net/lib/download_client/src/download_client.c:288
    #4  0x0002babc in client_connect (dl=dl@entry=0x20006600 <dlc>) at C:/ws/fw/project/nrf/subsys/net/lib/download_client/src/download_client.c:449
    #5  0x0002bbec in download_thread (client=0x20006600 <dlc>, a=<optimized out>, b=<optimized out>)
        at C:/ws/fw/project/nrf/subsys/net/lib/download_client/src/download_client.c:809
    

    So then the questions becomes:

    - how to configure the download client to use the same connection API's as the azure connection?

    Best regards.

  • Based on the logs you are never able to open a socket because memory could not be allocated for it, errno 12 is ENOMEM. Could you try to increase CONFIG_NET_MAX_CONTEXTS and check if that makes any difference?

  • Hi Benjamin,

     I've tried increasing the config field to `CONFIG_NET_MAX_CONTEXTS=32` it does not seem to do anything. Is still the same error:

    [00:00:39.231,048] <err> download_client: Failed to create socket, errno 12
    [00:00:39.231,079] <err> fota_download: Download client error
    [00:00:39.231,079] <dbg> fota_download: download_client_callback: No DFU target was initialized
    [00:00:39.231,140] <err> azure_fota: FOTA download failed
    

    Best regards.

Related