summaryrefslogtreecommitdiff
path: root/include/flash.h
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2015-02-04 10:44:02 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-02-05 21:03:01 +0000
commitf8af89c40d974e79b3e69698f6d8aa98e0e40fc9 (patch)
tree9d469c96dd9240af3bff374aa93dc92a041c45bc /include/flash.h
parentc0be4409522bc53447940ac88aff455a6844427c (diff)
downloadchrome-ec-f8af89c40d974e79b3e69698f6d8aa98e0e40fc9.tar.gz
Support vboot hash and system version if flash isn't memory-mapped
Some EC chips (mec1322) use external SPI flash which is not mapped into the EC CPU's address space. These must explicitly read data from flash when calculating the vboot hash or reading the version string of the image which isn't currently loaded into code RAM. To test this bug, I used a board with known working mapped flash, and temporarily patched it to act like it didn't have mapped flash. Also add a flashread console command, useful for manually testing. BUG=chrome-os-partner:35308 BRANCH=glower,strago TEST=manual 1. Apply this patch to samus 2. Check result for 'vboot hash RW' 3. Check result for 'version' 4a. In board/samus/board.h, #undef CONFIG_FLASH_MAPPED and #define CONFIG_CMD_FLASH 4b. In chip/lm4/flash.c, add the following: int flash_physical_read(int offset, int size, char *data) { const char *src; if (offset > CONFIG_FLASH_SIZE || offset + size > CONFIG_FLASH_SIZE) return EC_ERROR_INVAL; src = (const char *)((uintptr_t)CONFIG_FLASH_BASE + offset); memcpy(data, src, size); return EC_SUCCESS; } Steps 4a,4b will make the LM4 chip act like it doesn't have memory-mapped flash. 5. From the dev system, util/flash_ec --board=samus --ro 6. Check result for 'vboot hash RW'. Should be same as 2. 7. Check result for 'version' for RW version. Should be same as in 3. 8. From the dev system, util/flash_ec --board=samus 9. sysjump rw 10. Check result for 'version' for RO version. Should be same as in 3. 11. Compare 'flashread 0x100 0x100' with 'md 0x100 0x40'. The results should be the same (but endian-swapped, since flashread is byte ordered and md is 32-bit ordered). 12. Revert changes from steps 4a-4b. Change-Id: I951d6f5603a84e326740936e4e84dfe6296a0f59 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/246200 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'include/flash.h')
-rw-r--r--include/flash.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/flash.h b/include/flash.h
index a77d5a1cb2..3a4a120938 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -39,6 +39,15 @@ enum flash_wp_range {
/* Low-level methods, for use by flash_common. */
/**
+ * Read from physical flash.
+ *
+ * @param offset Flash offset to write.
+ * @param size Number of bytes to write.
+ * @param data Destination buffer for data. Must be 32-bit aligned.
+ */
+int flash_physical_read(int offset, int size, char *data);
+
+/**
* Write to physical flash.
*
* Offset and size must be a multiple of CONFIG_FLASH_WRITE_SIZE.
@@ -190,6 +199,19 @@ int flash_get_size(void);
int flash_dataptr(int offset, int size_req, int align, const char **ptrp);
/**
+ * Read from flash.
+ *
+ * If flash is mapped (CONFIG_FLASH_MAPPED), it is usually more efficient to
+ * use flash_dataptr() to get a pointer directly to the flash memory rather
+ * than use flash_read(), since the former saves a memcpy() operation.
+ *
+ * @param offset Flash offset to write.
+ * @param size Number of bytes to write.
+ * @param data Destination buffer for data. Must be 32-bit aligned.
+ */
+int flash_read(int offset, int size, char *data);
+
+/**
* Write to flash.
*
* Offset and size must be a multiple of CONFIG_FLASH_WRITE_SIZE.