Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version number extraction #1

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/imgtool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
with:
fetch-depth: 0
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/zephyr_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ jobs:
runs-on: ubuntu-latest
# Docker image from the zephyr upstream. Includes SDK and other required tools
container:
image: zephyrprojectrtos/ci:v0.26.4
image: zephyrprojectrtos/ci:v0.27.4
options: '--entrypoint /bin/bash'
volumes:
- /home/runners/zephyrproject:/github/cache/zephyrproject
env:
ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.1
ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.17.0

steps:
- name: Set versions when workflow_dispatch
Expand All @@ -69,6 +69,7 @@ jobs:
- name: Setup Zephyr
working-directory: repos/zephyr
run: |
west config --system manifest.project-filter -- -.*,+cmsis,+hal_nordic,+hal_nxp,+hal_stm32,+libmetal,+littlefs,+mbedtls,+mcuboot,+open-amp,+picolibc,+segger,+tinycrypt,+trusted-firmware-m,+zcbor
west init -l .
west update

Expand Down
3 changes: 3 additions & 0 deletions boot/bootutil/include/bootutil/bootutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ extern "C" {
_Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");

struct image_header;
struct image_version;

/**
* A response object provided by the boot loader code; indicates where to jump
* to execute the main image.
Expand Down Expand Up @@ -90,6 +92,7 @@ struct boot_loader_state;
void boot_state_clear(struct boot_loader_state *state);
fih_ret context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
const struct image_max_size *boot_get_max_app_size(void);
int boot_get_current_version(struct image_version *version);

#define SPLIT_GO_OK (0)
#define SPLIT_GO_NON_MATCHING (-1)
Expand Down
6 changes: 6 additions & 0 deletions boot/bootutil/src/boot_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
const uint8_t slot, const struct image_max_size *max_app_sizes)
{
int rc;
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
uint8_t image = 0;
#endif

#if defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
uint8_t mode = MCUBOOT_MODE_SINGLE_SLOT;
Expand Down Expand Up @@ -322,11 +324,13 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
sizeof(recovery), &recovery);
}

#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
if (!rc) {
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
BLINFO_RUNNING_SLOT,
sizeof(slot), (void *)&slot);
}
#endif

#if defined(MCUBOOT_VERSION_AVAILABLE)
if (!rc) {
Expand All @@ -337,6 +341,7 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
}
#endif

#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
while (image < BOOT_IMAGE_NUMBER && !rc) {
if (max_app_sizes[image].calculated == true) {
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
Expand All @@ -348,6 +353,7 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are

++image;
}
#endif

if (!rc) {
saved_bootinfo = true;
Expand Down
39 changes: 39 additions & 0 deletions boot/bootutil/src/bootutil_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,42 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
return rc;
}
#endif /* !MCUBOOT_OVERWRITE_ONLY */

/**
* Populates the version information of the
* currently installed primary application
*
* @param[in] version Destination version structure buffer
* @return 0 on success; nonzero on failure.
*/
int boot_get_current_version(struct image_version *version)
{
assert(version != NULL);

struct boot_loader_state boot_data;
struct boot_loader_state *state = &boot_data;

struct boot_status _bs;
struct boot_status *bs = &_bs;

memset(&boot_data, 0, sizeof(struct boot_loader_state));

boot_status_reset(bs);
int rc = swap_read_status(state, bs);
if (rc != 0) {
BOOT_LOG_WRN("Failed reading boot status; Image=%u", BOOT_CURR_IMG(state));
return 1;
}

struct image_header _hdr;
struct image_header *hdr = &_hdr;

rc = boot_read_image_header(state, BOOT_PRIMARY_SLOT, hdr, bs);
if (rc != 0) {
return rc;
}

/** Copy the header's version struct over into the caller-supplied buffer */
memcpy(version, &hdr->ih_ver, sizeof(struct image_version));
return 0;
}
2 changes: 1 addition & 1 deletion boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static const struct boot_swap_table boot_swap_tables[] = {
},
{
.magic_primary_slot = BOOT_MAGIC_GOOD,
.magic_secondary_slot = BOOT_MAGIC_UNSET,
.magic_secondary_slot = BOOT_MAGIC_ANY,
.image_ok_primary_slot = BOOT_FLAG_UNSET,
.image_ok_secondary_slot = BOOT_FLAG_ANY,
.copy_done_primary_slot = BOOT_FLAG_SET,
Expand Down
21 changes: 17 additions & 4 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,10 +1963,21 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
rc = boot_complete_partial_swap(state, bs);
assert(rc == 0);
#endif
/* Attempt to read an image header from each slot. Ensure that
* image headers in slots are aligned with headers in boot_data.
/* Attempt to read an image header from each slot. Ensure that image headers in slots
* are aligned with headers in boot_data.
*
* The boot status (last param) is used to figure out in which slot the header of each
* image is currently located. This is useful as in the middle of an upgrade process,
* the header of a given image could have already been moved to the other slot. However,
* providing it at the end of the upgrade, as it is the case here, would cause the
* reading of the header of the primary image from the secondary slot and the secondary
* image from the primary slot, since the images have been swapped. That's not what we
* want here, since the goal is to upgrade the bootloader state to reflect the new state
* of the slots: the image headers in the primary and secondary slots must now
* respectively be the headers of the new and previous active image. So NULL is provided
* as boot status.
*/
rc = boot_read_image_headers(state, false, bs);
rc = boot_read_image_headers(state, false, NULL);
assert(rc == 0);

/* Swap has finished set to NONE */
Expand Down Expand Up @@ -2244,7 +2255,9 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
#endif

/* Trigger status change callback with upgrading status */
mcuboot_status_change(MCUBOOT_STATUS_UPGRADING);
if (has_upgrade) {
mcuboot_status_change(MCUBOOT_STATUS_UPGRADING);
}

/* Iterate over all the images. At this point there are no aborted swaps
* and the swap types are determined for each image. By the end of the loop
Expand Down
17 changes: 1 addition & 16 deletions boot/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# SPDX-License-Identifier: Apache-2.0

# Mbed-MCUboot Port

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

get_filename_component(BOOT_UTIL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../bootutil REALPATH)

set(LIB_TARGET mbed-mcuboot)
Expand All @@ -15,7 +12,6 @@ add_library(${LIB_TARGET} STATIC)
target_include_directories(${LIB_TARGET}
PUBLIC
include
${BOOT_UTIL_DIR}/include
${BOOT_UTIL_DIR}/src
)

Expand All @@ -33,20 +29,9 @@ target_link_libraries(${LIB_TARGET}
mbed-mbedtls
mbed-storage-flashiap
mbed-storage-blockdevice
mbed-core-flags
)

if("_RTE_" IN_LIST MBED_CONFIG_DEFINITIONS)
target_link_libraries(${LIB_TARGET}
PUBLIC
mbed-os
)
else()
target_link_libraries(${LIB_TARGET}
PUBLIC
mbed-baremetal
)
endif()

# The cross-dependency requires that bootutil have access to the mbed port's
# include directory and is linked with the appropriate mbed-specific libraries.
target_include_directories(${LIB_BOOTUTIL}
Expand Down
20 changes: 20 additions & 0 deletions boot/zephyr/boards/ctcc_nrf52840.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Disable logging
CONFIG_LOG=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# MCUBoot serial configuration
CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_ENTRANCE_GPIO=n
CONFIG_BOOT_SERIAL_CDC_ACM=y
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y
CONFIG_BOOT_SERIAL_NO_APPLICATION=y
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=5000
CONFIG_BOOT_USB_DFU_WAIT=n

# Required by USB
CONFIG_MULTITHREADING=y

# USB
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_REMOTE_WAKEUP=n
15 changes: 15 additions & 0 deletions boot/zephyr/boards/ctcc_nrf9161.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Disable logging
CONFIG_LOG=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# MCUboot serial configuration
CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_UART=y
CONFIG_BOOT_SERIAL_ENTRANCE_GPIO=n
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y
CONFIG_BOOT_SERIAL_NO_APPLICATION=y
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=5000

# SPI NOR
CONFIG_SPI_NOR=n
5 changes: 5 additions & 0 deletions boot/zephyr/boards/frdm_mcxa156.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 NXP
# SPDX-License-Identifier: Apache-2.0

#MCXA156 does not support the MCUBoot swap mode.
CONFIG_BOOT_UPGRADE_ONLY=y
3 changes: 3 additions & 0 deletions boot/zephyr/boards/nrf54l15dk_nrf54l05_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ CONFIG_SPI_NOR=n
CONFIG_FPROTECT=y

CONFIG_BOOT_WATCHDOG_FEED=n

# Ensure the fastest RRAM write operations
CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE=32
3 changes: 3 additions & 0 deletions boot/zephyr/boards/nrf54l15dk_nrf54l10_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ CONFIG_SPI_NOR=n
CONFIG_FPROTECT=y

CONFIG_BOOT_WATCHDOG_FEED=n

# Ensure the fastest RRAM write operations
CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE=32
3 changes: 3 additions & 0 deletions boot/zephyr/boards/nrf54l15dk_nrf54l15_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ CONFIG_BOOT_MAX_IMG_SECTORS=256
CONFIG_SPI_NOR=n

CONFIG_BOOT_WATCHDOG_FEED=n

# Ensure the fastest RRAM write operations
CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE=32
33 changes: 32 additions & 1 deletion boot/zephyr/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@ sample:
tests:
sample.bootloader.mcuboot:
tags: bootloader_mcuboot
platform_allow: nrf52840dk/nrf52840 frdm_k64f disco_l475_iot1
platform_allow:
- frdm_k22f
- frdm_k64f
- frdm_k82f
- frdm_ke17z
- frdm_ke17z512
- frdm_mcxn947/mcxn947/cpu0
- lpcxpresso55s06
- lpcxpresso55s16
- lpcxpresso55s28
- lpcxpresso55s36
- lpcxpresso55s69/lpc55s69/cpu0
- mimxrt1010_evk
- mimxrt1015_evk
- mimxrt1020_evk
- mimxrt1024_evk
- mimxrt1040_evk
- mimxrt1050_evk
- mimxrt1060_evk
- mimxrt1062_fmurt6
- mimxrt1064_evk
- mimxrt1160_evk/mimxrt1166/cm7
- mimxrt1170_evk/mimxrt1176/cm7
- mimxrt595_evk/mimxrt595s/cm33
- mimxrt685_evk/mimxrt685s/cm33
- rd_rw612_bga
- rddrone_fmuk66
- twr_ke18f
- twr_kv58f220m
- vmu_rt1170/mimxrt1176/cm7
- nrf52840dk/nrf52840
- disco_l475_iot1
integration_platforms:
- nrf52840dk/nrf52840
- frdm_k64f
Expand Down
18 changes: 18 additions & 0 deletions boot/zephyr/single_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <assert.h>
#include "bootutil/image.h"
#include "bootutil_priv.h"
#include "bootutil/boot_record.h"
#include "bootutil/bootutil.h"
#include "bootutil/bootutil_log.h"
#include "bootutil/bootutil_public.h"
#include "bootutil/fault_injection_hardening.h"
Expand Down Expand Up @@ -140,6 +142,22 @@ boot_go(struct boot_rsp *rsp)
fih_rc = FIH_SUCCESS;
#endif /* MCUBOOT_VALIDATE_PRIMARY_SLOT */

#ifdef MCUBOOT_MEASURED_BOOT
rc = boot_save_boot_status(0, &_hdr, _fa_p);
if (rc != 0) {
BOOT_LOG_ERR("Failed to add image data to shared area");
return rc;
}
#endif /* MCUBOOT_MEASURED_BOOT */

#ifdef MCUBOOT_DATA_SHARING
rc = boot_save_shared_data(&_hdr, _fa_p, 0, NULL);
if (rc != 0) {
BOOT_LOG_ERR("Failed to add data to shared memory area.");
return rc;
}
#endif /* MCUBOOT_DATA_SHARING */

rsp->br_flash_dev_id = flash_area_get_device_id(_fa_p);
rsp->br_image_off = flash_area_get_off(_fa_p);
rsp->br_hdr = &_hdr;
Expand Down
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ types described above via a set of tables. These tables are reproduced below.
State III
| primary slot | secondary slot |
-----------------+--------------+----------------|
magic | Good | Unset |
magic | Good | Any |
image-ok | 0xff | Any |
copy-done | 0x01 | Any |
-----------------+--------------+----------------'
Expand Down
2 changes: 1 addition & 1 deletion scripts/imgtool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
compressed_img.create(key, public_key_format, enckey,
dependencies, boot_record, custom_tlvs, compression_tlvs,
compression, int(encrypt_keylen), clear, baked_signature,
pub_key, vector_to_sign)
pub_key, vector_to_sign, user_sha=user_sha)
img = compressed_img
img.save(outfile, hex_addr)
if sig_out is not None:
Expand Down