MCUBoot Not finding a image

Hi,

I have searched the forum but haven't been able to find a solution that works for me. But I am using a nRF9160 on a custom board and am trying to use SDK 2.5.0 with MCUBoot and TFM for secure boot. The application is a simple one to start with, I just want to print some statements using printk to get some information about the modem and then turn the modem on to connect to the network. I have the application building and can flash the nRF9160 using a jlink, but whenever I try to run the program, MCUBoot gives me an error saying that the primary slot is not valid. I have attached my configurations below as well as the static partitions I'm attempting to use. Can you please help? 

Terminal Output from device: 

*** Booting nRF Connect SDK v2.5.0 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: none
E: Image in the primary slot is not valid!
E: Unable to find bootable image

Configuration File for the board: 

# SPDX-License-Identifier: Apache-2.0

CONFIG_SOC_SERIES_NRF91X=y
CONFIG_SOC_NRF9160_SICA=y
CONFIG_BOARD_SANSA_NS=y

# Enable MPU
CONFIG_ARM_MPU=y

# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y

# Enable TrustZone-M
CONFIG_ARM_TRUSTZONE_M=y
CONFIG_BUILD_WITH_TFM=y

# This Board implies building Non-Secure firmware
CONFIG_TRUSTED_EXECUTION_NONSECURE=y

# enable GPIO
CONFIG_GPIO=y

# Enable uart driver
CONFIG_SERIAL=y

# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_PINCTRL=y

Configuration file of the project: 

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

# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_MODEM_INFO=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# NEWLIB C
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

#Ensure an MCUboot - compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_BOOTUTIL_LIB=y

# Enable the serial mcumgr transport.
#CONFIG_MCUMGR_SMP_UART=y

# Some command handlers require a large stack.
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=2048

CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UARTE1=y
CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_PWM=y

CONFIG_PM_SINGLE_IMAGE=y

pm_static.yml:

EMPTY_0:
  address: 0xf0000
  end_address: 0x100000
  region: flash_primary
  size: 0x10000
app:
  address: 0x50000
  end_address: 0x80000
  region: flash_primary
  size: 0x30000
mcuboot:
  address: 0x0
  end_address: 0x10000
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0x10000
mcuboot_pad:
  address: 0x10000
  end_address: 0x10200
  placement:
    align:
      start: 0x8000
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0x10000
  end_address: 0x80000
  orig_span: &id001
  - app
  - mcuboot_pad
  - tfm
  region: flash_primary
  sharers: 0x1
  size: 0x70000
  span: *id001
mcuboot_primary_app:
  address: 0x10200
  end_address: 0x80000
  orig_span: &id002
  - app
  - tfm
  region: flash_primary
  size: 0x6fe00
  span: *id002
mcuboot_secondary:
  address: 0x80000
  end_address: 0xf0000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x8000
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x70000
tfm:
  address: 0x10200
  end_address: 0x50000
  inside:
  - mcuboot_primary_app
  placement:
    before:
    - app
  region: flash_primary
  size: 0x3fe00
tfm_nonsecure:
  address: 0x50000
  end_address: 0x80000
  orig_span: &id007
  - app
  region: flash_primary
  size: 0x30000
  span: *id007
tfm_secure:
  address: 0x10000
  end_address: 0x50000
  orig_span: &id008
  - mcuboot_pad
  - tfm
  region: flash_primary
  size: 0x40000
  span: *id008

main.c (Based off of the modem callback example)

#include <stdio.h>
#include <stdint.h>
#include <zephyr/kernel.h>
#include <modem/nrf_modem_lib.h>
#include <modem/modem_info.h>
#include <modem/lte_lc.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#include <hal/nrf_regulators.h>

NRF_MODEM_LIB_ON_INIT(init_hook, on_modem_init, NULL);
NRF_MODEM_LIB_ON_SHUTDOWN(shutdown_hook, on_modem_shutdown, NULL);

static const struct gpio_dt_spec BOOT_PIN = GPIO_DT_SPEC_GET(DT_ALIAS(boot), gpios);

void shutdown();

static void on_modem_init(int ret, void *ctx)
{
    printk("> Initialized with value %d\r\n", ret);
}

