MCUBoot private key on nrf5340dk

Hi,

I work with win10 laptop, Toolchain  nrf Connect SDK 1.6.1 on a nrf5340dk. I use peripheral_uart sample.

I follow the guide:

https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/ncs-dfu

It's work well.

/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Nordic UART Bridge Service (NUS) sample
 */

#include <zephyr/types.h>
#include <zephyr.h>
#include <drivers/uart.h>

#include <device.h>
#include <soc.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
#include <bluetooth/hci.h>

#include <bluetooth/services/nus.h>

#include <dk_buttons_and_leds.h>

#include <settings/settings.h>

#include <stdio.h>

#include <logging/log.h>

#include <mgmt/mcumgr/smp_bt.h>
#include "os_mgmt/os_mgmt.h"
#include "img_mgmt/img_mgmt.h"

#define LOG_MODULE_NAME peripheral_uart
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#define STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
#define PRIORITY 7

#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN	(sizeof(DEVICE_NAME) - 1)

#define RUN_STATUS_LED DK_LED1
#define RUN_LED_BLINK_INTERVAL 1000

#define CON_STATUS_LED DK_LED2

#define KEY_PASSKEY_ACCEPT DK_BTN1_MSK
#define KEY_PASSKEY_REJECT DK_BTN2_MSK

#define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE
#define UART_WAIT_FOR_BUF_DELAY K_MSEC(50)
#define UART_WAIT_FOR_RX CONFIG_BT_NUS_UART_RX_WAIT_TIME

static K_SEM_DEFINE(ble_init_ok, 0, 1);

static struct bt_conn *current_conn;
static struct bt_conn *auth_conn;

static const struct device *uart;
static struct k_work_delayable uart_work;

struct uart_data_t {
	void *fifo_reserved;
	uint8_t data[UART_BUF_SIZE];
	uint16_t len;
};

static K_FIFO_DEFINE(fifo_uart_tx_data);
static K_FIFO_DEFINE(fifo_uart_rx_data);

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

static const struct bt_data sd[] = {
	//BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
	BT_DATA_BYTES(BT_DATA_UUID128_ALL,
		      0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
		      0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
};

static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	ARG_UNUSED(dev);

	static uint8_t *current_buf;
	static size_t aborted_len;
	static bool buf_release;
	struct uart_data_t *buf;
	static uint8_t *aborted_buf;

	switch (evt->type) {
	case UART_TX_DONE:
		if ((evt->data.tx.len == 0) ||
		    (!evt->data.tx.buf)) {
			return;
		}

		if (aborted_buf) {
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);
			aborted_buf = NULL;
			aborted_len = 0;
		} else {
			buf = CONTAINER_OF(evt->data.tx.buf, struct uart_data_t,
					   data);
		}

		k_free(buf);

		buf = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);
		if (!buf) {
			return;
		}

		if (uart_tx(uart, buf->data, buf->len, SYS_FOREVER_MS)) {
			LOG_WRN("Failed to send data over UART");
		}

		break;

	case UART_RX_RDY:
		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
		buf->len += evt->data.rx.len;
		buf_release = false;

		if (buf->len == UART_BUF_SIZE) {
			k_fifo_put(&fifo_uart_rx_data, buf);
		} else if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
			  (evt->data.rx.buf[buf->len - 1] == '\r')) {
			k_fifo_put(&fifo_uart_rx_data, buf);
			current_buf = evt->data.rx.buf;
			buf_release = true;
			uart_rx_disable(uart);
		}

		break;

	case UART_RX_DISABLED:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf->len = 0;
		} else {
			LOG_WRN("Not able to allocate UART receive buffer");
			k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
			return;
		}

		uart_rx_enable(uart, buf->data, sizeof(buf->data),
			       UART_WAIT_FOR_RX);

		break;

	case UART_RX_BUF_REQUEST:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf->len = 0;
			uart_rx_buf_rsp(uart, buf->data, sizeof(buf->data));
		} else {
			LOG_WRN("Not able to allocate UART receive buffer");
		}

		break;

	case UART_RX_BUF_RELEASED:
		buf = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t,
				   data);
		if (buf_release && (current_buf != evt->data.rx_buf.buf)) {
			k_free(buf);
			buf_release = false;
			current_buf = NULL;
		}

		break;

	case UART_TX_ABORTED:
			if (!aborted_buf) {
				aborted_buf = (uint8_t *)evt->data.tx.buf;
			}

			aborted_len += evt->data.tx.len;
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);

			uart_tx(uart, &buf->data[aborted_len],
				buf->len - aborted_len, SYS_FOREVER_MS);

		break;

	default:
		break;
	}
}

