Reformat cgptlib to kernel style

No code changes, just reformatting.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: Ib8748df93c64395c88e1f789805393fcfe3ac419
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/42397
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Randall Spangler
2013-01-30 12:52:02 -08:00
committed by ChromeBot
parent 7993f257af
commit cefe12c105
6 changed files with 832 additions and 752 deletions

View File

@@ -9,20 +9,20 @@
#include "sysincludes.h"
enum {
GPT_SUCCESS = 0,
GPT_ERROR_NO_VALID_KERNEL,
GPT_ERROR_INVALID_HEADERS,
GPT_ERROR_INVALID_ENTRIES,
GPT_ERROR_INVALID_SECTOR_SIZE,
GPT_ERROR_INVALID_SECTOR_NUMBER,
GPT_ERROR_INVALID_UPDATE_TYPE,
GPT_ERROR_CRC_CORRUPTED,
GPT_ERROR_OUT_OF_REGION,
GPT_ERROR_START_LBA_OVERLAP,
GPT_ERROR_END_LBA_OVERLAP,
GPT_ERROR_DUP_GUID,
/* Number of errors */
GPT_ERROR_COUNT
GPT_SUCCESS = 0,
GPT_ERROR_NO_VALID_KERNEL,
GPT_ERROR_INVALID_HEADERS,
GPT_ERROR_INVALID_ENTRIES,
GPT_ERROR_INVALID_SECTOR_SIZE,
GPT_ERROR_INVALID_SECTOR_NUMBER,
GPT_ERROR_INVALID_UPDATE_TYPE,
GPT_ERROR_CRC_CORRUPTED,
GPT_ERROR_OUT_OF_REGION,
GPT_ERROR_START_LBA_OVERLAP,
GPT_ERROR_END_LBA_OVERLAP,
GPT_ERROR_DUP_GUID,
/* Number of errors */
GPT_ERROR_COUNT
};
/* Bit masks for GptData.modified field. */
@@ -31,56 +31,64 @@ enum {
#define GPT_MODIFIED_ENTRIES1 0x04
#define GPT_MODIFIED_ENTRIES2 0x08
#define TOTAL_ENTRIES_SIZE 16384 /* Size of GptData.primary_entries
* and secondary_entries: 128
* bytes/entry * 128 entries. */
/*
* Size of GptData.primary_entries and secondary_entries: 128 bytes/entry * 128
* entries.
*/
#define TOTAL_ENTRIES_SIZE 16384
/* The 'update_type' of GptUpdateKernelEntry()
* We expose TRY and BAD only because those are what verified boot needs.
* For more precise control on GPT attribute bits, please refer to
* gpt_internal.h */
/*
* The 'update_type' of GptUpdateKernelEntry(). We expose TRY and BAD only
* because those are what verified boot needs. For more precise control on GPT
* attribute bits, please refer to gpt_internal.h.
*/
enum {
GPT_UPDATE_ENTRY_TRY = 1,
/* System will be trying to boot the currently selected kernel partition.
* Update its try count if necessary. */
GPT_UPDATE_ENTRY_BAD = 2,
/* The currently selected kernel partition failed validation. Mark entry as
* invalid. */
/*
* System will be trying to boot the currently selected kernel
* partition. Update its try count if necessary.
*/
GPT_UPDATE_ENTRY_TRY = 1,
/*
* The currently selected kernel partition failed validation. Mark
* entry as invalid.
*/
GPT_UPDATE_ENTRY_BAD = 2,
};
typedef struct {
/* Fill in the following fields before calling GptInit() */
uint8_t *primary_header; /* GPT primary header, from sector 1 of disk
* (size: 512 bytes) */
uint8_t *secondary_header; /* GPT secondary header, from last sector of
* disk (size: 512 bytes) */
uint8_t *primary_entries; /* primary GPT table, follows primary header
* (size: 16 KB) */
uint8_t *secondary_entries; /* secondary GPT table, precedes secondary
* header (size: 16 KB) */
uint32_t sector_bytes; /* Size of a LBA sector, in bytes */
uint64_t drive_sectors; /* Size of drive in LBA sectors, in sectors */
/* Fill in the following fields before calling GptInit() */
/* GPT primary header, from sector 1 of disk (size: 512 bytes) */
uint8_t *primary_header;
/* GPT secondary header, from last sector of disk (size: 512 bytes) */
uint8_t *secondary_header;
/* Primary GPT table, follows primary header (size: 16 KB) */
uint8_t *primary_entries;
/* Secondary GPT table, precedes secondary header (size: 16 KB) */
uint8_t *secondary_entries;
/* Size of a LBA sector, in bytes */
uint32_t sector_bytes;
/* Size of drive in LBA sectors, in sectors */
uint64_t drive_sectors;
/* Outputs */
uint8_t modified; /* Which inputs have been modified?
* 0x01 = header1
* 0x02 = header2
* 0x04 = table1
* 0x08 = table2 */
int current_kernel; /* the current chromeos kernel index in partition table.
* -1 means not found on drive. Note that GPT partition
* numbers are traditionally 1-based, but we're using
* a zero-based index here.
*/
/* Outputs */
/* Which inputs have been modified? GPT_MODIFIED_* */
uint8_t modified;
/*
* The current chromeos kernel index in partition table. -1 means not
* found on drive. Note that GPT partition numbers are traditionally
* 1-based, but we're using a zero-based index here.
*/
int current_kernel;
/* Internal variables */
uint32_t valid_headers, valid_entries;
int current_priority;
/* Internal variables */
uint32_t valid_headers, valid_entries;
int current_priority;
} GptData;
int GptInit(GptData* gpt);
/* Initializes the GPT data structure's internal state. The following fields
* must be filled before calling this function:
/**
* Initializes the GPT data structure's internal state.
*
* The following fields must be filled before calling this function:
*
* primary_header
* secondary_header
@@ -100,19 +108,23 @@ int GptInit(GptData* gpt);
* GPT_ERROR_INVALID_SECTOR_SIZE, size of a sector is not supported,
* GPT_ERROR_INVALID_SECTOR_NUMBER, number of sectors in drive is invalid (too
* small) */
int GptInit(GptData *gpt);
int GptNextKernelEntry(GptData* gpt, uint64_t* start_sector, uint64_t* size);
/* Provides the location of the next kernel partition, in order of decreasing
* priority. On return the start_sector parameter contains the LBA sector
* for the start of the kernel partition, and the size parameter contains the
* size of the kernel partition in LBA sectors. gpt.current_kernel contains
* the partition index of the current chromeos kernel partition.
/**
* Provides the location of the next kernel partition, in order of decreasing
* priority.
*
* On return the start_sector parameter contains the LBA sector for the start
* of the kernel partition, and the size parameter contains the size of the
* kernel partition in LBA sectors. gpt.current_kernel contains the partition
* index of the current chromeos kernel partition.
*
* Returns GPT_SUCCESS if successful, else
* GPT_ERROR_NO_VALID_KERNEL, no avaliable kernel, enters recovery mode */
int GptNextKernelEntry(GptData *gpt, uint64_t *start_sector, uint64_t *size);
int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type);
/* Updates the kernel entry with the specified index, using the specified type
/**
* Updates the kernel entry with the specified index, using the specified type
* of update (GPT_UPDATE_ENTRY_*).
*
* On return the modified field may be set, if the GPT data has been modified
@@ -121,5 +133,6 @@ int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type);
* Returns GPT_SUCCESS if successful, else
* GPT_ERROR_INVALID_UPDATE_TYPE, invalid 'update_type' is given.
*/
int GptUpdateKernelEntry(GptData *gpt, uint32_t update_type);
#endif /* VBOOT_REFERENCE_CGPTLIB_H_ */