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

@@ -57,6 +57,24 @@ enum {
GPT_UPDATE_ENTRY_BAD = 2,
};
enum {
GPT_STORED_ON_DEVICE = 0, /* The GPT is stored on the same device. */
GPT_STORED_OFF_DEVICE = 1, /* The GPT is stored on another place. */
};
/*
* A note about stored_on_device and gpt_drive_sectors:
*
* This code is used by both the "cgpt" utility and depthcharge/vboot. ATM,
* depthcharge does not have logic to properly setup stored_on_device and
* gpt_drive_sectors, but it does do a memset(gpt, 0, sizeof(GptData)). And so,
* GPT_STORED_ON_DEVICE should be 0 to make stored_on_device compatible with
* present behavior. At the same time, in vboot_kernel:LoadKernel(), and
* cgpt_common:GptLoad(), we need to have simple shims to set gpt_drive_sectors
* to drive_sectors.
*
* TODO(namnguyen): Remove those shims when the firmware can set these fields.
*/
typedef struct {
/* Fill in the following fields before calling GptInit() */
/* GPT primary header, from sector 1 of disk (size: 512 bytes) */
@@ -69,8 +87,12 @@ typedef struct {
uint8_t *secondary_entries;
/* Size of a LBA sector, in bytes */
uint32_t sector_bytes;
/* Size of drive in LBA sectors, in sectors */
/* Size of drive (that the partitions are on) in LBA sectors */
uint64_t drive_sectors;
/* Are the GPT structures stored on the same device */
uint8_t stored_on_device;
/* Size of the device that holds the GPT structures, 512-byte sectors */
uint64_t gpt_drive_sectors;
/* Outputs */
/* Which inputs have been modified? GPT_MODIFIED_* */
@@ -98,6 +120,8 @@ typedef struct {
* secondary_entries
* sector_bytes
* drive_sectors
* stored_on_device
* gpt_device_sectors
*
* On return the modified field may be set, if the GPT data has been modified
* and should be written to disk.