diff options
author | Bill Richardson <wfrichar@chromium.org> | 2014-06-20 14:33:00 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-06-26 02:41:51 +0000 |
commit | 4cb5497984642b8cbd592c14cb1912a787b2d4d7 (patch) | |
tree | ccbe3692c68a78c7e4ee27bd31d967ade51f0a3f | |
parent | c9e039c1b39509cf301dc38947db021f0243c817 (diff) | |
download | vboot-4cb5497984642b8cbd592c14cb1912a787b2d4d7.tar.gz |
Remove cgpt app-specific symbols from libvboot_host.a
Three symbols used by the standalone cgpt executable were being referenced
in the files used to create the external libvboot_host.a needed by non-vboot
userspace applications.
This cleans things up so those symbols don't have to be explictly defined
by other repos just to link with that library.
BUG=chromium:318536
BRANCH=ToT
TEST=manual
No new functionality, just code cleanup. Tested with
make runtests runfutiltests runlongtests
Change-Id: Ibc77fb9800c89d7109ebf38d4d6729f52665722f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/205667
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | cgpt/cgpt.c | 12 | ||||
-rw-r--r-- | cgpt/cgpt.h | 25 | ||||
-rw-r--r-- | cgpt/cgpt_add.c | 7 | ||||
-rw-r--r-- | cgpt/cgpt_boot.c | 1 | ||||
-rw-r--r-- | cgpt/cgpt_common.c | 11 | ||||
-rw-r--r-- | cgpt/cgpt_create.c | 5 | ||||
-rw-r--r-- | cgpt/cgpt_endian.h (renamed from cgpt/endian.h) | 0 | ||||
-rw-r--r-- | cgpt/cmd_add.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_boot.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_create.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_find.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_legacy.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_prioritize.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_repair.c | 2 | ||||
-rw-r--r-- | cgpt/cmd_show.c | 2 |
15 files changed, 48 insertions, 29 deletions
diff --git a/cgpt/cgpt.c b/cgpt/cgpt.c index e49d430f..ccf73184 100644 --- a/cgpt/cgpt.c +++ b/cgpt/cgpt.c @@ -15,8 +15,13 @@ #include "vboot_host.h" const char* progname; -const char* command; -void (*uuid_generator)(uint8_t* buffer); + +int GenerateGuid(Guid *newguid) +{ + /* From libuuid */ + uuid_generate(newguid->u.raw); + return CGPT_OK; +} struct { const char *name; @@ -90,8 +95,7 @@ int main(int argc, char *argv[]) { int i; int match_count = 0; int match_index = 0; - - uuid_generator = uuid_generate; + char* command; progname = strrchr(argv[0], '/'); if (progname) diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h index c6b0b9b4..aa47314d 100644 --- a/cgpt/cgpt.h +++ b/cgpt/cgpt.h @@ -10,12 +10,11 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include "endian.h" -#include "gpt.h" +#include "cgpt_endian.h" #include "cgptlib.h" +#include "gpt.h" #include "mtdlib.h" - struct legacy_partition { uint8_t status; uint8_t f_head; @@ -180,19 +179,19 @@ int IsKernel(struct drive *drive, int secondary, uint32_t index); int LookupMtdTypeForGuid(const Guid *type); const Guid *LookupGuidForMtdType(int type); +// Optional. Applications that need this must provide an implementation. +// +// Explanation: +// Some external utilities need to manipulate the GPT, but don't create new +// partitions from scratch. The cgpt executable uses libuuid to provide this +// functionality, but we don't want to have to build or install a separate +// instance of that library just for the 32-bit static post-install tool, +// which doesn't need this function. +int GenerateGuid(Guid *newguid); + // For usage and error messages. -extern const char* progname; -extern const char* command; void Error(const char *format, ...); -// The code paths that require uuid_generate are not used currently in -// libcgpt-cc.a so using this method would create an unnecessary dependency -// on libuuid which then requires us to build it for 32-bit for the static -// post-installer. So, we just expose this function pointer which should be -// set to uuid_generate in case of the cgpt binary and can be null or some -// no-op method in case of ilbcgpt-cc.a. -extern void (*uuid_generator)(uint8_t* buffer); - // Command functions. int cmd_show(int argc, char *argv[]); int cmd_repair(int argc, char *argv[]); diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c index fc40ebc5..b87fe4b4 100644 --- a/cgpt/cgpt_add.c +++ b/cgpt/cgpt_add.c @@ -78,11 +78,10 @@ static int GptSetEntryAttributes(struct drive *drive, if (params->set_unique) { memcpy(&entry->unique, ¶ms->unique_guid, sizeof(Guid)); } else if (GuidIsZero(&entry->type)) { - if (!uuid_generator) { - Error("Unable to generate new GUID. uuid_generator not set.\n"); - return -1; + if (CGPT_OK != GenerateGuid(&entry->unique)) { + Error("Unable to generate new GUID.\n"); + return -1; } - (*uuid_generator)((uint8_t *)&entry->unique); } if (params->set_type) memcpy(&entry->type, ¶ms->type_guid, sizeof(Guid)); diff --git a/cgpt/cgpt_boot.c b/cgpt/cgpt_boot.c index 993e8654..d23c303a 100644 --- a/cgpt/cgpt_boot.c +++ b/cgpt/cgpt_boot.c @@ -10,7 +10,6 @@ #include "cgpt.h" #include "cgpt_params.h" #include "cgptlib_internal.h" -#include "endian.h" #include "vboot_host.h" int CgptGetBootPartitionNumber(CgptBootParams *params) { diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c index 1a1c9e86..c8a069a4 100644 --- a/cgpt/cgpt_common.c +++ b/cgpt/cgpt_common.c @@ -41,17 +41,16 @@ void EnableNandImage(int bytes_per_page, int pages_per_block, void Error(const char *format, ...) { va_list ap; va_start(ap, format); - fprintf(stderr, "ERROR: %s %s: ", progname, command); + fprintf(stderr, "ERROR: "); vfprintf(stderr, format, ap); va_end(ap); } - int CheckValid(const struct drive *drive) { if ((drive->gpt.valid_headers != MASK_BOTH) || (drive->gpt.valid_entries != MASK_BOTH)) { - fprintf(stderr, "\nWARNING: one of the GPT header/entries is invalid, " - "please run '%s repair'\n", progname); + fprintf(stderr, + "\nWARNING: one of the GPT header/entries is invalid\n\n"); return CGPT_FAILED; } return CGPT_OK; @@ -1180,3 +1179,7 @@ void PMBRToStr(struct pmbr *pmbr, char *str, unsigned int buflen) { require(snprintf(str, buflen, "PMBR (Boot GUID: %s)", buf) < buflen); } } + +/* Optional */ +int __GenerateGuid(Guid *newguid) { return CGPT_FAILED; }; +int GenerateGuid(Guid *newguid) __attribute__((weak, alias("__GenerateGuid"))); diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c index 90b746c6..3341fa25 100644 --- a/cgpt/cgpt_create.c +++ b/cgpt/cgpt_create.c @@ -33,11 +33,10 @@ int GptCreate(struct drive *drive, CgptCreateParams *params) { 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"); + if (CGPT_OK != GenerateGuid(&h->disk_uuid)) { + Error("Unable to generate new GUID.\n"); return -1; } - (*uuid_generator)((uint8_t *)&h->disk_uuid); h->entries_lba = 2; h->number_of_entries = 128; h->size_of_entry = sizeof(GptEntry); diff --git a/cgpt/endian.h b/cgpt/cgpt_endian.h index 04204e74..04204e74 100644 --- a/cgpt/endian.h +++ b/cgpt/cgpt_endian.h diff --git a/cgpt/cmd_add.c b/cgpt/cmd_add.c index a48ab336..2bb5df43 100644 --- a/cgpt/cmd_add.c +++ b/cgpt/cmd_add.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s add [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_boot.c b/cgpt/cmd_boot.c index caa94bc7..2a65f202 100644 --- a/cgpt/cmd_boot.c +++ b/cgpt/cmd_boot.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s boot [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_create.c b/cgpt/cmd_create.c index 4f042204..c751b24d 100644 --- a/cgpt/cmd_create.c +++ b/cgpt/cmd_create.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s create [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_find.c b/cgpt/cmd_find.c index 1a3dc696..bdd745c2 100644 --- a/cgpt/cmd_find.c +++ b/cgpt/cmd_find.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s find [OPTIONS] [DRIVE]\n\n" diff --git a/cgpt/cmd_legacy.c b/cgpt/cmd_legacy.c index a1269493..955ce3f4 100644 --- a/cgpt/cmd_legacy.c +++ b/cgpt/cmd_legacy.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s legacy [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_prioritize.c b/cgpt/cmd_prioritize.c index 3a692b8d..9bf292e4 100644 --- a/cgpt/cmd_prioritize.c +++ b/cgpt/cmd_prioritize.c @@ -11,6 +11,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s prioritize [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_repair.c b/cgpt/cmd_repair.c index ac5578af..b5f7d31e 100644 --- a/cgpt/cmd_repair.c +++ b/cgpt/cmd_repair.c @@ -8,6 +8,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n" diff --git a/cgpt/cmd_show.c b/cgpt/cmd_show.c index 1b31f392..df4cba1f 100644 --- a/cgpt/cmd_show.c +++ b/cgpt/cmd_show.c @@ -10,6 +10,8 @@ #include "cgpt.h" #include "vboot_host.h" +extern const char* progname; + static void Usage(void) { printf("\nUsage: %s show [OPTIONS] DRIVE\n\n" |