Skip to content

Commit c477e9b

Browse files
Update for Mbed CE
1 parent a127d01 commit c477e9b

14 files changed

+241
-86
lines changed

.github/workflows/compile.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Example GitHub Actions workflow which provides a CI build for your Mbed CE project.
2+
3+
name: Test that this Mbed project compiles
4+
5+
on: push
6+
7+
jobs:
8+
compile:
9+
runs-on: ubuntu-latest
10+
container: ghcr.io/armmbed/mbed-os-env:master-latest
11+
12+
strategy:
13+
matrix:
14+
mbed_target:
15+
# Change the below to match the target(s) you want to compile the project for.
16+
- NUCLEO_H743ZI2
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
24+
- name: Install python3-venv
25+
run: |
26+
apt-get update
27+
apt-get install -y python3-venv
28+
29+
- name: Generate transient key pair
30+
run: |
31+
python3 -m pip install --user -r mcuboot/scripts/requirements.txt
32+
python3 -m pip install --user mcuboot/scripts
33+
imgtool keygen -k signing-keys.pem -t rsa-2048
34+
imgtool getpub -k signing-keys.pem > signing_keys.c
35+
36+
- name: Build project for ${{ matrix.mbed_target }}
37+
run: |
38+
mkdir build && cd build
39+
python3 -m pip install -r
40+
cmake .. -GNinja -DMBED_TARGET=${{ matrix.mbed_target }}
41+
ninja

.gitignore

+43-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
1-
/Debug/
2-
BUILD/
3-
.cproject
4-
*~
5-
.mbed
6-
.project
7-
.settings/
8-
GettingStarted.html
9-
makefile.targets
10-
mbed_settings.py
11-
mbed_settings.pyc
12-
mbed_config.h
13-
*.hex
14-
*.pem
1+
# Public key file
152
signing_keys.c
16-
mbed-os/*
17-
mcuboot/*
3+
4+
# Private key file
5+
signing-keys.pem
6+
7+
# CLion build dirs
8+
cmake-build-*/
9+
10+
# User-specific CLion stuff
11+
.idea/**/workspace.xml
12+
.idea/**/tasks.xml
13+
.idea/**/usage.statistics.xml
14+
.idea/**/dictionaries
15+
.idea/**/shelf
16+
.idea/runConfigurations
17+
18+
# Generated CLion files
19+
.idea/**/contentModel.xml
20+
21+
# Sensitive or high-churn CLion files
22+
.idea/**/dataSources/
23+
.idea/**/dataSources.ids
24+
.idea/**/dataSources.local.xml
25+
.idea/**/sqlDataSources.xml
26+
.idea/**/dynamic.xml
27+
.idea/**/uiDesigner.xml
28+
.idea/**/dbnavigator.xml
29+
30+
# Gradle
31+
.idea/**/gradle.xml
32+
.idea/**/libraries
33+
34+
# VS Code build dir
35+
build/
36+
37+
# VS Code config files
38+
.vscode/
39+
40+
# Python stuff
41+
*.pyc
42+
43+
# Mac stuff
44+
.DS_Store

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "mbed-os"]
2+
path = mbed-os
3+
url = https://github.com/mbed-ce/mbed-os.git
4+
[submodule "mcuboot"]
5+
path = mcuboot
6+
url = https://github.com/multiplemonomials/mcuboot.git

.mbedignore

-3
This file was deleted.

CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
cmake_policy(VERSION 3.19)
3+
4+
set(MBED_APP_JSON_PATH mbed_app.json5)
5+
6+
include(mbed-os/tools/cmake/app.cmake)
7+
8+
add_subdirectory(mbed-os)
9+
10+
project(mbed-mcuboot-bootloader)
11+
12+
set(MBED_MCUBOOT_BOOTLOADER_SOURCES
13+
default_bd.cpp
14+
enc_key.c
15+
shared_data.c
16+
signing_keys.c)
17+
18+
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/signing_keys.c)
19+
message(FATAL_ERROR "Missing signing_keys.c in source directory! Please follow the README instructions to generate the signing keys!")
20+
endif()
21+
22+
# Compile mcuboot sources
23+
add_subdirectory(mcuboot/boot/bootutil)
24+
add_subdirectory(mcuboot/boot/mbed)
25+
26+
add_executable(${CMAKE_PROJECT_NAME} ${MBED_MCUBOOT_BOOTLOADER_SOURCES})
27+
target_link_libraries(${CMAKE_PROJECT_NAME} mbed-baremetal mbed-mcuboot)
28+
mbed_set_post_build(${CMAKE_PROJECT_NAME})
29+
30+
mbed_finalize_build()

README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ The demo application prints the version number of the application installed in t
124124

125125
It is beneficial to first install mcuboot's imgtool python command line tool:
126126

127-
`pip3 install --user -r mcuboot/scripts/requirements.txt && python3 mcuboot/scripts/setup.py install`
127+
```
128+
python3 -m pip install --user -r mcuboot/scripts/requirements.txt
129+
python3 -m pip install --user mcuboot/scripts
130+
```
131+
(on Windows, use `python` instead of `python3`)
128132

129133
You should also install the python package `intelhex` if it is not already installed:
130134

@@ -140,9 +144,17 @@ For this project the required steps to sign an application are:
140144

141145
1.) Generate an rsa2048 key pair: `imgtool keygen -k signing-keys.pem -t rsa-2048`
142146

143-
2.) Extract the public key into a C data structure so it can be built into the bootloader:
147+
2.) Extract the public key into a C data structure so it can be built into the bootloader.
144148

145-
`imgtool getpub -k signing-keys.pem >> signing_keys.c`
149+
In bash or cmd shell:
150+
```
151+
imgtool getpub -k signing-keys.pem > signing_keys.c
152+
```
153+
154+
In Powershell:
155+
```
156+
imgtool getpub -k signing-keys.pem | Out-File signing_keys.c -Encoding utf8
157+
```
146158

147159
**Note:** The output of this command formats the variables to a specific name that is declared as an extern in mcuboot's sources. It must **not** be modified manually.
148160

default_bd.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "BlockDevice.h"
99

1010
#include "SlicingBlockDevice.h"
11+
#include "FlashIAPBlockDevice.h"
12+
1113

1214
#if COMPONENT_SPIF
1315
#include "SPIFBlockDevice.h"
@@ -29,6 +31,16 @@ const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBE
2931
#endif
3032
#endif
3133

