summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-04-14 15:38:45 +0800
committerSimon Glass <sjg@chromium.org>2011-08-24 10:01:05 -0700
commit9d608973a908965749f0b005f92ba9585ebc2c98 (patch)
tree5310eb2b11744464f604c95f06eb1533277151ef
parent1d38d11a56bef244575a2f79f8fe7e722e80eddd (diff)
HACK: Temporarily change VbNvContext from SPI to eMMC
So far kernel does not have a SPI flash driver. That means kernel cannot access VbNvContext in SPI flash for now. Here is a temporary workaround for factory bring up that changes the VbNvContext storage device from SPI flash to eMMC, where we are certain that kernel is able to access. R=rongchang@chromium.org BUG=none TEST=none Review URL: http://codereview.chromium.org/6825069 Change-Id: I60059ef23e57facc278340db6613caa83c76529a
-rw-r--r--common/cmd_mmc.c7
-rw-r--r--include/mmc.h2
-rw-r--r--lib/chromeos/vboot_nvstorage_helper.c115
3 files changed, 122 insertions, 2 deletions
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 64eeeb43e21..5df66e431d4 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -27,6 +27,13 @@
static int curr_device = -1;
#ifndef CONFIG_GENERIC_MMC
+
+/* TODO: temporary hack for factory bring up; remove/rewrite when necessary */
+int get_mmc_current_device(void)
+{
+ return curr_device;
+}
+
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int dev;
diff --git a/include/mmc.h b/include/mmc.h
index 4701e2482f5..6891613ea98 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -313,6 +313,8 @@ int atmel_mci_init(void *regs);
struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
#else
int mmc_legacy_init(int verbose);
+/* TODO: temporary hack for factory bring up; remove/rewrite when necessary */
+int get_mmc_current_device(void);
#endif
#endif /* _MMC_H_ */
diff --git a/lib/chromeos/vboot_nvstorage_helper.c b/lib/chromeos/vboot_nvstorage_helper.c
index c03a60dfc16..e8fd63003d7 100644
--- a/lib/chromeos/vboot_nvstorage_helper.c
+++ b/lib/chromeos/vboot_nvstorage_helper.c
@@ -37,6 +37,118 @@
#include <common.h>
#include <chromeos/vboot_nvstorage_helper.h>
+/* TODO: temporary hack for factory bring up; remove/rewrite when necessary */
+#include <mmc.h>
+#include <part.h>
+#include <linux/string.h>
+
+/*
+ * TODO: So far (2011/04/12) kernel does not have a SPI flash driver. That
+ * means kernel cannot access cookies in SPI flash. (In addition, there is
+ * an on-going discussion about the storage device for these cookies. So the
+ * final storage of the cookies might even not be SPI flash after a couple of
+ * months.) Here is a temporary workaround for factory bring up that stores
+ * the cookies in mmc device where we are certain that kernel can access.
+ */
+
+#define PREFIX "vboot_nvstorage_helper: "
+
+#define BACKUP_LBA_OFFSET 0x20
+
+uint64_t get_nvcxt_lba(void)
+{
+ int cur_dev = get_mmc_current_device();
+ block_dev_desc_t *dev_desc = NULL;
+ uint64_t nvcxt_lba;
+ uint8_t buf[512];
+
+ /* use side effect of "mmc init 0" to set current device for us */
+ if (cur_dev == -1)
+ run_command("mmc init 0", 0);
+ else if (cur_dev != 0)
+ initialize_mmc_device(0);
+
+ if ((dev_desc = get_dev("mmc", 0)) == NULL) {
+ debug(PREFIX "get_dev fail\n");
+ return ~0ULL;
+ }
+
+ if (dev_desc->block_read(dev_desc->dev, 1, 1, buf) < 0) {
+ debug(PREFIX "read primary GPT table fail\n");
+ return ~0ULL;
+ }
+
+ nvcxt_lba = 1 + *(uint64_t*) (buf + BACKUP_LBA_OFFSET);
+
+ /* restore previous device */
+ if (cur_dev != -1 && cur_dev != 0)
+ initialize_mmc_device(cur_dev);
+
+ return nvcxt_lba;
+}
+
+static int access_nvcontext(firmware_storage_t *file, VbNvContext *nvcxt,
+ int is_read)
+{
+ int cur_dev = get_mmc_current_device();
+ block_dev_desc_t *dev_desc = NULL;
+ uint64_t nvcxt_lba;
+ uint8_t buf[512];
+
+ debug(PREFIX "cur_dev: %d\n", cur_dev);
+
+ /* use side effect of "mmc init 0" to set current device for us */
+ if (cur_dev == -1)
+ run_command("mmc init 0", 0);
+ else if (cur_dev != 0)
+ initialize_mmc_device(0);
+
+ if ((dev_desc = get_dev("mmc", 0)) == NULL) {
+ debug(PREFIX "get_dev fail\n");
+ return -1;
+ }
+
+ if (dev_desc->block_read(dev_desc->dev, 1, 1, buf) < 0) {
+ debug(PREFIX "read primary GPT table fail\n");
+ return -1;
+ }
+
+ nvcxt_lba = 1 + *(uint64_t*) (buf + BACKUP_LBA_OFFSET);
+
+ if (is_read) {
+ if (dev_desc->block_read(dev_desc->dev,
+ nvcxt_lba, 1, buf) < 0) {
+ debug(PREFIX "block_read fail\n");
+ return -1;
+ }
+ memcpy(nvcxt->raw, buf, VBNV_BLOCK_SIZE);
+ } else {
+ memcpy(buf, nvcxt->raw, VBNV_BLOCK_SIZE);
+ if (dev_desc->block_write(dev_desc->dev,
+ nvcxt_lba, 1, buf) < 0) {
+ debug(PREFIX "block_write fail\n");
+ return -1;
+ }
+ }
+
+ /* restore previous device */
+ if (cur_dev != -1 && cur_dev != 0)
+ initialize_mmc_device(cur_dev);
+
+ return 0;
+}
+
+int read_nvcontext(firmware_storage_t *file, VbNvContext *nvcxt)
+{
+ return access_nvcontext(file, nvcxt, 1);
+}
+
+int write_nvcontext(firmware_storage_t *file, VbNvContext *nvcxt)
+{
+ return access_nvcontext(file, nvcxt, 0);
+}
+
+#if 0
/*
* TODO It should averagely distributed erase/write operation to entire flash
* memory section allocated for VBNVCONTEXT to increase maximal lifetime.
@@ -45,8 +157,6 @@
* an overkill.
*/
-#define PREFIX "vboot_nvstorage_helper: "
-
int read_nvcontext(firmware_storage_t *file, VbNvContext *nvcxt)
{
if (firmware_storage_read(file,
@@ -75,3 +185,4 @@ int write_nvcontext(firmware_storage_t *file, VbNvContext *nvcxt)
return 0;
}
+#endif