[coreboot-gerrit] Patch set updated for coreboot: ifdtool: refactor VSCC table parsing

Alexander Couzens (lynxis@fe80.eu) gerrit at coreboot.org
Fri Oct 28 00:33:35 CEST 2016


Alexander Couzens (lynxis at fe80.eu) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16569

-gerrit

commit f350049b3f9add4b83fad0abce57560328991e88
Author: Alexander Couzens <lynxis at fe80.eu>
Date:   Sat Sep 10 13:30:32 2016 +0200

    ifdtool: refactor VSCC table parsing
    
    - move into own files
    - use structs instead of bit operations
    
    Change-Id: I15780068ff5827bc4381a2e951e1c4384dd4c18e
    Signed-off-by: Alexander Couzens <lynxis at fe80.eu>
---
 util/ifdtool/Makefile  |  2 +-
 util/ifdtool/ifdtool.c | 77 +----------------------------------------------
 util/ifdtool/ifdtool.h | 11 -------
 util/ifdtool/vtba.c    | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++
 util/ifdtool/vtba.h    | 59 ++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 88 deletions(-)

diff --git a/util/ifdtool/Makefile b/util/ifdtool/Makefile
index 77547ef..945b501 100644
--- a/util/ifdtool/Makefile
+++ b/util/ifdtool/Makefile
@@ -21,7 +21,7 @@ PREFIX  = /usr/local
 CFLAGS  = -O2 -g -Wall -W -Werror
 LDFLAGS =
 
-OBJS = ifdtool.o
+OBJS = vtba.o ifdtool.o
 
 all: dep $(PROGRAM)
 
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index 74588e1..94a81ee 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "ifdtool.h"
+#include "vtba.h"
 
 #ifndef O_BINARY
 #define O_BINARY 0
@@ -518,82 +519,6 @@ static void dump_fmsba(fmsba_t * fmsba)
 	printf("????:      0x%08x\n", fmsba->data[3]);
 }
 
