Skip to content

Commit 96a85a7

Browse files
committed
Try using uninitialized linker section for shared data
1 parent 50e9cde commit 96a85a7

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,11 @@ With `mcuboot.shared-data` enabled, the MCUboot bootloader expects a C function
433433
Once you have shared data setup and configured for both the bootloader and application, you are ready to access the shared data. During boot, the bootloader will populate the shared data RAM region with the information as you specify in the `boot_save_shared_data` function. The application may then read that information back.
434434

435435
An example of how to do this is built into the `mbed-mcuboot-blinky` application when `mcuboot.share-data` is set to true.
436+
437+
## Minimizing Code Size
438+
439+
A common goal of bootloader implementers is to minimize the code size of the bootloader, thereby maximizing the available space for the application. Through configuration, it is possible to acheive relatively small MCUboot-based bootloader builds.
440+
441+
For example, you can configure `target.printf_lib` to `minimal-printf` rather than `std` to use a reduced-feature-set version of `printf`.
442+
443+
You can also entirely disable logging output by setting `mbed-trace.enable` to `false`. You can also eliminate the stdio console entirely (TODO - explain how to do this).

mbed_app.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "spif-driver", "qspif", "mbed-trace"],
2+
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "spif-driver", "qspif", "mbed-trace", "sd"],
33
"config": {
44
"serial-bootloader-enable": {
55
"help": "Build bootloader with serial update support",
@@ -8,10 +8,12 @@
88
},
99
"target_overrides": {
1010
"*": {
11+
"platform.stdio-baud-rate": 115200,
1112
"target.restrict_size": "0x20000",
1213
"target.c_lib": "small",
1314
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_DEBUG",
1415
"mbed-trace.enable": true,
16+
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
1517
"mbed-trace.fea-ipv6": false
1618
},
1719
"NRF52840_DK": {
@@ -44,6 +46,14 @@
4446
"mcuboot.max-img-sectors": "0x180",
4547
"mcuboot.read-granularity": 1,
4648
"qspif.QSPI_MIN_PROG_SIZE": 1
49+
},
50+
"K64F": {
51+
"mcuboot.primary-slot-address": "0x20000",
52+
"mcuboot.slot-size": "0xC0000",
53+
"mcuboot.scratch-address": "0xE0000",
54+
"mcuboot.scratch-size": "0x20000",
55+
"mcuboot.max-img-sectors": "0x180",
56+
"mcuboot.read-granularity": 512
4757
}
4858
}
4959
}

mbed_app_data_sharing.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "mbed-trace", "qspif"],
2+
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "spif-driver", "qspif", "mbed-trace", "sd"],
33
"config": {
44
"serial-bootloader-enable": {
55
"help": "Build bootloader with serial update support",
@@ -8,13 +8,14 @@
88
},
99
"target_overrides": {
1010
"*": {
11+
"platform.stdio-baud-rate": 115200,
1112
"target.restrict_size": "0x20000",
1213
"target.c_lib": "small",
1314
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_DEBUG",
14-
"mbed-trace.enable": false,
15+
"mbed-trace.enable": true,
16+
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
1517
"mbed-trace.fea-ipv6": false,
1618
"platform.crash-capture-enabled": false,
17-
"platform.minimal-printf-enable-64-bit": false,
1819
"platform.callback-comparable": false
1920
},
2021
"NRF52840_DK": {
@@ -64,6 +65,17 @@
6465
"mcuboot.read-granularity": 4,
6566
"target.device_has_remove": ["STDIO_MESSAGES"],
6667
"target.macros_add": ["MBED_FAULT_HANDLER_DISABLED"]
68+
},
69+
"K64F": {
70+
"mcuboot.primary-slot-address": "0x20000",
71+
"mcuboot.slot-size": "0xC0000",
72+
"mcuboot.scratch-address": "0xE0000",
73+
"mcuboot.scratch-size": "0x20000",
74+
"mcuboot.max-img-sectors": "0x180",
75+
"mcuboot.read-granularity": 512,
76+
"mcuboot.share-data": true,
77+
"mcuboot.share-data-base-address": "0x20000000",
78+
"mcuboot.share-data-size": "0x80"
6779
}
6880
}
6981
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Created on: Sep 13, 2021
3+
* Created by: gdbeckstein
4+
*
5+
* Built with ARM Mbed-OS
6+
*
7+
* Copyright (c) Embedded Planet, Inc - All rights reserved
8+
*
9+
* This source file is private and confidential.
10+
* Unauthorized copying of this file is strictly prohibited.
11+
*/
12+
13+
/**
14+
* If the shared data feature of MCUboot is used in this demo,
15+
* this feature uses an uninitialized region of RAM to share data between the bootloader and the
16+
* booted application. When building the for the K64F target, the K64F has two RAM
17+
* regions (that are adjacent): `SRAM_L` and `SRAM_U`. The default K64F linker script will not initialize variables
18+
* stored in the "uninitialized" section of RAM, which begins at `SRAM_U` aka 0x20000000. `SRMA_L` is the first 64kB
19+
* of RAM while `SRAM_U` is the rest (64kB for a total of 128kB).
20+
*
21+
* To ensure a section of RAM is uninitialized at startup, we must declare an array here. We use GCC attributes to specify that the linker should
22+
* keep this symbol and the name of the section ("uninitialized") into which it should be placed.
23+
*
24+
* See the linker script and associated documentation for more details
25+
*/
26+
27+
#if defined(MCUBOOT_DATA_SHARING)
28+
29+
static char SHARED_DATA_RESERVED_MEMORY_REGION[MCUBOOT_SHARED_DATA_SIZE] __attribute__((used,section(".keep.uninitialized")));
30+
31+
#endif

shared_data.c renamed to shared-data/shared_data.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "boot_record.h"
2424
#include "shared_data.h"
2525

26+
#include <string.h>
27+
2628
#if MCUBOOT_DATA_SHARING && MCUBOOT_BOOTLOADER_BUILD
2729

2830
int boot_save_shared_data(const struct image_header *hdr,
File renamed without changes.

0 commit comments

Comments
 (0)