Skip to content

Commit

Permalink
add support for MCUboot bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
ihidchaos committed Jul 8, 2023
1 parent 26297db commit 758cbbc
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 1 deletion.
8 changes: 7 additions & 1 deletion boards/arm/connectkit_nrf52840/board.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Copyright (c) 2016-2023 Makerdiary
# SPDX-License-Identifier: Apache-2.0

board_runner_args(nrfjprog "--nrf-family=NRF52")
board_runner_args(jlink "--device=nRF52840_xxAA" "--speed=4000")
board_runner_args(pyocd "--target=nrf52840")
board_runner_args(uf2 "--board-id=nRF52840-Connect-Kit")
include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/uf2.board.cmake)
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
48 changes: 48 additions & 0 deletions boards/arm/connectkit_nrf52840/mcuboot-bootloader.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2016-2023 Makerdiary
*
* SPDX-License-Identifier: Apache-2.0
*/

/* Flash partition table compatible with MCUboot bootloader */

/delete-node/ &flash0 ;

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

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x0000C000>;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000C000 0x00067000>;
};
slot1_partition: partition@73000 {
label = "image-1";
reg = <0x00073000 0x00067000>;
};
scratch_partition: partition@da000 {
label = "image-scratch";
reg = <0x000da000 0x0001e000>;
};

/*
* The flash starting at 0x000f8000 and ending at
* 0x000fffff is reserved for use by the application.
*/

/*
* Storage partition will be used by FCB/LittleFS/NVS
* if enabled.
*/
storage_partition: partition@f8000 {
label = "storage";
reg = <0x000f8000 0x00008000>;
};
};
};
13 changes: 13 additions & 0 deletions samples/mcuboot_hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

list(APPEND DTC_OVERLAY_FILE "${CMAKE_CURRENT_LIST_DIR}/boards/mcuboot.overlay")

list(APPEND mcuboot_OVERLAY_CONFIG "${CMAKE_CURRENT_LIST_DIR}/boards/mcuboot.conf")
list(APPEND mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_LIST_DIR}/boards/mcuboot.overlay")

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

target_sources(app PRIVATE src/main.c)
15 changes: 15 additions & 0 deletions samples/mcuboot_hello_world/boards/connectkit_nrf52840.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2016-2023 Makerdiary
#
# SPDX-License-Identifier: Apache-2.0
#

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

# USB subsystem configuration
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB Console"
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y
17 changes: 17 additions & 0 deletions samples/mcuboot_hello_world/boards/connectkit_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2016-2023 Makerdiary
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
15 changes: 15 additions & 0 deletions samples/mcuboot_hello_world/boards/dongle_nrf52840.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2016-2023 Makerdiary
#
# SPDX-License-Identifier: Apache-2.0
#

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

# USB subsystem configuration
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB Console"
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y
17 changes: 17 additions & 0 deletions samples/mcuboot_hello_world/boards/dongle_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2016-2023 Makerdiary
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
1 change: 1 addition & 0 deletions samples/mcuboot_hello_world/boards/mcuboot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_MULTITHREADING=y
50 changes: 50 additions & 0 deletions samples/mcuboot_hello_world/boards/mcuboot.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2016-2023 Makerdiary
*
* SPDX-License-Identifier: Apache-2.0
*/

/* Flash partition table compatible with MCUboot bootloader */

/delete-node/ &boot_partition;
/delete-node/ &slot0_partition;
/delete-node/ &storage_partition;

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

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x0000C000>;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000C000 0x00067000>;
};
slot1_partition: partition@73000 {
label = "image-1";
reg = <0x00073000 0x00067000>;
};
scratch_partition: partition@da000 {
label = "image-scratch";
reg = <0x000da000 0x0001e000>;
};

/*
* The flash starting at 0x000f8000 and ending at
* 0x000fffff is reserved for use by the application.
*/

/*
* Storage partition will be used by FCB/LittleFS/NVS
* if enabled.
*/
storage_partition: partition@f8000 {
label = "storage";
reg = <0x000f8000 0x00008000>;
};
};
};
2 changes: 2 additions & 0 deletions samples/mcuboot_hello_world/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# nothing here
CONFIG_BOOTLOADER_MCUBOOT=y
9 changes: 9 additions & 0 deletions samples/mcuboot_hello_world/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sample:
name: Hello World sample
common:
build_only: true
integration_platforms:
- connectkit_nrf52840
- dongle_nrf52840
tests:
sample.hello_world: {}
17 changes: 17 additions & 0 deletions samples/mcuboot_hello_world/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2016-2023 Makerdiary
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

int main(void)
{
while (1) {
printk("Hello World with MCUboot enabled! %s\n", CONFIG_BOARD);
k_sleep(K_SECONDS(1));
}
return 0;
}

0 comments on commit 758cbbc

Please sign in to comment.