Skip to content

Commit

Permalink
Update for Mbed CE
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Dec 4, 2024
1 parent a127d01 commit c477e9b
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 86 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Example GitHub Actions workflow which provides a CI build for your Mbed CE project.

name: Test that this Mbed project compiles

on: push

jobs:
compile:
runs-on: ubuntu-latest
container: ghcr.io/armmbed/mbed-os-env:master-latest

strategy:
matrix:
mbed_target:
# Change the below to match the target(s) you want to compile the project for.
- NUCLEO_H743ZI2

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install python3-venv
run: |
apt-get update
apt-get install -y python3-venv
- name: Generate transient key pair
run: |
python3 -m pip install --user -r mcuboot/scripts/requirements.txt
python3 -m pip install --user mcuboot/scripts
imgtool keygen -k signing-keys.pem -t rsa-2048
imgtool getpub -k signing-keys.pem > signing_keys.c
- name: Build project for ${{ matrix.mbed_target }}
run: |
mkdir build && cd build
python3 -m pip install -r
cmake .. -GNinja -DMBED_TARGET=${{ matrix.mbed_target }}
ninja
59 changes: 43 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
/Debug/
BUILD/
.cproject
*~
.mbed
.project
.settings/
GettingStarted.html
makefile.targets
mbed_settings.py
mbed_settings.pyc
mbed_config.h
*.hex
*.pem
# Public key file
signing_keys.c
mbed-os/*
mcuboot/*

# Private key file
signing-keys.pem

# CLion build dirs
cmake-build-*/

# User-specific CLion stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/runConfigurations

# Generated CLion files
.idea/**/contentModel.xml

# Sensitive or high-churn CLion files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# VS Code build dir
build/

# VS Code config files
.vscode/

# Python stuff
*.pyc

# Mac stuff
.DS_Store
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "mbed-os"]
path = mbed-os
url = https://github.com/mbed-ce/mbed-os.git
[submodule "mcuboot"]
path = mcuboot
url = https://github.com/multiplemonomials/mcuboot.git
3 changes: 0 additions & 3 deletions .mbedignore

This file was deleted.

30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19)

set(MBED_APP_JSON_PATH mbed_app.json5)

include(mbed-os/tools/cmake/app.cmake)

add_subdirectory(mbed-os)

project(mbed-mcuboot-bootloader)

set(MBED_MCUBOOT_BOOTLOADER_SOURCES
default_bd.cpp
enc_key.c
shared_data.c
signing_keys.c)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/signing_keys.c)
message(FATAL_ERROR "Missing signing_keys.c in source directory! Please follow the README instructions to generate the signing keys!")
endif()

# Compile mcuboot sources
add_subdirectory(mcuboot/boot/bootutil)
add_subdirectory(mcuboot/boot/mbed)

add_executable(${CMAKE_PROJECT_NAME} ${MBED_MCUBOOT_BOOTLOADER_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} mbed-baremetal mbed-mcuboot)
mbed_set_post_build(${CMAKE_PROJECT_NAME})

mbed_finalize_build()
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ The demo application prints the version number of the application installed in t

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

`pip3 install --user -r mcuboot/scripts/requirements.txt && python3 mcuboot/scripts/setup.py install`
```
python3 -m pip install --user -r mcuboot/scripts/requirements.txt
python3 -m pip install --user mcuboot/scripts
```
(on Windows, use `python` instead of `python3`)

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

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

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

2.) Extract the public key into a C data structure so it can be built into the bootloader:
2.) Extract the public key into a C data structure so it can be built into the bootloader.

`imgtool getpub -k signing-keys.pem >> signing_keys.c`
In bash or cmd shell:
```
imgtool getpub -k signing-keys.pem > signing_keys.c
```

In Powershell:
```
imgtool getpub -k signing-keys.pem | Out-File signing_keys.c -Encoding utf8
```

**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.

Expand Down
16 changes: 14 additions & 2 deletions default_bd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "BlockDevice.h"

#include "SlicingBlockDevice.h"
#include "FlashIAPBlockDevice.h"


#if COMPONENT_SPIF
#include "SPIFBlockDevice.h"
Expand All @@ -29,6 +31,16 @@ const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBE
#endif
#endif

#if MBED_CONF_APP_SECONDARY_SLOT_IN_FLASH

mbed::BlockDevice* get_secondary_bd(void) {

// Use a section of FlashIAP immediately after the secondary slot
static FlashIAPBlockDevice flashBD(MCUBOOT_PRIMARY_SLOT_START_ADDR + MCUBOOT_SLOT_SIZE, MCUBOOT_SLOT_SIZE);
return &flashBD;
}

