vboot: cgpt: Treat drive_path as the GPT storage
Previously, "cgpt" called out to "flashrom" directly to read and write
NOR area. This CL removes that dependency and always treats "drive_path"
as the storage of GPT structs. This makes it consistent that whatever
device that cgpt reads from or writes to is always the device that
stores GPT structs. We only need to pass in the size of the drive that
contains the partitions, but we do not need to access to that drive.
More information is in the bug.
BUG=chromium:432611
BRANCH=none
TEST=unittest
CQ-DEPEND=CL:228942
Change-Id: Id0139adf70463cec4f2924de8b9a4725dbec822b
Reviewed-on: https://chromium-review.googlesource.com/229736
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h
index ea459cb..bb3438a 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -12,7 +12,6 @@
#include <stdlib.h>
#include "cgpt_endian.h"
#include "cgptlib.h"
-#include "drive.h"
#include "gpt.h"
#include "mtdlib.h"
@@ -48,28 +47,7 @@
GptData gpt;
MtdData mtd;
struct pmbr pmbr;
- /*
- * For use with regular file or block device.
- * GPT structures will occupy the first and last few blocks.
- */
- struct {
- int fd; /* file descriptor */
- };
- /*
- * For use with flash.
- * GPT structures will be stored in flash, while the partitions are in
- * /dev/mtd*.
- */
- struct {
- off_t current_position; /* for used by DriveSeekFunc */
- uint32_t flash_start; /* offset where we can write to flash, in FMAP */
- uint32_t flash_size; /* size of that area, in bytes, in FMAP */
- }; /* for use with flashrom */
- DriveSeekFunc seek;
- DriveReadFunc read;
- DriveWriteFunc write;
- DriveSyncFunc sync;
- DriveCloseFunc close;
+ int fd; /* file descriptor */
};
struct nand_layout {
@@ -83,11 +61,16 @@
int fts_block_offset, int fts_block_size);
// Opens a block device or file, loads raw GPT data from it.
-// mode should be O_RDONLY or O_RDWR
+// 'mode' should be O_RDONLY or O_RDWR.
+// If 'drive_size' is 0, both the partitions and GPT structs reside on the same
+// 'drive_path'.
+// Otherwise, 'drive_size' is taken as the size of the device that all
+// partitions will reside on, and 'drive_path' is where we store GPT structs.
//
// Returns CGPT_FAILED if any error happens.
-// Returns CGPT_OK if success and information are stored in 'drive'.
-int DriveOpen(const char *drive_path, struct drive *drive, int mode);
+// Returns CGPT_OK if success and information are stored in 'drive'. */
+int DriveOpen(const char *drive_path, struct drive *drive, int mode,
+ uint64_t drive_size);
int DriveClose(struct drive *drive, int update_as_needed);
int CheckValid(const struct drive *drive);