-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'yann/feature/basic-bootloader' into develop
* yann/feature/basic-bootloader: 🙈 (firmware): Ignore _tmp and _release folders 🔨 (firmware): Script to generate firmware 🚚 (mcuboot): Add spikes to demonstrate how to use mcuboot in apps 🎉 (boot): Add bootloader 🚚 (cmake): Rename ENABLE_BOOTLOADER to BUILD_TARGETS_TO_USE_WITH_BOOTLOADER 🔧 (mcuboot): Add missing macro to use MCUBoot in bootloader or apps 🐛 (qspi): Up address size from 8 to 24bits
- Loading branch information
Showing
19 changed files
with
501 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ cmake/config/ | |
.clangd | ||
*.ioc.csv | ||
cube_path.json | ||
_release | ||
_tmp | ||
|
||
|
||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Leka - LekaOS | ||
# Copyright 2021 APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_mbed_executable(bootloader) | ||
|
||
target_include_directories(bootloader | ||
PRIVATE | ||
. | ||
) | ||
|
||
target_sources(bootloader | ||
PRIVATE | ||
main.cpp | ||
default_bd.cpp | ||
signing_keys.c | ||
) | ||
|
||
target_link_libraries(bootloader | ||
bootutil | ||
) | ||
|
||
target_link_custom_leka_targets(bootloader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "QSPIFBlockDevice.h" | ||
#include "SlicingBlockDevice.h" | ||
|
||
auto get_secondary_bd() -> mbed::BlockDevice * | ||
{ | ||
// In this case, our flash is much larger than a single image so | ||
// slice it into the size of an image slot | ||
|
||
static auto _bd = QSPIFBlockDevice {}; | ||
|
||
static auto sliced_bd = mbed::SlicingBlockDevice {&_bd, 0x0, MCUBOOT_SLOT_SIZE}; | ||
|
||
return &sliced_bd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2020 Embedded Planet | ||
* Copyright (c) 2020 ARM Limited | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License | ||
*/ | ||
|
||
#include "mbed_application.h" | ||
#include "mbedtls/platform.h" | ||
|
||
#include "drivers/BufferedSerial.h" | ||
|
||
#include "LogKit.h" | ||
#include "bootutil/bootutil.h" | ||
#include "bootutil/image.h" | ||
#include "hal/serial_api.h" | ||
|
||
static auto serial = mbed::BufferedSerial(USBTX, USBRX, 115200); | ||
|
||
auto main() -> int | ||
{ | ||
int rc; | ||
|
||
log_info("Starting MCUboot"); | ||
|
||
// Initialize mbedtls crypto for use by MCUboot | ||
mbedtls_platform_context unused_ctx; | ||
rc = mbedtls_platform_setup(&unused_ctx); | ||
if (rc != 0) { | ||
log_error("Failed to setup Mbed TLS, error: %d", rc); | ||
exit(rc); | ||
} | ||
|
||
struct boot_rsp rsp; | ||
rc = boot_go(&rsp); | ||
if (rc != 0) { | ||
log_error("Failed to locate firmware image, error: %d", rc); | ||
exit(rc); | ||
} | ||
|
||
uint32_t address = rsp.br_image_off + rsp.br_hdr->ih_hdr_size; | ||
|
||
// Workaround: The extra \n ensures the last trace gets flushed | ||
// before mbed_start_application() destroys the stack and jumps | ||
// to the application | ||
log_info("Booting firmware image at 0x%x\n", address); | ||
|
||
// Run the application in the primary slot | ||
// Add header size offset to calculate the actual start address of application | ||
mbed_start_application(address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Autogenerated by imgtool.py, do not edit. */ | ||
const unsigned char rsa_pub_key[] = { | ||
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, | ||
0x00, 0xc1, 0x3c, 0x9a, 0x1b, 0xd5, 0x96, 0x02, | ||
0xdc, 0xdc, 0xc2, 0x5a, 0xf7, 0x31, 0x81, 0x84, | ||
0x46, 0xe6, 0xb5, 0x63, 0x73, 0x51, 0x76, 0xea, | ||
0x94, 0xf7, 0x3d, 0x81, 0xb4, 0x48, 0xa2, 0x9c, | ||
0x00, 0xab, 0x7d, 0x66, 0x9c, 0xcc, 0x84, 0x9c, | ||
0x15, 0x5d, 0x7f, 0x5f, 0x7c, 0x46, 0xb1, 0x6d, | ||
0x8b, 0x5d, 0x47, 0x26, 0x68, 0xff, 0x50, 0xb7, | ||
0x8d, 0x34, 0xa5, 0x25, 0xc6, 0x0f, 0x62, 0xc8, | ||
0x1f, 0xa5, 0x93, 0xcb, 0xc9, 0x21, 0x7e, 0xe6, | ||
0xc2, 0xae, 0x20, 0xc2, 0xaf, 0x85, 0x4f, 0xaa, | ||
0xef, 0xac, 0x16, 0xd8, 0x79, 0xac, 0xc1, 0x02, | ||
0x65, 0x45, 0x23, 0x53, 0xee, 0x7d, 0x8e, 0x8b, | ||
0x87, 0xaa, 0x97, 0x3e, 0xb4, 0xc0, 0xdd, 0xe5, | ||
0xd9, 0xb0, 0xd4, 0x0d, 0x38, 0x67, 0x29, 0x2d, | ||
0xb9, 0xf7, 0xfa, 0x8c, 0x06, 0xd9, 0xb4, 0x29, | ||
0xc2, 0x13, 0x7c, 0xce, 0xcd, 0x2e, 0x48, 0xce, | ||
0x87, 0x0f, 0xb0, 0x61, 0x19, 0x44, 0x71, 0x7c, | ||
0xe9, 0xef, 0x5f, 0x65, 0x16, 0xf9, 0x94, 0xa3, | ||
0x46, 0x17, 0x85, 0xb7, 0x68, 0xb0, 0xc2, 0x9e, | ||
0xe5, 0xd6, 0x56, 0xd6, 0xc8, 0xc6, 0xcc, 0x0b, | ||
0x5f, 0x63, 0xf7, 0x0c, 0x4f, 0xf2, 0xd4, 0xd9, | ||
0xd5, 0x1d, 0x40, 0x5b, 0x6e, 0x73, 0x2f, 0x4d, | ||
0xc7, 0x4a, 0xe5, 0xae, 0x74, 0xaa, 0x35, 0x9a, | ||
0x05, 0xa7, 0x24, 0xd3, 0xba, 0x3a, 0x7c, 0xe9, | ||
0x55, 0x67, 0x35, 0x63, 0xb2, 0x6a, 0x14, 0x6f, | ||
0xfa, 0x5f, 0x1e, 0xc7, 0x71, 0xc9, 0xf7, 0x5a, | ||
0x0b, 0x2c, 0x51, 0xab, 0xdc, 0x11, 0x65, 0x4e, | ||
0xec, 0x10, 0x0e, 0x2e, 0x0e, 0x41, 0x6f, 0x56, | ||
0x64, 0xf5, 0x5c, 0x8f, 0xfa, 0xb4, 0x0b, 0x3b, | ||
0xe0, 0xb0, 0xba, 0x28, 0xb2, 0x48, 0x8c, 0xe0, | ||
0x59, 0xd7, 0x3b, 0xbf, 0x5e, 0x7f, 0x4b, 0xc9, | ||
0x98, 0xdd, 0x03, 0xbd, 0xd2, 0xdc, 0xc8, 0x3e, | ||
0xf1, 0x02, 0x03, 0x01, 0x00, 0x01, | ||
}; | ||
const unsigned int rsa_pub_key_len = 270; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
mkdir _tmp > /dev/null 2> /dev/null | ||
|
||
# Variables | ||
BOOTLOADER_HEX_SOURCE="$1" | ||
BOOTLOADER_HEX="$2" | ||
|
||
if [ -z "$BOOTLOADER_HEX_SOURCE" ]; then | ||
echo "BOOTLOADER_HEX_SOURCE is unset" | ||
BOOTLOADER_HEX_SOURCE="_build/LEKA_V1_2_DEV/bootloader/bootloader.hex" | ||
fi | ||
|
||
if [ -z "$BOOTLOADER_HEX" ]; then | ||
echo "BOOTLOADER_HEX is unset" | ||
BOOTLOADER_HEX="_tmp/bootloader.hex" | ||
fi | ||
|
||
# Compile bootloader | ||
make deep_clean | ||
make config | ||
make | ||
|
||
# Get bootloader binary | ||
cp $BOOTLOADER_HEX_SOURCE $BOOTLOADER_HEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
mkdir _tmp > /dev/null 2> /dev/null | ||
mkdir _release > /dev/null 2> /dev/null | ||
|
||
# Variables | ||
RECOMPILE_APPLICATIONS="$1" | ||
|
||
APPLICATION_HEX_SOURCE="$2" | ||
APPLICATION_VERSION="$3" | ||
APPLICATION_HEX="_tmp/application.hex" | ||
APPLICATION_SIGNED_HEX="$4" | ||
APPLICATION_SIGNED_BIN="_release/application-signed.bin" | ||
|
||
if [ -z "$APPLICATION_HEX_SOURCE" ]; then | ||
echo "APPLICATION_HEX_SOURCE is unset" | ||
APPLICATION_HEX_SOURCE="_build/LEKA_V1_2_DEV/src/LekaOS.hex" | ||
fi | ||
|
||
if [ -z "$APPLICATION_VERSION" ]; then | ||
echo "APPLICATION_VERSION is unset" | ||
APPLICATION_VERSION="1.2.3+4" | ||
fi | ||
|
||
if [ -z "$APPLICATION_SIGNED_HEX" ]; then | ||
echo "APPLICATION_SIGNED_HEX is unset" | ||
APPLICATION_SIGNED_HEX="_tmp/application-signed.hex" | ||
fi | ||
|
||
# Compile applications | ||
if [ "$RECOMPILE_APPLICATIONS" = "true" ]; | ||
then | ||
make deep_clean | ||
make config BUILD_TARGETS_TO_USE_WITH_BOOTLOADER=ON | ||
fi; | ||
make | ||
|
||
# Get application binary | ||
cp $APPLICATION_HEX_SOURCE $APPLICATION_HEX | ||
|
||
# Sign application with private key | ||
imgtool sign -k signing-keys.pem --align 4 -v $APPLICATION_VERSION --header-size 4096 --pad-header -S 0x180000 $APPLICATION_HEX $APPLICATION_SIGNED_HEX | ||
|
||
# Convert in binary | ||
arm-none-eabi-objcopy -I ihex -O binary $APPLICATION_SIGNED_HEX $APPLICATION_SIGNED_BIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
mkdir _tmp > /dev/null 2> /dev/null | ||
mkdir _release > /dev/null 2> /dev/null | ||
|
||
# Variables | ||
RECOMPILE_BOOTLOADER="false" | ||
while getopts r flag | ||
do | ||
case "${flag}" in | ||
r) RECOMPILE_BOOTLOADER="true";; | ||
esac | ||
done | ||
|
||
BOOTLOADER_HEX_SOURCE="_build/LEKA_V1_2_DEV/bootloader/bootloader.hex" | ||
BOOTLOADER_HEX="_tmp/bootloader.hex" | ||
|
||
APPLICATION_HEX_SOURCE="_build/LEKA_V1_2_DEV/spikes/lk_update_process_app_base/spike_lk_update_process_app_base.hex" | ||
APPLICATION_VERSION="1.2.3+4" | ||
APPLICATION_SIGNED_HEX="_tmp/application-signed.hex" | ||
|
||
FIRMWARE_HEX="_tmp/firmwware.hex" | ||
FIRMWARE_RELEASE="_release/firmware.bin" | ||
|
||
# Get bootloader | ||
if [ "$RECOMPILE_BOOTLOADER" = "true" ]; | ||
then | ||
./build_bootloader.sh $BOOTLOADER_HEX_SOURCE $BOOTLOADER_HEX | ||
fi; | ||
|
||
# Get application | ||
./build_update.sh $RECOMPILE_BOOTLOADER $APPLICATION_HEX_SOURCE $APPLICATION_VERSION $APPLICATION_SIGNED_HEX | ||
|
||
# Merge bootloader and application | ||
hexmerge.py -o $FIRMWARE_HEX --no-start-addr $BOOTLOADER_HEX $APPLICATION_SIGNED_HEX | ||
arm-none-eabi-objcopy -I ihex -O binary $FIRMWARE_HEX $FIRMWARE_RELEASE |
Oops, something went wrong.