Skip to content

Commit

Permalink
Add Mbed MCUboot to third_party
Browse files Browse the repository at this point in the history
Add Mbed bootloader application
  • Loading branch information
ATmobica committed Dec 9, 2021
1 parent 827662e commit 9910ff8
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@
[submodule "p6/lwip"]
path = third_party/p6/p6_sdk/libs/lwip
url = https://git.savannah.nongnu.org/git/lwip
[submodule "third_party/mbed-mcu-boot/repo"]
path = third_party/mbed-mcu-boot/repo
url = https://github.com/lambda-shuttle/mcuboot.git
45 changes: 44 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
"configFiles": ["${input:mbedTarget}.tcl"],
"overrideLaunchCommands": [
"monitor reset halt",
"monitor program {./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-unit-tests}",
"monitor program {./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-unit-tests.hex}",
"monitor reset run",
"quit"
],
Expand All @@ -289,6 +289,49 @@
"quit"
],
"showDevDebugOutput": false // When set to true, displays output of GDB.
},

{
"name": "Flash Mbed bootlaoder",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceRoot}/examples/platform/mbed/bootloader",
"executable": "./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-bootloader.elf",
"armToolchainPath": "${env:PW_ENVIRONMENT_ROOT}/cipd/pigweed/bin/", // Pigweed environment bootstraping required
"servertype": "openocd",
"openocdPath": "${env:OPENOCD_PATH/bin}",
"searchDir": [
"${workspaceRoot}/config/mbed/scripts",
"${env:OPENOCD_PATH/scripts}"
],
"configFiles": ["${input:mbedTarget}.tcl"],
"overrideLaunchCommands": [
"monitor reset halt",
"monitor program {./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-bootloader.hex}",
"monitor reset run",
"quit"
],
"numberOfProcessors": 2,
"targetProcessor": 1, // Set to 0 for the CM0+, set to 1 for the CM4
"showDevDebugOutput": false // When set to true, displays output of GDB.
},

{
"name": "Flash Mbed bootloader [remote]",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceRoot}/examples/platform/mbed/bootloader",
"executable": "./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-bootloader.elf",
"armToolchainPath": "${env:PW_ENVIRONMENT_ROOT}/cipd/pigweed/bin/", // Pigweed environment bootstraping required
"servertype": "external",
"gdbTarget": "host.docker.internal:3334", //port 3333 for the CM0+, 3334 for the CM4
"overrideLaunchCommands": [
"monitor reset halt",
"load ./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-bootloader.hex",
"monitor reset run",
"quit"
],
"showDevDebugOutput": false // When set to true, displays output of GDB.
}
],
"inputs": [
Expand Down
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
"pigweed-app",
"all-clusters-app",
"shell",
"ota-requestor-app"
"ota-requestor-app",
"bootloader"
],
"default": "lock-app"
},
Expand Down
5 changes: 5 additions & 0 deletions examples/platform/mbed/bootloader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build-*/
dist/
imgtool*
mcuboot
signing*
41 changes: 41 additions & 0 deletions examples/platform/mbed/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MCUBOOT_PATH ${MBED_MCU_BOOT_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-bootloader)

include(${MBED_PATH}/tools/cmake/app.cmake)

project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory(${MCUBOOT_PATH}/boot/bootutil/ ./mbed_mcu_boot_util)
add_subdirectory(${MCUBOOT_PATH}/boot/mbed/ ./mbed_mcu_boot) # Mbed-MCUboot Port

add_executable(${APP_TARGET})

target_sources(${APP_TARGET}
PUBLIC
default_bd.cpp
signing_keys.c
)

target_link_libraries(${APP_TARGET}
PUBLIC
bootutil
mbed-mcuboot
mbed-storage-spif
mbed-storage-qspif
mbed-baremetal
)

mbed_set_post_build(${APP_TARGET})

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
78 changes: 78 additions & 0 deletions examples/platform/mbed/bootloader/default_bd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* default_bd.cpp
*
* Created on: Jul 30, 2020
* Author: gdbeckstein
*/

#include "BlockDevice.h"

#include "SlicingBlockDevice.h"

#if COMPONENT_SPIF
#include "SPIFBlockDevice.h"
#endif

#if COMPONENT_QSPIF
#include "QSPIFBlockDevice.h"
#endif

#if COMPONENT_DATAFLASH
#include "DataFlashBlockDevice.h"
#endif

#if COMPONENT_SD
#include "SDBlockDevice.h"

#if (STATIC_PINMAP_READY)
const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, NC);
#endif
#endif

BlockDevice * BlockDevice::get_default_instance()
{
#if COMPONENT_SPIF

static SPIFBlockDevice default_bd;

return &default_bd;

#elif COMPONENT_QSPIF

static QSPIFBlockDevice default_bd;

return &default_bd;

#elif COMPONENT_DATAFLASH

static DataFlashBlockDevice default_bd;

return &default_bd;

#elif COMPONENT_SD

#if (STATIC_PINMAP_READY)
static SDBlockDevice default_bd(static_spi_pinmap, MBED_CONF_SD_SPI_CS);
#else
static SDBlockDevice default_bd;
#endif

return &default_bd;

#else

return NULL;

#endif
}

