summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Chaulk <achaulk@chromium.org>2013-07-09 14:38:08 -0700
committerChromeBot <chrome-bot@google.com>2013-07-16 13:18:59 -0700
commit4464354b7805b7d81667d79624275f525b5a8b11 (patch)
treee3c9baa84092cb9efe11ff1cfe86a0c4a18a1c9d
parentabd06d1270fe5a48551d85a332bbc11f72805990 (diff)
downloadvboot-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>
-rw-r--r--cgpt/cgpt.c2
-rw-r--r--cgpt/cgpt.h3
-rw-r--r--cgpt/cgpt_add.c2
-rw-r--r--cgpt/cgpt_common.c58
-rw-r--r--cgpt/flash_ts_api.h25
5 files changed, 83 insertions, 7 deletions
diff --git a/cgpt/cgpt.c b/cgpt/cgpt.c
index 2851f7c5..e02bf4d6 100644
--- a/cgpt/cgpt.c
+++ b/cgpt/cgpt.c
@@ -118,6 +118,8 @@ int main(int argc, char *argv[]) {
}
}
+ TryInitMtd();
+
if (argc < 2) {
Usage();
return CGPT_FAILED;
diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h
index 7595c0e7..038a6d49 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -54,6 +54,7 @@ struct drive {
struct nand_layout {
int enabled;
+ int use_host_ioctl; /* Use ioctl() on /dev/fts to read/write. */
int bytes_per_page, pages_per_block, fts_block_offset, fts_block_size;
};
@@ -63,6 +64,8 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode);
int DriveClose(struct drive *drive, int update_as_needed);
int CheckValid(const struct drive *drive);
+void TryInitMtd(void);
+
/* Loads sectors from 'drive'.
* *buf is pointed to an allocated memory when returned, and should be
* freed.
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index e0e24b81..117b4a11 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -203,6 +203,7 @@ int CgptSetAttributes(CgptAddParams *params) {
if (params == NULL)
return CGPT_FAILED;
+ TryInitMtd();
if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR))
return CGPT_FAILED;
@@ -240,6 +241,7 @@ int CgptGetPartitionDetails(CgptAddParams *params) {
if (params == NULL)
return CGPT_FAILED;
+ TryInitMtd();
if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR))
return CGPT_FAILED;
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;
diff --git a/cgpt/flash_ts_api.h b/cgpt/flash_ts_api.h
new file mode 100644
index 00000000..47264a4d
--- /dev/null
+++ b/cgpt/flash_ts_api.h
@@ -0,0 +1,25 @@
+/* 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.
+ */
+#ifndef _LINUX_FLASH_TS_H_
+#define _LINUX_FLASH_TS_H_
+
+#include <asm/ioctl.h>
+#include <asm/types.h>
+
+#define FLASH_TS_MAX_KEY_SIZE 64
+#define FLASH_TS_MAX_VAL_SIZE 2048
+
+struct flash_ts_io_req {
+ char key[FLASH_TS_MAX_KEY_SIZE];
+ char val[FLASH_TS_MAX_VAL_SIZE];
+};
+
+#define FLASH_TS_IO_MAGIC 0xFE
+#define FLASH_TS_IO_SET _IOW(FLASH_TS_IO_MAGIC, 0, struct flash_ts_io_req)
+#define FLASH_TS_IO_GET _IOWR(FLASH_TS_IO_MAGIC, 1, struct flash_ts_io_req)
+
+#define FTS_DEVICE "/dev/fts"
+
+#endif /* _LINUX_FLASH_TS_H_ */