Naman Govil (namangov@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6507
-gerrit
commit 0184f54cd44ca542f49adc661a2eed7032298746 Author: Naman Govil namangov@gmail.com Date: Wed Aug 6 11:46:17 2014 +0530
Remove inessential mappings in cbfs_media
Reducing sram usage while booting by removing unwanted map()s by creating a structure to replace it with appropriate read()s
Change-Id: I6e49543f5bb30936162ebea11a3ca8cee8213dc2 Signed-off-by: Naman Govil namangov@gmail.com --- src/arch/x86/boot/smbios.c | 3 +-- src/include/cbfs_core.h | 10 +++++----- src/lib/cbfs.c | 21 +++++++++++---------- src/lib/cbfs_core.c | 20 ++++++-------------- src/lib/loaders/cbfs_payload_loader.c | 6 ++---- 5 files changed, 25 insertions(+), 35 deletions(-)
diff --git a/src/arch/x86/boot/smbios.c b/src/arch/x86/boot/smbios.c index ec3e5e8..37c4b80 100644 --- a/src/arch/x86/boot/smbios.c +++ b/src/arch/x86/boot/smbios.c @@ -153,9 +153,8 @@ static int smbios_write_type0(unsigned long *current, int handle) { struct cbfs_header header; u32 romsize = CONFIG_ROM_SIZE; - if (!cbfs_get_header(CBFS_DEFAULT_MEDIA, &header)) { + if (!cbfs_get_header(CBFS_DEFAULT_MEDIA, &header)) romsize = header.romsize; - } t->bios_rom_size = (romsize / 65535) - 1; }
diff --git a/src/include/cbfs_core.h b/src/include/cbfs_core.h index 11de0ee..ecfee36 100644 --- a/src/include/cbfs_core.h +++ b/src/include/cbfs_core.h @@ -232,18 +232,18 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name); int cbfs_decompress(int algo, void *src, void *dst, int len);
/* finds the CBFS master header and fills it in a cbfs_header structure, - return 0 on success and <0 if header not found */ + * return 0 on success and <0 if header not found */ int cbfs_get_header(struct cbfs_media *media, struct cbfs_header *header);
/* Returns success (0) on finding the file requested by verifying name; - -1 if file not found - The absolute data_offset to the file is stored */ + * -1 if file not found + * The absolute data_offset to the file is stored */ int cbfs_find_file(struct cbfs_media *media, struct cbfs_file_handle *f, const char *name);
/* Returns success (0) on finding the file requested by verifying name and type; - -1 if file not found - The absolute data_offset to the file is stored */ + * -1 if file not found + * The absolute data_offset to the file is stored */ int cbfs_find_file_by_type(struct cbfs_media *media, struct cbfs_file_handle *f, const char *name, int type);
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 5442ddc..05c201b 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -126,29 +126,30 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) void * data; ssize_t v_read; struct cbfs_media default_media; + const void * errorptr = (void *)-1;
if (media == CBFS_DEFAULT_MEDIA) { media = &default_media; if (init_default_cbfs_media(media) != 0) { ERROR("Failed to initialize default media.\n"); - return (void *)-1; + return errorptr; } }
c = cbfs_find_file_by_type(media, &f, name, CBFS_TYPE_STAGE);
if (c < 0) { - ERROR("Stage not loaded\n"); - return (void *)-1; + ERROR("Stage not loaded.\n"); + return errorptr; }
value_read = media->read(media, &stage, f.data_offset, sizeof(stage)); /* this is a mess. There is no ntohll. */ /* for now, assume compatible byte order until we solve this. */ if (value_read != sizeof(stage)) - return (void *)-1; + return errorptr;
- uint32_t entry; + void * entry; uint32_t final_size;
DEBUG("Read Complete @offset = 0x%x and length = %d\n", @@ -166,7 +167,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) v_read = media->read(media, (void *) (uintptr_t) stage.load, f.data_offset + sizeof(stage), f.data_len); if (v_read != f.data_len) - return (void *)-1; + return errorptr;
final_size = f.data_len; } @@ -174,7 +175,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) data = media->map(media, f.data_offset + sizeof(stage), f.data_len); if (data == CBFS_MEDIA_INVALID_MAP_ADDRESS) { ERROR("Map not successful"); - return (void *) -1; + return errorptr; }
DEBUG("Map Done\n"); @@ -183,7 +184,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) stage.len);
if (!final_size) - return (void *) -1; + return errorptr; }
/* Stages rely the below clearing so that the bss is initialized. */ @@ -191,8 +192,8 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) stage.memlen - final_size);
DEBUG("stage loaded.\n"); - entry = stage.entry; - return (void *) entry; + entry = (void *)(uintptr_t)stage.entry; + return entry; }
/* Simple buffer */ diff --git a/src/lib/cbfs_core.c b/src/lib/cbfs_core.c index 164473e..348ff77 100644 --- a/src/lib/cbfs_core.c +++ b/src/lib/cbfs_core.c @@ -191,15 +191,6 @@ int cbfs_find_file(struct cbfs_media *media, struct cbfs_file_handle *f, int cbfs_find_file_by_type(struct cbfs_media *media, struct cbfs_file_handle *f, const char *name, int type) { - struct cbfs_media default_media; - - if (media == CBFS_DEFAULT_MEDIA) { - media = &default_media; - if (init_default_cbfs_media(media) != 0) { - ERROR("Failed to initialize default media/\n"); - return -1; - } - }
if (cbfs_find_file(media, f, name) < 0) { ERROR("Failed to find file\n"); @@ -211,10 +202,7 @@ int cbfs_find_file_by_type(struct cbfs_media *media, struct cbfs_file_handle *f, return 0; } else - { - ERROR("File of matching type not found\n"); return -1; - } }
@@ -277,8 +265,12 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name) return NULL; }
- fileptr = media->map(media, f.data_offset, f.data_len); - return fileptr; + fileptr = media->map(media, f.data_offset - f.file.offset, f.data_len + f.file.offset); + + if (fileptr == CBFS_MEDIA_INVALID_MAP_ADDRESS) + return NULL; + else + return fileptr; }
int cbfs_decompress(int algo, void *src, void *dst, int len) diff --git a/src/lib/loaders/cbfs_payload_loader.c b/src/lib/loaders/cbfs_payload_loader.c index d1ebd84..2fa42c4 100644 --- a/src/lib/loaders/cbfs_payload_loader.c +++ b/src/lib/loaders/cbfs_payload_loader.c @@ -25,11 +25,9 @@ static int cbfs_locate_payload(struct payload *payload) { const int type = CBFS_TYPE_PAYLOAD; - struct cbfs_media default_media, *m; + struct cbfs_media *m;
- m = &default_media; - if (init_default_cbfs_media(m) != 0) - return -1; + m = CBFS_DEFAULT_MEDIA;
if (cbfs_find_file_by_type(m, &payload->f, payload->name, type) < 0) return -1;