CBFS: Change how the bss is zeroed when loading a stage.
For reasons explained in a previous CL, it might be necessary to "load" a file from CBFS in place. The loading code in CBFS was, however, zeroing the area of memory the stage was about to be loaded into. When the CBFS data is located elsewhere this works fine, but when it isn't you end up clobbering the data you're trying to load. Also, there's no reason to zero memory we're about to load something into or have just loaded something into. This change makes it so that we only zero out the portion of the memory between what was loaded/decompressed and the final size of the stage in memory. Change-Id: If34df16bd74b2969583e11ef6a26eb4065842f57 Signed-off-by: Gabe Black <gabeblack@chromium.org> Reviewed-on: http://review.coreboot.org/3579 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
parent
0c605a5a6c
commit
ec3a462d03
|
@ -136,6 +136,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
/* this is a mess. There is no ntohll. */
|
/* this is a mess. There is no ntohll. */
|
||||||
/* for now, assume compatible byte order until we solve this. */
|
/* for now, assume compatible byte order until we solve this. */
|
||||||
uint32_t entry;
|
uint32_t entry;
|
||||||
|
uint32_t final_size;
|
||||||
|
|
||||||
if (stage == NULL)
|
if (stage == NULL)
|
||||||
return (void *) -1;
|
return (void *) -1;
|
||||||
|
@ -144,15 +145,18 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
name,
|
name,
|
||||||
(uint32_t) stage->load, stage->memlen,
|
(uint32_t) stage->load, stage->memlen,
|
||||||
stage->entry);
|
stage->entry);
|
||||||
memset((void *) (uint32_t) stage->load, 0, stage->memlen);
|
|
||||||
|
|
||||||
if (!cbfs_decompress(stage->compression,
|
final_size = cbfs_decompress(stage->compression,
|
||||||
((unsigned char *) stage) +
|
((unsigned char *) stage) +
|
||||||
sizeof(struct cbfs_stage),
|
sizeof(struct cbfs_stage),
|
||||||
(void *) (uint32_t) stage->load,
|
(void *) (uint32_t) stage->load,
|
||||||
stage->len))
|
stage->len);
|
||||||
|
if (!final_size)
|
||||||
return (void *) -1;
|
return (void *) -1;
|
||||||
|
|
||||||
|
memset((void *)((uintptr_t)stage->load + final_size), 0,
|
||||||
|
stage->memlen - final_size);
|
||||||
|
|
||||||
DEBUG("stage loaded.\n");
|
DEBUG("stage loaded.\n");
|
||||||
|
|
||||||
entry = stage->entry;
|
entry = stage->entry;
|
||||||
|
|
|
@ -268,8 +268,6 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
name,
|
name,
|
||||||
(uint32_t) stage->load, stage->memlen,
|
(uint32_t) stage->load, stage->memlen,
|
||||||
stage->entry);
|
stage->entry);
|
||||||
/* Stages rely the below clearing so that the bss is initialized. */
|
|
||||||
memset((void *) (uint32_t) stage->load, 0, stage->memlen);
|
|
||||||
|
|
||||||
final_size = cbfs_decompress(stage->compression,
|
final_size = cbfs_decompress(stage->compression,
|
||||||
((unsigned char *) stage) +
|
((unsigned char *) stage) +
|
||||||
|
@ -279,6 +277,10 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
if (!final_size)
|
if (!final_size)
|
||||||
return (void *) -1;
|
return (void *) -1;
|
||||||
|
|
||||||
|
/* Stages rely the below clearing so that the bss is initialized. */
|
||||||
|
memset((void *)((uintptr_t)stage->load + final_size), 0,
|
||||||
|
stage->memlen - final_size);
|
||||||
|
|
||||||
DEBUG("stage loaded.\n");
|
DEBUG("stage loaded.\n");
|
||||||
|
|
||||||
entry = stage->entry;
|
entry = stage->entry;
|
||||||
|
|
Loading…
Reference in New Issue