Skip to content

Commit

Permalink
➕ (mcuboot): Add mcuboot to extern dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli authored and ladislas committed Jul 7, 2021
1 parent 08caef3 commit 09f666c
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 31 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/ci-code_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,23 @@ jobs:
sudo apt-get install -y --no-install-recommends ninja-build ccache lcov gcovr
#
# Mark: - Download mbed-os & ccache
# Mark: - Download `extern` dependencies & ccache
#

- name: Cache Mbed OS
id: cache_mbed_os
- name: Cache extern dependencies
id: cache_extern_dependencies
uses: actions/cache@v2
with:
path: extern/mbed-os
key: ${{ runner.os }}-global_cache-mbed_os-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version') }}
path: |
extern/mbed-os
extern/mcuboot
key: ${{ runner.os }}-global_cache-extern_dependencies-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version', '.mcuboot_version') }}

- name: Curl Mbed OS
if: steps.cache_mbed_os.outputs.cache-hit != 'true'
- name: Pull extern dependencies
if: steps.cache_extern_dependencies.outputs.cache-hit != 'true'
run: |
make mbed_curl
make mcuboot_clone
- name: Cache ccache
id: cache_ccache
Expand Down Expand Up @@ -266,20 +269,23 @@ jobs:
sudo apt-get install -y --no-install-recommends ninja-build
#
# Mark: - Download mbed-os & ccache
# Mark: - Download `extern` dependencies & ccache
#

- name: Cache Mbed OS
id: cache_mbed_os
- name: Cache extern dependencies
id: cache_extern_dependencies
uses: actions/cache@v2
with:
path: extern/mbed-os
key: ${{ runner.os }}-global_cache-mbed_os-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version') }}
path: |
extern/mbed-os
extern/mcuboot
key: ${{ runner.os }}-global_cache-extern_dependencies-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version', '.mcuboot_version') }}

- name: Curl Mbed OS
if: steps.cache_mbed_os.outputs.cache-hit != 'true'
- name: Pull extern dependencies
if: steps.cache_extern_dependencies.outputs.cache-hit != 'true'
run: |
make mbed_curl
make mcuboot_clone
#
# Mark: - Install python/pip dependencies
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/ci-cross_compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,23 @@ jobs:
sudo apt-get install -y --no-install-recommends ninja-build ccache
#
# Mark: - Download mbed-os & ccache
# Mark: - Download `extern` dependencies & ccache
#

- name: Cache Mbed OS
id: cache_mbed_os
- name: Cache extern dependencies
id: cache_extern_dependencies
uses: actions/cache@v2
with:
path: extern/mbed-os
key: ${{ runner.os }}-global_cache-mbed_os-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version') }}
path: |
extern/mbed-os
extern/mcuboot
key: ${{ runner.os }}-global_cache-extern_dependencies-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version', '.mcuboot_version') }}

