diff options
author | Ronald G. Minnich <rminnich@google.com> | 2013-12-30 13:16:18 -0800 |
---|---|---|
committer | Ronald G. Minnich <rminnich@gmail.com> | 2014-02-02 20:18:55 +0100 |
commit | a8a133ded34d82a7baa9a439969eae780a501992 (patch) | |
tree | ef64f06102d378795ea3b84920e6fba9f4a424eb /util/cbfstool/cbfs.h | |
parent | 25fc8d181fde674fb35ad56c841ffb3b4b0489e9 (diff) | |
download | coreboot-a8a133ded34d82a7baa9a439969eae780a501992.tar.xz |
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@google.com>
Reviewed-on: https://chromium-review.googlesource.com/181272
Reviewed-by: Ronald Minnich <rminnich@chromium.org>
Commit-Queue: Ronald Minnich <rminnich@chromium.org>
Tested-by: Ronald Minnich <rminnich@chromium.org>
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
Reviewed-on: http://review.coreboot.org/5098
Tested-by: build bot (Jenkins)
Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Diffstat (limited to 'util/cbfstool/cbfs.h')
-rw-r--r-- | util/cbfstool/cbfs.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h index 35d0670928..585a26d96c 100644 --- a/util/cbfstool/cbfs.h +++ b/util/cbfstool/cbfs.h @@ -20,6 +20,18 @@ #define __CBFS_H #include <stdint.h> +#include "elf.h" + +/* create a magic number in host-byte order. + * b3 is the high order byte. + * in the coreboot tools, we go with the 32-bit + * magic number convention. + * This was an inline func but that breaks anything + * that uses it in a case statement. + */ + +#define makemagic(b3, b2, b1, b0)\ + (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0)) #define CBFS_HEADER_MAGIC 0x4F524243 #define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC @@ -60,11 +72,11 @@ struct cbfs_stage { uint32_t memlen; } __attribute__ ((packed)); -#define PAYLOAD_SEGMENT_CODE 0x45444F43 -#define PAYLOAD_SEGMENT_DATA 0x41544144 -#define PAYLOAD_SEGMENT_BSS 0x20535342 -#define PAYLOAD_SEGMENT_PARAMS 0x41524150 -#define PAYLOAD_SEGMENT_ENTRY 0x52544E45 +#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E') +#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A') +#define PAYLOAD_SEGMENT_BSS makemagic(' ', 'B', 'S', 'S') +#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A') +#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R') struct cbfs_payload_segment { uint32_t type; @@ -110,7 +122,22 @@ struct cbfs_payload { int cbfs_file_header(unsigned long physaddr); #define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file)) #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) ) - +/* cbfs_image.c */ +uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value); +const char *get_cbfs_entry_type_name(uint32_t type); +uint32_t get_cbfs_compression(const char *name, uint32_t unknown); + +/* common.c */ +int find_master_header(void *romarea, size_t size); +void recalculate_rom_geometry(void *romarea); struct cbfs_file *cbfs_create_empty_file(uint32_t physaddr, uint32_t size); +const char *strfiletype(uint32_t number); + +/* elfheaders.c */ +int +elf_headers(const struct buffer *pinput, + Elf64_Ehdr *ehdr, + Elf64_Phdr **pphdr, + Elf64_Shdr **pshdr); #endif |