[coreboot-gerrit] Patch set updated for coreboot: change memory mapping and region device memcpy
George Trudeau (george.trudeau@usherbrooke.ca)
gerrit at coreboot.org
Mon Apr 11 06:25:13 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/14295
-gerrit
commit 5f7723ece5c76d6db0a0daa9d644ecf84afaf3bc
Author: George Trudeau <george.trudeau at usherbrooke.ca>
Date: Mon Apr 4 00:57:31 2016 -0400
change memory mapping and region device memcpy
Use the xdr interface and remove byte ordering functions.
selfboot.c memory mapping of segments is deserialized into
a local segment.
cbfs.c was using rdev_readat(), which memcpy from
the memory device. Replaced by redev_deserialize() that
takes a mapping function from the xdr_map and apply it
after normalizing region device.
Change-Id: I85c0491a235c726b6ea1935453dd360931ac4758
Signed-off-by: George Trudeau <george.trudeau at usherbrooke.ca>
---
src/lib/cbfs.c | 14 +++++------
src/lib/selfboot.c | 70 +++++++++++++++++++++++++++++++++---------------------
2 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index e1626d7..b99b725 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -20,7 +20,7 @@
#include <boot_device.h>
#include <cbfs.h>
#include <commonlib/compression.h>
-#include <endian.h>
+#include <commonlib/xdr.h>
#include <lib.h>
#include <symbols.h>
#include <timestamp.h>
@@ -230,16 +230,16 @@ static int cbfs_master_header_props(struct cbfs_props *props)
/* Find location of header using signed 32-bit offset from
* end of CBFS region. */
offset = CONFIG_CBFS_SIZE - sizeof(int32_t);
- if (rdev_readat(bdev, &rel_offset, offset, sizeof(int32_t)) < 0)
+
+ if (rdev_deserialize(&rel_offset, xdr_map.int32, bdev, offset,
+ sizeof(int32_t)) < 0)
return -1;
offset = CONFIG_CBFS_SIZE + rel_offset;
- if (rdev_readat(bdev, &header, offset, sizeof(header)) < 0)
- return -1;
- header.magic = ntohl(header.magic);
- header.romsize = ntohl(header.romsize);
- header.offset = ntohl(header.offset);
+ if (rdev_deserialize(&header, xdr_map.cbfs_header, bdev, offset,
+ sizeof(header)) < 0)
+ return -1;
if (header.magic != CBFS_HEADER_MAGIC)
return -1;
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 23eda14..876a5be 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -15,6 +15,7 @@
*/
#include <commonlib/compression.h>
+#include <commonlib/xdr.h>
#include <console/console.h>
#include <cpu/cpu.h>
#include <endian.h>
@@ -209,42 +210,55 @@ static int relocate_segment(unsigned long buffer, struct segment *seg)
return ret;
}
+static inline void load_segment(
+ struct cbfs_payload_segment *local,
+ struct cbfs_payload_segment *memory)
+{
+ xdr_map.cbfs_payload_segment(local, memory);
+}
static int build_self_segment_list(
struct segment *head,
struct cbfs_payload *cbfs_payload, uintptr_t *entry)
{
- struct segment *new;
- struct segment *ptr;
- struct cbfs_payload_segment *segment, *first_segment;
+ struct segment *new, *ptr;
+ struct cbfs_payload_segment *current_segment, *first_segment, segment;
+
memset(head, 0, sizeof(*head));
head->next = head->prev = head;
- first_segment = segment = &cbfs_payload->segments;
+
+ first_segment = current_segment = &cbfs_payload->segments;
+ load_segment(&segment, current_segment);
while(1) {
- printk(BIOS_DEBUG, "Loading segment from rom address 0x%p\n", segment);
- switch(segment->type) {
+ printk(BIOS_DEBUG,
+ "Loading segment from rom address 0x%p\n",
+ current_segment);
+
+ switch (segment.type) {
case PAYLOAD_SEGMENT_PARAMS:
printk(BIOS_DEBUG, " parameter section (skipped)\n");
- segment++;
+ load_segment(&segment, ++current_segment);
continue;
case PAYLOAD_SEGMENT_CODE:
case PAYLOAD_SEGMENT_DATA:
printk(BIOS_DEBUG, " %s (compression=%x)\n",
- segment->type == PAYLOAD_SEGMENT_CODE ? "code" : "data",
- ntohl(segment->compression));
- new = malloc(sizeof(*new));
- new->s_dstaddr = ntohll(segment->load_addr);
- new->s_memsz = ntohl(segment->mem_len);
- new->compression = ntohl(segment->compression);
+ segment.type == PAYLOAD_SEGMENT_CODE
+ ? "code" : "data", segment.compression);
+ new = malloc(sizeof(*new));
+ new->s_dstaddr = segment.load_addr;
+ new->s_memsz = segment.mem_len;
+ new->compression = segment.compression;
new->s_srcaddr = (uintptr_t)
- ((unsigned char *)first_segment)
- + ntohl(segment->offset);
- new->s_filesz = ntohl(segment->len);
+ ((unsigned char *)first_segment)
+ + segment.offset;
+ new->s_filesz = segment.len;
+
printk(BIOS_DEBUG, " New segment dstaddr 0x%lx memsize 0x%lx srcaddr 0x%lx filesize 0x%lx\n",
new->s_dstaddr, new->s_memsz, new->s_srcaddr, new->s_filesz);
+
/* Clean up the values */
if (new->s_filesz > new->s_memsz) {
new->s_filesz = new->s_memsz;
@@ -256,21 +270,22 @@ static int build_self_segment_list(
case PAYLOAD_SEGMENT_BSS:
printk(BIOS_DEBUG, " BSS 0x%p (%d byte)\n", (void *)
- (intptr_t)ntohll(segment->load_addr),
- ntohl(segment->mem_len));
+ (intptr_t)segment.load_addr, segment.mem_len);
+
new = malloc(sizeof(*new));
new->s_filesz = 0;
new->s_srcaddr = (uintptr_t)
((unsigned char *)first_segment)
- + ntohl(segment->offset);
- new->s_dstaddr = ntohll(segment->load_addr);
- new->s_memsz = ntohl(segment->mem_len);
+ + segment.offset;
+ new->s_dstaddr = segment.load_addr;
+ new->s_memsz = segment.mem_len;
break;
case PAYLOAD_SEGMENT_ENTRY:
- printk(BIOS_DEBUG, " Entry Point 0x%p\n",
- (void *)(intptr_t)ntohll(segment->load_addr));
- *entry = ntohll(segment->load_addr);
+ printk(BIOS_DEBUG, " Entry Point 0x%p\n", (void *)
+ (intptr_t)segment.load_addr);
+
+ *entry = segment.load_addr;
/* Per definition, a payload always has the entry point
* as last segment. Thus, we use the occurrence of the
* entry point as break condition for the loop.
@@ -282,16 +297,17 @@ static int build_self_segment_list(
/* We found something that we don't know about. Throw
* hands into the sky and run away!
*/
- printk(BIOS_EMERG, "Bad segment type %x\n", segment->type);
+ printk(BIOS_EMERG, "Bad segment type %x\n",
+ segment.type);
return -1;
}
/* We have found another CODE, DATA or BSS segment */
- segment++;
+ load_segment(&segment, ++current_segment);
/* Find place where to insert our segment */
for(ptr = head->next; ptr != head; ptr = ptr->next) {
- if (new->s_srcaddr < ntohll(segment->load_addr))
+ if (new->s_srcaddr < segment.load_addr)
break;
}
More information about the coreboot-gerrit
mailing list