From 5591ec6b7e22c8f4386522a5d2ca00d36478a2cf Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Wed, 4 Dec 2024 09:21:40 -0800 Subject: [PATCH] Build for K64F as well (with external SD card) --- .github/workflows/compile.yml | 1 + CMakeLists.txt | 7 ++- mbed_app.json5 | 36 +++++++++------ default_bd.cpp => secondary_bd.cpp | 71 ++++-------------------------- 4 files changed, 38 insertions(+), 77 deletions(-) rename default_bd.cpp => secondary_bd.cpp (50%) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 2d77493..134fde9 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -14,6 +14,7 @@ jobs: mbed_target: # Change the below to match the target(s) you want to compile the project for. - NUCLEO_H743ZI2 + - K64F steps: - name: Checkout diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aab90b..889c981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ add_subdirectory(mbed-os) project(mbed-mcuboot-bootloader) set(MBED_MCUBOOT_BOOTLOADER_SOURCES - default_bd.cpp + secondary_bd.cpp enc_key.c shared_data.c signing_keys.c) @@ -24,7 +24,10 @@ 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) +target_link_libraries(${CMAKE_PROJECT_NAME} + mbed-baremetal + mbed-storage + mbed-mcuboot) mbed_set_post_build(${CMAKE_PROJECT_NAME}) mbed_finalize_build() \ No newline at end of file diff --git a/mbed_app.json5 b/mbed_app.json5 index 8437d14..d0f26de 100644 --- a/mbed_app.json5 +++ b/mbed_app.json5 @@ -14,7 +14,6 @@ "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, @@ -52,14 +51,27 @@ // "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 - // }, + + "K64F": { + // Configure bootloader to live in the first sector of flash + "target.memory_bank_config": { + "IROM1": { + "size": 0x20000 + } + }, + + // On K64F we store the secondary slot in external memory, not internal. + // So, the primary slot can take up most of flash. + "mcuboot.primary-slot-address": "0x20000", + "mcuboot.slot-size": "0xC0000", + + // Store the scratch space at the end of flash + "mcuboot.scratch-address": "0xE0000", + "mcuboot.scratch-size": "0x20000", + + "mcuboot.max-img-sectors": "0x180", + "mcuboot.read-granularity": 512 // External SD card used as block device, this is its read size. + }, "MCU_STM32H743xI": { // Configure bootloader to live in the first sector of flash @@ -75,14 +87,12 @@ // 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.max-img-sectors": "7", // 7 flash sectors per slot "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", + "mcuboot.scratch-size": "0x20000" } } diff --git a/default_bd.cpp b/secondary_bd.cpp similarity index 50% rename from default_bd.cpp rename to secondary_bd.cpp index 2f0c6d1..52c1ba6 100644 --- a/default_bd.cpp +++ b/secondary_bd.cpp @@ -10,27 +10,6 @@ #include "SlicingBlockDevice.h" #include "FlashIAPBlockDevice.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 - #if MBED_CONF_APP_SECONDARY_SLOT_IN_FLASH mbed::BlockDevice* get_secondary_bd(void) { @@ -41,55 +20,23 @@ mbed::BlockDevice* get_secondary_bd(void) { } #else -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 - -#error No block device set up for secondary slot! - -#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) { + + // Use the PlatformStorage API to get the "default" block device for this project. + // This will return the (O/Q)SPI flash or SD card instance if those components are available. + // Otherwise it will return the flash IAP block device. + mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance(); + + // If this assert fails, there is no block def + MBED_ASSERT(default_bd != nullptr); + // In this case, our flash is much larger than a single image so // slice it into the size of an image slot - mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance(); static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE); return &sliced_bd; }