static void uart_work_handler(struct k_work *item)
{
	struct uart_data_t *buf;

	buf = k_malloc(sizeof(*buf));
	if (buf) {
		buf->len = 0;
	} else {
		LOG_WRN("Not able to allocate UART receive buffer");
		k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
		return;
	}

	uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);
}

static int uart_init(void)
{
	int err;
	struct uart_data_t *rx;

	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
	if (!uart) {
		return -ENXIO;
	}

	rx = k_malloc(sizeof(*rx));
	if (rx) {
		rx->len = 0;
	} else {
		return -ENOMEM;
	}

	k_work_init_delayable(&uart_work, uart_work_handler);

	err = uart_callback_set(uart, uart_cb, NULL);
	if (err) {
		return err;
	}

	return uart_rx_enable(uart, rx->data, sizeof(rx->data), 50);
}

static void connected(struct bt_conn *conn, uint8_t err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	if (err) {
		LOG_ERR("Connection failed (err %u)", err);
		return;
	}

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
	LOG_INF("Connected %s", log_strdup(addr));

	current_conn = bt_conn_ref(conn);

	dk_set_led_on(CON_STATUS_LED);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Disconnected: %s (reason %u)", log_strdup(addr), reason);

	if (auth_conn) {
		bt_conn_unref(auth_conn);
		auth_conn = NULL;
	}

	if (current_conn) {
		bt_conn_unref(current_conn);
		current_conn = NULL;
		dk_set_led_off(CON_STATUS_LED);
	}
}

#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
static void security_changed(struct bt_conn *conn, bt_security_t level,
			     enum bt_security_err err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (!err) {
		LOG_INF("Security changed: %s level %u", log_strdup(addr),
			level);
	} else {
		LOG_WRN("Security failed: %s level %u err %d", log_strdup(addr),
			level, err);
	}
}
#endif

static struct bt_conn_cb conn_callbacks = {
	.connected    = connected,
	.disconnected = disconnected,
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
	.security_changed = security_changed,
#endif
};

#if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Passkey for %s: %06u", log_strdup(addr), passkey);
}

static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	auth_conn = bt_conn_ref(conn);

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Passkey for %s: %06u", log_strdup(addr), passkey);
	LOG_INF("Press Button 1 to confirm, Button 2 to reject.");
}


static void auth_cancel(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Pairing cancelled: %s", log_strdup(addr));
}


static void pairing_confirm(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	bt_conn_auth_pairing_confirm(conn);

	LOG_INF("Pairing confirmed: %s", log_strdup(addr));
}


static void pairing_complete(struct bt_conn *conn, bool bonded)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Pairing completed: %s, bonded: %d", log_strdup(addr),
		bonded);
}


static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Pairing failed conn: %s, reason %d", log_strdup(addr),
		reason);
}


static struct bt_conn_auth_cb conn_auth_callbacks = {
	.passkey_display = auth_passkey_display,
	.passkey_confirm = auth_passkey_confirm,
	.cancel = auth_cancel,
	.pairing_confirm = pairing_confirm,
	.pairing_complete = pairing_complete,
	.pairing_failed = pairing_failed
};
#else
static struct bt_conn_auth_cb conn_auth_callbacks;
#endif

