Skip to content

Commit 1496129

Browse files
committed
boot: zephyr: Add optional MCUboot boot banner
Adds an optional MCUboot boot banner which displays the MCUboot version and zephyr version Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 7174dd2 commit 1496129

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

boot/zephyr/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ zephyr_library_sources(
358358
)
359359
endif()
360360

361+
if(CONFIG_MCUBOOT_BOOT_BANNER)
362+
# Replace Zephyr's boot banner with the MCUboot one
363+
zephyr_sources(kernel/banner.c)
364+
endif()
365+
361366
if(SYSBUILD)
362367
function(align_up num align result)
363368
math(EXPR out "(((${num}) + ((${align}) - 1)) & ~((${align}) - 1))")

boot/zephyr/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,23 @@ config BOOT_DISABLE_CACHES
700700
increases protection against data leakage from MCUboot to applications via
701701
these caches.
702702

703+
config MCUBOOT_BOOT_BANNER
704+
bool "Use MCUboot boot banner"
705+
depends on BOOT_BANNER
706+
depends on "$(APP_VERSION_EXTENDED_STRING)" != ""
707+
default y
708+
help
709+
Uses a MCUboot boot banner instead of the default zephyr one, which will output the
710+
MCUboot name and version, followed by the zephyr name and version.
711+
712+
For example:
713+
714+
*** Booting MCUboot v2.0.0-72-g8c0e36c88663 ***
715+
*** Using Zephyr OS build v3.6.0-2607-gd0be2010c31f ***
716+
717+
config BOOT_BANNER_STRING
718+
default "Using Zephyr OS build" if MCUBOOT_BOOT_BANNER
719+
703720
endmenu
704721

705722
config MCUBOOT_DEVICE_SETTINGS

boot/zephyr/kernel/banner.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation
3+
* Copyright (c) 2024 Nordic Semiconductor ASA
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/init.h>
10+
#include <zephyr/device.h>
11+
#include <version.h>
12+
#include <app_version.h>
13+
14+
#if defined(CONFIG_BOOT_DELAY) && (CONFIG_BOOT_DELAY > 0)
15+
#define DELAY_STR STRINGIFY(CONFIG_BOOT_DELAY)
16+
#define BANNER_POSTFIX " (delayed boot " DELAY_STR "ms)"
17+
#else
18+
#define BANNER_POSTFIX ""
19+
#endif /* defined(CONFIG_BOOT_DELAY) && (CONFIG_BOOT_DELAY > 0) */
20+
21+
#ifndef BANNER_VERSION
22+
#if defined(BUILD_VERSION) && !IS_EMPTY(BUILD_VERSION)
23+
#define BANNER_VERSION STRINGIFY(BUILD_VERSION)
24+
#else
25+
#define BANNER_VERSION KERNEL_VERSION_STRING
26+
#endif /* BUILD_VERSION */
27+
#endif /* !BANNER_VERSION */
28+
29+
#if defined(APP_BUILD_VERSION)
30+
#define APPLICATION_BANNER_VERSION STRINGIFY(APP_BUILD_VERSION)
31+
#elif defined(APP_VERSION_EXTENDED_STRING)
32+
#define APPLICATION_BANNER_VERSION APP_VERSION_EXTENDED_STRING
33+
#endif
34+
35+
#if defined(APPLICATION_BANNER_VERSION)
36+
void boot_banner(void)
37+
{
38+
#if defined(CONFIG_BOOT_DELAY) && (CONFIG_BOOT_DELAY > 0)
39+
printk("***** delaying boot " DELAY_STR "ms (per build configuration) *****\n");
40+
k_busy_wait(CONFIG_BOOT_DELAY * USEC_PER_MSEC);
41+
#endif /* defined(CONFIG_BOOT_DELAY) && (CONFIG_BOOT_DELAY > 0) */
42+
43+
printk("*** Booting MCUboot " APPLICATION_BANNER_VERSION " ***\n");
44+
printk("*** " CONFIG_BOOT_BANNER_STRING " " BANNER_VERSION BANNER_POSTFIX " ***\n");
45+
}
46+
#endif /* APP_BUILD_VERSION */

0 commit comments

Comments
 (0)