-static void dump_jid(uint32_t jid)
-{
-	printf("    SPI Componend Device ID 1:          0x%02x\n",
-		(jid >> 16) & 0xff);
-	printf("    SPI Componend Device ID 0:          0x%02x\n",
-		(jid >> 8) & 0xff);
-	printf("    SPI Componend Vendor ID:            0x%02x\n",
-		jid & 0xff);
-}
-
-static void dump_vscc(uint32_t vscc)
-{
-	printf("    Lower Erase Opcode:                 0x%02x\n",
-		vscc >> 24);
-	printf("    Lower Write Enable on Write Status: 0x%02x\n",
-		vscc & (1 << 20) ? 0x06 : 0x50);
-	printf("    Lower Write Status Required:        %s\n",
-		vscc & (1 << 19) ? "Yes" : "No");
-	printf("    Lower Write Granularity:            %d bytes\n",
-		vscc & (1 << 18) ? 64 : 1);
-	printf("    Lower Block / Sector Erase Size:    ");
-	switch ((vscc >> 16) & 0x3) {
-	case 0:
-		printf("256 Byte\n");
-		break;
-	case 1:
-		printf("4KB\n");
-		break;
-	case 2:
-		printf("8KB\n");
-		break;
-	case 3:
-		printf("64KB\n");
-		break;
-	}
-
-	printf("    Upper Erase Opcode:                 0x%02x\n",
-		(vscc >> 8) & 0xff);
-	printf("    Upper Write Enable on Write Status: 0x%02x\n",
-		vscc & (1 << 4) ? 0x06 : 0x50);
-	printf("    Upper Write Status Required:        %s\n",
-		vscc & (1 << 3) ? "Yes" : "No");
-	printf("    Upper Write Granularity:            %d bytes\n",
-		vscc & (1 << 2) ? 64 : 1);
-	printf("    Upper Block / Sector Erase Size:    ");
-	switch (vscc & 0x3) {
-	case 0:
-		printf("256 Byte\n");
-		break;
-	case 1:
-		printf("4KB\n");
-		break;
-	case 2:
-		printf("8KB\n");
-		break;
-	case 3:
-		printf("64KB\n");
-		break;
-	}
-}
-
-static void dump_vtba(vtba_t *vtba, int vtl)
-{
-	int i;
-	int num = (vtl >> 1) < 8 ? (vtl >> 1) : 8;
-
-	printf("ME VSCC table:\n");
-	for (i = 0; i < num; i++) {
-		printf("  JID%d:  0x%08x\n", i, vtba->entry[i].jid);
-		dump_jid(vtba->entry[i].jid);
-		printf("  VSCC%d: 0x%08x\n", i, vtba->entry[i].vscc);
-		dump_vscc(vtba->entry[i].vscc);
-	}
-	printf("\n");
-}
-
 static void dump_oem(uint8_t *oem)
 {
 	int i, j;
diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h
index 7878712..2b5da4f 100644
--- a/util/ifdtool/ifdtool.h
+++ b/util/ifdtool/ifdtool.h
@@ -120,17 +120,6 @@ typedef struct {
 	uint32_t data[8];
 } __attribute__((packed)) fmsba_t;
 
-// ME VSCC
-typedef struct {
-	uint32_t jid;
-	uint32_t vscc;
-} vscc_t;
-
-typedef struct {
-	// Actual number of entries specified in vtl
-	vscc_t entry[8];
-} vtba_t;
-
 typedef struct {
 	int base, limit, size;
 } region_t;
diff --git a/util/ifdtool/vtba.c b/util/ifdtool/vtba.c
new file mode 100644
index 0000000..1fe5b6d
--- /dev/null
+++ b/util/ifdtool/vtba.c
@@ -0,0 +1,82 @@
+/*
+ * vscc table tool
+ *
+ * Copyright (C) 2016 Alexander Couzens <lynxis at fe80.eu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#include "vtba.h"
+
+
+static void dump_jid(struct jid *jid)
+{
+	printf("    SPI Componend Device ID 1:          0x%02x\n",
+		jid->device_id1);
+	printf("    SPI Componend Device ID 0:          0x%02x\n",
+		jid->device_id0);
+	printf("    SPI Componend Vendor ID:            0x%02x\n",
+		jid->vendor);
+}
+
+static void dump_vscc_entry(const char *prefix, struct vscc_entry *entry)
+{
+	printf("    %s Erase Opcode:                 0x%02x\n",
+		prefix, entry->erase_opcode);
+	printf("    %s Write Enable on Write Status: 0x%02x\n",
+		prefix, entry->write_enable_on_write_status ? 0x06 : 0x50);
+	printf("    %s Write Status Required:        %s\n",
+		prefix, entry->status_required ? "Yes" : "No");
+	printf("    %s Write Granularity:            %d bytes\n",
+		prefix, entry->granularity ? 64 : 1);
+	printf("    %s Block / Sector Erase Size:    ", prefix);
+	switch ((enum sector_size) entry->sector_size) {
+	case SECTOR_256B:
+		printf("256 Byte\n");
+		break;
+	case SECTOR_4KB:
+		printf("4KB\n");
+		break;
+	case SECTOR_8KB:
+		printf("8KB\n");
+		break;
+	case SECTOR_64KB:
+		printf("64KB\n");
+		break;
+	default:
+		printf("Unknown %x\n", entry->sector_size);
+	}
+}
+
+static void dump_vscc(struct vscc *vscc)
+{
+	dump_vscc_entry("Lower", &vscc->lower);
+	dump_vscc_entry("Upper", &vscc->upper);
+}
+
+void dump_vtba(vtba_t *vtba, int vtl)
+{
+	int i;
+	int num = (vtl >> 1) < 8 ? (vtl >> 1) : 8;
+
+	printf("ME VSCC table:\n");
+	for (i = 0; i < num; i++) {
+		printf("  JID%d:  0x%08x\n",
+			i, (*((uint32_t *) &vtba->entry[i].jid)));
+		dump_jid(&vtba->entry[i].jid);
+		printf("  VSCC%d: 0x%08x\n",
+			i, (*((uint32_t *) &vtba->entry[i].vscc)));
+		dump_vscc(&vtba->entry[i].vscc);
+	}
+	printf("\n");
+}
diff --git a/util/ifdtool/vtba.h b/util/ifdtool/vtba.h
new file mode 100644
index 0000000..3814c90
--- /dev/null
+++ b/util/ifdtool/vtba.h
@@ -0,0 +1,59 @@
+/*
+ * ifdtool - dump Intel Firmware Descriptor information
+ *
+ * Copyright (C) 2016 Alexander Couzens <lynxis at fe80.eu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdint.h>
+
+// ME VSCC
+
+enum sector_size {
+	SECTOR_256B = 0,
+	SECTOR_4KB,
+	SECTOR_8KB,
+	SECTOR_64KB,
+};
+
+/* 16 bit */
+struct vscc_entry {
+	int sector_size:2;
+	int granularity:1;
+	int status_required:1;
+	int write_enable_on_write_status:1;
+	int blank:3;
+	uint8_t erase_opcode;
+} __attribute__((packed));
+
+struct vscc {
+	struct vscc_entry upper;
+	struct vscc_entry lower;
+} __attribute__((packed));
+
+struct jid {
+	uint8_t vendor;
+	uint8_t device_id0;
+	uint8_t device_id1;
+	uint8_t blank;
+} __attribute__((packed));
+
+struct vss_combined {
+	struct jid jid;
+	struct vscc vscc;
+} __attribute__((packed));
+
+typedef struct  {
+	// Actual number of entries specified in vtl
+	struct vss_combined entry[8];
+} vtba_t;
+
+void dump_vtba(vtba_t *vtba, int vtl);



More information about the coreboot-gerrit mailing list