static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
			  uint16_t len)
{
	int err;
	char addr[BT_ADDR_LE_STR_LEN] = {0};

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

	LOG_INF("Received data from: %s", log_strdup(addr));

	for (uint16_t pos = 0; pos != len;) {
		struct uart_data_t *tx = k_malloc(sizeof(*tx));

		if (!tx) {
			LOG_WRN("Not able to allocate UART send data buffer");
			return;
		}

		/* Keep the last byte of TX buffer for potential LF char. */
		size_t tx_data_size = sizeof(tx->data) - 1;

		if ((len - pos) > tx_data_size) {
			tx->len = tx_data_size;
		} else {
			tx->len = (len - pos);
		}

		memcpy(tx->data, &data[pos], tx->len);

		pos += tx->len;

		/* Append the LF character when the CR character triggered
		 * transmission from the peer.
		 */
		if ((pos == len) && (data[len - 1] == '\r')) {
			tx->data[tx->len] = '\n';
			tx->len++;
		}

		err = uart_tx(uart, tx->data, tx->len, SYS_FOREVER_MS);
		if (err) {
			k_fifo_put(&fifo_uart_tx_data, tx);
		}
	}
}

static struct bt_nus_cb nus_cb = {
	.received = bt_receive_cb,
};

void error(void)
{
	dk_set_leds_state(DK_ALL_LEDS_MSK, DK_NO_LEDS_MSK);

	while (true) {
		/* Spin for ever */
		k_sleep(K_MSEC(1000));
	}
}

static void num_comp_reply(bool accept)
{
	if (accept) {
		bt_conn_auth_passkey_confirm(auth_conn);
		LOG_INF("Numeric Match, conn %p", (void *)auth_conn);
	} else {
		bt_conn_auth_cancel(auth_conn);
		LOG_INF("Numeric Reject, conn %p", (void *)auth_conn);
	}

	bt_conn_unref(auth_conn);
	auth_conn = NULL;
}

void button_changed(uint32_t button_state, uint32_t has_changed)
{
	uint32_t buttons = button_state & has_changed;

	if (auth_conn) {
		if (buttons & KEY_PASSKEY_ACCEPT) {
			num_comp_reply(true);
		}

		if (buttons & KEY_PASSKEY_REJECT) {
			num_comp_reply(false);
		}
	}
}

static void configure_gpio(void)
{
	int err;

	err = dk_buttons_init(button_changed);
	if (err) {
		LOG_ERR("Cannot init buttons (err: %d)", err);
	}

	err = dk_leds_init();
	if (err) {
		LOG_ERR("Cannot init LEDs (err: %d)", err);
	}
}

void main(void)
{
	int blink_status = 0;
	int err = 0;

	configure_gpio();

	err = uart_init();
	if (err) {
		error();
	}

	printk("build time: " __DATE__ " " __TIME__ "\n");
	os_mgmt_register_group();
	img_mgmt_register_group();
	smp_bt_register();

	bt_conn_cb_register(&conn_callbacks);

	if (IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) {
		bt_conn_auth_cb_register(&conn_auth_callbacks);
	}

	err = bt_enable(NULL);
	if (err) {
		error();
	}

	LOG_INF("Bluetooth initialized");

	k_sem_give(&ble_init_ok);

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	err = bt_nus_init(&nus_cb);
	if (err) {
		LOG_ERR("Failed to initialize UART service (err: %d)", err);
		return;
	}

	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
			      ARRAY_SIZE(sd));
	if (err) {
		LOG_ERR("Advertising failed to start (err %d)", err);
	}

	printk("Starting Nordic UART service example\n");

	for (;;) {
		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
	}
}

void ble_write_thread(void)
{
	/* Don't go any further until BLE is initialized */
	k_sem_take(&ble_init_ok, K_FOREVER);

	for (;;) {
		/* Wait indefinitely for data to be sent over bluetooth */
		struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
						     K_FOREVER);

		if (bt_nus_send(NULL, buf->data, buf->len)) {
			LOG_WRN("Failed to send data over BLE connection");
		}

		k_free(buf);
	}
}