#else
BlockDevice *BlockDevice::get_default_instance()
{
#if COMPONENT_SPIF
Expand Down Expand Up @@ -64,7 +76,7 @@ BlockDevice *BlockDevice::get_default_instance()

#else

return NULL;
#error No block device set up for secondary slot!

#endif

Expand All @@ -81,4 +93,4 @@ mbed::BlockDevice* get_secondary_bd(void) {
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
return &sliced_bd;
}

#endif
1 change: 1 addition & 0 deletions mbed-os
Submodule mbed-os added at 2564b2
1 change: 0 additions & 1 deletion mbed-os.lib

This file was deleted.

59 changes: 0 additions & 59 deletions mbed_app.json

This file was deleted.

89 changes: 89 additions & 0 deletions mbed_app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"config": {
"serial-bootloader-enable": {
"help": "Build bootloader with serial update support",
"value": 0
},
"secondary-slot-in-flash": {
"help": "If enabled, store the secondary slot in the application flash immediately after the primary slot.",
"value": false
}
},


"target_overrides": {
"*": {
"platform.stdio-baud-rate": 115200,
"target.restrict_size": "0x20000",
"target.c_lib": "small",
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_DEBUG",
"mbed-trace.enable": true,
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
"mbed-trace.fea-ipv6": false
},
// "NRF52840_DK": {
// "target.features_remove": ["CRYPTOCELL310"],
// "target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
// "mcuboot.primary-slot-address": "0x20000",
// "mcuboot.slot-size": "0xC0000",
// "mcuboot.scratch-address": "0xE0000",
// "mcuboot.scratch-size": "0x20000",
// "mcuboot.max-img-sectors": "0x180",
// "mcuboot.read-granularity": 4,
// "qspif.QSPI_MIN_PROG_SIZE": 4
// },
// "EP_AGORA": {
// "target.features_remove": ["CRYPTOCELL310"],
// "target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
// "mcuboot.primary-slot-address": "0x20000",
// "mcuboot.slot-size": "0xC0000",
// "mcuboot.scratch-address": "0xE0000",
// "mcuboot.scratch-size": "0x20000",
// "mcuboot.max-img-sectors": "0x180",
// "mcuboot.read-granularity": 4,
// "qspif.QSPI_MIN_PROG_SIZE": 4
// },
// "DISCO_L475VG_IOT01A": {
// "mcuboot.primary-slot-address": "0x8020000",
// "mcuboot.slot-size": "0xC0000",
// "mcuboot.scratch-address": "0x80E0000",
// "mcuboot.scratch-size": "0x20000",
// "mcuboot.max-img-sectors": "0x180",
// "mcuboot.read-granularity": 1,
// "qspif.QSPI_MIN_PROG_SIZE": 1
// },
// "K64F": {
// "mcuboot.primary-slot-address": "0x20000",
// "mcuboot.slot-size": "0xC0000",
// "mcuboot.scratch-address": "0xE0000",
// "mcuboot.scratch-size": "0x20000",
// "mcuboot.max-img-sectors": "0x180",
// "mcuboot.read-granularity": 512
// },

"MCU_STM32H743xI": {
// Configure bootloader to live in the first sector of flash
"target.memory_bank_config": {
"IROM1": {
"size": 0x20000
}
},

// Since STM32H743 boards have no external block device, keep everything in the MCU flash.
"app.secondary-slot-in-flash": true,

// Slot size can be as big as 896k, since we need to reserve the first flash sector for the bootloader
// and the last flash sector for scratch space
"mcuboot.primary-slot-address": "0x20000",
"mcuboot.slot-size": "0xE0000",

"mcuboot.max-img-sectors": "0x180",
"mcuboot.read-granularity": 512,

// STM32H7 flash sector size is 128k, so we need to make the scratch region at least that big
"mcuboot.scratch-address": "0x1E0000",
"mcuboot.scratch-size": "0x20000",

}
}
}
1 change: 1 addition & 0 deletions mcuboot
Submodule mcuboot added at 464c79
1 change: 0 additions & 1 deletion mcuboot.lib

This file was deleted.

2 changes: 1 addition & 1 deletion shared_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* limitations under the License.
*/

#include "boot_record.h"
#include "bootutil/boot_record.h"
#include "shared_data.h"

#include <string.h>
Expand Down

0 comments on commit c477e9b

Please sign in to comment.