34+
#if MBED_CONF_APP_SECONDARY_SLOT_IN_FLASH
35+
36+
mbed::BlockDevice* get_secondary_bd(void) {
37+
38+
// Use a section of FlashIAP immediately after the secondary slot
39+
static FlashIAPBlockDevice flashBD(MCUBOOT_PRIMARY_SLOT_START_ADDR + MCUBOOT_SLOT_SIZE, MCUBOOT_SLOT_SIZE);
40+
return &flashBD;
41+
}
42+
43+
#else
3244
BlockDevice *BlockDevice::get_default_instance()
3345
{
3446
#if COMPONENT_SPIF
@@ -64,7 +76,7 @@ BlockDevice *BlockDevice::get_default_instance()
6476

6577
#else
6678

67-
return NULL;
79+
#error No block device set up for secondary slot!
6880

6981
#endif
7082

@@ -81,4 +93,4 @@ mbed::BlockDevice* get_secondary_bd(void) {
8193
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
8294
return &sliced_bd;
8395
}
84-
96+
#endif

mbed-os

Submodule mbed-os added at 2564b2c

mbed-os.lib

-1
This file was deleted.

mbed_app.json

-59
This file was deleted.

mbed_app.json5

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"config": {
3+
"serial-bootloader-enable": {
4+
"help": "Build bootloader with serial update support",
5+
"value": 0
6+
},
7+
"secondary-slot-in-flash": {
8+
"help": "If enabled, store the secondary slot in the application flash immediately after the primary slot.",
9+
"value": false
10+
}
11+
},
12+
13+
14+
"target_overrides": {
15+
"*": {
16+
"platform.stdio-baud-rate": 115200,
17+
"target.restrict_size": "0x20000",
18+
"target.c_lib": "small",
19+
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_DEBUG",
20+
"mbed-trace.enable": true,
21+
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
22+
"mbed-trace.fea-ipv6": false
23+
},
24+
// "NRF52840_DK": {
25+
// "target.features_remove": ["CRYPTOCELL310"],
26+
// "target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
27+
// "mcuboot.primary-slot-address": "0x20000",
28+
// "mcuboot.slot-size": "0xC0000",
29+
// "mcuboot.scratch-address": "0xE0000",
30+
// "mcuboot.scratch-size": "0x20000",
31+
// "mcuboot.max-img-sectors": "0x180",
32+
// "mcuboot.read-granularity": 4,
33+
// "qspif.QSPI_MIN_PROG_SIZE": 4
34+
// },
35+
// "EP_AGORA": {
36+
// "target.features_remove": ["CRYPTOCELL310"],
37+
// "target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
38+
// "mcuboot.primary-slot-address": "0x20000",
39+
// "mcuboot.slot-size": "0xC0000",
40+
// "mcuboot.scratch-address": "0xE0000",
41+
// "mcuboot.scratch-size": "0x20000",
42+
// "mcuboot.max-img-sectors": "0x180",
43+
// "mcuboot.read-granularity": 4,
44+
// "qspif.QSPI_MIN_PROG_SIZE": 4
45+
// },
46+
// "DISCO_L475VG_IOT01A": {
47+
// "mcuboot.primary-slot-address": "0x8020000",
48+
// "mcuboot.slot-size": "0xC0000",
49+
// "mcuboot.scratch-address": "0x80E0000",
50+
// "mcuboot.scratch-size": "0x20000",
51+
// "mcuboot.max-img-sectors": "0x180",
52+
// "mcuboot.read-granularity": 1,
53+
// "qspif.QSPI_MIN_PROG_SIZE": 1
54+
// },
55+
// "K64F": {
56+
// "mcuboot.primary-slot-address": "0x20000",
57+
// "mcuboot.slot-size": "0xC0000",
58+
// "mcuboot.scratch-address": "0xE0000",
59+
// "mcuboot.scratch-size": "0x20000",
60+
// "mcuboot.max-img-sectors": "0x180",
61+
// "mcuboot.read-granularity": 512
62+
// },
63+
64+
"MCU_STM32H743xI": {
65+
// Configure bootloader to live in the first sector of flash
66+
"target.memory_bank_config": {
67+
"IROM1": {
68+
"size": 0x20000
69+
}
70+
},
71+
72+
// Since STM32H743 boards have no external block device, keep everything in the MCU flash.
73+
"app.secondary-slot-in-flash": true,
74+
75+
// Slot size can be as big as 896k, since we need to reserve the first flash sector for the bootloader
76+
// and the last flash sector for scratch space
77+
"mcuboot.primary-slot-address": "0x20000",
78+
"mcuboot.slot-size": "0xE0000",
79+
80+
"mcuboot.max-img-sectors": "0x180",
81+
"mcuboot.read-granularity": 512,
82+
83+
// STM32H7 flash sector size is 128k, so we need to make the scratch region at least that big
84+
"mcuboot.scratch-address": "0x1E0000",
85+
"mcuboot.scratch-size": "0x20000",
86+
87+
}
88+
}
89+
}

mcuboot

Submodule mcuboot added at 464c796

mcuboot.lib

-1
This file was deleted.

shared_data.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* limitations under the License.
2121
*/
2222

23-
#include "boot_record.h"
23+
#include "bootutil/boot_record.h"
2424
#include "shared_data.h"
2525

2626
#include <string.h>

0 commit comments

Comments
 (0)