K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
		NULL, PRIORITY, 0, 0);

But now, I need to use a private MCUBoot Key like on this ticket:

https://devzone.nordicsemi.com/f/nordic-q-a/71892/cmake-warning-using-default-mcuboot-key-it-should-not-be-used-for-production

I created the priv.pem file with opennssl:

"

-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIFOsF97yRp38uZW7PJbvFAwK1Uivv6VzIA7Kw79z3Am+oAoGCCqGSM49
AwEHoUQDQgAEHYxvVXgkcjwdhVkUDEDJ7EdLO5HAdiwDLCHXcS5uH41mMAbp8rDI
Ykb+splDuAQFsxV8sxuXZYW2zg3jb4+vxg==
-----END EC PRIVATE KEY-----

"

I put priv.pem in my repertory:

D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key

I created the mcuboot.conf:

7875.mcuboot.conf

I modified the prj.conf:

5722.prj.conf

I modified the CmakeList.txt:

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.13.1)

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf")
    list(APPEND mcuboot_OVERLAY_CONFIG
      "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf"
      )
endif()

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(NONE)

# NORDIC SDK APP START
target_sources(app PRIVATE
  src/main.c
)
# NORDIC SDK APP END

zephyr_library_include_directories(.)

But when I build it with west I this following "fatal error":

FATAL ERROR: command exited with status 1: 'D:\elect\ncs\v1.6.1\toolchain\opt\bin\cmake.EXE' --build 'D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key\build'

NCS repositories are not yet cloned here. To do so run the following command:

git-bash -c "ncsmgr init-ncs"

Microsoft Windows [version 10.0.19044.1586]
(c) Microsoft Corporation. Tous droits réservés.

C:\Users\elect\AppData\Local\Temp>d:

D:\elect\ncs\v1.6.1>cd D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key

D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key>west build -b nrf5340dk_nrf5340_cpuapp
-- west build: generating a build system
Including boilerplate (Zephyr base): D:/elect/ncs/v1.6.1/zephyr/cmake/app/boilerplate.cmake
-- Application: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key
-- Using NCS Toolchain 1.6.1 for building. (D:/elect/ncs/v1.6.1/toolchain/cmake)
-- Zephyr version: 2.6.0-rc1 (D:/elect/ncs/v1.6.1/zephyr), build: v2.6.0-rc1-ncs1
-- Found Python3: D:/elect/ncs/v1.6.1/toolchain/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpuapp
-- Cache files will be written to: D:/elect/ncs/v1.6.1/zephyr/.cache
-- Found dtc: D:/elect/ncs/v1.6.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (D:/elect/ncs/v1.6.1/toolchain/opt)
-- Found BOARD.dts: D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
-- Generated zephyr.dts: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/include/generated/device_extern.h
Parsing D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/Kconfig
Loaded configuration 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/.config'
No change to configuration in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/.config'
No change to Kconfig header in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- The ASM compiler identification is GNU
-- Found assembler: D:/elect/ncs/v1.6.1/toolchain/opt/bin/arm-none-eabi-gcc.exe

=== child image b0 -  begin ===
Including boilerplate (Zephyr base (cached)): D:/elect/ncs/v1.6.1/zephyr/cmake/app/boilerplate.cmake
-- Application: D:/elect/ncs/v1.6.1/nrf/samples/bootloader
-- Using NCS Toolchain 1.6.1 for building. (D:/elect/ncs/v1.6.1/toolchain/cmake)
-- Zephyr version: 2.6.0-rc1 (D:/elect/ncs/v1.6.1/zephyr), build: v2.6.0-rc1-ncs1
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpuapp
-- Cache files will be written to: D:/elect/ncs/v1.6.1/zephyr/.cache
-- Found dtc: D:/elect/ncs/v1.6.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (D:/elect/ncs/v1.6.1/toolchain/opt)
-- Found BOARD.dts: D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
-- Generated zephyr.dts: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/include/generated/device_extern.h
Parsing D:/elect/ncs/v1.6.1/zephyr/Kconfig
Loaded configuration 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/.config'
No change to configuration in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/.config'
No change to Kconfig header in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0/zephyr/include/generated/autoconf.h'
CMake Warning at ../../subsys/bootloader/CMakeLists.txt:21 (message):


        --------------------------------------------------------
        --- WARNING: When using the immutable bootloader on  ---
        --- this SoC, the UICR must be erased when flashing. ---
        --- E.g. by calling 'west flash --erase'             ---
        --------------------------------------------------------