- name: Curl Mbed OS
if: steps.cache_mbed_os.outputs.cache-hit != 'true'
- name: Pull extern dependencies
if: steps.cache_extern_dependencies.outputs.cache-hit != 'true'
run: |
make mbed_curl
make mcuboot_clone
- name: Cache ccache
id: cache_ccache
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.vscode
extern/mbed-os
extern/mcuboot
_build*
_coverage*
cmake/config/
Expand Down
1 change: 1 addition & 0 deletions .mcuboot_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8abacc834be69e15e553c0af545e8bd79365ee5b
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_compile_options(
# Before all, set ROOT_DIR, MBED_OS_DIR
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(MBED_OS_DIR ${ROOT_DIR}/extern/mbed-os)
set(MCUBOOT_DIR ${ROOT_DIR}/extern/mcuboot/boot)

# Bootloader option
option(ENABLE_BOOTLOADER "Build LekaOS with bootloader" OFF)
Expand Down Expand Up @@ -113,6 +114,9 @@ link_libraries(
CriticalSection
)

# Add external libraries
add_subdirectory(${MCUBOOT_DIR})

# Add drivers & libraries
add_subdirectory(${DRIVERS_DIR})
add_subdirectory(${LIBS_DIR})
Expand Down
40 changes: 30 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CMAKE_DIR := $(ROOT_DIR)/cmake
MBED_OS_DIR := $(ROOT_DIR)/extern/mbed-os
MCUBOOT_DIR := $(ROOT_DIR)/extern/mcuboot

#
# MARK: - Arguments
#

PORT ?= /dev/tty.usbmodem14303
BRANCH ?= $(shell cat $(ROOT_DIR)/.mbed_version)
VERSION ?= $(shell cat $(ROOT_DIR)/.mbed_version)
BAUDRATE ?= 115200
BUILD_TYPE ?= Release
TARGET_BOARD ?= LEKA_V1_2_DEV
PORT ?= /dev/tty.usbmodem14303
MBED_BRANCH ?= $(shell cat $(ROOT_DIR)/.mbed_version)
MBED_VERSION ?= $(shell cat $(ROOT_DIR)/.mbed_version)
MCUBOOT_VERSION ?= $(shell cat $(ROOT_DIR)/.mcuboot_version)
BAUDRATE ?= 115200
BUILD_TYPE ?= Release
TARGET_BOARD ?= LEKA_V1_2_DEV

#
# MARK: - Options
Expand Down Expand Up @@ -254,17 +256,17 @@ mbed_clone:
@echo ""
@echo "🧬 Cloning Mbed OS 📦"
@rm -rf $(MBED_OS_DIR)
git clone --depth=1 --branch=$(BRANCH) https://github.com/ARMmbed/mbed-os $(MBED_OS_DIR)
git clone --depth=1 --branch=$(MBED_BRANCH) https://github.com/ARMmbed/mbed-os $(MBED_OS_DIR)
@$(MAKE) mbed_symlink_files

mbed_curl:
@echo ""
@echo "🧬 Curling Mbed OS 📦"
@rm -rf $(MBED_OS_DIR)
@mkdir -p $(MBED_OS_DIR)
curl -O -L https://github.com/ARMmbed/mbed-os/archive/$(VERSION).tar.gz
tar -xzf $(VERSION).tar.gz --strip-components=1 -C extern/mbed-os
rm -rf $(VERSION).tar.gz
curl -O -L https://github.com/ARMmbed/mbed-os/archive/$(MBED_VERSION).tar.gz
tar -xzf $(MBED_VERSION).tar.gz --strip-components=1 -C extern/mbed-os
rm -rf $(MBED_VERSION).tar.gz
@$(MAKE) mbed_symlink_files

mbed_symlink_files:
Expand All @@ -273,6 +275,24 @@ mbed_symlink_files:
ln -srf $(CMAKE_DIR)/templates/Template_MbedOS_CMakelists.txt $(MBED_OS_DIR)/CMakeLists.txt
ln -srf $(CMAKE_DIR)/templates/Template_MbedOS_mbedignore.txt $(MBED_OS_DIR)/.mbedignore

#
# MARK: - Mcuboot targets
#

mcuboot_clone:
@echo ""
@echo "🧬 Cloning MCUBoot 📦"
@rm -rf $(MCUBOOT_DIR)
@git clone --single-branch https://github.com/mcu-tools/mcuboot.git $(MCUBOOT_DIR)
@cd $(MCUBOOT_DIR) && git reset --hard $(MCUBOOT_VERSION) && cd $(ROOT_DIR)
@$(MAKE) mcuboot_symlink_files

mcuboot_symlink_files:
@echo ""
@echo "🔗 Symlinking CMakeLists.txt to MCUBoot directory 🗂️"
ln -srf $(CMAKE_DIR)/templates/Template_MCUBoot_CMakeLists.txt $(MCUBOOT_DIR)/boot/CMakeLists.txt
ln -srf $(CMAKE_DIR)/templates/Template_MCUBoot_mbed_CMakeLists.txt $(MCUBOOT_DIR)/boot/mbed/CMakeLists.txt

#
# MARK: - Utils targets
#
Expand Down
30 changes: 30 additions & 0 deletions cmake/templates/Template_MCUBoot_CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# vim: set filetype=cmake:
# Leka
# Copyright 2021 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_compile_definitions(MCUBOOT_BOOTLOADER_BUILD=false)
add_compile_definitions(MCUBOOT_BOOTLOADER_SIZE=0x40000)

add_compile_definitions(MCUBOOT_SCRATCH_SIZE=0x40000)
add_compile_definitions(MCUBOOT_SCRATCH_START_ADDR=0x081C0000)

add_compile_definitions(MCUBOOT_CRYPTO_BACKEND=MBEDTLS)
add_compile_definitions(MCUBOOT_SIGNATURE_ALGORITHM=SIGNATURE_TYPE_RSA)
add_compile_definitions(MCUBOOT_RSA_SIGNATURE_LENGTH=2048)

add_compile_definitions(MCUBOOT_LOG_BOOTLOADER_ONLY=true)
add_compile_definitions(MCUBOOT_LOG_LEVEL=MCUBOOT_LOG_LEVEL_DEBUG)

add_compile_definitions(MCUBOOT_OVERWRITE_ONLY_FAST=null)
add_compile_definitions(MCUBOOT_OVERWRITE_ONLY=null)

add_compile_definitions(MCUBOOT_PRIMARY_SLOT_START_ADDR=0x08040000)
add_compile_definitions(MCUBOOT_SLOT_SIZE=0x200000-MCUBOOT_BOOTLOADER_SIZE-MCUBOOT_SCRATCH_SIZE)
add_compile_definitions(MCUBOOT_VALIDATE_PRIMARY_SLOT=true)

add_compile_definitions(MCUBOOT_READ_GRANULARITY=1)
add_compile_definitions(MCUBOOT_MAX_IMG_SECTORS=256)

add_subdirectory(${MCUBOOT_DIR}/bootutil)
add_subdirectory(${MCUBOOT_DIR}/mbed)
26 changes: 26 additions & 0 deletions cmake/templates/Template_MCUBoot_mbed_CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# vim: set filetype=cmake:
# Leka
# Copyright 2021 APF France handicap
# SPDX-License-Identifier: Apache-2.0

target_include_directories(bootutil
PUBLIC
./
include
include/flash_map_backend
include/mcuboot_config
include/os
include/sysflash
)

target_sources(bootutil
PRIVATE
src/flash_map_backend.cpp
src/secondary_bd.cpp
app_enc_keys.c
mcuboot_main.cpp
)

target_link_libraries(bootutil
mbed-os
)

0 comments on commit 09f666c

Please sign in to comment.