[coreboot] [v2] r4692 - trunk/coreboot-v2/util/cbfstool

svn at coreboot.org svn at coreboot.org
Wed Sep 30 13:21:18 CEST 2009


Author: oxygene
Date: 2009-09-30 13:21:18 +0200 (Wed, 30 Sep 2009)
New Revision: 4692

Modified:
   trunk/coreboot-v2/util/cbfstool/cbfstool.c
   trunk/coreboot-v2/util/cbfstool/common.c
Log:
Fix endless loop when trying to add a too large file to CBFS,
and report the correct error code, and a hopefully helpful
error message.


Signed-off-by: Patrick Georgi <patrick.georgi at coresystems.de>
Acked-by: Stefan Reinauer <stepan at coresystems.de>


Modified: trunk/coreboot-v2/util/cbfstool/cbfstool.c
===================================================================
--- trunk/coreboot-v2/util/cbfstool/cbfstool.c	2009-09-29 21:35:48 UTC (rev 4691)
+++ trunk/coreboot-v2/util/cbfstool/cbfstool.c	2009-09-30 11:21:18 UTC (rev 4692)
@@ -80,7 +80,8 @@
 	}
 	cbfsfile =
 	    create_cbfs_file(cbfsname, filedata, &filesize, type, &base);
-	add_file_to_cbfs(cbfsfile, filesize, base);
+	if (add_file_to_cbfs(cbfsfile, filesize, base))
+		return 1;
 	writerom(romname, rom, romsize);
 	return 0;
 }
@@ -127,7 +128,8 @@
 	cbfsfile =
 	    create_cbfs_file(cbfsname, payload, &filesize,
 			     CBFS_COMPONENT_PAYLOAD, &base);
-	add_file_to_cbfs(cbfsfile, filesize, base);
+	if (add_file_to_cbfs(cbfsfile, filesize, base))
+		return 1;
 	writerom(romname, rom, romsize);
 	return 0;
 }
@@ -175,7 +177,8 @@
 	    create_cbfs_file(cbfsname, stage, &filesize,
 			     CBFS_COMPONENT_STAGE, &base);
 
-	add_file_to_cbfs(cbfsfile, filesize, base);
+	if (add_file_to_cbfs(cbfsfile, filesize, base))
+		return 1;
 	writerom(romname, rom, romsize);
 	return 0;
 }

Modified: trunk/coreboot-v2/util/cbfstool/common.c
===================================================================
--- trunk/coreboot-v2/util/cbfstool/common.c	2009-09-29 21:35:48 UTC (rev 4691)
+++ trunk/coreboot-v2/util/cbfstool/common.c	2009-09-30 11:21:18 UTC (rev 4692)
@@ -40,7 +40,7 @@
 		content = malloc(*romsize_p);
 		if (!content) {
 			printf("Could not get %d bytes for file %s\n",
-					*romsize_p, filename);
+			       *romsize_p, filename);
 			exit(1);
 		}
 	} else if (place == SEEK_END)
@@ -205,40 +205,42 @@
 				dprintf("copying data\n");
 				memcpy(phys_to_virt(current), content,
 				       contentsize);
-				break;
+				return 0;
 			}
-			if (location == 0)
-				continue;
+			if (location != 0) {
+				/* CBFS has the constraint that the chain always moves up in memory. so once
+				   we're past the place we seek, we don't need to look any further */
+				if (current > location) {
+					printf
+					    ("the requested space is not available\n");
+					return 1;
+				}
 
-			/* CBFS has the constraint that the chain always moves up in memory. so once
-			   we're past the place we seek, we don't need to look any further */
-			if (current > location) {
-				printf
-				    ("the requested space is not available\n");
-				return 1;
+				/* Is the requested location inside the current chunk? */
+				if ((current < location)
+				    && ((location + contentsize) <=
+					(current + length))) {
+					/* Split it up. In the next iteration the code will be at the right place. */
+					dprintf("split up. new length: %x\n",
+						location - current -
+						ntohl(thisfile->offset));
+					thisfile->len =
+					    htonl(location - current -
+						  ntohl(thisfile->offset));
+					struct cbfs_file *nextfile =
+					    cbfs_create_empty_file(location,
+								   length -
+								   (location -
+								    current));
+				}
 			}
-
-			/* Is the requested location inside the current chunk? */
-			if ((current < location)
-			    && ((location + contentsize) <= (current + length))) {
-				/* Split it up. In the next iteration the code will be at the right place. */
-				dprintf("split up. new length: %x\n",
-					location - current -
-					ntohl(thisfile->offset));
-				thisfile->len =
-				    htonl(location - current -
-					  ntohl(thisfile->offset));
-				struct cbfs_file *nextfile =
-				    cbfs_create_empty_file(location,
-							   length - (location -
-								     current));
-			}
 		}
 		current =
 		    ALIGN(current + ntohl(thisfile->len) +
 			  ntohl(thisfile->offset), align);
 	}
-	return 0;
+	printf("Could not add the file to CBFS, it's probably too big.\n");
+	return 1;
 }
 
 /* returns new data block with cbfs_file header, suitable to dump into the ROM. location returns
@@ -263,7 +265,7 @@
 	void *newdata = malloc(*datasize + headersize);
 	if (!newdata) {
 		printf("Could not get %d bytes for CBFS file.\n", *datasize +
-				headersize);
+		       headersize);
 		exit(1);
 	}
 	struct cbfs_file *nextfile = (struct cbfs_file *)newdata;
@@ -285,7 +287,7 @@
 	unsigned char *romarea = malloc(romsize);
 	if (!romarea) {
 		printf("Could not get %d bytes of memory for CBFS image.\n",
-				romsize);
+		       romsize);
 		exit(1);
 	}
 	memset(romarea, 0xff, romsize);





More information about the coreboot mailing list