-- Configuring done
-- Generating done
-- Build files have been written to: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/b0
=== child image b0 -  end ===

Adding 'hci_rpmsg' firmware as child image since CONFIG_BT_RPMSG_NRF53 is set to 'y'

=== child image hci_rpmsg - CPUNET begin ===
Including boilerplate (Zephyr base (cached)): D:/elect/ncs/v1.6.1/zephyr/cmake/app/boilerplate.cmake
-- Application: D:/elect/ncs/v1.6.1/zephyr/samples/bluetooth/hci_rpmsg
-- Using NCS Toolchain 1.6.1 for building. (D:/elect/ncs/v1.6.1/toolchain/cmake)
-- Zephyr version: 2.6.0-rc1 (D:/elect/ncs/v1.6.1/zephyr), build: v2.6.0-rc1-ncs1
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpunet
-- Cache files will be written to: D:/elect/ncs/v1.6.1/zephyr/.cache
-- Found dtc: D:/elect/ncs/v1.6.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (D:/elect/ncs/v1.6.1/toolchain/opt)
-- Found BOARD.dts: D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts
-- Generated zephyr.dts: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/include/generated/device_extern.h
Parsing D:/elect/ncs/v1.6.1/zephyr/Kconfig
Loaded configuration 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/.config'
No change to configuration in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/.config'
No change to Kconfig header in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/zephyr/include/generated/autoconf.h'

=== child image b0n - CPUNET (inherited) begin ===
Including boilerplate (Zephyr base (cached)): D:/elect/ncs/v1.6.1/zephyr/cmake/app/boilerplate.cmake
-- Application: D:/elect/ncs/v1.6.1/nrf/samples/nrf5340/netboot
-- Using NCS Toolchain 1.6.1 for building. (D:/elect/ncs/v1.6.1/toolchain/cmake)
-- Zephyr version: 2.6.0-rc1 (D:/elect/ncs/v1.6.1/zephyr), build: v2.6.0-rc1-ncs1
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpunet
-- Cache files will be written to: D:/elect/ncs/v1.6.1/zephyr/.cache
-- Found dtc: D:/elect/ncs/v1.6.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (D:/elect/ncs/v1.6.1/toolchain/opt)
-- Found BOARD.dts: D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts
-- Generated zephyr.dts: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/include/generated/device_extern.h
Parsing D:/elect/ncs/v1.6.1/nrf/samples/nrf5340/netboot/Kconfig
Loaded configuration 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/.config'
No change to configuration in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/.config'
No change to Kconfig header in 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n/zephyr/include/generated/autoconf.h'
CMake Warning at D:/elect/ncs/v1.6.1/zephyr/CMakeLists.txt:1607 (message):
  __ASSERT() statements are globally ENABLED


-- Configuring done
-- Generating done
-- Build files have been written to: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg/b0n
=== child image b0n - CPUNET (inherited) end ===

-- libmetal version: 1.0.0 (D:/elect/ncs/v1.6.1/zephyr/samples/bluetooth/hci_rpmsg)
-- Build type:
-- Host:    Windows/AMD64
-- Target:  Generic/arm
-- Machine: cortexm
-- open-amp version: 1.0.0 (D:/elect/ncs/v1.6.1/modules/lib/open-amp/open-amp)
-- Host:    Windows/AMD64
-- Target:  Generic/arm
-- Machine: cortexm
-- C_FLAGS :  -Wall -Wextra
-- Configuring done
-- Generating done
-- Build files have been written to: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/hci_rpmsg
=== child image hci_rpmsg - CPUNET end ===


