[coreboot-gerrit] Change in coreboot[master]: intelvbttool: Add several fixes
Patrick Rudolph (Code Review)
gerrit at coreboot.org
Sun Mar 19 14:28:31 CET 2017
Patrick Rudolph has uploaded a new change for review. ( https://review.coreboot.org/18902 )
Change subject: intelvbttool: Add several fixes
......................................................................
intelvbttool: Add several fixes
The following features have been added:
* Print help message on -h.
* Update Makefile to rebuild binary on source file changes.
* Add support for writing VBT to file.
To extract the VBT from Intel OptionRom called 'OPROM.bin' and store it as
binary file 'vbt.bin' call it with the following args:
./intelvbttool -d OPROM.bin vbt.bin
Change-Id: I8cbde042c7f5632f36648419becd23e248ba6f76
Signed-off-by: Patrick Rudolph <siro at das-labor.org>
---
M util/intelvbttool/Makefile
M util/intelvbttool/intelvbttool.c
2 files changed, 112 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/02/18902/1
diff --git a/util/intelvbttool/Makefile b/util/intelvbttool/Makefile
index 7d50d30..b772412 100644
--- a/util/intelvbttool/Makefile
+++ b/util/intelvbttool/Makefile
@@ -20,7 +20,7 @@
all: $(PROGRAM)
-$(PROGRAM):
+$(PROGRAM): $(PROGRAM).c
$(CC) $(CFLAGS) $(CPPFLAGS) $(PROGRAM).c -o $(PROGRAM)
clean:
diff --git a/util/intelvbttool/intelvbttool.c b/util/intelvbttool/intelvbttool.c
index f0216dd..562a153 100644
--- a/util/intelvbttool/intelvbttool.c
+++ b/util/intelvbttool/intelvbttool.c
@@ -17,10 +17,10 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include <getopt.h>
typedef uint8_t u8;
typedef uint16_t u16;
@@ -511,13 +511,100 @@
parse_vbt((const char *) ptr + oh->vbt_offset);
}
+static int dump_vbt(const void *ptr, int fd)
+{
+ const optionrom_header_t *oh;
+ const struct bdb_header *bdb;
+ struct vbt_header *head;
+
+ oh = ptr;
+ if (oh->signature != 0xaa55) {
+ fprintf(stderr, "bad oprom signature: %x\n",
+ oh->signature);
+ return 1;
+ }
+ if (!oh->vbt_offset) {
+ fprintf(stderr, "no VBT found\n");
+ return 1;
+ }
+
+ head = (struct vbt_header *)((const char *)ptr + oh->vbt_offset);
+
+ if (memcmp(head->signature, "$VBT", 4) != 0) {
+ fprintf(stderr, "invalid VBT signature\n");
+ return 1;
+ }
+ printf("Found VBT:\n");
+ printf("signature: <%20.20s>\n", head->signature);
+ printf("version: %d.%02d\n", head->version / 100,
+ head->version % 100);
+ if (head->header_size != sizeof(struct vbt_header))
+ printf("header size: 0x%x\n", head->header_size);
+ printf("VBT size: 0x%x\n", head->vbt_size);
+ printf("VBT checksum: 0x%x\n", head->vbt_checksum);
+
+ bdb = (const void *) ((const char *) head + head->bdb_offset);
+
+ if (memcmp("BIOS_DATA_BLOCK ", bdb->signature, 16) != 0) {
+ fprintf(stderr, "invalid BDB signature:%s\n",
+ bdb->signature);
+ return 1;
+ }
+ printf("BDB version: %d.%02d\n", bdb->version / 100,
+ bdb->version % 100);
+
+ return write(fd, head, head->vbt_size) != head->vbt_size;
+}
+
+void print_usage(const char *name)
+{
+ printf("usage: %s [-h|-d] [<input file>] [<output file>]\n", name);
+ printf("In case no input file is given, the physical address 0xc0000 is beeing used.\n");
+ printf("\n"
+ " -h | --help: print this help\n"
+ " -d | --dump: save VBT to <output file>\n"
+ "\n");
+ exit(1);
+}
+
int main(int argc, char **argv)
{
const void *ptr;
- int fd;
+ char *filename = NULL;
+ int fd, fd_out = 0;
off_t offset;
- if (argc == 2) {
+ int ret = 0, opt, option_index = 0;
+ int dump = 0;
+
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+ {"dump", 0, 0, 'd'},
+ {0, 0, 0, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, "hd",
+ long_options, &option_index)) != EOF) {
+ switch (opt) {
+ case 'd':
+ dump = 1;
+ break;
+ case '?':
+ case 'h':
+ print_usage(argv[0]);
+ exit(0);
+ break;
+ }
+ }
+
+ if (dump && argc < 3) {
+ fprintf(stderr, "Missing argument.\n");
+ return 1;
+ }
+ if (argc == 2 && !dump) {
fd = open(argv[1], O_RDONLY);
+ offset = 0;
+ } else if (argc == 4 && dump) {
+ fd = open(argv[2], O_RDONLY);
offset = 0;
} else {
fd = open("/dev/mem", O_RDONLY);
@@ -528,12 +615,31 @@
return 1;
}
+ if (argc == 4 && dump) {
+ fd_out = open(argv[3], O_WRONLY | O_CREAT, 0664);
+ filename = argv[3];
+ } else if (argc == 3 && dump) {
+ fd_out = open(argv[2], O_WRONLY | O_CREAT, 0664);
+ filename = argv[2];
+ }
+ if (fd_out < 0) {
+ close(fd);
+ fprintf(stderr, "open failed: %s\n", strerror(errno));
+ return 1;
+ }
+
ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, offset);
if (ptr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
return 1;
}
- parse_vbios(ptr);
+ if (dump) {
+ ret = dump_vbt(ptr, fd_out);
+ if (!ret)
+ printf("VBT successfully stored as %s.\n", filename);
+ }
+ else
+ parse_vbios(ptr);
close(fd);
- return 0;
+ return ret;
}
--
To view, visit https://review.coreboot.org/18902
To unsubscribe, visit https://review.coreboot.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cbde042c7f5632f36648419becd23e248ba6f76
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Patrick Rudolph <siro at das-labor.org>
More information about the coreboot-gerrit
mailing list