[coreboot-gerrit] New patch to review for coreboot: adb002d lbtdump: Allow printing only relevant info

Vladimir Serbinenko (phcoder@gmail.com) gerrit at coreboot.org
Sat Aug 23 01:22:05 CEST 2014


Vladimir Serbinenko (phcoder at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6744

-gerrit

commit adb002d651754f851a011004d8773dba056ec5f3
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Fri Aug 22 23:38:45 2014 +0200

    lbtdump: Allow printing only relevant info
    
    Change-Id: I8d4c26cc01a112c8f9c7de09da4fa06cfa77a9ac
    Signed-off-by: Vladimir Serbinenko <phcoder at gmail.com>
---
 util/lbtdump/lbtdump.c | 79 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 64 insertions(+), 15 deletions(-)

diff --git a/util/lbtdump/lbtdump.c b/util/lbtdump/lbtdump.c
index c5e4f28..34d1165 100644
--- a/util/lbtdump/lbtdump.c
+++ b/util/lbtdump/lbtdump.c
@@ -7,9 +7,14 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/mman.h>
+#include <getopt.h>
 #include "../../src/include/boot/coreboot_tables.h"
 
-uint64_t print_lb_records(struct lb_record *rec, struct lb_record *last, unsigned long addr);
+#define PRINT_ALL 0xffffffff
+
+static int verbose = 0;
+
+uint64_t print_lb_records(struct lb_record *rec, struct lb_record *last, unsigned long addr, uint32_t target);
 
 unsigned long compute_checksum(void *addr, unsigned long length)
 {
@@ -72,8 +77,9 @@ struct lb_header *find_lb_table(void *base, unsigned long start, unsigned long e
 		struct lb_record *recs = (struct lb_record *)(((char*)base) + addr + sizeof(*head));
 		if (memcmp(head->signature, "LBIO", 4) != 0)
 			continue;
-		fprintf(stdout, "Found candidate at: %08lx-%08lx\n",
-			addr, addr + head->table_bytes);
+		if (verbose)
+			fprintf(stdout, "Found candidate at: %08lx-%08lx\n",
+				addr, addr + head->table_bytes);
 		if (head->header_bytes != sizeof(*head)) {
 			fprintf(stderr, "Header bytes of %d are incorrect\n",
 				head->header_bytes);
@@ -94,7 +100,8 @@ struct lb_header *find_lb_table(void *base, unsigned long start, unsigned long e
 				head->table_checksum);
 			continue;
 		}
-		fprintf(stdout, "Found coreboot table at: %08lx\n", addr);
+		if (verbose)
+			fprintf(stdout, "Found coreboot table at: %08lx\n", addr);
 		return head;
 
 	};
@@ -196,7 +203,7 @@ void print_option_table(struct lb_record *ptr, unsigned long addr)
 	last = (struct lb_record *)(((char *)hdr) + hdr->size);
 	printf("cmos option header record = type %d, size %d, header length %d\n",
 		hdr->tag, hdr->size, hdr->header_length);
-	print_lb_records(rec, last, addr + hdr->header_length);
+	print_lb_records(rec, last, addr + hdr->header_length, PRINT_ALL);
 #if 0
 	{
 		unsigned char *data = (unsigned char *)ptr;
@@ -266,6 +273,7 @@ struct {
 	{ LB_TAG_COMPILER,          "Compiler",           print_string },
 	{ LB_TAG_LINKER,            "Linker",             print_string },
 	{ LB_TAG_ASSEMBLER,         "Assembler",          print_string },
+	{ LB_TAG_MAINBOARD_ID,      "Mainboard ID",       print_string },
 	{ LB_TAG_CMOS_OPTION_TABLE, "CMOS option table",  print_option_table },
 	{ LB_TAG_OPTION,            "Option",             print_option },
 	{ LB_TAG_OPTION_ENUM,       "Option Enumeration", print_option_enumeration },
@@ -281,7 +289,7 @@ static struct lb_record *next_record(struct lb_record *rec)
 }
 
 uint64_t print_lb_records(struct lb_record *rec, struct lb_record *last,
-	unsigned long addr)
+			  unsigned long addr, uint32_t target)
 {
 	struct lb_record *next;
 	int i;
@@ -298,9 +306,10 @@ uint64_t print_lb_records(struct lb_record *rec, struct lb_record *last,
 				break;
 			}
 		}
-		printf("lb_record #%d type %d @ 0x%08lx %s\n",
-			count, rec->tag, addr, lb_types[i].type_name);
-		if (lb_types[i].print) {
+		if (target == PRINT_ALL)
+			printf("lb_record #%d type %d @ 0x%08lx %s\n",
+			       count, rec->tag, addr, lb_types[i].type_name);
+		if (lb_types[i].print && (target == PRINT_ALL || target == rec->tag)) {
 			lb_types[i].print(rec, addr);
 		}
 		if (rec->tag == LB_TAG_FORWARD)
@@ -326,7 +335,7 @@ static void *do_map(int fd, uint64_t addr, uint32_t len, void **mpaddr_out, size
 	return ret + addr - mpaddr;
 }
 
-uint64_t print_lb_table(int fd, uint64_t addr)
+uint64_t print_lb_table(int fd, uint64_t addr, uint32_t target)
 {
 	struct lb_record *rec, *last;
 	struct lb_header *head;
@@ -344,19 +353,59 @@ uint64_t print_lb_table(int fd, uint64_t addr)
 	rec  = (struct lb_record *)(((char *)head) + head->header_bytes);
 	last = (struct lb_record *)(((char *)rec) + head->table_bytes);
 
-	printf("Coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n",
-		head->header_bytes, head->header_checksum,
-		head->table_bytes, head->table_checksum, head->table_entries);
-	forward = print_lb_records(rec, last, addr + head->header_bytes);
+	if (target == PRINT_ALL)
+		printf("Coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n",
+		       head->header_bytes, head->header_checksum,
+		       head->table_bytes, head->table_checksum, head->table_entries);
+	forward = print_lb_records(rec, last, addr + head->header_bytes, target);
 	munmap (mp, mplen);
 	return forward;
 }
 
+static void print_usage(const char *name)
+{
+	printf("usage: %s [-mh?]\n", name);
+	printf("\n"
+	     "   -w | --coreboot-version:          dump coreboot version\n"
+	     "   -V | --verbose:                   verbose (debugging) output\n"
+	     "   -h | --help:                      print this help\n"
+	     "\n");
+	exit(1);
+}
+
 int main(int argc, char **argv)
 {
 	unsigned char *low_1MB;
 	struct lb_header *lb_table;
 	int fd;
+	uint32_t target = PRINT_ALL;
+	int opt, option_index = 0;
+
+	static struct option long_options[] = {
+		{"coreboot-version", 0, 0, 'w'},
+		{"verbose", 0, 0, 'V'},
+		{"help", 0, 0, 'h'},
+		{0, 0, 0, 0}
+	};
+	while ((opt = getopt_long(argc, argv, "Vmwh?",
+				  long_options, &option_index)) != EOF) {
+		switch (opt) {
+		case 'w':
+			target = LB_TAG_VERSION;
+			break;
+		case 'V':
+			verbose = 1;
+			break;
+		case 'h':
+		case '?':
+		default:
+			print_usage(argv[0]);
+			exit(0);
+			break;
+		}
+	}
+
+
 	fd = open("/dev/mem", O_RDONLY);
 	if (fd < 0) {
 		fprintf(stderr, "Can not open /dev/mem\n");
@@ -378,7 +427,7 @@ int main(int argc, char **argv)
 		addr = ((char *)lb_table) - ((char *)low_1MB);
 
 		while (addr)
-			addr = print_lb_table(fd, addr);
+			addr = print_lb_table(fd, addr, target);
 	}
 	else {
 		printf("lb_table not found\n");



More information about the coreboot-gerrit mailing list