Skip to content

Commit 5591ec6

Browse files
Build for K64F as well (with external SD card)
1 parent 961d3d8 commit 5591ec6

File tree

4 files changed

+38
-77
lines changed

4 files changed

+38
-77
lines changed

.github/workflows/compile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
mbed_target:
1515
# Change the below to match the target(s) you want to compile the project for.
1616
- NUCLEO_H743ZI2
17+
- K64F
1718

1819
steps:
1920
- name: Checkout

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_subdirectory(mbed-os)
1010
project(mbed-mcuboot-bootloader)
1111

1212
set(MBED_MCUBOOT_BOOTLOADER_SOURCES
13-
default_bd.cpp
13+
secondary_bd.cpp
1414
enc_key.c
1515
shared_data.c
1616
signing_keys.c)
@@ -24,7 +24,10 @@ add_subdirectory(mcuboot/boot/bootutil)
2424
add_subdirectory(mcuboot/boot/mbed)
2525

2626
add_executable(${CMAKE_PROJECT_NAME} ${MBED_MCUBOOT_BOOTLOADER_SOURCES})
27-
target_link_libraries(${CMAKE_PROJECT_NAME} mbed-baremetal mbed-mcuboot)
27+
target_link_libraries(${CMAKE_PROJECT_NAME}
28+
mbed-baremetal
29+
mbed-storage
30+
mbed-mcuboot)
2831
mbed_set_post_build(${CMAKE_PROJECT_NAME})
2932

3033
mbed_finalize_build()

mbed_app.json5

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"target_overrides": {
1515
"*": {
1616
"platform.stdio-baud-rate": 115200,
17-
"target.restrict_size": "0x20000",
1817
"target.c_lib": "small",
1918
"mcuboot.log-level": "MCUBOOT_LOG_LEVEL_DEBUG",
2019
"mbed-trace.enable": true,
@@ -52,14 +51,27 @@
5251
// "mcuboot.read-granularity": 1,
5352
// "qspif.QSPI_MIN_PROG_SIZE": 1
5453
// },
55-
// "K64F": {
56-
// "mcuboot.primary-slot-address": "0x20000",
57-
// "mcuboot.slot-size": "0xC0000",
58-
// "mcuboot.scratch-address": "0xE0000",
59-
// "mcuboot.scratch-size": "0x20000",
60-
// "mcuboot.max-img-sectors": "0x180",
61-
// "mcuboot.read-granularity": 512
62-
// },
54+
55+
"K64F": {
56+
// Configure bootloader to live in the first sector of flash
57+
"target.memory_bank_config": {
58+
"IROM1": {
59+
"size": 0x20000
60+
}
61+
},
62+
63+
// On K64F we store the secondary slot in external memory, not internal.
64+
// So, the primary slot can take up most of flash.
65+
"mcuboot.primary-slot-address": "0x20000",
66+
"mcuboot.slot-size": "0xC0000",
67+
68+
// Store the scratch space at the end of flash
69+
"mcuboot.scratch-address": "0xE0000",
70+
"mcuboot.scratch-size": "0x20000",
71+
72+
"mcuboot.max-img-sectors": "0x180",
73+
"mcuboot.read-granularity": 512 // External SD card used as block device, this is its read size.
74+
},
6375

6476
"MCU_STM32H743xI": {
6577
// Configure bootloader to live in the first sector of flash
@@ -75,14 +87,12 @@
7587
// Slot size can be as big as 896k, since we need to reserve the first flash sector for the bootloader
7688
// and the last flash sector for scratch space
7789
"mcuboot.primary-slot-address": "0x20000",
90+
"mcuboot.max-img-sectors": "7", // 7 flash sectors per slot
7891
"mcuboot.slot-size": "0xE0000",
79-
80-
"mcuboot.max-img-sectors": "0x180",
81-
"mcuboot.read-granularity": 512,
8292

8393
// STM32H7 flash sector size is 128k, so we need to make the scratch region at least that big
8494
"mcuboot.scratch-address": "0x1E0000",
85-
"mcuboot.scratch-size": "0x20000",
95+
"mcuboot.scratch-size": "0x20000"
8696

8797
}
8898
}

default_bd.cpp renamed to secondary_bd.cpp

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@
1010
#include "SlicingBlockDevice.h"
1111
#include "FlashIAPBlockDevice.h"
1212

13-
14-
#if COMPONENT_SPIF
15-
#include "SPIFBlockDevice.h"
16-
#endif
17-
18-
#if COMPONENT_QSPIF
19-
#include "QSPIFBlockDevice.h"
20-
#endif
21-
22-
#if COMPONENT_DATAFLASH
23-
#include "DataFlashBlockDevice.h"
24-
#endif
25-
26-
#if COMPONENT_SD
27-
#include "SDBlockDevice.h"
28-
29-
#if (STATIC_PINMAP_READY)
30-
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);
31-
#endif
32-
#endif
33-
3413
#if MBED_CONF_APP_SECONDARY_SLOT_IN_FLASH
3514

3615
mbed::BlockDevice* get_secondary_bd(void) {
@@ -41,55 +20,23 @@ mbed::BlockDevice* get_secondary_bd(void) {
4120
}
4221

4322
#else
44-
BlockDevice *BlockDevice::get_default_instance()
45-
{
46-
#if COMPONENT_SPIF
47-
48-
static SPIFBlockDevice default_bd;
49-
50-
return &default_bd;
51-
52-
#elif COMPONENT_QSPIF
53-
54-
static QSPIFBlockDevice default_bd;
55-
56-
return &default_bd;
57-
58-
#elif COMPONENT_DATAFLASH
59-
60-
static DataFlashBlockDevice default_bd;
61-
62-
return &default_bd;
63-
64-
#elif COMPONENT_SD
65-
66-
#if (STATIC_PINMAP_READY)
67-
static SDBlockDevice default_bd(
68-
static_spi_pinmap,
69-
MBED_CONF_SD_SPI_CS
70-
);
71-
#else
72-
static SDBlockDevice default_bd;
73-
#endif
74-
75-
return &default_bd;
76-
77-
#else
78-
79-
#error No block device set up for secondary slot!
80-
81-
#endif
82-
83-
}
8423

8524
/**
8625
* You can override this function to suit your hardware/memory configuration
8726
* By default it simply returns what is returned by BlockDevice::get_default_instance();
8827
*/
8928
mbed::BlockDevice* get_secondary_bd(void) {
29+
30+
// Use the PlatformStorage API to get the "default" block device for this project.
31+
// This will return the (O/Q)SPI flash or SD card instance if those components are available.
32+
// Otherwise it will return the flash IAP block device.
33+
mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance();
34+
35+
// If this assert fails, there is no block def
36+
MBED_ASSERT(default_bd != nullptr);
37+
9038
// In this case, our flash is much larger than a single image so
9139
// slice it into the size of an image slot
92-
mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance();
9340
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
9441
return &sliced_bd;
9542
}

0 commit comments

Comments
 (0)