aboutsummaryrefslogtreecommitdiff
path: root/bl2
diff options
context:
space:
mode:
authorMichel Jaouen <michel.jaouen@st.com>2020-12-03 10:37:22 +0100
committerMichel Jaouen <michel.jaouen@st.com>2020-12-18 08:00:13 +0100
commit26f6c028a5b336bd5b3a65b6c2fd728212f32b76 (patch)
tree0add430ea7363b71d93594b6912b81a316cd03bc /bl2
parent0a9e53749e5759af242f3d62eb6d6e65b9cfc81e (diff)
downloadtrusted-firmware-m-26f6c028a5b336bd5b3a65b6c2fd728212f32b76.tar.gz
Boot: Add multiple flash driver support
(T862) External flash support on stm uses 2 drivers : - internal flash slot 0/1, scratch : driver internal flash - external flash slot 2/3 : octospi driver external flash Change-Id: I58d86a48081ad0bca3dda961318a15fe17248a93 Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
Diffstat (limited to 'bl2')
-rw-r--r--bl2/ext/mcuboot/flash_map_extended.c12
-rw-r--r--bl2/ext/mcuboot/include/flash_map/flash_map.h12
-rw-r--r--bl2/ext/mcuboot/include/target.h25
-rw-r--r--bl2/src/flash_map.c63
4 files changed, 92 insertions, 20 deletions
diff --git a/bl2/ext/mcuboot/flash_map_extended.c b/bl2/ext/mcuboot/flash_map_extended.c
index cf7d3f52a..e854b552c 100644
--- a/bl2/ext/mcuboot/flash_map_extended.c
+++ b/bl2/ext/mcuboot/flash_map_extended.c
@@ -14,16 +14,14 @@
#include <errno.h>
#include "target.h"
+#include "cmsis.h"
#include "Driver_Flash.h"
#include "sysflash/sysflash.h"
#include "flash_map/flash_map.h"
#include "flash_map_backend/flash_map_backend.h"
#include "bootutil/bootutil_log.h"
-/* Flash device name must be specified by target */
-extern ARM_DRIVER_FLASH FLASH_DEV_NAME;
-
-int flash_device_base(uint8_t fd_id, uintptr_t *ret)
+__WEAK int flash_device_base(uint8_t fd_id, uintptr_t *ret)
{
if (fd_id != FLASH_DEVICE_ID) {
BOOT_LOG_ERR("invalid flash ID %d; expected %d",
@@ -75,9 +73,7 @@ int flash_area_id_to_image_slot(int area_id)
uint8_t flash_area_erased_val(const struct flash_area *fap)
{
- (void)fap;
-
- return FLASH_DEV_NAME.GetInfo()->erased_value;
+ return DRV_FLASH_AREA(fap)->GetInfo()->erased_value;
}
int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
@@ -90,7 +86,7 @@ int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
BOOT_LOG_DBG("read_is_empty area=%d, off=%#x, len=%#x",
fa->fa_id, off, len);
- rc = FLASH_DEV_NAME.ReadData(fa->fa_off + off, dst, len);
+ rc = DRV_FLASH_AREA(fa)->ReadData(fa->fa_off + off, dst, len);
if (rc) {
return -1;
}
diff --git a/bl2/ext/mcuboot/include/flash_map/flash_map.h b/bl2/ext/mcuboot/include/flash_map/flash_map.h
index d858ef458..b66dfc02d 100644
--- a/bl2/ext/mcuboot/include/flash_map/flash_map.h
+++ b/bl2/ext/mcuboot/include/flash_map/flash_map.h
@@ -50,6 +50,7 @@ extern "C" {
*/
#include <inttypes.h>
#include "region_defs.h"
+#include "Driver_Flash.h"
/*
* For now, we only support one flash device.
@@ -91,6 +92,11 @@ struct flash_area {
uint16_t pad16;
/**
+ * Pointer to driver
+ */
+ ARM_DRIVER_FLASH *fa_driver;
+
+ /**
* This area's offset, relative to the beginning of its flash
* device's storage.
*/
@@ -121,6 +127,12 @@ struct flash_sector {
uint32_t fs_size;
};
+/**
+ * @brief Macro retrieving driver from struct flash area
+ *
+ */
+#define DRV_FLASH_AREA(area) ((area)->fa_driver)
+
/*
* Start using flash area.
*/
diff --git a/bl2/ext/mcuboot/include/target.h b/bl2/ext/mcuboot/include/target.h
index d4350b032..9ead12986 100644
--- a/bl2/ext/mcuboot/include/target.h
+++ b/bl2/ext/mcuboot/include/target.h
@@ -47,6 +47,11 @@ defined by the target"
#error "FLASH_AREA_0_SIZE must be defined by the target"
#endif
+#if defined(FLASH_DEV_NAME_0) != defined(FLASH_DEVICE_ID_0)
+#error "FLASH DEV_NAME_0 and DEVICE_ID_0 must be simultaneously defined or not \
+by target"
+#endif
+
#ifndef FLASH_AREA_2_OFFSET
#error "FLASH_AREA_2_OFFSET must be defined by the target"
#endif
@@ -55,6 +60,11 @@ defined by the target"
#error "FLASH_AREA_2_SIZE must be defined by the target"
#endif
+#if defined(FLASH_DEV_NAME_2) != defined(FLASH_DEVICE_ID_2)
+#error "FLASH DEV_NAME_2 and DEVICE_ID_2 must be simultaneously defined or not \
+by target"
+#endif
+
#if (MCUBOOT_IMAGE_NUMBER == 2)
#ifndef FLASH_AREA_1_OFFSET
#error "FLASH_AREA_1_OFFSET must be defined by the target"
@@ -64,6 +74,11 @@ defined by the target"
#error "FLASH_AREA_1_SIZE must be defined by the target"
#endif
+#if defined(FLASH_DEV_NAME_1) != defined(FLASH_DEVICE_ID_1)
+#error "FLASH DEV_NAME_1 and DEVICE_ID_1 must be simultaneously defined or not \
+by target"
+#endif
+
#ifndef FLASH_AREA_3_OFFSET
#error "FLASH_AREA_3_OFFSET must be defined by the target"
#endif
@@ -71,6 +86,11 @@ defined by the target"
#ifndef FLASH_AREA_3_SIZE
#error "FLASH_AREA_3_SIZE must be defined by the target"
#endif
+
+#if defined(FLASH_DEV_NAME_3) != defined(FLASH_DEVICE_ID_3)
+#error "FLASH DEV_NAME_3 and DEVICE_ID_3 must be simultaneously defined or not \
+by target"
+#endif
#endif /* (MCUBOOT_IMAGE_NUMBER == 2) */
#ifndef FLASH_AREA_SCRATCH_OFFSET
@@ -81,6 +101,11 @@ defined by the target"
#error "FLASH_AREA_SCRATCH_SIZE must be defined by the target"
#endif
+#if defined(FLASH_DEV_NAME_SCRATCH) != defined(FLASH_DEVICE_ID_SCRATCH)
+#error "FLASH DEV_NAME_SCRATCH and DEVICE_ID_SCRATCH must be simultaneously defined \
+or not by target"
+#endif
+
#ifndef FLASH_DEV_NAME
#error "BL2 supports CMSIS flash interface and device name must be specified"
#endif
diff --git a/bl2/src/flash_map.c b/bl2/src/flash_map.c
index 7676da2f7..4286f86e6 100644
--- a/bl2/src/flash_map.c
+++ b/bl2/src/flash_map.c
@@ -12,41 +12,80 @@
#include "bootutil/bootutil_log.h"
#include "Driver_Flash.h"
-/* Flash device name must be specified by target */
-extern ARM_DRIVER_FLASH FLASH_DEV_NAME;
+/* When undefined FLASH_DEV_NAME_0 or FLASH_DEVICE_ID_0 , default */
+#if !defined(FLASH_DEV_NAME_0) || !defined(FLASH_DEVICE_ID_0)
+#define FLASH_DEV_NAME_0 FLASH_DEV_NAME
+#define FLASH_DEVICE_ID_0 FLASH_DEVICE_ID
+#endif
+
+/* When undefined FLASH_DEV_NAME_1 or FLASH_DEVICE_ID_1 , default */
+#if !defined(FLASH_DEV_NAME_1) || !defined(FLASH_DEVICE_ID_1)
+#define FLASH_DEV_NAME_1 FLASH_DEV_NAME
+#define FLASH_DEVICE_ID_1 FLASH_DEVICE_ID
+#endif
+
+/* When undefined FLASH_DEV_NAME_2 or FLASH_DEVICE_ID_2 , default */
+#if !defined(FLASH_DEV_NAME_2) || !defined(FLASH_DEVICE_ID_2)
+#define FLASH_DEV_NAME_2 FLASH_DEV_NAME
+#define FLASH_DEVICE_ID_2 FLASH_DEVICE_ID
+#endif
+
+/* When undefined FLASH_DEV_NAME_3 or FLASH_DEVICE_ID_3 , default */
+#if !defined(FLASH_DEV_NAME_3) || !defined(FLASH_DEVICE_ID_3)
+#define FLASH_DEV_NAME_3 FLASH_DEV_NAME
+#define FLASH_DEVICE_ID_3 FLASH_DEVICE_ID
+#endif
+
+/* When undefined FLASH_DEV_NAME_SCRATCH or FLASH_DEVICE_ID_SCRATCH , default */
+#if !defined(FLASH_DEV_NAME_SCRATCH) || !defined(FLASH_DEVICE_ID_SCRATCH)
+#define FLASH_DEV_NAME_SCRATCH FLASH_DEV_NAME
+#define FLASH_DEVICE_ID_SCRATCH FLASH_DEVICE_ID
+#endif
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
+/* Flash device names must be specified by target */
+extern ARM_DRIVER_FLASH FLASH_DEV_NAME_0;
+extern ARM_DRIVER_FLASH FLASH_DEV_NAME_1;
+extern ARM_DRIVER_FLASH FLASH_DEV_NAME_2;
+extern ARM_DRIVER_FLASH FLASH_DEV_NAME_3;
+extern ARM_DRIVER_FLASH FLASH_DEV_NAME_SCRATCH;
+
static const struct flash_area flash_map[] = {
{
.fa_id = FLASH_AREA_0_ID,
- .fa_device_id = FLASH_DEVICE_ID,
+ .fa_device_id = FLASH_DEVICE_ID_0,
+ .fa_driver = &FLASH_DEV_NAME_0,
.fa_off = FLASH_AREA_0_OFFSET,
.fa_size = FLASH_AREA_0_SIZE,
},
{
.fa_id = FLASH_AREA_2_ID,
- .fa_device_id = FLASH_DEVICE_ID,
+ .fa_device_id = FLASH_DEVICE_ID_2,
+ .fa_driver = &FLASH_DEV_NAME_2,
.fa_off = FLASH_AREA_2_OFFSET,
.fa_size = FLASH_AREA_2_SIZE,
},
#if (MCUBOOT_IMAGE_NUMBER == 2)
{
.fa_id = FLASH_AREA_1_ID,
- .fa_device_id = FLASH_DEVICE_ID,
+ .fa_device_id = FLASH_DEVICE_ID_1,
+ .fa_driver = &FLASH_DEV_NAME_1,
.fa_off = FLASH_AREA_1_OFFSET,
.fa_size = FLASH_AREA_1_SIZE,
},
{
.fa_id = FLASH_AREA_3_ID,
- .fa_device_id = FLASH_DEVICE_ID,
+ .fa_device_id = FLASH_DEVICE_ID_3,
+ .fa_driver = &FLASH_DEV_NAME_3,
.fa_off = FLASH_AREA_3_OFFSET,
.fa_size = FLASH_AREA_3_SIZE,
},
#endif
{
.fa_id = FLASH_AREA_SCRATCH_ID,
- .fa_device_id = FLASH_DEVICE_ID,
+ .fa_device_id = FLASH_DEVICE_ID_SCRATCH,
+ .fa_driver = &FLASH_DEV_NAME_SCRATCH,
.fa_off = FLASH_AREA_SCRATCH_OFFSET,
.fa_size = FLASH_AREA_SCRATCH_SIZE,
},
@@ -86,14 +125,14 @@ int flash_area_read(const struct flash_area *area, uint32_t off, void *dst,
uint32_t len)
{
BOOT_LOG_DBG("read area=%d, off=%#x, len=%#x", area->fa_id, off, len);
- return FLASH_DEV_NAME.ReadData(area->fa_off + off, dst, len);
+ return DRV_FLASH_AREA(area)->ReadData(area->fa_off + off, dst, len);
}
int flash_area_write(const struct flash_area *area, uint32_t off,
const void *src, uint32_t len)
{
BOOT_LOG_DBG("write area=%d, off=%#x, len=%#x", area->fa_id, off, len);
- return FLASH_DEV_NAME.ProgramData(area->fa_off + off, src, len);
+ return DRV_FLASH_AREA(area)->ProgramData(area->fa_off + off, src, len);
}
int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
@@ -103,12 +142,12 @@ int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
int32_t rc = 0;
BOOT_LOG_DBG("erase area=%d, off=%#x, len=%#x", area->fa_id, off, len);
- flash_info = FLASH_DEV_NAME.GetInfo();
+ flash_info = DRV_FLASH_AREA(area)->GetInfo();
if (flash_info->sector_info == NULL) {
/* Uniform sector layout */
while (deleted_len < len) {
- rc = FLASH_DEV_NAME.EraseSector(area->fa_off + off);
+ rc = DRV_FLASH_AREA(area)->EraseSector(area->fa_off + off);
if (rc != 0) {
break;
}
@@ -128,6 +167,6 @@ uint32_t flash_area_align(const struct flash_area *area)
{
ARM_FLASH_INFO *flash_info;
- flash_info = FLASH_DEV_NAME.GetInfo();
+ flash_info = DRV_FLASH_AREA(area)->GetInfo();
return flash_info->program_unit;
}