mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-23 17:55:01 +00:00
This CL accesses the partition entry array through its header's
entries_lba value.
Previously, we assume the primary entry array lies on third sector, and
the secondary array lies (1 + 32) sectors from disk end. This assumption
was fine, even Wikipedia assumed the same.
But in order for us to support writing boot code to the third sector (as
required by some Freescale board), the primary entry array must be moved
to another location. Therefore, we must use "entries_lba" to locate the
arrays from now on.
BRANCH=none
BUG=chromium:406432
TEST=unittest
TEST=`cgpt create -p` and then `cgpt show`. Make sure the table
header and entries are properly moved.
Change-Id: Ia9008b0bb204f290b1f6240df562ce7d3a9bbff2
Reviewed-on: https://chromium-review.googlesource.com/213861
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
79 lines
1.7 KiB
C
79 lines
1.7 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 <getopt.h>
|
|
#include <string.h>
|
|
|
|
#include "cgpt.h"
|
|
#include "vboot_host.h"
|
|
|
|
extern const char* progname;
|
|
|
|
static void Usage(void)
|
|
{
|
|
printf("\nUsage: %s create [OPTIONS] DRIVE\n\n"
|
|
"Create or reset an empty GPT.\n\n"
|
|
"Options:\n"
|
|
" -z Zero the sectors of the GPT table and entries\n"
|
|
" -s Size (in byes) of the disk (MTD only)\n"
|
|
" -p Size (in blocks) of the disk to pad between the\n"
|
|
" primary GPT header and its entries, default 0\n"
|
|
"\n", progname);
|
|
}
|
|
|
|
int cmd_create(int argc, char *argv[]) {
|
|
CgptCreateParams params;
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
int c;
|
|
int errorcnt = 0;
|
|
char *e = 0;
|
|
|
|
opterr = 0; // quiet, you
|
|
while ((c=getopt(argc, argv, ":hzsp:")) != -1)
|
|
{
|
|
switch (c)
|
|
{
|
|
case 'z':
|
|
params.zap = 1;
|
|
break;
|
|
case 's':
|
|
params.size = strtoull(optarg, &e, 0);
|
|
break;
|
|
case 'p':
|
|
params.padding = strtoull(optarg, &e, 0);
|
|
break;
|
|
|
|
case 'h':
|
|
Usage();
|
|
return CGPT_OK;
|
|
case '?':
|
|
Error("unrecognized option: -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
case ':':
|
|
Error("missing argument to -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
default:
|
|
errorcnt++;
|
|
break;
|
|
}
|
|
}
|
|
if (errorcnt)
|
|
{
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
if (optind >= argc) {
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
params.drive_name = argv[optind];
|
|
|
|
return CgptCreate(¶ms);
|
|
}
|