[coreboot-gerrit] Patch set updated for coreboot: lib/selfboot: clear BSS segments

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Mon Jul 11 22:55:48 CEST 2016


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15603

-gerrit

commit ccfeaf6177d9f1acb158ed7c5c541d465f359ca4
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Mon Jul 11 15:36:50 2016 -0500

    lib/selfboot: clear BSS segments
    
    For some reason the self loader wasn't clearing segments
    marked as BSS type. Other segments which weren't fully
    written by the file-backed content were being cleared up
    to the indicated memsize. Treat segments marked BSS
    similarly by clearing their content.
    
    Change-Id: I9296c11a89455a02e5dd18bba13d4911517c04f6
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/lib/selfboot.c | 69 +++++++++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 832dad5..0b1cd86 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -296,6 +296,7 @@ static int build_self_segment_list(
 				+ segment.offset;
 			new->s_dstaddr = segment.load_addr;
 			new->s_memsz = segment.mem_len;
+			new->compression = CBFS_COMPRESS_NONE;
 			break;
 
 		case PAYLOAD_SEGMENT_ENTRY:
@@ -332,16 +333,9 @@ static int load_self_segments(
 	struct prog *payload)
 {
 	struct segment *ptr;
-	struct segment *last_non_empty;
 	const unsigned long one_meg = (1UL << 20);
 	unsigned long bounce_high = lb_end;
 
-	/* Determine last non-empty loaded segment. */
-	last_non_empty = NULL;
-	for(ptr = head->next; ptr != head; ptr = ptr->next)
-		if (ptr->s_filesz != 0)
-			last_non_empty = ptr;
-
 	for(ptr = head->next; ptr != head; ptr = ptr->next) {
 		if (bootmem_region_targets_usable_ram(ptr->s_dstaddr,
 							ptr->s_memsz))
@@ -384,7 +378,7 @@ static int load_self_segments(
 	}
 
 	for(ptr = head->next; ptr != head; ptr = ptr->next) {
-		unsigned char *dest, *src;
+		unsigned char *dest, *src, *end;
 		printk(BIOS_DEBUG, "Loading Segment: addr: 0x%016lx memsz: 0x%016lx filesz: 0x%016lx\n",
 			ptr->s_dstaddr, ptr->s_memsz, ptr->s_filesz);
 
@@ -401,10 +395,11 @@ static int load_self_segments(
 		/* Compute the boundaries of the segment */
 		dest = (unsigned char *)(ptr->s_dstaddr);
 		src = (unsigned char *)(ptr->s_srcaddr);
+		end = (unsigned char *)(ptr->s_dstaddr + ptr->s_memsz);
 
 		/* Copy data from the initial buffer */
 		if (ptr->s_filesz) {
-			unsigned char *middle, *end;
+			unsigned char *middle;
 			size_t len = ptr->s_filesz;
 			size_t memsz = ptr->s_memsz;
 			switch(ptr->compression) {
@@ -435,7 +430,6 @@ static int load_self_segments(
 					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,
@@ -451,32 +445,39 @@ static int load_self_segments(
 				/* 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);
-				}
-			}
+		} else  {
+			printk(BIOS_SPEW, "[ 0x%08lx, 0x%08lx) <- BSS\n",
+				(unsigned long)dest,
+				(unsigned long)end);
+			/* BSS segment */
+			memset(dest, 0, ptr->s_memsz);
+		}
 
-			/*
-			 * 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);
+		/* 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,
+				ptr->next == head ? SEG_FINAL : 0);
 	}
 
 	return 1;



More information about the coreboot-gerrit mailing list