Skip to content

Commit

Permalink
Build for K64F as well (with external SD card)
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Dec 4, 2024
1 parent 961d3d8 commit 5591ec6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 77 deletions.
1 change: 1 addition & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
36 changes: 23 additions & 13 deletions mbed_app.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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"

}
}
Expand Down
71 changes: 9 additions & 62 deletions default_bd.cpp → secondary_bd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 5591ec6

Please sign in to comment.