vboot: cgpt: Support writing GPT structs to NOR flash

This CL allows the GPT headers and partition entry arrays to be stored
in a NOR flash device. Instead of treating both the NOR and NAND devices
as one (in a sandwich way), this CL writes and reads the GPT structs
independently of the actual device that houses the partitions.
Therefore, the first usable LBA of the partitions will be at 0, and the
last usable LBA is at the end of the NAND.

  +------------------------+
  | NOR houses GPT structs |
  +------------------------+
        |
  0     |  Index into
  v     v
  +------------------------+
  | NAND houses partitions |
  +------------------------+

Note that the "my_lba", "alternate_lba", "entries_lba" in the GPT headers
are no longer meaningful.

Consumers of cgptlib will have to set "stored_on_device" to either
GPT_STORED_ON_DEVICE or GPT_STORED_OFF_DEVICE, and "gpt_drive_sectors"
to the number of 512-byte sectors available to store GPT structs.

The NOR read and write operations are done by "flashrom".

BUG=chromium:425677
BRANCH=none
TEST=unittest
TEST=build with DEBUG, cgpt create/add/show on a stumpy-moblab

Change-Id: I083b3c94da3b0bb3da1a7b10c6969774080a2afd
Reviewed-on: https://chromium-review.googlesource.com/226800
Reviewed-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
This commit is contained in:
Nam T. Nguyen
2014-10-24 13:20:39 -07:00
committed by chrome-internal-fetch
parent 43e0a9ed6c
commit 6ee52d9a92
15 changed files with 642 additions and 100 deletions

View File

@@ -90,7 +90,8 @@ int CheckParameters(GptData* gpt);
*
* Returns 0 if header is valid, 1 if invalid.
*/
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors);
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
uint8_t stored_on_device);
/**
* Calculate and return the header CRC.