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@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4692 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
@@ -80,7 +80,8 @@ static int cbfs_add(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
cbfsfile =
|
cbfsfile =
|
||||||
create_cbfs_file(cbfsname, filedata, &filesize, type, &base);
|
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);
|
writerom(romname, rom, romsize);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,8 @@ static int cbfs_add_payload(int argc, char **argv)
|
|||||||
cbfsfile =
|
cbfsfile =
|
||||||
create_cbfs_file(cbfsname, payload, &filesize,
|
create_cbfs_file(cbfsname, payload, &filesize,
|
||||||
CBFS_COMPONENT_PAYLOAD, &base);
|
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);
|
writerom(romname, rom, romsize);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -175,7 +177,8 @@ static int cbfs_add_stage(int argc, char **argv)
|
|||||||
create_cbfs_file(cbfsname, stage, &filesize,
|
create_cbfs_file(cbfsname, stage, &filesize,
|
||||||
CBFS_COMPONENT_STAGE, &base);
|
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);
|
writerom(romname, rom, romsize);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -205,11 +205,9 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
|
|||||||
dprintf("copying data\n");
|
dprintf("copying data\n");
|
||||||
memcpy(phys_to_virt(current), content,
|
memcpy(phys_to_virt(current), content,
|
||||||
contentsize);
|
contentsize);
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
if (location == 0)
|
if (location != 0) {
|
||||||
continue;
|
|
||||||
|
|
||||||
/* CBFS has the constraint that the chain always moves up in memory. so once
|
/* 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 */
|
we're past the place we seek, we don't need to look any further */
|
||||||
if (current > location) {
|
if (current > location) {
|
||||||
@@ -220,7 +218,8 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
|
|||||||
|
|
||||||
/* Is the requested location inside the current chunk? */
|
/* Is the requested location inside the current chunk? */
|
||||||
if ((current < location)
|
if ((current < location)
|
||||||
&& ((location + contentsize) <= (current + length))) {
|
&& ((location + contentsize) <=
|
||||||
|
(current + length))) {
|
||||||
/* Split it up. In the next iteration the code will be at the right place. */
|
/* Split it up. In the next iteration the code will be at the right place. */
|
||||||
dprintf("split up. new length: %x\n",
|
dprintf("split up. new length: %x\n",
|
||||||
location - current -
|
location - current -
|
||||||
@@ -230,15 +229,18 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
|
|||||||
ntohl(thisfile->offset));
|
ntohl(thisfile->offset));
|
||||||
struct cbfs_file *nextfile =
|
struct cbfs_file *nextfile =
|
||||||
cbfs_create_empty_file(location,
|
cbfs_create_empty_file(location,
|
||||||
length - (location -
|
length -
|
||||||
|
(location -
|
||||||
current));
|
current));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
current =
|
current =
|
||||||
ALIGN(current + ntohl(thisfile->len) +
|
ALIGN(current + ntohl(thisfile->len) +
|
||||||
ntohl(thisfile->offset), align);
|
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
|
/* returns new data block with cbfs_file header, suitable to dump into the ROM. location returns
|
||||||
|
Reference in New Issue
Block a user