aboutsummaryrefslogtreecommitdiff
path: root/bl2
diff options
context:
space:
mode:
authorDavid Vincze <david.vincze@arm.com>2019-12-09 17:32:48 +0100
committerDavid Vincze <david.vincze@arm.com>2020-01-27 14:54:41 +0100
commit225c58fc4db1e4455f6a39541f51e1d20a62f6b7 (patch)
tree65e7886299ffa453815cfedceeeeecdc2134db27 /bl2
parente50af97f37ea17c8a395a87059b36de7a9f7e230 (diff)
downloadtrusted-firmware-m-225c58fc4db1e4455f6a39541f51e1d20a62f6b7.tar.gz
Boot: Use the same flash_map module as upstream MCUBoot
Add new sysflash.h and flash_map_extended.h files as they are needed to build TF-M with the original MCUBoot. Some of the macro definitions and function declarations from flash_map.h were moved into these new headers. Change-Id: I9b5ddeba9528c82c7ccfc59fbba5c661f0ad1084 Signed-off-by: David Vincze <david.vincze@arm.com>
Diffstat (limited to 'bl2')
-rw-r--r--bl2/ext/mcuboot/bl2_main.c8
-rw-r--r--bl2/ext/mcuboot/bootutil/src/bootutil_misc.c5
-rw-r--r--bl2/ext/mcuboot/bootutil/src/loader.c4
-rw-r--r--bl2/ext/mcuboot/flash_map_extended.c4
-rw-r--r--bl2/ext/mcuboot/include/flash_map/flash_map.h58
-rw-r--r--bl2/ext/mcuboot/include/flash_map_backend/flash_map_backend.h80
-rw-r--r--bl2/ext/mcuboot/include/sysflash/sysflash.h50
-rw-r--r--bl2/include/boot_record.h6
-rw-r--r--bl2/src/boot_record.c8
-rw-r--r--bl2/src/flash_map.c3
10 files changed, 154 insertions, 72 deletions
diff --git a/bl2/ext/mcuboot/bl2_main.c b/bl2/ext/mcuboot/bl2_main.c
index be231b0428..33d2156667 100644
--- a/bl2/ext/mcuboot/bl2_main.c
+++ b/bl2/ext/mcuboot/bl2_main.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2017-2020 Arm Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +24,10 @@
#include "bootutil/bootutil_log.h"
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
-#include "flash_map/flash_map.h"
-#include "bl2/include/boot_record.h"
+#include "flash_map_backend/flash_map_backend.h"
+#include "boot_record.h"
#include "security_cnt.h"
-#include "bl2/include/boot_hal.h"
+#include "boot_hal.h"
#if MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF
#include "uart_stdout.h"
#endif
diff --git a/bl2/ext/mcuboot/bootutil/src/bootutil_misc.c b/bl2/ext/mcuboot/bootutil/src/bootutil_misc.c
index a546916cdf..812443aa3e 100644
--- a/bl2/ext/mcuboot/bootutil/src/bootutil_misc.c
+++ b/bl2/ext/mcuboot/bootutil/src/bootutil_misc.c
@@ -21,7 +21,7 @@
* Original code taken from mcuboot project at:
* https://github.com/JuulLabs-OSS/mcuboot
* Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
- * Modifications are Copyright (c) 2019 Arm Limited.
+ * Modifications are Copyright (c) 2019-2020 Arm Limited.
*/
#include <assert.h>
@@ -30,7 +30,10 @@
#include <stddef.h>
#include <stdbool.h>
+#include "sysflash/sysflash.h"
#include "flash_map/flash_map.h"
+#include "flash_map_backend/flash_map_backend.h"
+
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
#include "bootutil_priv.h"
diff --git a/bl2/ext/mcuboot/bootutil/src/loader.c b/bl2/ext/mcuboot/bootutil/src/loader.c
index 5acf6bc1d3..e60467744a 100644
--- a/bl2/ext/mcuboot/bootutil/src/loader.c
+++ b/bl2/ext/mcuboot/bootutil/src/loader.c
@@ -21,7 +21,7 @@
* Original code taken from mcuboot project at:
* https://github.com/JuulLabs-OSS/mcuboot
* Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
- * Modifications are Copyright (c) 2018-2019 Arm Limited.
+ * Modifications are Copyright (c) 2018-2020 Arm Limited.
*/
/**
@@ -35,7 +35,9 @@
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
+#include "sysflash/sysflash.h"
#include "flash_map/flash_map.h"
+#include "flash_map_backend/flash_map_backend.h"
#include "bootutil/bootutil.h"
#include "bootutil/image.h"
#include "bootutil_priv.h"
diff --git a/bl2/ext/mcuboot/flash_map_extended.c b/bl2/ext/mcuboot/flash_map_extended.c
index 2e019bdc97..887f89be15 100644
--- a/bl2/ext/mcuboot/flash_map_extended.c
+++ b/bl2/ext/mcuboot/flash_map_extended.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2015 Runtime Inc
- * Copyright (c) 2019 Arm Limited.
+ * Copyright (c) 2019-2020 Arm Limited.
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,7 +15,9 @@
#include <errno.h>
#include "target.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 */
diff --git a/bl2/ext/mcuboot/include/flash_map/flash_map.h b/bl2/ext/mcuboot/include/flash_map/flash_map.h
index 1bc30f1698..f47b585622 100644
--- a/bl2/ext/mcuboot/include/flash_map/flash_map.h
+++ b/bl2/ext/mcuboot/include/flash_map/flash_map.h
@@ -21,7 +21,7 @@
* Original code taken from mcuboot project at:
* https://github.com/JuulLabs-OSS/mcuboot
* Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
- * Modifications are Copyright (c) 2018-2019 Arm Limited.
+ * Modifications are Copyright (c) 2018-2020 Arm Limited.
*/
#ifndef H_UTIL_FLASH_MAP_
@@ -50,33 +50,6 @@ extern "C" {
*/
#include <inttypes.h>
-#if (MCUBOOT_IMAGE_NUMBER == 1)
-/*
- * NOTE: the definition below returns the same values for true/false on
- * purpose, to avoid having to mark x as non-used by all callers when
- * running in single image mode.
- */
-#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_0_ID : \
- FLASH_AREA_0_ID)
-#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_2_ID : \
- FLASH_AREA_2_ID)
-#elif (MCUBOOT_IMAGE_NUMBER == 2)
-/* MCUBoot currently supports only up to 2 updatable firmware images.
- * If the number of the current image is greater than MCUBOOT_IMAGE_NUMBER - 1
- * then a dummy value will be assigned to the flash area macros.
- */
-#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_0_ID : \
- ((x) == 1) ? FLASH_AREA_1_ID : \
- 255 )
-#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_2_ID : \
- ((x) == 1) ? FLASH_AREA_3_ID : \
- 255 )
-#else
-#error "Image slot and flash area mapping is not defined"
-#endif
-
-#define FLASH_AREA_IMAGE_SCRATCH FLASH_AREA_SCRATCH_ID
-
/*
* For now, we only support one flash device.
*
@@ -138,16 +111,6 @@ struct flash_sector {
};
/*
- * Retrieve a memory-mapped flash device's base address.
- *
- * On success, the address will be stored in the value pointed to by
- * ret.
- *
- * Returns 0 on success, or an error code on failure.
- */
-int flash_device_base(uint8_t fd_id, uintptr_t *ret);
-
-/*
* Start using flash area.
*/
int flash_area_open(uint8_t id, const struct flash_area **area);
@@ -171,20 +134,6 @@ int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len);
uint32_t flash_area_align(const struct flash_area *area);
/*
- * Returns the value expected to be read when accessing any erased
- * flash byte.
- */
-uint8_t flash_area_erased_val(const struct flash_area *area);
-
-/*
- * Reads len bytes from off, and checks if the read data is erased.
- *
- * Returns 1 if erased, 0 if non-erased, and -1 on failure.
- */
-int flash_area_read_is_empty(const struct flash_area *area, uint32_t off,
- void *dst, uint32_t len);
-
-/*
* Given flash area ID, return info about sectors within the area.
*/
int flash_area_get_sectors(int fa_id, uint32_t *count,
@@ -197,11 +146,6 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,
__attribute__((deprecated))
int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);
-int flash_area_id_from_image_slot(int slot);
-int flash_area_id_from_multi_image_slot(int image_index, int slot);
-int flash_area_id_to_image_slot(int area_id);
-int flash_area_id_to_multi_image_slot(int image_index, int area_id);
-
#ifdef __cplusplus
}
#endif
diff --git a/bl2/ext/mcuboot/include/flash_map_backend/flash_map_backend.h b/bl2/ext/mcuboot/include/flash_map_backend/flash_map_backend.h
new file mode 100644
index 0000000000..09d69eaeb5
--- /dev/null
+++ b/bl2/ext/mcuboot/include/flash_map_backend/flash_map_backend.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2018 Nordic Semiconductor ASA
+ * Copyright (c) 2015 Runtime Inc
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/*
+ * Original code taken from mcuboot project at:
+ * https://github.com/JuulLabs-OSS/mcuboot
+ * Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
+ */
+
+#ifndef __FLASH_MAP_BACKEND_H__
+#define __FLASH_MAP_BACKEND_H__
+
+#include "flash_map/flash_map.h"
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Provides abstraction of flash regions for type of use.
+ *
+ * System will contain a map which contains flash areas. Every
+ * region will contain flash identifier, offset within flash and length.
+ */
+
+/*
+ * Retrieve a memory-mapped flash device's base address.
+ *
+ * On success, the address will be stored in the value pointed to by
+ * ret.
+ *
+ * Returns 0 on success, or an error code on failure.
+ */
+int flash_device_base(uint8_t fd_id, uintptr_t *ret);
+
+int flash_area_id_from_image_slot(int slot);
+int flash_area_id_from_multi_image_slot(int image_index, int slot);
+
+/**
+ * Converts the specified flash area ID to an image slot index.
+ *
+ * Returns image slot index (0 or 1), or -1 if ID doesn't correspond to an image
+ * slot.
+ */
+int flash_area_id_to_image_slot(int area_id);
+
+/**
+ * Converts the specified flash area ID and image index (in multi-image setup)
+ * to an image slot index.
+ *
+ * Returns image slot index (0 or 1), or -1 if ID doesn't correspond to an image
+ * slot.
+ */
+int flash_area_id_to_multi_image_slot(int image_index, int area_id);
+
+/*
+ * Returns the value expected to be read when accessing any erased
+ * flash byte.
+ */
+uint8_t flash_area_erased_val(const struct flash_area *fap);
+
+/*
+ * Reads len bytes from off, and checks if the read data is erased.
+ *
+ * Returns 1 if erased, 0 if non-erased, and -1 on failure.
+ */
+int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
+ void *dst, uint32_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __FLASH_MAP_BACKEND_H__ */
diff --git a/bl2/ext/mcuboot/include/sysflash/sysflash.h b/bl2/ext/mcuboot/include/sysflash/sysflash.h
new file mode 100644
index 0000000000..9ade3a3808
--- /dev/null
+++ b/bl2/ext/mcuboot/include/sysflash/sysflash.h
@@ -0,0 +1,50 @@
+/* Manual version of auto-generated version. */
+
+/*
+ * Original code taken from mcuboot project at:
+ * https://github.com/JuulLabs-OSS/mcuboot
+ * Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
+ * Modifications are Copyright (c) 2020 Arm Limited.
+ */
+
+#ifndef __SYSFLASH_H__
+#define __SYSFLASH_H__
+
+#include "flash_layout.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if (MCUBOOT_IMAGE_NUMBER == 1)
+/*
+ * NOTE: the definition below returns the same values for true/false on
+ * purpose, to avoid having to mark x as non-used by all callers when
+ * running in single image mode.
+ */
+#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_0_ID : \
+ FLASH_AREA_0_ID)
+#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_2_ID : \
+ FLASH_AREA_2_ID)
+#elif (MCUBOOT_IMAGE_NUMBER == 2)
+/* MCUBoot currently supports only up to 2 updatable firmware images.
+ * If the number of the current image is greater than MCUBOOT_IMAGE_NUMBER - 1
+ * then a dummy value will be assigned to the flash area macros.
+ */
+#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_0_ID : \
+ ((x) == 1) ? FLASH_AREA_1_ID : \
+ 255 )
+#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_2_ID : \
+ ((x) == 1) ? FLASH_AREA_3_ID : \
+ 255 )
+#else
+#error "Image slot and flash area mapping is not defined"
+#endif
+
+#define FLASH_AREA_IMAGE_SCRATCH FLASH_AREA_SCRATCH_ID
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SYSFLASH_H__ */ \ No newline at end of file
diff --git a/bl2/include/boot_record.h b/bl2/include/boot_record.h
index 51bfc1dc10..c39d7525b9 100644
--- a/bl2/include/boot_record.h
+++ b/bl2/include/boot_record.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -11,8 +11,8 @@
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
-#include "../ext/mcuboot/bootutil/include/bootutil/image.h"
-#include "../ext/mcuboot/include/flash_map/flash_map.h"
+#include "bootutil/image.h"
+#include "flash_map/flash_map.h"
#ifdef __cplusplus
extern "C" {
diff --git a/bl2/src/boot_record.c b/bl2/src/boot_record.c
index 758525184c..2c6146ac85 100644
--- a/bl2/src/boot_record.c
+++ b/bl2/src/boot_record.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -10,9 +10,9 @@
#include "tfm_boot_status.h"
#include "target.h"
#include "../ext/mcuboot/bootutil/src/bootutil_priv.h"
-#include "../ext/mcuboot/bootutil/include/bootutil/image.h"
-#include "../ext/mcuboot/bootutil/include/bootutil/sha256.h"
-#include "../ext/mcuboot/include/flash_map/flash_map.h"
+#include "bootutil/image.h"
+#include "bootutil/sha256.h"
+#include "flash_map/flash_map.h"
#include <stdint.h>
#include <string.h>
#include <stdio.h>
diff --git a/bl2/src/flash_map.c b/bl2/src/flash_map.c
index 1b0f20bc45..72e7ca137a 100644
--- a/bl2/src/flash_map.c
+++ b/bl2/src/flash_map.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,6 +9,7 @@
#include "target.h"
#include "bl2_util.h"
#include "flash_map/flash_map.h"
+#include "flash_map_backend/flash_map_backend.h"
#include "bootutil/bootutil_log.h"
#include "Driver_Flash.h"