mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-26 19:25:02 +00:00
This reduces the number of exported header files to the minimum needed by
the existing userspace utilities and firmware implementations.
BUG=chromium:221544
BRANCH=none
TEST=manual, trybots
CQ-DEPEND=CL:47019,CL:47022,CL:47023
sudo FEATURES=test emerge vboot_reference
FEATURES=test emerge-$BOARD \
vboot_reference \
chromeos-cryptohome \
chromeos-installer \
chromeos-u-boot \
peach-u-boot \
depthcharge
Change-Id: I2946cc2dbaf5459a6c5eca92ca57d546498e6d85
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47021
Reviewed-by: Randall Spangler <rspangler@chromium.org>
68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
// Copyright (c) 2012 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.
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "cgpt.h"
|
|
#include "cgptlib_internal.h"
|
|
#include "vboot_host.h"
|
|
|
|
int CgptCreate(CgptCreateParams *params) {
|
|
struct drive drive;
|
|
|
|
if (params == NULL)
|
|
return CGPT_FAILED;
|
|
|
|
if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR))
|
|
return CGPT_FAILED;
|
|
|
|
// Erase the data
|
|
memset(drive.gpt.primary_header, 0,
|
|
drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
|
|
memset(drive.gpt.secondary_header, 0,
|
|
drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
|
|
memset(drive.gpt.primary_entries, 0,
|
|
drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
|
|
memset(drive.gpt.secondary_entries, 0,
|
|
drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
|
|
|
|
drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
|
|
GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2);
|
|
|
|
// Initialize a blank set
|
|
if (!params->zap)
|
|
{
|
|
GptHeader *h = (GptHeader *)drive.gpt.primary_header;
|
|
memcpy(h->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
|
|
h->revision = GPT_HEADER_REVISION;
|
|
h->size = sizeof(GptHeader);
|
|
h->my_lba = 1;
|
|
h->alternate_lba = drive.gpt.drive_sectors - 1;
|
|
h->first_usable_lba = 1 + 1 + GPT_ENTRIES_SECTORS;
|
|
h->last_usable_lba = drive.gpt.drive_sectors - 1 - GPT_ENTRIES_SECTORS - 1;
|
|
if (!uuid_generator) {
|
|
Error("Unable to generate new GUID. uuid_generator not set.\n");
|
|
goto bad;
|
|
}
|
|
(*uuid_generator)((uint8_t *)&h->disk_uuid);
|
|
h->entries_lba = 2;
|
|
h->number_of_entries = 128;
|
|
h->size_of_entry = sizeof(GptEntry);
|
|
|
|
// Copy to secondary
|
|
RepairHeader(&drive.gpt, MASK_PRIMARY);
|
|
|
|
UpdateCrc(&drive.gpt);
|
|
}
|
|
|
|
// Write it all out
|
|
return DriveClose(&drive, 1);
|
|
|
|
bad:
|
|
|
|
DriveClose(&drive, 0);
|
|
return CGPT_FAILED;
|
|
}
|