summaryrefslogtreecommitdiff
path: root/include/flash.h
diff options
context:
space:
mode:
authorRong Chang <rongchang@google.com>2017-02-20 16:15:09 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-06-02 16:59:36 -0700
commit9ca4586129844b86ca4b346860ab658754228d2b (patch)
treee8bd729cb6cca3f76b9aca3a9a0b0f1d204d6ef4 /include/flash.h
parentd0ee126b4cdc368c36ae6660d66fed1524476e59 (diff)
downloadchrome-ec-9ca4586129844b86ca4b346860ab658754228d2b.tar.gz
common: Add support for flash with regions of different size
Add support to handle devices with flash regions of different sizes. BRANCH=none TEST=compile BUG=b:38018926 Change-Id: I8f842abaa50de724df60dd7e19f9e97cb9660367 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/264031 Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Diffstat (limited to 'include/flash.h')
-rw-r--r--include/flash.h56
1 files changed, 51 insertions, 5 deletions
diff --git a/include/flash.h b/include/flash.h
index 5963020c8a..cdd8148d03 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -11,11 +11,51 @@
#include "common.h"
#include "ec_commands.h" /* For EC_FLASH_PROTECT_* flags */
-/* Number of physical flash banks */
+#ifdef CONFIG_FLASH_MULTIPLE_REGION
+extern struct ec_flash_bank const flash_bank_array[
+ CONFIG_FLASH_REGION_TYPE_COUNT];
+
+/*
+ * Return the bank the offset is in.
+ * Return -1 if the offset is not at the beginning of that bank.
+ */
+int flash_bank_index(int offset);
+
/*
- * TODO(crosbug.com/p/62372): This assumes flash protection blocks are all of
- * identical sizes, which is incorrect, for example, on STM32F091VC.
+ * Number of banks between offset and offset+size.
+ *
+ * offset and offset + size should be addresses at the beginning of bank:
+ * 0 32
+ * +-------------------+--------...
+ * | bank 0 | bank 1 ...
+ * +-------------------+--------...
+ * In that case, begin = 0, end = 1, return is 1.
+ * otherwise, this is an error:
+ * 0 32 64
+ * +----------+--------+--------...
+ * | bank 0 | bank 1 ...
+ * +----------+--------+--------...
+ * begin = 0, end = -1....
+ * The idea is to prevent erasing more than you think.
*/
+int flash_bank_count(int offset, int size);
+
+/*
+ * Return the size of the specified bank in bytes.
+ * Return -1 if the bank is too large.
+ */
+int flash_bank_size(int bank);
+
+/* Number of physical flash banks */
+#define PHYSICAL_BANKS CONFIG_FLASH_MULTIPLE_REGION
+
+/* WP region offset and size in units of flash banks */
+#define WP_BANK_OFFSET flash_bank_index(CONFIG_WP_STORAGE_OFF)
+#define WP_BANK_COUNT \
+ (flash_bank_count(CONFIG_WP_STORAGE_OFF, CONFIG_WP_STORAGE_SIZE))
+
+#else /* CONFIG_FLASH_MULTIPLE_REGION */
+/* Number of physical flash banks */
#ifndef PHYSICAL_BANKS
#define PHYSICAL_BANKS (CONFIG_FLASH_SIZE / CONFIG_FLASH_BANK_SIZE)
#endif
@@ -25,18 +65,24 @@
#ifndef WP_BANK_COUNT
#define WP_BANK_COUNT (CONFIG_WP_STORAGE_SIZE / CONFIG_FLASH_BANK_SIZE)
#endif
+#endif /* CONFIG_FLASH_MULTIPLE_REGION */
/* Persistent protection state flash offset / size / bank */
#if defined(CONFIG_FLASH_PSTATE) && defined(CONFIG_FLASH_PSTATE_BANK)
+
+#ifdef CONFIG_FLASH_MULTIPLE_REGION
+#error "Not supported."
+#endif
+
#ifndef PSTATE_BANK
#define PSTATE_BANK (CONFIG_FW_PSTATE_OFF / CONFIG_FLASH_BANK_SIZE)
#endif
#ifndef PSTATE_BANK_COUNT
#define PSTATE_BANK_COUNT (CONFIG_FW_PSTATE_SIZE / CONFIG_FLASH_BANK_SIZE)
#endif
-#else
+#else /* CONFIG_FLASH_PSTATE && CONFIG_FLASH_PSTATE_BANK */
#define PSTATE_BANK_COUNT 0
-#endif
+#endif /* CONFIG_FLASH_PSTATE && CONFIG_FLASH_PSTATE_BANK */
#ifdef CONFIG_ROLLBACK
/*