cbfs: fix issues with word size and endianness.

Add XDR functions and use them to convert the ELF headers
to native headers, using the Elf64 structs to ensure we accomodate
all word sizes. Also, use these XDR functions for output.

This may seem overly complex but it turned out to be much the easiest
way to do this. Note that the basic elf parsing function
in cbfs-mkstage.c now works over all ELF files, for all architectures,
endian, and word size combinations. At the same time, the basic elf
parsing in cbfs-mkstage.c is a loop that has no architecture-specific
conditionals.

Add -g to the LDFLAGS while we're here. It's on the CFLAGS so there is
no harm done.

This code has been tested on all chromebooks that use coreboot to date.

I added most of the extra checks from ChromeOS and they triggered a
lot of warnings, hence the other changes. I had to take -Wshadow back
out due to the many errors it triggers in LZMA.

BUG=None
TEST=Build and boot for Peppy; works fine. Build and boot for nyan,
     works fine. Build for qemu targets and armv8 targets.
BRANCH=None

Change-Id: I5a4cee9854799189115ac701e22efc406a8d902f
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
Reviewed-on: https://chromium-review.googlesource.com/178606
Reviewed-by: Ronald Minnich <rminnich@chromium.org>
Commit-Queue: Ronald Minnich <rminnich@chromium.org>
Tested-by: Ronald Minnich <rminnich@chromium.org>
Reviewed-on: http://review.coreboot.org/4817
Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 401654e..2cd0c7a 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -69,7 +69,7 @@
 	return value;
 }
 
-uint32_t lookup_type_by_name(const struct typedesc_t *desc, const char *name,
+static uint32_t lookup_type_by_name(const struct typedesc_t *desc, const char *name,
 			     uint32_t default_value)
 {
 	int i;
@@ -79,7 +79,7 @@
 	return default_value;
 }
 
-const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t type,
+static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t type,
 				const char *default_value)
 {
 	int i;
@@ -139,7 +139,7 @@
 }
 
 int cbfs_image_create(struct cbfs_image *image,
-		      uint32_t arch,
+		      uint32_t myarch,
 		      size_t size,
 		      uint32_t align,
 		      struct buffer *bootblock,
@@ -206,7 +206,7 @@
 	header->bootblocksize = htonl(bootblock->size);
 	header->align = htonl(align);
 	header->offset = htonl(entries_offset);
-	header->architecture = htonl(arch);
+	header->architecture = htonl(myarch);
 
 	// Prepare entries
 	if (align_up(entries_offset, align) != entries_offset) {
@@ -356,10 +356,10 @@
 
 	if (IS_TOP_ALIGNED_ADDRESS(content_offset)) {
 		// legacy cbfstool takes top-aligned address.
-		uint32_t romsize = ntohl(image->header->romsize);
+		uint32_t theromsize = ntohl(image->header->romsize);
 		INFO("Converting top-aligned address 0x%x to offset: 0x%x\n",
-		     content_offset, content_offset + romsize);
-		content_offset += romsize;
+		     content_offset, content_offset + theromsize);
+		content_offset += theromsize;
 	}
 
 	// Merge empty entries.
@@ -488,7 +488,7 @@
 
 	buffer.data = CBFS_SUBHEADER(entry);
 	buffer.size = ntohl(entry->len);
-	buffer.name = "(cbfs_export_entry)";
+	buffer.name = (char *)"(cbfs_export_entry)";
 	if (buffer_write_file(&buffer, filename) != 0) {
 		ERROR("Failed to write %s into %s.\n",
 		      entry_name, filename);
@@ -793,16 +793,6 @@
 		       sizeof(entry->magic)) == 0);
 }
 
-int cbfs_init_entry(struct cbfs_file *entry,
-		    struct buffer *buffer)
-{
-	memset(entry, 0, sizeof(*entry));
-	memcpy(entry->magic, CBFS_FILE_MAGIC, sizeof(entry->magic));
-	entry->len = htonl(buffer->size);
-	entry->offset = htonl(sizeof(*entry) + strlen(buffer->name) + 1);
-	return 0;
-}
-
 int cbfs_create_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
 		      size_t len, const char *name)
 {