[coreboot-gerrit] New patch to review for coreboot: WIP: ifdtool: Do proper ser/deser of descriptor

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Mon Sep 14 16:47:03 CET 2015


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11635

-gerrit

commit 833da426447c0b2d9aff299143f6cfd9459e8a08
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Mon Sep 14 09:47:24 2015 -0700

    WIP: ifdtool: Do proper ser/deser of descriptor
    
    Change-Id: Iccc063d08beb2fcafe9af910a0b1b984fcbc134f
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 util/ifdtool/Makefile      |  2 +-
 util/ifdtool/ifd_drv_bin.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++
 util/ifdtool/ifdtool.c     | 56 +++++++++++++++++++++----------
 util/ifdtool/ifdtool.h     | 22 +++++++++++++
 4 files changed, 143 insertions(+), 19 deletions(-)

diff --git a/util/ifdtool/Makefile b/util/ifdtool/Makefile
index 02a02c4..ac43293 100644
--- a/util/ifdtool/Makefile
+++ b/util/ifdtool/Makefile
@@ -25,7 +25,7 @@ PREFIX  = /usr/local
 CFLAGS  = -O2 -g -Wall -W -Werror
 LDFLAGS =
 
-OBJS = ifdtool.o
+OBJS = ifdtool.o ifd_drv_bin.o
 
 all: dep $(PROGRAM)
 
diff --git a/util/ifdtool/ifd_drv_bin.c b/util/ifdtool/ifd_drv_bin.c
new file mode 100644
index 0000000..146475a
--- /dev/null
+++ b/util/ifdtool/ifd_drv_bin.c
@@ -0,0 +1,82 @@
+
+#include "ifdtool.h"
+#include "helpers.h"
+
+#include <stdlib.h>
+
+static void des_flmap0(struct flash_descriptor *desc, uint32_t flmap0)
+{
+	desc->num_regions = (flmap0 >> 24) & 7;
+	desc->frba_offset = ((flmap0 >> 16) & 0xff) << 4;
+	desc->num_components = ((flmap0 >> 8) & 0x3) + 1;
+	desc->fcba_offset = ((flmap0 >> 0) & 0xff) << 4;
+}
+
+static uint32_t ser_flmap0(const struct flash_descriptor *desc)
+{
+	uint32_t flmap0;
+
+	flmap0 = (desc->num_regions & 0x7) << 24;
+	flmap0 |= ((desc->frba_offset >> 4) & 0xff)  << 16;
+	flmap0 |= ((desc->num_components - 1) & 0x3) << 8;
+	flmap0 |= ((desc->fcba_offset >> 4) & 0xff) << 0;
+
+	return flmap0;
+}
+
+static void des_flmap1(struct flash_descriptor *desc, uint32_t flmap1)
+{
+	desc->num_pch_straps = (flmap1 >> 24) & 0xff;
+	desc->fpsba_offset = ((flmap1 >> 16) & 0xff) << 4;
+	desc->num_masters = (flmap1 >> 8) & 3;
+	desc->fmba_offset = ((flmap1 >> 0) & 0xff) << 4;
+}
+
+static uint32_t ser_flmap1(const struct flash_descriptor *desc)
+{
+	uint32_t flmap1;
+
+	flmap1 = (desc->num_pch_straps & 0xff) << 24;
+	flmap1 |= ((desc->fpsba_offset >> 4) & 0xff)  << 16;
+	flmap1 |= (desc->num_masters & 0x3) << 8;
+	flmap1 |= ((desc->fmba_offset >> 4) & 0xff) << 0;
+
+	return flmap1;
+}
+
+static void des_flmap2(struct flash_descriptor *desc, uint32_t flmap2)
+{
+	desc->iccriba_offset = ((flmap2 >> 16) & 0xff) << 4;
+	desc->num_pch_straps = (flmap2 >> 8) & 0xff;
+	desc->fmsba_offset = ((flmap2 >> 0) & 0xff) << 4;
+}
+
+static uint32_t ser_flmap2(const struct flash_descriptor *desc)
+{
+	uint32_t flmap2;
+
+	flmap2 = ((desc->iccriba_offset >> 4) & 0xff)  << 16;
+	flmap2 |= (desc->num_pch_straps & 0x3) << 8;
+	flmap2 |= ((desc->fmsba_offset >> 4) & 0xff) << 0;
+
+	return flmap2;
+}
+
+void read_flash_descriptor(struct flash_descriptor *desc, const void *fud)
+{
+	const uint8_t *ifd_regs = fud;
+
+	des_flmap0(desc, read_le32(ifd_regs + 0x04));
+	des_flmap1(desc, read_le32(ifd_regs + 0x08));
+	des_flmap2(desc, read_le32(ifd_regs + 0x0C));
+}
+
+void dont_compile_fail_me(void)
+{
+	des_flmap0(NULL, 0);
+	ser_flmap0(NULL);
+	des_flmap1(NULL, 0);
+	ser_flmap1(NULL);
+	des_flmap2(NULL, 0);
+	ser_flmap2(NULL);
+}
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index e6ed110..7b59ada 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -18,6 +18,7 @@
  */
 
 #include <unistd.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,6 +26,8 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include "helpers.h"
 #include "ifdtool.h"
 
 #ifndef O_BINARY
@@ -33,7 +36,7 @@
 
 static int ifd_version;
 
