summaryrefslogtreecommitdiff
path: root/cgpt
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2018-01-31 11:39:14 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-06 18:18:35 -0800
commita4a8c02ad5988bd4b6fd85f6e09e9e0e79d18feb (patch)
treea1cc5fb4923c3d5a990fb486debc7cb2fe261f04 /cgpt
parent3585eb3d21da676db3d87e9e0490a0df92d597d2 (diff)
downloadvboot-a4a8c02ad5988bd4b6fd85f6e09e9e0e79d18feb.tar.gz
cgpt: add support for managing GPT platform required partition bit
Bit 0 in the GPT partition attributes is defined to indicate whether a partition is required by the platform. This CL adds the support for managing this bit to cgpt. BUG=b:70807006 BRANCH=None TEST=Run unit tests. Change-Id: Iaf87c828438b3df6730de502ae420fcf4c61277b Reviewed-on: https://chromium-review.googlesource.com/902196 Commit-Ready: Ben Chan <benchan@chromium.org> Tested-by: Ben Chan <benchan@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r--cgpt/cgpt.h3
-rw-r--r--cgpt/cgpt_add.c6
-rw-r--r--cgpt/cgpt_common.c14
-rw-r--r--cgpt/cgpt_show.c7
-rw-r--r--cgpt/cmd_add.c9
-rw-r--r--cgpt/cmd_show.c4
6 files changed, 39 insertions, 4 deletions
diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h
index 1216a72c..86f4b851 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -149,6 +149,9 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw);
uint32_t GetNumberOfEntries(const struct drive *drive);
GptEntry *GetEntry(GptData *gpt, int secondary, uint32_t entry_index);
+void SetRequired(struct drive *drive, int secondary, uint32_t entry_index,
+ int required);
+int GetRequired(struct drive *drive, int secondary, uint32_t entry_index);
void SetLegacyBoot(struct drive *drive, int secondary, uint32_t entry_index,
int legacy_boot);
int GetLegacyBoot(struct drive *drive, int secondary, uint32_t entry_index);
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index 5ac50677..c0e93f3d 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -53,6 +53,10 @@ static const char* DumpCgptAddParams(const CgptAddParams *params) {
snprintf(tmp, sizeof(tmp), "-P %d ", params->priority);
StrnAppend(buf, tmp, sizeof(buf));
}
+ if (params->set_required) {
+ snprintf(tmp, sizeof(tmp), "-R %d ", params->required);
+ StrnAppend(buf, tmp, sizeof(buf));
+ }
if (params->set_legacy_boot) {
snprintf(tmp, sizeof(tmp), "-B %d ", params->legacy_boot);
StrnAppend(buf, tmp, sizeof(buf));
@@ -113,6 +117,8 @@ static int SetEntryAttributes(struct drive *drive,
SetPriority(drive, PRIMARY, index, params->priority);
if (params->set_legacy_boot)
SetLegacyBoot(drive, PRIMARY, index, params->legacy_boot);
+ if (params->set_required)
+ SetRequired(drive, PRIMARY, index, params->required);
}
// New partitions must specify type, begin, and size.
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index 1a6bd3cb..f6108c1e 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -763,6 +763,20 @@ GptEntry *GetEntry(GptData *gpt, int secondary, uint32_t entry_index) {
return (GptEntry*)(&entries[stride * entry_index]);
}
+void SetRequired(struct drive *drive, int secondary, uint32_t entry_index,
+ int required) {
+ require(required >= 0 && required <= CGPT_ATTRIBUTE_MAX_REQUIRED);
+ GptEntry *entry;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ SetEntryRequired(entry, required);
+}
+
+int GetRequired(struct drive *drive, int secondary, uint32_t entry_index) {
+ GptEntry *entry;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ return GetEntryRequired(entry);
+}
+
void SetLegacyBoot(struct drive *drive, int secondary, uint32_t entry_index,
int legacy_boot) {
require(legacy_boot >= 0 && legacy_boot <= CGPT_ATTRIBUTE_MAX_LEGACY_BOOT);
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index cd4a6136..60d73ec7 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -136,9 +136,9 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
priority, tries, successful);
}
- if (entry->attrs.fields.system) {
+ if (entry->attrs.fields.required) {
clen += snprintf(contents + clen, sizeof(contents) - clen,
- "system=%d ", entry->attrs.fields.system);
+ "required=%d ", entry->attrs.fields.required);
require(clen < sizeof(contents));
}
@@ -230,6 +230,9 @@ static int GptShow(struct drive *drive, CgptShowParams *params) {
case 'P':
printf("%d\n", GetPriority(drive, ANY_VALID, index));
break;
+ case 'R':
+ printf("%d\n", GetRequired(drive, ANY_VALID, index));
+ break;
case 'B':
printf("%d\n", GetLegacyBoot(drive, ANY_VALID, index));
break;
diff --git a/cgpt/cmd_add.c b/cgpt/cmd_add.c
index 3c7741b8..f10489ac 100644
--- a/cgpt/cmd_add.c
+++ b/cgpt/cmd_add.c
@@ -27,6 +27,7 @@ static void Usage(void)
" -S NUM set Successful flag (0|1)\n"
" -T NUM set Tries flag (0-15)\n"
" -P NUM set Priority flag (0-15)\n"
+ " -R NUM set Required flag (0|1)\n"
" -B NUM set Legacy Boot flag (0|1)\n"
" -A NUM set raw 16-bit attribute value (bits 48-63)\n"
"\n"
@@ -46,7 +47,7 @@ int cmd_add(int argc, char *argv[]) {
char *e = 0;
opterr = 0; // quiet, you
- while ((c=getopt(argc, argv, ":hi:b:s:t:u:l:S:T:P:B:A:D:")) != -1)
+ while ((c=getopt(argc, argv, ":hi:b:s:t:u:l:S:T:P:R:B:A:D:")) != -1)
{
switch (c)
{
@@ -104,6 +105,12 @@ int cmd_add(int argc, char *argv[]) {
errorcnt += check_int_parse(c, e);
errorcnt += check_int_limit(c, params.priority, 0, 15);
break;
+ case 'R':
+ params.set_required = 1;
+ params.required = (uint32_t)strtoul(optarg, &e, 0);
+ errorcnt += check_int_parse(c, e);
+ errorcnt += check_int_limit(c, params.required, 0, 1);
+ break;
case 'B':
params.set_legacy_boot = 1;
params.legacy_boot = (uint32_t)strtoul(optarg, &e, 0);
diff --git a/cgpt/cmd_show.c b/cgpt/cmd_show.c
index b9e64818..6f31b3b5 100644
--- a/cgpt/cmd_show.c
+++ b/cgpt/cmd_show.c
@@ -32,6 +32,7 @@ static void Usage(void)
" -S Successful flag\n"
" -T Tries flag\n"
" -P Priority flag\n"
+ " -R Required flag\n"
" -B Legacy Boot flag\n"
" -A raw 16-bit attribute value (bits 48-63)\n"
" -d Debug output (including invalid headers)\n"
@@ -47,7 +48,7 @@ int cmd_show(int argc, char *argv[]) {
char *e = 0;
opterr = 0; // quiet, you
- while ((c=getopt(argc, argv, ":hnvqi:bstulSTPBAdD:")) != -1)
+ while ((c=getopt(argc, argv, ":hnvqi:bstulSTPRBAdD:")) != -1)
{
switch (c)
{
@@ -76,6 +77,7 @@ int cmd_show(int argc, char *argv[]) {
case 'S':
case 'T':
case 'P':
+ case 'R':
case 'B':
case 'A':
params.single_item = c;