=== child image mcuboot -  begin ===
Including boilerplate (Zephyr base): D:/elect/ncs/v1.6.1/zephyr/cmake/app/boilerplate.cmake
-- Application: D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/zephyr
-- Using NCS Toolchain 1.6.1 for building. (D:/elect/ncs/v1.6.1/toolchain/cmake)
-- Zephyr version: 2.6.0-rc1 (D:/elect/ncs/v1.6.1/zephyr), build: v2.6.0-rc1-ncs1
-- Found Python3: D:/elect/ncs/v1.6.1/toolchain/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
-- Found west (found suitable version "0.11.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpuapp
-- Cache files will be written to: D:/elect/ncs/v1.6.1/zephyr/.cache
-- Found dtc: D:/elect/ncs/v1.6.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (D:/elect/ncs/v1.6.1/toolchain/opt)
-- Found BOARD.dts: D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
-- Found devicetree overlay: D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/zephyr/dts.overlay
-- Generated zephyr.dts: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr/include/generated/device_extern.h
Parsing D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/zephyr/Kconfig
Loaded configuration 'D:/elect/ncs/v1.6.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
Merged configuration 'D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/zephyr/prj.conf'
Merged configuration 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/mcuboot.conf'
Configuration saved to 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr/.config'
Kconfig header saved to 'D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- The ASM compiler identification is GNU
-- Found assembler: D:/elect/ncs/v1.6.1/toolchain/opt/bin/arm-none-eabi-gcc.exe
MCUBoot bootloader key file: /elect/projets_nordic_D/dfu_peripheral_uart_private_key/priv.pem
-- Configuring done
-- Generating done
-- Build files have been written to: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot
=== child image mcuboot -  end ===

-- libmetal version: 1.0.0 (D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key)
-- Build type:
-- Host:    Windows/AMD64
-- Target:  Generic/arm
-- Machine: cortexm
-- Looking for include file stdatomic.h
-- Looking for include file stdatomic.h - found
-- open-amp version: 1.0.0 (D:/elect/ncs/v1.6.1/modules/lib/open-amp/open-amp)
-- Host:    Windows/AMD64
-- Target:  Generic/arm
-- Machine: cortexm
-- C_FLAGS :  -Wall -Wextra
-- Looking for include file fcntl.h
-- Looking for include file fcntl.h - found
CMake Warning at D:/elect/ncs/v1.6.1/zephyr/CMakeLists.txt:1607 (message):
  __ASSERT() statements are globally ENABLED


-- Configuring done
-- Generating done
-- Build files have been written to: D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build
-- west build: building application
[0/313] Generating extra provision key files
[17/313] Creating public key from private key used for signing
[21/313] Performing build step for 'mcuboot_subimage'
[245/252] Linking C executable zephyr\zephyr_prebuilt.elf
FAILED: zephyr/zephyr_prebuilt.elf zephyr/zephyr_prebuilt.map
cmd.exe /C "cd . && D:\elect\ncs\v1.6.1\toolchain\opt\bin\arm-none-eabi-gcc.exe    zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj  -o zephyr\zephyr_prebuilt.elf  -Wl,-T  zephyr/linker_zephyr_prebuilt.cmd  -Wl,-Map=D:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/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/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.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/drivers/gpio/libdrivers__gpio.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/mbedtls/libmodules__mbedtls.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -L"d:/elect/ncs/v1.6.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v8-m.main/nofp"  -LD:/elect/projets_nordic_D/dfu_peripheral_uart_private_key/build/mcuboot/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  D:/elect/ncs/v1.6.1/nrfxlib/crypto/nrf_cc312_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc312_platform_0.9.10.a  -mcpu=cortex-m33  -mthumb  -mabi=aapcs  -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 && cmd.exe /C "cd /D D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key\build\mcuboot\zephyr && D:\elect\ncs\v1.6.1\toolchain\opt\bin\cmake.exe -E echo ""
d:/elect/ncs/v1.6.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `main':
D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/zephyr/main.c:583: undefined reference to `pcd_lock_ram'
d:/elect/ncs/v1.6.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(loader.c.obj): in function `boot_validated_swap_type':
D:/elect/ncs/v1.6.1/bootloader/mcuboot/boot/bootutil/src/loader.c:828: undefined reference to `pcd_network_core_update'
d:/elect/ncs/v1.6.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(keys.c.obj):(.rodata.bootutil_keys+0x0): undefined reference to `rsa_pub_key'
d:/elect/ncs/v1.6.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(keys.c.obj):(.rodata.bootutil_keys+0x4): undefined reference to `rsa_pub_key_len'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
[278/313] Building C object zephyr/kernel/CMakeFiles/kernel.dir/timeout.c.obj
FAILED: modules/mcuboot/mcuboot_subimage-prefix/src/mcuboot_subimage-stamp/mcuboot_subimage-build mcuboot/zephyr/zephyr.hex mcuboot/zephyr/zephyr.elf
cmd.exe /C "cd /D D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key\build\mcuboot && D:\elect\ncs\v1.6.1\toolchain\opt\bin\cmake.exe --build . --"
[282/313] Building C object zephyr/kernel/CMakeFiles/kernel.dir/sched.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'D:\elect\ncs\v1.6.1\toolchain\opt\bin\cmake.EXE' --build 'D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key\build'

D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key>

Could you help to understand the error and make MCUBoot private key working ?

Best regards,

Rob

  • Hi,

    Try adding these configs to your mcuboot.conf

    CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
    CONFIG_PCD=y

  • Hi Øivind,

    Thank you for your answer.

    I tried to add to mcuboot.conf:

    "

    CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
    CONFIG_PCD=y

    "

    The build work, I had this message before flashing:

    "

    D:\elect\projets_nordic_D\dfu_peripheral_uart_private_key>west flash
    -- west flash: rebuilding
    [0/17] Performing build step for 'mcuboot_subimage'
    ninja: no work to do.
    [1/11] Performing build step for 'b0_subimage'
    ninja: no work to do.
    [2/7] Performing build step for 'hci_rpmsg_subimage'
    [0/5] Performing build step for 'b0n_subimage'
    ninja: no work to do.
    -- west flash: using runner nrfjprog
    Using board 960132679
    FATAL ERROR: The hex file contains data placed in the UICR, which needs a full erase before reprogramming. Run west flash again with --force, --erase, or --recover.

    "

    So I tried: "west flash recover"

    and I had this message from the Uart:

    "

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Attempting to boot slot 0.
    No fw_info struct found.
    Attempting to boot slot 1.
    No fw_info struct found.
    No bootable image found. Aborting boot.
    "

    It look like I miss something to make image bootable...

    Here is a zip of my project:dfu_peripheral_uart_private_key.zip

    Best Regards,

    Rob

  • Hi Øivind,

    Could you help me to make image bootable, please ?

    Best Regards,

    Rob

  • Hi,

    Sorry for the late reply, it has been busy this last week.

    I am able to boot the image when I add CONFIG_FW_INFO=y to mcuboot.conf.

  • Thanks you very much for your reply.

    I had CONFIG_FW_INFO=y to mcuboot.conf,

    but now I have this message:

    "

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Attempting to boot slot 0.
    Attempting to boot from address 0x8200.
    Verifying signature against key 0.
    Hash: 0x2e...e0
    Firmware signature verified.
    Firmware version 1
    Setting monotonic counter (version: 1, slot: 0)
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    I: Starting bootloader
    W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=128 - too small?
    E: Unable to find bootable image

    "

    How can I increase the BOOT_MAX_IMG_SECTORS ?

    Best Regards,

    Rob

Related