/**
* You can override this function to suit your hardware/memory configuration
* By default it simply returns what is returned by BlockDevice::get_default_instance();
*/
mbed::BlockDevice * get_secondary_bd(void)
{
mbed::BlockDevice * default_bd = mbed::BlockDevice::get_default_instance();
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
return &sliced_bd;
}
35 changes: 35 additions & 0 deletions examples/platform/mbed/bootloader/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"requires": ["bare-metal", "mbedtls", "mcuboot", "flashiap-block-device", "spif-driver", "qspif", "mbed-trace"],
"config": {
"serial-bootloader-enable": {
"help": "Build bootloader with serial update support",
"value": 0
}
},
"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
},
"CY8CPROTO_062_4343W": {
"target.network-default-interface-type": "WIFI",
"target.macros_add": [
"MXCRYPTO_DISABLED",
"NL_ASSERT_LOG=NL_ASSERT_LOG_DEFAULT",
"NL_ASSERT_EXPECT_FLAGS=NL_ASSERT_FLAG_LOG",
"WHD_PRINT_DISABLE"
],
"mcuboot.primary-slot-address": "0x10020000",
"mcuboot.slot-size": "0xC0000",
"mcuboot.scratch-address": "0x100E0000",
"mcuboot.scratch-size": "0x20000",
"mcuboot.max-img-sectors": "0x180",
"mcuboot.read-granularity": 512
}
}
}
43 changes: 42 additions & 1 deletion scripts/examples/mbed_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cd "$CHIP_ROOT"/examples

SUPPORTED_TOOLCHAIN=(GCC_ARM ARM)
SUPPORTED_TARGET_BOARD=(CY8CPROTO_062_4343W)
SUPPORTED_APP=(lock-app lighting-app pigweed-app all-clusters-app shell ota-requestor-app)
SUPPORTED_APP=(lock-app lighting-app pigweed-app all-clusters-app shell ota-requestor-app bootloader)
SUPPORTED_PROFILES=(release develop debug)
SUPPORTED_COMMAND=(build flash build-flash)

Expand Down Expand Up @@ -93,6 +93,47 @@ source "$CHIP_ROOT"/scripts/activate.sh
# Build directory setup
BUILD_DIRECTORY="$APP"/mbed/build-"$TARGET_BOARD"/"$PROFILE"/

if [[ "$APP" == "bootloader" ]]; then
echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile"

cd platform/mbed/bootloader
BUILD_DIRECTORY=build-"$TARGET_BOARD"/"$PROFILE"/

# Set Mbed OS path
MBED_OS_PATH="$CHIP_ROOT"/third_party/mbed-os/repo

# Set Mbed MCU boot path
MBED_MCU_BOOT_PATH="$CHIP_ROOT"/third_party/mbed-mcu-boot/repo

# Install mcuboot requirements (silently)
pip install -q -r "$MBED_MCU_BOOT_PATH"/scripts/requirements.txt ||
fail "Unable to install mcuboot requirements" "Please take a look at "$MBED_MCU_BOOT_PATH"/scripts/requirements.txt"

# Run mcuboot setup script
python "$MBED_MCU_BOOT_PATH"/scripts/setup.py install ||
fail "MCUboot setup script failed"

# Create the signing keys
# shellcheck disable=SC2015
"$MBED_MCU_BOOT_PATH"/scripts/imgtool.py keygen -k signing-keys.pem -t rsa-2048 &&
"$MBED_MCU_BOOT_PATH"/scripts/imgtool.py getpub -k signing-keys.pem >signing_keys.c ||
fail "Unable to create the signing keys"

ln -sfTr "$MBED_MCU_BOOT_PATH"/boot/mbed mcuboot

# Generate config file for selected target, toolchain and hardware
mbed-tools configure -t "$TOOLCHAIN" -m "$TARGET_BOARD" -o "$BUILD_DIRECTORY" --mbed-os-path "$MBED_OS_PATH"

# Remove old artifacts to force linking
rm -rf "$BUILD_DIRECTORY/chip-"*

# Build application
cmake -S . -B "$BUILD_DIRECTORY" -GNinja -DCMAKE_BUILD_TYPE="$PROFILE" -DMBED_OS_PATH="$MBED_OS_PATH" -DMBED_MCU_BOOT_PATH="$MBED_MCU_BOOT_PATH"
cmake --build "$BUILD_DIRECTORY"

exit
fi

if [[ "$COMMAND" == *"build"* ]]; then
echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile"

Expand Down
1 change: 1 addition & 0 deletions third_party/mbed-mcu-boot/repo
Submodule repo added at c1233d

0 comments on commit 9910ff8

Please sign in to comment.