[coreboot-gerrit] Patch set updated for coreboot: create xdr map to deserialize cbfs

George Trudeau (george.trudeau@usherbrooke.ca) gerrit at coreboot.org
Mon Apr 11 04:58:01 CEST 2016


George Trudeau (george.trudeau at usherbrooke.ca) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14294

-gerrit

commit a840bda9c20ac94cd1c78f61ad35822c83e20f29
Author: George Trudeau <george.trudeau at usherbrooke.ca>
Date:   Mon Apr 4 00:19:02 2016 -0400

    create xdr map to deserialize cbfs
    
    Creation of the xdr_map structure.
    The xdr interface provides functions to deserialize cbfs.
    The goal is to remove [nh]to[hn][sll] functions, and instead
    deserialize into native byte order using commonlib/endian.h.
    
    Change-Id: Icb3c6a7da2d253685a3bc157bc7f5a51183c9652
    Signed-off-by: George Trudeau <george.trudeau at usherbrooke.ca>
---
 src/commonlib/Makefile.inc               |  4 +++
 src/commonlib/include/commonlib/region.h |  4 +++
 src/commonlib/include/commonlib/xdr.h    | 25 +++++++++++++
 src/commonlib/region.c                   | 16 +++++++++
 src/commonlib/xdr.c                      | 61 ++++++++++++++++++++++++++++++++
 5 files changed, 110 insertions(+)

diff --git a/src/commonlib/Makefile.inc b/src/commonlib/Makefile.inc
index 7c14f7c..7e0be9f 100644
--- a/src/commonlib/Makefile.inc
+++ b/src/commonlib/Makefile.inc
@@ -25,3 +25,7 @@ verstage-y += lz4_wrapper.c
 romstage-y += lz4_wrapper.c
 ramstage-y += lz4_wrapper.c
 postcar-y += lz4_wrapper.c
+
+bootblock-y += xdr.c
+romstage-y += xdr.c
+ramstage-y += xdr.c
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index a13c66c..a1678a1 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -49,6 +49,10 @@ ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
 			size_t size);
 
 
+ssize_t rdev_deserialize(void *dest, void (*deserialize)(void *, const void *),
+		const struct region_device *rd, size_t offset, size_t size);
+
+
 /****************************************
  *  Implementation of a region device   *
  ****************************************/
diff --git a/src/commonlib/include/commonlib/xdr.h b/src/commonlib/include/commonlib/xdr.h
new file mode 100644
index 0000000..2681ade
--- /dev/null
+++ b/src/commonlib/include/commonlib/xdr.h
@@ -0,0 +1,25 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 George Trudeau
+ *
+ * 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.
+ */
+
+#ifndef _COMMONLIB_XDR_H_
+#define _COMMONLIB_XDR_H_
+
+extern struct xdr {
+	void (*cbfs_header)(void *, const void *);
+	void (*cbfs_payload_segment)(void *, const void *);
+	void (*int32)(void *, const void *);
+} xdr_map;
+
+#endif
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index bfc5fc8..3eeeee8 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -103,6 +103,22 @@ ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
 	return rdev->ops->readat(rdev, b, req.offset, req.size);
 }
 
+ssize_t rdev_deserialize(void *dest, void (*deserialize)(void *, const void *),
+		const struct region_device *rd, size_t offset, size_t size)
+{
+	const struct mem_region_device *mdev;
+	struct region req = { .offset = offset, .size = size };
+
+	if (!normalize_and_ok(&rd->region, &req))
+		return -1;
+
+	mdev = container_of(rdev_root(rd), __typeof__(*mdev), rdev);
+
+	deserialize(dest, &mdev->base[req.offset]);
+
+	return 0;
+}
+
 int rdev_chain(struct region_device *child, const struct region_device *parent,
 		size_t offset, size_t size)
 {
diff --git a/src/commonlib/xdr.c b/src/commonlib/xdr.c
new file mode 100644
index 0000000..2c95c84
--- /dev/null
+++ b/src/commonlib/xdr.c
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 George Trudeau
+ *
+ * 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 <commonlib/xdr.h>
+#include <commonlib/endian.h>
+
+#include <commonlib/cbfs_serialized.h>
+
+static void xdr_cbfs_header(void *dest, const void *data)
+{
+	struct cbfs_header *header = (struct cbfs_header *)dest;
+	const uint32_t *src = (uint32_t *)data;
+
+	header->magic         = read_be32(src++);
+	header->version       = read_be32(src++);
+	header->romsize       = read_be32(src++);
+	header->bootblocksize = read_be32(src++);
+	header->align         = read_be32(src++);
+	header->offset        = read_be32(src++);
+	header->architecture  = read_be32(src++);
+	header->pad[0]        = read_be32(src++);
+}
+
+static void xdr_cbfs_payload_segment(void *dest, const void *data)
+{
+	struct cbfs_payload_segment *segment =
+			(struct cbfs_payload_segment *)dest;
+	const uint32_t *src = (uint32_t *)data;
+
+	segment->type        = read_be32(src++);
+	segment->compression = read_be32(src++);
+	segment->offset      = read_be32(src++);
+	segment->load_addr   = read_be64(src++);
+	src++;
+	segment->len         = read_be32(src++);
+	segment->mem_len     = read_be32(src++);
+}
+
+static void xdr_int32(void *dest, const void *data)
+{
+	*(int32_t *)dest = read_be32(data);
+}
+
+
+struct xdr xdr_map = {
+	.cbfs_header          = xdr_cbfs_header,
+	.cbfs_payload_segment = xdr_cbfs_payload_segment,
+	.int32                = xdr_int32
+};



More information about the coreboot-gerrit mailing list