diff options
author | Albert Chaulk <achaulk@chromium.org> | 2013-07-09 14:38:08 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-16 13:18:59 -0700 |
commit | 4464354b7805b7d81667d79624275f525b5a8b11 (patch) | |
tree | e3c9baa84092cb9efe11ff1cfe86a0c4a18a1c9d /cgpt/cgpt_common.c | |
parent | abd06d1270fe5a48551d85a332bbc11f72805990 (diff) | |
download | vboot-4464354b7805b7d81667d79624275f525b5a8b11.tar.gz |
MTD: When running on the host (as during install) use the host FTS if possible.
BUG=chromium:252331
TEST='make runtests' still passes
BRANCH=none
Change-Id: I1deb70766b811b070f0f412cb5cfa583250dd687
Reviewed-on: https://gerrit.chromium.org/gerrit/61328
Commit-Queue: Albert Chaulk <achaulk@chromium.org>
Reviewed-by: Albert Chaulk <achaulk@chromium.org>
Tested-by: Albert Chaulk <achaulk@chromium.org>
Diffstat (limited to 'cgpt/cgpt_common.c')
-rw-r--r-- | cgpt/cgpt_common.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c index 7b206d68..8b3b8a45 100644 --- a/cgpt/cgpt_common.c +++ b/cgpt/cgpt_common.c @@ -24,6 +24,7 @@ #include "cgptlib_internal.h" #include "crc32.h" #include "flash_ts.h" +#include "flash_ts_api.h" #include "vboot_host.h" struct nand_layout nand = { @@ -149,12 +150,40 @@ static int get_hex_char_value(char ch) { return -1; } +void TryInitMtd(void) { + static int already_inited = 0; + if (nand.enabled || already_inited) + return; + + already_inited = 1; + + /* If we're running on the live system, we can just use /dev/fts and not + * actually need the specific parameters. + */ + if (!access(FTS_DEVICE, R_OK | W_OK)) { + nand.enabled = 1; + nand.use_host_ioctl = 1; + } +} + int FlashGet(const char *key, uint8_t *data, uint32_t *bufsz) { char *hex = (char*)malloc(*bufsz * 2); char *read; uint32_t written = 0; - flash_ts_get(key, hex, *bufsz * 2); + if (nand.use_host_ioctl) { + struct flash_ts_io_req req; + strncpy(req.key, key, sizeof(req.key)); + int fd = open("/dev/fts", O_RDWR); + if (fd < 0) + return -1; + if (ioctl(fd, FLASH_TS_IO_GET, &req)) + return -1; + strncpy(hex, req.val, *bufsz * 2); + close(fd); + } else { + flash_ts_get(key, hex, *bufsz * 2); + } /* Hex -> binary */ for (read = hex; read < hex + *bufsz * 2 && *read != '\0'; read += 2) { @@ -186,6 +215,19 @@ int FlashSet(const char *key, const uint8_t *data, uint32_t bufsz) { } /* Buffer must be NUL-terminated. */ hex[bufsz * 2] = '\0'; + if (nand.use_host_ioctl) { + struct flash_ts_io_req req; + strncpy(req.key, key, sizeof(req.key)); + strncpy(req.val, hex, sizeof(req.val)); + free(hex); + int fd = open("/dev/fts", O_RDWR); + if (fd < 0) + return -1; + if (ioctl(fd, FLASH_TS_IO_SET, &req)) + return -1; + close(fd); + return 0; + } ret = flash_ts_set(key, hex); free(hex); return ret; @@ -199,12 +241,14 @@ int MtdLoad(struct drive *drive, int sector_bytes) { mtd->sector_bytes = sector_bytes; mtd->drive_sectors = drive->size / mtd->sector_bytes; - ret = flash_ts_init(mtd->fts_block_offset, - mtd->fts_block_size, - mtd->flash_page_bytes, - mtd->flash_block_bytes, - mtd->sector_bytes, /* Needed for Load() and Save() */ - drive); + if (!nand.use_host_ioctl) { + ret = flash_ts_init(mtd->fts_block_offset, + mtd->fts_block_size, + mtd->flash_page_bytes, + mtd->flash_block_bytes, + mtd->sector_bytes, /* Needed for Load() and Save() */ + drive); + } if (ret) return ret; |