summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_nor.h
diff options
context:
space:
mode:
authorNam T. Nguyen <namnguyen@chromium.org>2015-01-08 11:43:27 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-17 05:49:12 +0000
commitd1236e4be6a7fe1c2b132ca8f63a513949d59775 (patch)
treea6abf13a37152c07a2a37f1b0eba3ac452b824c4 /cgpt/cgpt_nor.h
parent4edc75daa696f9e6fa39205117233ed68dcbed43 (diff)
downloadvboot-d1236e4be6a7fe1c2b132ca8f63a513949d59775.tar.gz
Add cgpt_wrapper binary to transparently support NAND
This CL adds a "cgpt_wrapper" binary that will forward to "cgpt" binary as needed to transparently support NAND. The idea is that if we are working with an MTD device, this binary will exec out to "flashrom" to read in the GPT section, then exec out to the actual "cgpt" binary to work on that file, and finally write it back with "flashrom". This CL introduces a make target "install_mtd" to install this wrapper. The corresponding ebuild should use this make target when "mtd" USE flag is on. BUG=chromium:442518 BRANCH=none CQ-DEPEND=CL:239573 TEST=unittest and some trial runs with mtdram TEST=test on a real device with NOR flash and NAND Change-Id: I54534afa9a970ec858f313f698c0eb210c827477 Reviewed-on: https://chromium-review.googlesource.com/239580 Tested-by: Nam Nguyen <namnguyen@chromium.org> Reviewed-by: Daniel Ehrenberg <dehrenberg@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Diffstat (limited to 'cgpt/cgpt_nor.h')
-rw-r--r--cgpt/cgpt_nor.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/cgpt/cgpt_nor.h b/cgpt/cgpt_nor.h
new file mode 100644
index 00000000..b01f88d8
--- /dev/null
+++ b/cgpt/cgpt_nor.h
@@ -0,0 +1,34 @@
+/* Copyright 2015 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.
+ *
+ * This module provides some utility functions to use "flashrom" to read from
+ * and write to NOR flash.
+ */
+
+#ifndef VBOOT_REFERCENCE_CGPT_CGPT_NOR_H_
+#define VBOOT_REFERCENCE_CGPT_CGPT_NOR_H_
+
+// Obtain the MTD size from its sysfs node. |mtd_device| should point to
+// a dev node such as /dev/mtd0. This function returns 0 on success.
+int GetMtdSize(const char *mtd_device, uint64_t *size);
+
+// Exec |argv| in |cwd|. Return -1 on error, or exit code on success. |argv|
+// must be terminated with a NULL element as is required by execv().
+int ForkExecV(const char *cwd, const char *const argv[]);
+
+// Similar to ForkExecV but with a vararg instead of an array of pointers.
+int ForkExecL(const char *cwd, const char *cmd, ...);
+
+// Exec "rm" to remove |dir|.
+int RemoveDir(const char *dir);
+
+// Read RW_GPT from NOR flash to "rw_gpt" in a temp dir |temp_dir_template|.
+// |temp_dir_template| is passed to mkdtemp() so it must satisfy all
+// requirements by mkdtemp().
+int ReadNorFlash(char *temp_dir_template);
+
+// Write "rw_gpt" back to NOR flash. We write the file in two parts for safety.
+int WriteNorFlash(const char *dir);
+
+#endif // VBOOT_REFERCENCE_CGPT_CGPT_NOR_H_