static void on_modem_shutdown(void *ctx)
{
    printk("> Shutting down\r\n");
}

LTE_LC_ON_CFUN(cfun_monitor, on_cfun, NULL);

static void on_cfun(enum lte_lc_func_mode mode, void *ctx)
{
    printk("> Functional mode has changed to %d\r\n", mode);
}

int main(void)
{
    printk("Huxley Sansa Firmware (nRF9160)\r\n");

    // Configure the boot pin so we can determine whether we need to be in boot mode (HIGH) or not (LOW)
    if (gpio_pin_configure_dt(&BOOT_PIN, GPIO_INPUT) != 0) {
        printk("ERROR: Unable to configure the LTE WakeUp pin\r\n");
        return 1;
    }
    
    //todo do more with this gpio pin later

    printk("Getting Modem Info First\r\n");

    int err = modem_info_init();
    if (err)
    {
        printk("Error: Modem Info Module Failed to initialize, err %d \r\n", err);
    }

    struct modem_param_info my_modem_info;
    err = modem_info_params_get(&my_modem_info);
    if (err)
    {
        printk("Error: Can't get modem parameters, err %d \r\n", err);
    }
    else
    {
        printk("Modem's ICCID: %s \r\n", my_modem_info.sim.iccid.value_string);
    }

    printk("Modem callbacks sample started\r\n");

    printk("Initializing modem library\r\n");
    err = nrf_modem_lib_init();
    if (err) {
        printk("Modem initialization failed, err %d\r\n", err);
        return 0;
    }

    printk("Changing functional moder\n");
    err = lte_lc_init_and_connect();
    if (err) {
        printk("lte_lc_init_and_connect() failed, err %d\r\n", err);
    }

    while(true)
    {
        // just wait forever since we don't want to shutdown
        k_cpu_idle();
        //k_msleep(1000);
    }

    printk("Bye\r\n");

    return 0;
}

void shutdown(void)
{
    printk("Shutting down modem library\r\n");
    int status = nrf_modem_lib_shutdown();
    if (status == 0)
    {
      printk("Modem shutdown successfully\r\n");
    }
    else
    {
      printk("Modem failed to shutdown: %d\r\n", status);
    }

    printk("Taking a nap...\r\n");

    nrf_regulators_system_off(NRF_REGULATORS);
}
 

Parents
  • Hello

    From your description and the update, it looks like there are issues or inconsistencies in the PM Static Yml file.

    As such, I would recommend if you remove static partition file, and then build the project such that it automatically generates the 'partitions.yml' in the build folder, and then see and modify as per your requirements.

    This will also allow you to track changes that are erroneous, and would provide a starting point.

    In the below image, I have just compiled the 'TFM_SECURE_PARTITION' project for 9160DK, and can see the 'partitions.yml' file in the build folder.

  • Hi,

    You just described how I arrived at this particular pm_static.yml file that I have posted. Between looking at generated partition.yml files for examples and reading various posts on this site, I have tried to remake this a few times now. If there are issues or inconsistencies in the static partitions then I'm asking if someone can take a look at it to see what those might be because I clearly am not seeing them. 

    To be clear, I can also compile examples for dev boards and run them on a dev board, but it's not translating to my custom board running the nRF9160 and I am not seeing why. So if you see something in my pm_static.yml file that seems odd or out of place, please let me know as it would be greatly appreciated. 

Reply
  • Hi,

    You just described how I arrived at this particular pm_static.yml file that I have posted. Between looking at generated partition.yml files for examples and reading various posts on this site, I have tried to remake this a few times now. If there are issues or inconsistencies in the static partitions then I'm asking if someone can take a look at it to see what those might be because I clearly am not seeing them. 

    To be clear, I can also compile examples for dev boards and run them on a dev board, but it's not translating to my custom board running the nRF9160 and I am not seeing why. So if you see something in my pm_static.yml file that seems odd or out of place, please let me know as it would be greatly appreciated. 

Children
  • Hello,

    I don't see any other issue except that one of the size (number) is wrong (snapshot attached below) and that the storage_partition is getting defined two times (in the board file and in the .yml file). 

    What I have seen is that if you need to change the storage_partition already defined in the board file, then first they delete it (using delete property in the overlay) and then redefine it.

Related