Massive refactoring of external header files.

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>
diff --git a/cgpt/cgpt.c b/cgpt/cgpt.c
index ac7aecd..a3b20d9 100644
--- a/cgpt/cgpt.c
+++ b/cgpt/cgpt.c
@@ -6,13 +6,14 @@
  * files for more details.
  */
 
-#include "cgpt.h"
-
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
 
+#include "cgpt.h"
+#include "vboot_host.h"
+
 const char* progname;
 const char* command;
 void (*uuid_generator)(uint8_t* buffer);
diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h
index 4763092..3d09fb9 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -5,11 +5,6 @@
 #ifndef VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_
 #define VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#define _FILE_OFFSET_BITS 64
 #include <fcntl.h>
 #include <features.h>
 #include <stdint.h>
@@ -20,13 +15,6 @@
 #include "cgptlib.h"
 
 
-// Just for clarity
-enum {
-  CGPT_OK = 0,
-  CGPT_FAILED,
-};
-
-
 struct legacy_partition {
   uint8_t  status;
   uint8_t  f_head;
@@ -67,19 +55,6 @@
 int DriveClose(struct drive *drive, int update_as_needed);
 int CheckValid(const struct drive *drive);
 
-/* GUID conversion functions. Accepted format:
- *
- *   "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
- *
- * At least GUID_STRLEN bytes should be reserved in 'str' (included the tailing
- * '\0').
- */
-#define GUID_STRLEN 37
-int StrToGuid(const char *str, Guid *guid);
-void GuidToStr(const Guid *guid, char *str, unsigned int buflen);
-int GuidEqual(const Guid *guid1, const Guid *guid2);
-int GuidIsZero(const Guid *guid);
-
 /* Constant global type values to compare against */
 extern const Guid guid_chromeos_firmware;
 extern const Guid guid_chromeos_kernel;
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index 684d4d2..eaf0b73 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -2,14 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <string.h>
 
-#include "cgptlib_internal.h"
-#include "cgpt_params.h"
 #define _STUB_IMPLEMENTATION_
+
+#include "cgpt.h"
+#include "cgpt_params.h"
+#include "cgptlib_internal.h"
 #include "utility.h"
+#include "vboot_host.h"
 
 static const char* DumpCgptAddParams(const CgptAddParams *params) {
   static char buf[256];
diff --git a/cgpt/cgpt_boot.c b/cgpt/cgpt_boot.c
index 4de9c4c..00b783f 100644
--- a/cgpt/cgpt_boot.c
+++ b/cgpt/cgpt_boot.c
@@ -11,7 +11,7 @@
 #include "cgpt_params.h"
 #include "cgptlib_internal.h"
 #include "endian.h"
-
+#include "vboot_host.h"
 
 int CgptGetBootPartitionNumber(CgptBootParams *params) {
   struct drive drive;
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index dc42d41..dec26d1 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -6,8 +6,6 @@
  * files for more details.
  */
 
-#include "cgpt.h"
-
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -22,8 +20,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
 #include "crc32.h"
+#include "vboot_host.h"
 
 void Error(const char *format, ...) {
   va_list ap;
diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c
index f4d67d5..b0256c5 100644
--- a/cgpt/cgpt_create.c
+++ b/cgpt/cgpt_create.c
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
 
 #include <string.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
-#include "cgpt_params.h"
+#include "vboot_host.h"
 
 int CgptCreate(CgptCreateParams *params) {
   struct drive drive;
diff --git a/cgpt/cgpt_find.c b/cgpt/cgpt_find.c
index 795eab6..c7c77b0 100644
--- a/cgpt/cgpt_find.c
+++ b/cgpt/cgpt_find.c
@@ -8,8 +8,8 @@
 #include <unistd.h>
 
 #include "cgpt.h"
-#include "cgpt_params.h"
 #include "cgptlib_internal.h"
+#include "vboot_host.h"
 
 #define BUFSIZE 1024
 // FIXME: currently we only support 512-byte sectors.
diff --git a/cgpt/cgpt_legacy.c b/cgpt/cgpt_legacy.c
index ac2d4f0..932fbb9 100644
--- a/cgpt/cgpt_legacy.c
+++ b/cgpt/cgpt_legacy.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <string.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
-#include "cgpt_params.h"
+#include "vboot_host.h"
 
 int CgptLegacy(CgptLegacyParams *params) {
   struct drive drive;
diff --git a/cgpt/cgpt_params.h b/cgpt/cgpt_params.h
deleted file mode 100644
index 470e0ff..0000000
--- a/cgpt/cgpt_params.h
+++ /dev/null
@@ -1,128 +0,0 @@
-// 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.
-
-#ifndef VBOOT_REFERENCE_CGPT_CGPT_PARAMS_H_
-#define VBOOT_REFERENCE_CGPT_CGPT_PARAMS_H_
-
-#include "cgpt.h"
-
-// This file defines the internal methods that use the user-mode cgpt programatically.
-// This is the interface for the callers such as the cgpt tool or the C++ post installer
-// executable.
-
-typedef struct CgptCreateParams {
-  char *drive_name;
-  int zap;
-} CgptCreateParams;
-
-typedef struct CgptAddParams {
-  char *drive_name;
-  uint32_t partition;
-  uint64_t begin;
-  uint64_t size;
-  Guid type_guid;
-  Guid unique_guid;
-  char *label;
-  int successful;
-  int tries;
-  int priority;
-  uint16_t raw_value;
-  int set_begin;
-  int set_size;
-  int set_type;
-  int set_unique;
-  int set_successful;
-  int set_tries;
-  int set_priority;
-  int set_raw;
-} CgptAddParams;
-
-typedef struct CgptShowParams {
-  char *drive_name;
-  int numeric;
-  int verbose;
-  int quick;
-  uint32_t partition;
-  int single_item;
-  int debug;
-
-  // This is filled in by the relevant methods in CgptShow.c
-  int num_partitions;
-} CgptShowParams;
-
-typedef struct CgptRepairParams {
-  char *drive_name;
-  int verbose;
-} CgptRepairParams;
-
-typedef struct CgptBootParams {
-  char *drive_name;
-  uint32_t partition;
-  char *bootfile;
-  int create_pmbr;
-} CgptBootParams;
-
-typedef struct CgptPrioritizeParams {
-  char *drive_name;
-
-  uint32_t set_partition;
-  int set_friends;
-  int max_priority;
-  int orig_priority;
-} CgptPrioritizeParams;
-
-typedef struct CgptFindParams {
-  char *drive_name;
-
-  int verbose;
-  int set_unique;
-  int set_type;
-  int set_label;
-  int oneonly;
-  int numeric;
-  uint8_t *matchbuf;
-  uint64_t matchlen;
-  uint64_t matchoffset;
-  uint8_t *comparebuf;
-  Guid unique_guid;
-  Guid type_guid;
-  char *label;
-  int hits;
-  int match_partnum;           // 0 for no match, 1-N for match
-} CgptFindParams;
-
-typedef struct CgptLegacyParams {
-  char *drive_name;
-  int efipart;
-} CgptLegacyParams;
-
-// create related methods.
-int CgptCreate(CgptCreateParams *params);
-
-// add/attribute/details related methods
-int CgptAdd(CgptAddParams *params);
-int CgptSetAttributes(CgptAddParams *params);
-int CgptGetPartitionDetails(CgptAddParams *params);
-
-// boot related methods.
-int CgptBoot(CgptBootParams *params);
-int CgptGetBootPartitionNumber(CgptBootParams *params);
-
-// show/get related methods.
-int CgptShow(CgptShowParams *params);
-int CgptGetNumNonEmptyPartitions(CgptShowParams *params);
-
-// repair related methods.
-int CgptRepair(CgptRepairParams *params);
-
-// priority related methods.
-int CgptPrioritize(CgptPrioritizeParams *params);
-
-// find related methods.
-void CgptFind(CgptFindParams *params);
-
-// legacy related methods.
-int CgptLegacy(CgptLegacyParams *params);
-
-#endif  // VBOOT_REFERENCE_CGPT_CGPT_PARAMS_H_
diff --git a/cgpt/cgpt_prioritize.c b/cgpt/cgpt_prioritize.c
index dd74ccf..7cd73c0 100644
--- a/cgpt/cgpt_prioritize.c
+++ b/cgpt/cgpt_prioritize.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <string.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
-#include "cgpt_params.h"
+#include "vboot_host.h"
 
 //////////////////////////////////////////////////////////////////////////////
 // We need a sorted list of priority groups, where each element in the list
diff --git a/cgpt/cgpt_repair.c b/cgpt/cgpt_repair.c
index aeac0b9..e591c75 100644
--- a/cgpt/cgpt_repair.c
+++ b/cgpt/cgpt_repair.c
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
 
 #include <string.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
-#include "cgpt_params.h"
+#include "vboot_host.h"
 
 int CgptRepair(CgptRepairParams *params) {
   struct drive drive;
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 6c2160c..cb5e275 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -2,15 +2,14 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #define __STDC_FORMAT_MACROS
 
 #include <string.h>
 
+#include "cgpt.h"
 #include "cgptlib_internal.h"
-#include "cgpt_params.h"
 #include "crc32.h"
+#include "vboot_host.h"
 
 /* Generate output like:
  *
diff --git a/cgpt/cmd_add.c b/cgpt/cmd_add.c
index 500633b..a48ab33 100644
--- a/cgpt/cmd_add.c
+++ b/cgpt/cmd_add.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_boot.c b/cgpt/cmd_boot.c
index d2e63b7..caa94bc 100644
--- a/cgpt/cmd_boot.c
+++ b/cgpt/cmd_boot.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_create.c b/cgpt/cmd_create.c
index c2b8adf..0d91b08 100644
--- a/cgpt/cmd_create.c
+++ b/cgpt/cmd_create.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_find.c b/cgpt/cmd_find.c
index 4b2964d..1a3dc69 100644
--- a/cgpt/cmd_find.c
+++ b/cgpt/cmd_find.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_legacy.c b/cgpt/cmd_legacy.c
index 593d2ec..a126949 100644
--- a/cgpt/cmd_legacy.c
+++ b/cgpt/cmd_legacy.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_prioritize.c b/cgpt/cmd_prioritize.c
index 05e7e0e..3a692b8 100644
--- a/cgpt/cmd_prioritize.c
+++ b/cgpt/cmd_prioritize.c
@@ -8,7 +8,8 @@
 #include <string.h>
 #include <uuid/uuid.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_repair.c b/cgpt/cmd_repair.c
index 3c31330..ac5578a 100644
--- a/cgpt/cmd_repair.c
+++ b/cgpt/cmd_repair.c
@@ -2,12 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #include <getopt.h>
 #include <string.h>
 
-#include "cgpt_params.h"
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {
diff --git a/cgpt/cmd_show.c b/cgpt/cmd_show.c
index 2df199d..1b31f39 100644
--- a/cgpt/cmd_show.c
+++ b/cgpt/cmd_show.c
@@ -2,13 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "cgpt.h"
-
 #define __STDC_FORMAT_MACROS
 #include <getopt.h>
 #include <inttypes.h>
 #include <string.h>
-#include "cgpt_params.h"
+
+#include "cgpt.h"
+#include "vboot_host.h"
 
 static void Usage(void)
 {