[coreboot-gerrit] New patch to review for coreboot: selfboot: define load_self_segment()

Antonello Dettori (dev@dettori.io) gerrit at coreboot.org
Thu Jul 14 15:57:12 CEST 2016


Antonello Dettori (dev at dettori.io) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15692

-gerrit

commit 2bbdf68633386941e2bba78b9fec481de628b50e
Author: Antonello Dettori <dev at dettori.io>
Date:   Thu Jul 14 15:54:04 2016 +0200

    selfboot: define load_self_segment()
    
    Introduce the function load_self_segment() in order to simplify the
    structure of the complementary load_self_segments().
    
    Change-Id: I6a7ceccf9ae6a57fa2d68fde92bd20ab9f08f5c9
    Signed-off-by: Antonello Dettori <dev at dettori.io>
---
 src/lib/selfboot.c | 189 +++++++++++++++++++++++++++++------------------------
 1 file changed, 102 insertions(+), 87 deletions(-)

diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 6e890c4..a97d8da 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -344,6 +344,107 @@ static int build_self_segment_list(struct segment *head,
 	return 1;
 }
 
+static int load_self_segment(struct segment *current, struct segment *previous,
+		struct region_device *payload)
+{
+	unsigned char *dest, *src;
+
+	/* Compute the boundaries of the segment */
+	dest = (unsigned char *)(current->s_dstaddr);
+	src = NULL;
+
+	/* Copy data from the initial buffer */
+	if (segment_file_sz(current)) {
+		unsigned char *middle, *end;
+		size_t len = segment_file_sz(current);
+		size_t memsz = current->s_memsz;
+		size_t offset = segment_file_offset(current);
+
+		switch (current->compression) {
+
+		case CBFS_COMPRESS_LZMA: {
+			printk(BIOS_DEBUG, "using LZMA\n");
+			timestamp_add_now(TS_START_ULZMA);
+			src = rdev_mmap_full(&current->src);
+			len = ulzman(src, len, dest, memsz);
+			timestamp_add_now(TS_END_ULZMA);
+			if (!len) /* Decompression Error. */
+				return 0;
+			break;
+		}
+		case CBFS_COMPRESS_LZ4: {
+			printk(BIOS_DEBUG, "using LZ4\n");
+			timestamp_add_now(TS_START_ULZ4F);
+			src = rdev_mmap(payload, offset, len);
+			len = ulz4fn(src, len, dest, memsz);
+			timestamp_add_now(TS_END_ULZ4F);
+			if (!len) /* Decompression Error. */
+				return 0;
+			break;
+		}
+		case CBFS_COMPRESS_NONE: {
+			printk(BIOS_DEBUG, "it's not compressed!\n");
+			rdev_readat(payload, dest, offset, len);
+			break;
+		}
+		default:
+			printk(BIOS_INFO, "CBFS:  Unknown compression type %d\n",
+					current->compression);
+			return -1;
+	}
+		end = dest + memsz;
+		middle = dest + len;
+		printk(BIOS_SPEW, "[ 0x%08lx, %08lx, 0x%08lx) <- %08lx\n",
+			(unsigned long)dest,
+			(unsigned long)middle,
+			(unsigned long)end,
+			(unsigned long)src);
+
+		/* Zero the extra bytes between middle & end */
+		if (middle < end) {
+			printk(BIOS_DEBUG, "Clearing Segment: addr: 0x%016lx memsz: 0x%016lx\n",
+				(unsigned long)middle, (unsigned long)(end - middle));
+
+			/* Zero the extra bytes */
+			memset(middle, 0, end - middle);
+		}
+		/* Copy the data that's outside the area that shadows ramstage */
+		printk(BIOS_DEBUG, "dest %p, end %p, bouncebuffer %lx\n", dest, end, bounce_buffer);
+		if ((unsigned long)end > bounce_buffer) {
+			if ((unsigned long)dest < bounce_buffer) {
+				unsigned char *from = dest;
+				unsigned char *to = (unsigned char *)
+					(lb_start-(bounce_buffer-(unsigned long)dest));
+				unsigned long amount = bounce_buffer-(unsigned long)dest;
+
+				printk(BIOS_DEBUG, "move prefix around: from %p, to %p, amount: %lx\n", from, to, amount);
+				memcpy(to, from, amount);
+			}
+			if ((unsigned long)end > bounce_buffer + (lb_end - lb_start)) {
+				unsigned long from = bounce_buffer + (lb_end - lb_start);
+				unsigned long to = lb_end;
+				unsigned long amount = (unsigned long)end - from;
+
+				printk(BIOS_DEBUG, "move suffix around: from %lx, to %lx, amount: %lx\n", from, to, amount);
+				memcpy((char *)to, (char *)from, amount);
+			}
+		}
+
+		/*
+		 * Each architecture can perform additonal operations
+		 * on the loaded segment
+		 */
+		prog_segment_loaded((uintptr_t)dest, current->s_memsz,
+				previous == current ? SEG_FINAL : 0);
+	}
+
+	/* munmap the segment that was compressed */
+	if (current->compression != CBFS_COMPRESS_NONE)
+		rdev_munmap(payload, src);
+
+	return 0;
+}
+
 static int load_self_segments(struct segment *head,
 		struct region_device *payload)
 {
@@ -400,7 +501,6 @@ static int load_self_segments(struct segment *head,
 	}
 
 	for(ptr = head->next; ptr != head; ptr = ptr->next) {
-		unsigned char *dest, *src;
 		printk(BIOS_DEBUG, "Loading Segment: addr: 0x%016lx memsz: 0x%016lx filesz: 0x%016zx\n",
 			ptr->s_dstaddr, ptr->s_memsz, segment_file_sz(ptr));
 
@@ -414,92 +514,7 @@ static int load_self_segments(struct segment *head,
 		printk(BIOS_DEBUG, "Post relocation: addr: 0x%016lx memsz: 0x%016lx filesz: 0x%016zx\n",
 			ptr->s_dstaddr, ptr->s_memsz, segment_file_sz(ptr));
 
-		/* Compute the boundaries of the segment */
-		dest = (unsigned char *)(ptr->s_dstaddr);
-		src = NULL;
-
-		/* Copy data from the initial buffer */
-		if (segment_file_sz(ptr)) {
-			unsigned char *middle, *end;
-			size_t len = segment_file_sz(ptr);
-			size_t memsz = ptr->s_memsz;
-			size_t offset = segment_file_offset(ptr);
-			switch(ptr->compression) {
-				case CBFS_COMPRESS_LZMA: {
-					printk(BIOS_DEBUG, "using LZMA\n");
-					timestamp_add_now(TS_START_ULZMA);
-					src = rdev_mmap_full(&ptr->src);
-					len = ulzman(src, len, dest, memsz);
-					timestamp_add_now(TS_END_ULZMA);
-					if (!len) /* Decompression Error. */
-						return 0;
-					break;
-				}
-				case CBFS_COMPRESS_LZ4: {
-					printk(BIOS_DEBUG, "using LZ4\n");
-					timestamp_add_now(TS_START_ULZ4F);
-					src = rdev_mmap(payload, offset, len);
-					len = ulz4fn(src, len, dest, memsz);
-					timestamp_add_now(TS_END_ULZ4F);
-					if (!len) /* Decompression Error. */
-						return 0;
-					break;
-				}
-				case CBFS_COMPRESS_NONE: {
-					printk(BIOS_DEBUG, "it's not compressed!\n");
-					rdev_readat(payload, dest, offset, len);
-					break;
-				}
-				default:
-					printk(BIOS_INFO,  "CBFS:  Unknown compression type %d\n", ptr->compression);
-					return -1;
-			}
-			end = dest + memsz;
-			middle = dest + len;
-			printk(BIOS_SPEW, "[ 0x%08lx, %08lx, 0x%08lx) <- %08lx\n",
-				(unsigned long)dest,
-				(unsigned long)middle,
-				(unsigned long)end,
-				(unsigned long)src);
-
-			/* Zero the extra bytes between middle & end */
-			if (middle < end) {
-				printk(BIOS_DEBUG, "Clearing Segment: addr: 0x%016lx memsz: 0x%016lx\n",
-					(unsigned long)middle, (unsigned long)(end - middle));
-
-				/* Zero the extra bytes */
-				memset(middle, 0, end - middle);
-			}
-			/* Copy the data that's outside the area that shadows ramstage */
-			printk(BIOS_DEBUG, "dest %p, end %p, bouncebuffer %lx\n", dest, end, bounce_buffer);
-			if ((unsigned long)end > bounce_buffer) {
-				if ((unsigned long)dest < bounce_buffer) {
-					unsigned char *from = dest;
-					unsigned char *to = (unsigned char*)(lb_start-(bounce_buffer-(unsigned long)dest));
-					unsigned long amount = bounce_buffer-(unsigned long)dest;
-					printk(BIOS_DEBUG, "move prefix around: from %p, to %p, amount: %lx\n", from, to, amount);
-					memcpy(to, from, amount);
-				}
-				if ((unsigned long)end > bounce_buffer + (lb_end - lb_start)) {
-					unsigned long from = bounce_buffer + (lb_end - lb_start);
-					unsigned long to = lb_end;
-					unsigned long amount = (unsigned long)end - from;
-					printk(BIOS_DEBUG, "move suffix around: from %lx, to %lx, amount: %lx\n", from, to, amount);
-					memcpy((char*)to, (char*)from, amount);
-				}
-			}
-
-			/*
-			 * Each architecture can perform additonal operations
-			 * on the loaded segment
-			 */
-			prog_segment_loaded((uintptr_t)dest, ptr->s_memsz,
-					last_non_empty == ptr ? SEG_FINAL : 0);
-		}
-
-		/* munmap the segment that was compressed */
-		if (ptr->compression != CBFS_COMPRESS_NONE)
-			rdev_munmap(payload, src);
+		load_self_segment(ptr, last_non_empty, payload);
 	}
 
 	return 1;



More information about the coreboot-gerrit mailing list