forked from AGlass0fMilk/mbed-mcuboot-blinky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondary_bd.cpp
53 lines (39 loc) · 1.76 KB
/
secondary_bd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* default_bd.cpp
*
* Created on: Jul 30, 2020
* Author: gdbeckstein
*/
#include "BlockDevice.h"
#include "SlicingBlockDevice.h"
#include "FlashIAPBlockDevice.h"
#include "BufferedBlockDevice.h"
#if MBED_CONF_APP_SECONDARY_SLOT_IN_FLASH
mbed::BlockDevice* get_secondary_bd(void) {
// Use FlashIAP for the secondary BD.
static FlashIAPBlockDevice flashBD(MBED_CONF_APP_SECONDARY_SLOT_FLASH_START_ADDR, MCUBOOT_SLOT_SIZE);
// Our UpdaterApp needs to be able to program the flash with single-byte granularity
static mbed::BufferedBlockDevice bufferedBD(&flashBD);
return &bufferedBD;
}
#else
/**
* 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 default block device defined for your board.
MBED_ASSERT(default_bd != nullptr);
// mcuboot assumes that the read size of the secondary block device is the same as the read size
// of flash, so use a BufferedBlockDevice to wrap the underlying BD and ensure this is the case.
static mbed::BufferedBlockDevice buffered_bd(default_bd);
// In this case, our flash is much larger than a single image so
// slice it into the size of an image slot
static mbed::SlicingBlockDevice sliced_bd(&buffered_bd, 0x0, MCUBOOT_SLOT_SIZE);
return &sliced_bd;
}
#endif