summaryrefslogtreecommitdiff
path: root/cgpt/flash_ts_drv.c
diff options
context:
space:
mode:
authorAlbert Chaulk <achaulk@chromium.org>2013-03-20 14:46:50 -0700
committerChromeBot <chrome-bot@google.com>2013-06-10 18:08:34 -0700
commit534723a6519267461855441279b321e6fc1e4e90 (patch)
tree3db0f4b48cb3c5a70934d85c036d7ba5eeabd245 /cgpt/flash_ts_drv.c
parent7e3f8601ba7240c86581f9bcfb6cb4c38f2ebb44 (diff)
downloadvboot-534723a6519267461855441279b321e6fc1e4e90.tar.gz
Integrate the flash key-value store code into cgpt.stabilize-4255.B
Integrates the FTS driver into cgpt. This driver is binary-format compatible with the linux driver for interoperabiilty. The cgpt changes load & store a hex-encoded mtd partition table in the FTS; we need some sort of encoding because FTS only stores NUL-terminated strings. Currently, the mtd code paths aren't executed in cgpt, only in the tests. It's also not hooked up to the vboot code yet, we will need to do that eventually. BUG=chromium:221745 TEST=new unit test added BRANCH=none Change-Id: I94eb0389d29aca0beb9d9a644465c7d86161b3c2 Original-Change-Id: I9fe2fa91b666572563426adb8fa9d426f9b60bbf Reviewed-on: https://gerrit.chromium.org/gerrit/46796 Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49789
Diffstat (limited to 'cgpt/flash_ts_drv.c')
-rw-r--r--cgpt/flash_ts_drv.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/cgpt/flash_ts_drv.c b/cgpt/flash_ts_drv.c
new file mode 100644
index 00000000..8c918866
--- /dev/null
+++ b/cgpt/flash_ts_drv.c
@@ -0,0 +1,76 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Utility for ChromeOS-specific GPT partitions, Please see corresponding .c
+ * files for more details.
+ */
+
+#include "flash_ts.h"
+
+#include "cgpt.h"
+#include "errno.h"
+#include "stdio.h"
+#include "string.h"
+
+inline int page_to_sector(const nand_geom *nand, int page) {
+ return page * (nand->szofpg / nand->szofsector);
+}
+
+int nand_read_page(const nand_geom *nand, int page, void *buf, int size) {
+ uint8_t *page_buff;
+
+ if (size > nand->szofpg) {
+ return -1;
+ }
+ if (Load((struct drive *)nand->user, &page_buff,
+ page_to_sector(nand, page), nand->szofsector,
+ (size + nand->szofsector - 1) / nand->szofsector)) {
+
+ // page may be not erased. return default data.
+ memset(buf, 0xff, size);
+ return 0;
+ }
+ memcpy(buf, page_buff, size);
+ free(page_buff);
+ return 0;
+}
+
+int nand_write_page(const nand_geom *nand,
+ int page, const void *buf, int size) {
+ void *page_buff;
+ int ret;
+
+ if (size > nand->szofpg) {
+ return -1;
+ }
+ page_buff = malloc(nand->szofpg);
+ if (!page_buff)
+ return -1;
+
+ memset(page_buff, 0xff, nand->szofpg);
+ memcpy(page_buff, buf, size < nand->szofpg ? size : nand->szofpg);
+
+ ret = Save((struct drive *)nand->user, page_buff, page_to_sector(nand, page),
+ nand->szofsector, nand->szofpg / nand->szofsector);
+ free(page_buff);
+ return ret;
+}
+
+int nand_erase_block(const nand_geom *nand, int block) {
+ int sector = block * (nand->szofblk / nand->szofsector);
+ int res;
+ void *erase_buff = malloc(nand->szofblk);
+ if (!erase_buff)
+ return -1;
+
+ memset(erase_buff, 0xff, nand->szofblk);
+ res = Save((struct drive *)nand->user, erase_buff, sector,
+ nand->szofsector, nand->szofblk / nand->szofsector);
+ free(erase_buff);
+ return res;
+}
+
+int nand_is_bad_block(const nand_geom *nand, int block) {
+ return 0;
+}