Alexandru Gagniuc (mr.nuke.me(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5100
-gerrit
commit e757220cfcb335a200d41cae990a4295e410ab0b
Author: Ronald G. Minnich <rminnich(a)google.com>
Date: Mon Jan 6 08:38:15 2014 -0800
cbfstool: add code to serialize the header using the new xdr functions
This change adds a header serialization function. Programmers can thus just
set up a header as needed, without worrying about forgetting if and how to
use the [hn]to[hn]* functions.
In the long term, we will work to remove swab.h, i.e. we need to get to the
point where programmers don't have to try to remember [hn]to[nh]* and where
it goes. To date, even the best programmers we have have made an error with
those functions, and those errors have persisted for 6 or 7 years now. It's
very easy to make that mistake.
BUG=None
TEST=Build a peppy image and verify that it's bit for bit the same. All
chromebooks use this code and build and boot correctly.
BRANCH=None
Change-Id: I0f9b8e7cac5f52d0ea330ba948650fa0803aa0d5
Signed-off-by: Ronald G. Minnich <rminnich(a)google.com>
Reviewed-on: https://chromium-review.googlesource.com/181552
Reviewed-by: Ronald Minnich <rminnich(a)chromium.org>
Commit-Queue: Ronald Minnich <rminnich(a)chromium.org>
Tested-by: Ronald Minnich <rminnich(a)chromium.org>
---
util/cbfstool/cbfs_image.c | 41 ++++++++++++++++++++++++++++-------------
util/cbfstool/cbfs_image.h | 4 ++++
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 363691f..dddd480 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -139,6 +139,21 @@ static int cbfs_fix_legacy_size(struct cbfs_image *image)
return 0;
}
+void cbfs_put_header(void *dest, const struct cbfs_header *header)
+{
+ struct buffer outheader;
+
+ outheader.data = dest;
+ outheader.size = 0;
+
+ xdr_be.put32(&outheader, header->magic);
+ xdr_be.put32(&outheader, header->version);
+ xdr_be.put32(&outheader, header->romsize);
+ xdr_be.put32(&outheader, header->bootblocksize);
+ xdr_be.put32(&outheader, header->align);
+ xdr_be.put32(&outheader, header->offset);
+ xdr_be.put32(&outheader, header->architecture);
+}
int cbfs_image_create(struct cbfs_image *image,
uint32_t myarch,
size_t size,
@@ -148,7 +163,7 @@ int cbfs_image_create(struct cbfs_image *image,
int32_t header_offset,
int32_t entries_offset)
{
- struct cbfs_header *header;
+ struct cbfs_header header;
struct cbfs_file *entry;
uint32_t cbfs_len;
size_t entry_header_len;
@@ -156,7 +171,7 @@ int cbfs_image_create(struct cbfs_image *image,
DEBUG("cbfs_image_create: bootblock=0x%x+0x%zx, "
"header=0x%x+0x%zx, entries_offset=0x%x\n",
bootblock_offset, bootblock->size,
- header_offset, sizeof(*header), entries_offset);
+ header_offset, sizeof(header), entries_offset);
if (buffer_create(&image->buffer, size, "(new)") != 0)
return -1;
@@ -194,20 +209,20 @@ int cbfs_image_create(struct cbfs_image *image,
bootblock->size);
// Prepare header
- if (header_offset + sizeof(*header) > size) {
+ if (header_offset + sizeof(header) > size) {
ERROR("Header (0x%x+0x%zx) exceed ROM size (0x%zx)\n",
- header_offset, sizeof(*header), size);
+ header_offset, sizeof(header), size);
return -1;
}
- header = (struct cbfs_header *)(image->buffer.data + header_offset);
- image->header = header;
- header->magic = htonl(CBFS_HEADER_MAGIC);
- header->version = htonl(CBFS_HEADER_VERSION);
- header->romsize = htonl(size);
- header->bootblocksize = htonl(bootblock->size);
- header->align = htonl(align);
- header->offset = htonl(entries_offset);
- header->architecture = htonl(myarch);
+ image->header = (struct cbfs_header *)(image->buffer.data + header_offset);
+ header.magic = CBFS_HEADER_MAGIC;
+ header.version = CBFS_HEADER_VERSION;
+ header.romsize = size;
+ header.bootblocksize = bootblock->size;
+ header.align = align;
+ header.offset = entries_offset;
+ header.architecture = myarch;
+ cbfs_put_header(image->header, &header);
// Prepare entries
if (align_up(entries_offset, align) != entries_offset) {
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 7ad418a..8ea4e47 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -31,6 +31,10 @@ struct cbfs_image {
struct cbfs_header *header;
};
+/* Given a pointer, serialize the header from host-native byte format
+ * to cbfs format, i.e. big-endian. */
+void cbfs_put_header(void *dest, const struct cbfs_header *header);
+
/* Creates an empty CBFS image by given size, and description to its content
* (bootblock, align, header location, starting offset of CBFS entries.
* The output image will contain a valid cbfs_header, with one cbfs_file
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5100
-gerrit
commit 790e09346fefb3508169c1abf9717018dd353aef
Author: Ronald G. Minnich <rminnich(a)google.com>
Date: Mon Jan 6 08:38:15 2014 -0800
cbfstool: add code to serialize the header using the new xdr functions
This change adds a header serialization function. Programmers can thus just
set up a header as needed, without worrying about forgetting if and how to
use the [hn]to[hn]* functions.
In the long term, we will work to remove swab.h, i.e. we need to get to the
point where programmers don't have to try to remember [hn]to[nh]* and where
it goes. To date, even the best programmers we have have made an error with
those functions, and those errors have persisted for 6 or 7 years now. It's
very easy to make that mistake.
BUG=None
TEST=Build a peppy image and verify that it's bit for bit the same. All chromebooks use this code
and build and boot correctly.
BRANCH=None
Change-Id: I0f9b8e7cac5f52d0ea330ba948650fa0803aa0d5
Signed-off-by: Ronald G. Minnich <rminnich(a)google.com>
Reviewed-on: https://chromium-review.googlesource.com/181552
Reviewed-by: Ronald Minnich <rminnich(a)chromium.org>
Commit-Queue: Ronald Minnich <rminnich(a)chromium.org>
Tested-by: Ronald Minnich <rminnich(a)chromium.org>
---
3rdparty | 2 +-
util/cbfstool/cbfs_image.c | 41 ++++++++++++++++++++++++++++-------------
util/cbfstool/cbfs_image.h | 4 ++++
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/3rdparty b/3rdparty
index 324ec3c..aebd218 160000
--- a/3rdparty
+++ b/3rdparty
@@ -1 +1 @@
-Subproject commit 324ec3cb642a278d6d97ae809bc6098045bc6e65
+Subproject commit aebd21811dc9c9a171e629150d9d8a239a8b0338
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 363691f..fd10015 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -139,6 +139,21 @@ static int cbfs_fix_legacy_size(struct cbfs_image *image)
return 0;
}
+void cbfs_put_header(void *dest, struct cbfs_header *header)
+{
+ struct buffer outheader;
+
+ outheader.data = dest;
+ outheader.size = 0;
+
+ xdr_be.put32(&outheader, header->magic);
+ xdr_be.put32(&outheader, header->version);
+ xdr_be.put32(&outheader, header->romsize);
+ xdr_be.put32(&outheader, header->bootblocksize);
+ xdr_be.put32(&outheader, header->align);
+ xdr_be.put32(&outheader, header->offset);
+ xdr_be.put32(&outheader, header->architecture);
+}
int cbfs_image_create(struct cbfs_image *image,
uint32_t myarch,
size_t size,
@@ -148,7 +163,7 @@ int cbfs_image_create(struct cbfs_image *image,
int32_t header_offset,
int32_t entries_offset)
{
- struct cbfs_header *header;
+ struct cbfs_header header;
struct cbfs_file *entry;
uint32_t cbfs_len;
size_t entry_header_len;
@@ -156,7 +171,7 @@ int cbfs_image_create(struct cbfs_image *image,
DEBUG("cbfs_image_create: bootblock=0x%x+0x%zx, "
"header=0x%x+0x%zx, entries_offset=0x%x\n",
bootblock_offset, bootblock->size,
- header_offset, sizeof(*header), entries_offset);
+ header_offset, sizeof(header), entries_offset);
if (buffer_create(&image->buffer, size, "(new)") != 0)
return -1;
@@ -194,20 +209,20 @@ int cbfs_image_create(struct cbfs_image *image,
bootblock->size);
// Prepare header
- if (header_offset + sizeof(*header) > size) {
+ if (header_offset + sizeof(header) > size) {
ERROR("Header (0x%x+0x%zx) exceed ROM size (0x%zx)\n",
- header_offset, sizeof(*header), size);
+ header_offset, sizeof(header), size);
return -1;
}
- header = (struct cbfs_header *)(image->buffer.data + header_offset);
- image->header = header;
- header->magic = htonl(CBFS_HEADER_MAGIC);
- header->version = htonl(CBFS_HEADER_VERSION);
- header->romsize = htonl(size);
- header->bootblocksize = htonl(bootblock->size);
- header->align = htonl(align);
- header->offset = htonl(entries_offset);
- header->architecture = htonl(myarch);
+ image->header = (struct cbfs_header *)(image->buffer.data + header_offset);
+ header.magic = CBFS_HEADER_MAGIC;
+ header.version = CBFS_HEADER_VERSION;
+ header.romsize = size;
+ header.bootblocksize = bootblock->size;
+ header.align = align;
+ header.offset = entries_offset;
+ header.architecture = myarch;
+ cbfs_put_header(image->header, &header);
// Prepare entries
if (align_up(entries_offset, align) != entries_offset) {
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 7ad418a..74c8f97 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -31,6 +31,10 @@ struct cbfs_image {
struct cbfs_header *header;
};
+/* Given a pointer, serialize the header from host-native byte format
+ * to cbfs format, i.e. big-endian. */
+void cbfs_put_header(void *dest, struct cbfs_header *header);
+
/* Creates an empty CBFS image by given size, and description to its content
* (bootblock, align, header location, starting offset of CBFS entries.
* The output image will contain a valid cbfs_header, with one cbfs_file
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5100
-gerrit
commit b22f55c26fc83bcfffa3b788b772b341b41c4c82
Author: Ronald G. Minnich <rminnich(a)google.com>
Date: Mon Jan 6 08:38:15 2014 -0800
cbfstool: add code to serialize the header using the new xdr functions
This change adds a header serialization function. Programmers can thus just
set up a header as needed, without worrying about forgetting if and how to
use the [hn]to[hn]* functions.
In the long term, we will work to remove swab.h, i.e. we need to get to the
point where programmers don't have to try to remember [hn]to[nh]* and where
it goes. To date, even the best programmers we have have made an error with
those functions, and those errors have persisted for 6 or 7 years now. It's
very easy to make that mistake.
BUG=None
TEST=Build a peppy image and verify that it's bit for bit the same. All chromebooks use this code
and build and boot correctly.
BRANCH=None
Change-Id: I0f9b8e7cac5f52d0ea330ba948650fa0803aa0d5
Signed-off-by: Ronald G. Minnich <rminnich(a)google.com>
Reviewed-on: https://chromium-review.googlesource.com/181552
Reviewed-by: Ronald Minnich <rminnich(a)chromium.org>
Commit-Queue: Ronald Minnich <rminnich(a)chromium.org>
Tested-by: Ronald Minnich <rminnich(a)chromium.org>
---
util/cbfstool/cbfs_image.c | 41 ++++++++++++++++++++++++++++-------------
util/cbfstool/cbfs_image.h | 4 ++++
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 363691f..d453899 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -139,6 +139,21 @@ static int cbfs_fix_legacy_size(struct cbfs_image *image)
return 0;
}
+void cbfs_put_header(void *dest, struct cbfs_header *header)
+{
+ struct buffer outheader;
+
+ outheader.data = dest;
+ outheader.size = 0;
+
+ xdr_be.put32(&outheader, header->magic);
+ xdr_be.put32(&outheader, header->version);
+ xdr_be.put32(&outheader, header->romsize);
+ xdr_be.put32(&outheader, header->bootblocksize);
+ xdr_be.put32(&outheader, header->align);
+ xdr_be.put32(&outheader, header->offset);
+ xdr_be.put32(&outheader, header->architecture);
+}
int cbfs_image_create(struct cbfs_image *image,
uint32_t myarch,
size_t size,
@@ -148,7 +163,7 @@ int cbfs_image_create(struct cbfs_image *image,
int32_t header_offset,
int32_t entries_offset)
{
- struct cbfs_header *header;
+ struct cbfs_header header;
struct cbfs_file *entry;
uint32_t cbfs_len;
size_t entry_header_len;
@@ -156,7 +171,7 @@ int cbfs_image_create(struct cbfs_image *image,
DEBUG("cbfs_image_create: bootblock=0x%x+0x%zx, "
"header=0x%x+0x%zx, entries_offset=0x%x\n",
bootblock_offset, bootblock->size,
- header_offset, sizeof(*header), entries_offset);
+ header_offset, sizeof(header), entries_offset);
if (buffer_create(&image->buffer, size, "(new)") != 0)
return -1;
@@ -194,20 +209,20 @@ int cbfs_image_create(struct cbfs_image *image,
bootblock->size);
// Prepare header
- if (header_offset + sizeof(*header) > size) {
+ if (header_offset + sizeof(header) > size) {
ERROR("Header (0x%x+0x%zx) exceed ROM size (0x%zx)\n",
- header_offset, sizeof(*header), size);
+ header_offset, sizeof(header), size);
return -1;
}
- header = (struct cbfs_header *)(image->buffer.data + header_offset);
- image->header = header;
- header->magic = htonl(CBFS_HEADER_MAGIC);
- header->version = htonl(CBFS_HEADER_VERSION);
- header->romsize = htonl(size);
- header->bootblocksize = htonl(bootblock->size);
- header->align = htonl(align);
- header->offset = htonl(entries_offset);
- header->architecture = htonl(myarch);
+ image->header = (struct cbfs_header *)(image->buffer.data + header_offset);
+ header.magic = CBFS_HEADER_MAGIC;
+ header.version = CBFS_HEADER_VERSION;
+ header.romsize = size;
+ header.bootblocksize = bootblock->size;
+ header.align = align;
+ header.offset = entries_offset;
+ header.architecture = architecture;
+ cbfs_put_header(image->header, &header);
// Prepare entries
if (align_up(entries_offset, align) != entries_offset) {
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 7ad418a..74c8f97 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -31,6 +31,10 @@ struct cbfs_image {
struct cbfs_header *header;
};
+/* Given a pointer, serialize the header from host-native byte format
+ * to cbfs format, i.e. big-endian. */
+void cbfs_put_header(void *dest, struct cbfs_header *header);
+
/* Creates an empty CBFS image by given size, and description to its content
* (bootblock, align, header location, starting offset of CBFS entries.
* The output image will contain a valid cbfs_header, with one cbfs_file
the following patch was just integrated into master:
commit f38f84855f01b31a2de070d1237bb18f33584081
Author: Ronald G. Minnich <rminnich(a)google.com>
Date: Mon Dec 30 13:16:18 2013 -0800
Add section header parsing and use it in the mk-payload step
This completes the improvements to the ELF file parsing code. We can
now parse section headers too, across all 4 combinations of word size
and endianness. I had hoped to completely remove the use of htonl
until I found it in cbfs_image.c. That's a battle for another day.
There's now a handy macro to create magic numbers in host byte order.
I'm using it for all the PAYLOAD_SEGMENT_* constants and maybe
we can use it for the others too, but this is sensitive code and
I'd rather change one thing at a time.
To maximize the ease of use for users, elf parsing is accomplished with
just one function:
int
elf_headers(const struct buffer *pinput,
Elf64_Ehdr *ehdr,
Elf64_Phdr **pphdr,
Elf64_Shdr **pshdr)
which requires the ehdr and pphdr pointers to be non-NULL, but allows
the pshdr to be NULL. If pshdr is NULL, the code will not try to read
in section headers.
To satisfy our powerful scripts, I had to remove the ^M from an unrelated
microcode file.
BUG=None
TEST=Build a peppy image (known to boot) with old and new versions and verify they are bit-for-bit the same. This was also fully tested across all chromebooks for building and booting and running chromeos.
BRANCH=None
Change-Id: I54dad887d922428b6175fdb6a9cdfadd8a6bb889
Signed-off-by: Ronald G. Minnich <rminnich(a)google.com>
Reviewed-on: https://chromium-review.googlesource.com/181272
Reviewed-by: Ronald Minnich <rminnich(a)chromium.org>
Commit-Queue: Ronald Minnich <rminnich(a)chromium.org>
Tested-by: Ronald Minnich <rminnich(a)chromium.org>
Signed-off-by: Ronald G. Minnich <rminnich(a)google.com>
See http://review.coreboot.org/5098 for details.
-gerrit