summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Srinivasan <jaysri@chromium.org>2012-02-23 10:59:01 -0800
committerGerrit <chrome-bot@google.com>2012-02-23 15:10:38 -0800
commit5fac757abef456bf66d9dd96b316ec61fe04b48e (patch)
tree2b1871edc450cc37ff67974aeb122ec36bd7089b
parenta5e1519b5ef6c9ff9508f18bc66735524bff2d42 (diff)
downloadvboot-5fac757abef456bf66d9dd96b316ec61fe04b48e.tar.gz
Enable building of Cgpt C++ Library for 32-bit.
The existing library had a bunch of dependencies which are too many to build for the 32-bit platform. So this checkin prunes the dependency list by building only things that are absolutely required for the functionality used in 32-bit Post-Installer. Made the use of libuuid restricted only to cgpt and unit tests so that libcgpt-cc.a doesn't depend on it. BUG=chromium-os:25374 TEST=Built 32-bit and 64-bit. Tested 32-bit post-install. Change-Id: Idd0826fdf507a95728fee8adac9520e26f05d469 Reviewed-on: https://gerrit.chromium.org/gerrit/16433 Reviewed-by: Don Garrett <dgarrett@chromium.org> Reviewed-by: Sonny Rao <sonnyrao@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org>
-rw-r--r--Makefile12
-rw-r--r--cgpt/CgptManager.cc2
-rw-r--r--cgpt/CgptManager.h4
-rw-r--r--cgpt/Makefile18
-rw-r--r--cgpt/cgpt.c5
-rw-r--r--cgpt/cgpt.h7
-rw-r--r--cgpt/cgpt_add.c6
-rw-r--r--cgpt/cgpt_create.c11
-rw-r--r--tests/CgptManagerTests.cc8
-rw-r--r--tests/Makefile6
10 files changed, 65 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 9b4e1622..78840b77 100644
--- a/Makefile
+++ b/Makefile
@@ -105,9 +105,17 @@ all:
make -C $$i; \
done
-libcgpt_cc: all
+libcgpt_cc:
+ mkdir -p ${BUILD}/cgpt ${BUILD}/firmware/lib/cgptlib ${BUILD}/firmware/stub
$(MAKE) -C cgpt libcgpt_cc
- $(MAKE) -C tests CgptManagerTests
+
+cgptmanager_tests: libcgpt_cc
+ mkdir -p ${BUILD}/tests
+ $(MAKE) -C tests cgptmanager_tests
+
+libdump_kernel_config:
+ mkdir -p ${BUILD}/utility
+ $(MAKE) -C utility $(DUMPKERNELCONFIGLIB)
clean:
/bin/rm -rf ${BUILD}
diff --git a/cgpt/CgptManager.cc b/cgpt/CgptManager.cc
index 67ed5cce..a1a018a3 100644
--- a/cgpt/CgptManager.cc
+++ b/cgpt/CgptManager.cc
@@ -15,6 +15,8 @@ using std::string;
// We don't use these variables for the libcgpt version.
const char* progname = "";
const char* command = "";
+void (*uuid_generator)(uint8_t* buffer) = NULL;
+
// This file implements the C++ wrapper methods over the C cgpt methods.
diff --git a/cgpt/CgptManager.h b/cgpt/CgptManager.h
index 85fd882e..2dbca6f2 100644
--- a/cgpt/CgptManager.h
+++ b/cgpt/CgptManager.h
@@ -6,7 +6,6 @@
#define VBOOT_REFERENCE_CGPT_CGPTMANAGER_H_
#include <string>
-#include <base/basictypes.h>
#include "gpt.h"
// This file defines a simple C++ wrapper class interface for the cgpt methods.
@@ -166,7 +165,8 @@ class CgptManager {
std::string device_name_;
bool is_initialized_;
- DISALLOW_COPY_AND_ASSIGN(CgptManager);
+ CgptManager(const CgptManager &);
+ void operator=(const CgptManager &);
};
#endif // VBOOT_REFERENCE_CGPT_CGPTMANAGER_H_
diff --git a/cgpt/Makefile b/cgpt/Makefile
index d3ca978e..dc345215 100644
--- a/cgpt/Makefile
+++ b/cgpt/Makefile
@@ -33,18 +33,28 @@ ALL_SRCS = \
cgpt_common.c
LIB_CGPT_CC_SRCS = \
- CgptManager.cc
+ CgptManager.cc \
+ cgpt_create.c \
+ cgpt_add.c \
+ cgpt_boot.c \
+ cgpt_show.c \
+ cgpt_repair.c \
+ cgpt_prioritize.c \
+ cgpt_common.c \
+ ../firmware/lib/cgptlib/crc32.c \
+ ../firmware/lib/cgptlib/cgptlib_internal.c \
+ ../firmware/stub/utility_stub.c
main: $(PROGNAME)
include ../common.mk
-LIB_CGPT_CC_OBJS = $(LIB_CGPT_CC_SRCS:%.cc=${BUILD_ROOT}/%.o)
+LIB_CGPT_CC_OBJS = $(LIB_CGPT_CC_SRCS:%.c=${BUILD_ROOT}/%.o) $(LIB_CGPT_CC_SRCS:%.cc=${BUILD_ROOT}/%.o)
LIB_CGPT_CC_DEPS = $(LIB_CGPT_CC_OBJS:%.o=%.o.d)
-libcgpt_cc: main $(LIB_CGPT_CC)
+libcgpt_cc: $(LIB_CGPT_CC)
-$(LIB_CGPT_CC): $(ALL_OBJS) $(LIB_CGPT_CC_OBJS)
+$(LIB_CGPT_CC): $(LIB_CGPT_CC_OBJS)
rm -f $@
ar qc $@ $^
diff --git a/cgpt/cgpt.c b/cgpt/cgpt.c
index 4c9fc328..e963142a 100644
--- a/cgpt/cgpt.c
+++ b/cgpt/cgpt.c
@@ -11,10 +11,11 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-
+#include <uuid/uuid.h>
const char* progname;
const char* command;
+void (*uuid_generator)(uint8_t* buffer);
struct {
const char *name;
@@ -51,6 +52,8 @@ int main(int argc, char *argv[]) {
int match_count = 0;
int match_index = 0;
+ uuid_generator = uuid_generate;
+
progname = strrchr(argv[0], '/');
if (progname)
progname++;
diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h
index d510f5ad..1c809161 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -136,6 +136,13 @@ 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[]);
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index 5a3aeec7..e3e1a483 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -233,7 +233,11 @@ int cgpt_add(CgptAddParams *params) {
goto bad;
}
if (!params->set_unique)
- uuid_generate((uint8_t *)&entry->unique);
+ if (!uuid_generator) {
+ Error("Unable to generate new GUID. uuid_generator not set.\n");
+ goto bad;
+ }
+ (*uuid_generator)((uint8_t *)&entry->unique);
}
if (params->set_begin)
diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c
index eab61225..dc25d8fa 100644
--- a/cgpt/cgpt_create.c
+++ b/cgpt/cgpt_create.c
@@ -42,7 +42,11 @@ int cgpt_create(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;
- uuid_generate((uint8_t *)&h->disk_uuid);
+ 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);
@@ -55,4 +59,9 @@ int cgpt_create(CgptCreateParams *params) {
// Write it all out
return DriveClose(&drive, 1);
+
+bad:
+
+ DriveClose(&drive, 0);
+ return CGPT_FAILED;
}
diff --git a/tests/CgptManagerTests.cc b/tests/CgptManagerTests.cc
index dee6b6c9..35da0d09 100644
--- a/tests/CgptManagerTests.cc
+++ b/tests/CgptManagerTests.cc
@@ -22,6 +22,7 @@ extern "C" {
#include <base/logging.h>
#include <gflags/gflags.h>
#include <gtest/gtest.h>
+#include <uuid/uuid.h>
using std::string;
@@ -36,7 +37,12 @@ DEFINE_int32(v, 0, 0);
// This class unit tests the CgptManager class.
class CgptManagerUnitTest : public ::testing::Test {
public:
- CgptManagerUnitTest() { }
+ CgptManagerUnitTest() {
+ // Even though the post-installer doesn't use any methods that require
+ // uuid_generate, for the unit test we use those methods, so we need to
+ // set the uuid_generator.
+ uuid_generator = uuid_generate;
+ }
void SetUp() {
const string device_name = "/tmp/DummyFileForCgptManagerTests.bin";
diff --git a/tests/Makefile b/tests/Makefile
index 7ab641fc..70db9889 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -59,6 +59,8 @@ all: $(TEST_BINS) ${EXTRA_TARGET}
rbtest: $(BUILD_ROOT)/rollback_index_test
+cgptmanager_tests: $(BUILD_ROOT)/CgptManagerTests
+
${TEST_LIB}: ${TEST_LIB_OBJS}
rm -f $@
ar qc $@ $^
@@ -67,9 +69,9 @@ ${TEST_LIB}: ${TEST_LIB_OBJS}
${BUILD_ROOT}/CgptManagerTests.o: CgptManagerTests.cc
$(CXX) -DWITH_UTIL_MAIN $(CXXFLAGS) $(INCLUDES) -c $< -o $@
-CgptManagerTests: ${BUILD_ROOT}/CgptManagerTests.o ${LIBS}
+${BUILD_ROOT}/CgptManagerTests: ${BUILD_ROOT}/CgptManagerTests.o
$(CXX) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) -lgtest -lgflags $^ \
- ${BUILD}/cgpt/libcgpt-cc.a ${FWLIB} $(HOSTLIB) -lbase -lpthread -lrt -o ${BUILD_ROOT}/$@
+ ${BUILD}/cgpt/libcgpt-cc.a -lbase -lpthread -lrt -o $@
${BUILD_ROOT}/vboot_audio_for_test.o : $(FWDIR)/lib/vboot_audio.c
$(CC) $(CFLAGS) -DCUSTOM_MUSIC $(INCLUDES) \