-static const struct region_name region_names[MAX_REGIONS] = {
+static const struct region_name region_names_old_yester_years[9] = {
 	{ "Flash Descriptor", "fd" },
 	{ "BIOS", "bios" },
 	{ "Intel ME", "me" },
@@ -45,15 +48,29 @@ static const struct region_name region_names[MAX_REGIONS] = {
 	{ "EC", "ec" },
 };
 
-static fdbar_t *find_fd(char *image, int size)
+static const struct region_name region_names[9] = {
+	{ "Flash Descriptor", "fd" },
+	{ "IFWI", "bios" },
+	{ "TXE", "me" },
+	{ "Platform Data", "pd" },
+	{ "Device Expansion", "bs0" },
+	{ "Reserved", "res1" },
+	{ "Reserved", "res2" },
+	{ "Reserved", "res3" },
+	{ "Reserved", "res4" },
+};
+
+static void *find_fd(void *image, size_t size)
 {
-	int i, found = 0;
+	size_t i;
+	bool found = false;
+	uint8_t *base = image;
 
 	/* Scan for FD signature */
 	for (i = 0; i < (size - 4); i += 4) {
-		if (*(uint32_t *) (image + i) == 0x0FF0A55A) {
-			found = 1;
-			break;	// signature found.
+		if (read_le32(base + i) == 0x0FF0A55A) {
+			found = true;
+			break;	/* signature found. */
 		}
 	}
 
@@ -62,7 +79,7 @@ static fdbar_t *find_fd(char *image, int size)
 		return NULL;
 	}
 
-	return (fdbar_t *) (image + i);
+	return base + i;
 }
 
 /*
@@ -221,7 +238,7 @@ static int region_num(const char *name)
 
 static const char *region_filename(int region_type)
 {
-	static const char *region_filenames[MAX_REGIONS] = {
+	static const char *region_filenames[9] = {
 		"flashregion_0_flashdescriptor.bin",
 		"flashregion_1_bios.bin",
 		"flashregion_2_intel_me.bin",
@@ -590,25 +607,28 @@ static void dump_oem(uint8_t *oem)
 
 static void dump_fd(char *image, int size)
 {
+	struct flash_descriptor desc;
 	fdbar_t *fdb = find_fd(image, size);
 	if (!fdb)
 		exit(EXIT_FAILURE);
 
+	read_flash_descriptor(&desc,fdb);
+
 	printf("FLMAP0:    0x%08x\n", fdb->flmap0);
-	printf("  NR:      %d\n", (fdb->flmap0 >> 24) & 7);
-	printf("  FRBA:    0x%x\n", ((fdb->flmap0 >> 16) & 0xff) << 4);
-	printf("  NC:      %d\n", ((fdb->flmap0 >> 8) & 3) + 1);
-	printf("  FCBA:    0x%x\n", ((fdb->flmap0) & 0xff) << 4);
+	printf("  NR:      %d\n", desc.num_regions);
+	printf("  FRBA:    0x%x\n", desc.frba_offset);
+	printf("  NC:      %d\n", desc.num_components);
+	printf("  FCBA:    0x%x\n", desc.fcba_offset);
 
 	printf("FLMAP1:    0x%08x\n", fdb->flmap1);
-	printf("  ISL:     0x%02x\n", (fdb->flmap1 >> 24) & 0xff);
-	printf("  FPSBA:   0x%x\n", ((fdb->flmap1 >> 16) & 0xff) << 4);
-	printf("  NM:      %d\n", (fdb->flmap1 >> 8) & 3);
-	printf("  FMBA:    0x%x\n", ((fdb->flmap1) & 0xff) << 4);
+	printf("  ISL:     0x%02x\n", desc.num_pch_straps);
+	printf("  FPSBA:   0x%x\n", desc.fpsba_offset);
+	printf("  NM:      %d\n", desc.num_masters);
+	printf("  FMBA:    0x%x\n", desc.fmba_offset);
 
 	printf("FLMAP2:    0x%08x\n", fdb->flmap2);
-	printf("  PSL:     0x%04x\n", (fdb->flmap2 >> 8) & 0xffff);
-	printf("  FMSBA:   0x%x\n", ((fdb->flmap2) & 0xff) << 4);
+	printf("  PSL:     0x%04x\n", desc.num_cpu_straps);
+	printf("  FMSBA:   0x%x\n", desc.fmsba_offset);
 
 	printf("FLUMAP1:   0x%08x\n", fdb->flumap1);
 	printf("  Intel ME VSCC Table Length (VTL):        %d\n",
diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h
index 8b13283..8a222e5 100644
--- a/util/ifdtool/ifdtool.h
+++ b/util/ifdtool/ifdtool.h
@@ -134,3 +134,25 @@ struct region_name {
 	char *pretty;
 	char *terse;
 };
+
+struct flash_descriptor
+{
+	/* FLMAP0 */
+	uint8_t num_regions;
+	uint16_t frba_offset;
+	uint8_t num_components;
+	uint16_t fcba_offset;
+
+	/* FLMAP1 */
+	uint8_t num_pch_straps;
+	uint16_t fpsba_offset;
+	uint8_t num_masters;
+	uint16_t fmba_offset;
+
+	/* FLMAP2 */
+	uint16_t iccriba_offset;
+	uint8_t num_cpu_straps;
+	uint16_t fmsba_offset;
+};
+
+void read_flash_descriptor(struct flash_descriptor *desc, const void *fud);



More information about the coreboot-gerrit mailing list