summaryrefslogtreecommitdiff
path: root/include/flash.h
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-06-24 11:57:25 -0700
committerGerrit <chrome-bot@google.com>2012-07-02 22:35:51 -0700
commit9a4eff992fa0efdbbe909ed0e635b7139f178948 (patch)
treef1eac29e6b67087cc80bce256687af7dcb7c0dca /include/flash.h
parent9b48067b09aaace6e1d5526a65473392f12389c1 (diff)
downloadchrome-ec-9a4eff992fa0efdbbe909ed0e635b7139f178948.tar.gz
flash: Provide direct flash access with flash_dataptr()
Sometimes it is useful to get access to the flash directly, without using flash_read(). Add a function to do this. Since the range checking is done in every function in flash_common, use the new function to do it for us. That way we get a slight (64 byte) code size reduction. BUG=chrome-os-partner:10146 TEST=manual: build and boot on snow with SPI flash emulation, in U-Boot: See that the 32KB of flash has been provided correctly. Change-Id: I6622a24234edaed371dd5b9bf43d1f3974d55e39 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/26174
Diffstat (limited to 'include/flash.h')
-rw-r--r--include/flash.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/flash.h b/include/flash.h
index 9b0a60a5e2..7611639add 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -24,6 +24,22 @@ int flash_get_protect_block_size(void);
/* Return the physical size of flash in bytes */
int flash_physical_size(void);
+/**
+ * Get the physical memory address of a flash offset
+ *
+ * This is used for direct flash access. We assume that the flash is
+ * contiguous from this start address through to the end of the usable
+ * flash.
+ *
+ * @param offset Flash offset to get address of
+ * @param dataptrp Returns pointer to memory address of flash offset
+ * @return pointer to flash memory offset, if ok, else NULL
+ */
+static inline char *flash_physical_dataptr(int offset)
+{
+ return (char *)offset;
+}
+
/* Read <size> bytes of data from offset <offset> into <data>. */
int flash_physical_read(int offset, int size, char *data);
@@ -50,6 +66,27 @@ int flash_pre_init(void);
* smaller than the actual flash size, */
int flash_get_size(void);
+/**
+ * Get the physical memory address of a flash offset
+ *
+ * This is used for direct flash access. We assume that the flash is
+ * contiguous from this start address through to the end of the usable
+ * flash.
+ *
+ * This function returns NULL if offset + size_req extends beyond the end
+ * of flash, or if either size_req or offset are not aligned to 'align'.
+ *
+ * @param offset Flash offset to get address of
+ * @param size_req Number of bytes requested
+ * @param align Ensure offset and size_req are aligned to given
+ * power of two.
+ * @param sizep If not NULL, returns amount of flash available at
+ * this memory addr, unless function fails, iwc it is
+ * unset.
+ * @return pointer to flash, or NULL on error
+ */
+char *flash_dataptr(int offset, int size_req, int align, int *sizep);
+
/* Reads <size> bytes of data from offset <offset> into <data>. */
int flash_read(int offset, int size, char *data);