lib/cbfs_core.c: Supply size of file as well in cbfs_get_file_content
Change-Id: I5b93e5321e470f19ad22ca2cfdb1ebf3b340b252 Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-on: http://review.coreboot.org/4659 Reviewed-by: Patrick Georgi <patrick@georgi-clan.de> Tested-by: build bot (Jenkins)
This commit is contained in:
parent
e4ac9c043a
commit
0af61b6c82
|
@ -215,7 +215,7 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name);
|
|||
|
||||
/* returns pointer to file content inside CBFS after if type is correct */
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||
int type);
|
||||
int type, size_t *sz);
|
||||
|
||||
/* returns decompressed size on success, 0 on failure */
|
||||
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
||||
|
|
|
@ -102,7 +102,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
|
|||
tohex16(device, name+8);
|
||||
|
||||
orom = (struct cbfs_optionrom *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_OPTIONROM);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_OPTIONROM, NULL);
|
||||
|
||||
if (orom == NULL)
|
||||
return NULL;
|
||||
|
@ -132,7 +132,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
|
|||
void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||
{
|
||||
struct cbfs_stage *stage = (struct cbfs_stage *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL);
|
||||
/* this is a mess. There is no ntohll. */
|
||||
/* for now, assume compatible byte order until we solve this. */
|
||||
uint32_t entry;
|
||||
|
@ -168,7 +168,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
|||
int cbfs_execute_stage(struct cbfs_media *media, const char *name)
|
||||
{
|
||||
struct cbfs_stage *stage = (struct cbfs_stage *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL);
|
||||
|
||||
if (stage == NULL)
|
||||
return 1;
|
||||
|
@ -187,7 +187,7 @@ int cbfs_execute_stage(struct cbfs_media *media, const char *name)
|
|||
void *cbfs_load_payload(struct cbfs_media *media, const char *name)
|
||||
{
|
||||
return (struct cbfs_payload *)cbfs_get_file_content(
|
||||
media, name, CBFS_TYPE_PAYLOAD);
|
||||
media, name, CBFS_TYPE_PAYLOAD, NULL);
|
||||
}
|
||||
|
||||
struct cbfs_file *cbfs_find(const char *name) {
|
||||
|
@ -195,7 +195,7 @@ struct cbfs_file *cbfs_find(const char *name) {
|
|||
}
|
||||
|
||||
void *cbfs_find_file(const char *name, int type) {
|
||||
return cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
|
||||
return cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type, NULL);
|
||||
}
|
||||
|
||||
const struct cbfs_header *get_cbfs_header(void) {
|
||||
|
|
|
@ -173,10 +173,14 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name, int type)
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||
int type, size_t *sz)
|
||||
{
|
||||
struct cbfs_file *file = cbfs_get_file(media, name);
|
||||
|
||||
if (sz)
|
||||
*sz = 0;
|
||||
|
||||
if (file == NULL) {
|
||||
ERROR("Could not find file '%s'.\n", name);
|
||||
return NULL;
|
||||
|
@ -188,6 +192,9 @@ void *cbfs_get_file_content(struct cbfs_media *media, const char *name, int type
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (sz)
|
||||
*sz = ntohl(file->len);
|
||||
|
||||
return (void *)CBFS_SUBHEADER(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -273,7 +273,8 @@ void vbe_set_graphics(void)
|
|||
decdata = malloc(sizeof(*decdata));
|
||||
unsigned char *jpeg = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
|
||||
"bootsplash.jpg",
|
||||
CBFS_TYPE_BOOTSPLASH);
|
||||
CBFS_TYPE_BOOTSPLASH,
|
||||
NULL);
|
||||
if (!jpeg) {
|
||||
printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
|
||||
return;
|
||||
|
|
|
@ -727,7 +727,8 @@ void vbe_set_graphics(void)
|
|||
|
||||
unsigned char *jpeg = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
|
||||
"bootsplash.jpg",
|
||||
CBFS_TYPE_BOOTSPLASH);
|
||||
CBFS_TYPE_BOOTSPLASH,
|
||||
NULL);
|
||||
if (!jpeg) {
|
||||
DEBUG_PRINTF_VBE("Could not find bootsplash.jpg\n");
|
||||
return;
|
||||
|
|
|
@ -193,7 +193,7 @@ enum cb_err get_option(void *dest, const char *name)
|
|||
|
||||
/* find the requested entry record */
|
||||
ct = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "cmos_layout.bin",
|
||||
CBFS_COMPONENT_CMOS_LAYOUT);
|
||||
CBFS_COMPONENT_CMOS_LAYOUT, NULL);
|
||||
if (!ct) {
|
||||
printk(BIOS_ERR, "RTC: cmos_layout.bin could not be found. "
|
||||
"Options are disabled\n");
|
||||
|
@ -272,7 +272,7 @@ enum cb_err set_option(const char *name, void *value)
|
|||
|
||||
/* find the requested entry record */
|
||||
ct = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "cmos_layout.bin",
|
||||
CBFS_COMPONENT_CMOS_LAYOUT);
|
||||
CBFS_COMPONENT_CMOS_LAYOUT, NULL);
|
||||
if (!ct) {
|
||||
printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n");
|
||||
return CB_CMOS_LAYOUT_NOT_FOUND;
|
||||
|
|
|
@ -222,7 +222,7 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name);
|
|||
|
||||
/* returns pointer to file content inside CBFS after if type is correct */
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||
int type);
|
||||
int type, size_t *sz);
|
||||
|
||||
/* returns decompressed size on success, 0 on failure */
|
||||
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
||||
|
|
|
@ -96,7 +96,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
|
|||
tohex16(device, name+8);
|
||||
|
||||
orom = (struct cbfs_optionrom *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_OPTIONROM);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_OPTIONROM, NULL);
|
||||
|
||||
if (orom == NULL)
|
||||
return NULL;
|
||||
|
@ -187,7 +187,7 @@ static void *load_stage_from_cbfs(struct cbfs_media *media, const char *name,
|
|||
const struct cbmem_entry *ramstage_entry;
|
||||
|
||||
stage = (struct cbfs_stage *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL);
|
||||
|
||||
if (stage == NULL)
|
||||
return (void *) -1;
|
||||
|
@ -257,7 +257,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
|||
void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||
{
|
||||
struct cbfs_stage *stage = (struct cbfs_stage *)
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE);
|
||||
cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL);
|
||||
/* this is a mess. There is no ntohll. */
|
||||
/* for now, assume compatible byte order until we solve this. */
|
||||
uint32_t entry;
|
||||
|
@ -302,7 +302,7 @@ void *cbfs_load_payload(struct cbfs_media *media, const char *name)
|
|||
return payload;
|
||||
|
||||
payload = (struct cbfs_payload *)cbfs_get_file_content(
|
||||
media, name, CBFS_TYPE_PAYLOAD);
|
||||
media, name, CBFS_TYPE_PAYLOAD, NULL);
|
||||
return payload;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -173,10 +173,14 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name, int type)
|
||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||
int type, size_t *sz)
|
||||
{
|
||||
struct cbfs_file *file = cbfs_get_file(media, name);
|
||||
|
||||
if (sz)
|
||||
*sz = 0;
|
||||
|
||||
if (file == NULL) {
|
||||
ERROR("Could not find file '%s'.\n", name);
|
||||
return NULL;
|
||||
|
@ -188,6 +192,9 @@ void *cbfs_get_file_content(struct cbfs_media *media, const char *name, int type
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (sz)
|
||||
*sz = ntohl(file->len);
|
||||
|
||||
return (void *)CBFS_SUBHEADER(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -505,7 +505,7 @@ unsigned long write_coreboot_table(
|
|||
{
|
||||
struct cmos_option_table *option_table = cbfs_get_file_content(
|
||||
CBFS_DEFAULT_MEDIA, "cmos_layout.bin",
|
||||
CBFS_COMPONENT_CMOS_LAYOUT);
|
||||
CBFS_COMPONENT_CMOS_LAYOUT, NULL);
|
||||
if (option_table) {
|
||||
struct lb_record *rec_dest = lb_new_record(head);
|
||||
/* Copy the option config table, it's already a lb_record... */
|
||||
|
|
|
@ -428,7 +428,7 @@ AGESA_STATUS fam15tn_HookGfxGetVbiosImage(UINT32 Func, UINT32 FchData, VOID *Con
|
|||
GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
|
||||
pVbiosImageInfo->ImagePtr = cbfs_get_file_content(
|
||||
CBFS_DEFAULT_MEDIA, "pci"CONFIG_VGA_BIOS_ID".rom",
|
||||
CBFS_TYPE_OPTIONROM);
|
||||
CBFS_TYPE_OPTIONROM, NULL);
|
||||
/* printk(BIOS_DEBUG, "IMGptr=%x\n", pVbiosImageInfo->ImagePtr); */
|
||||
return pVbiosImageInfo->ImagePtr == NULL ? AGESA_WARNING : AGESA_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -401,7 +401,7 @@ AGESA_STATUS fam16kb_HookGfxGetVbiosImage(UINT32 Func, UINT32 FchData, VOID *Con
|
|||
GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
|
||||
pVbiosImageInfo->ImagePtr = cbfs_get_file_content(
|
||||
CBFS_DEFAULT_MEDIA, "pci"CONFIG_VGA_BIOS_ID".rom",
|
||||
CBFS_TYPE_OPTIONROM);
|
||||
CBFS_TYPE_OPTIONROM, NULL);
|
||||
/* printk(BIOS_DEBUG, "IMGptr=%x\n", pVbiosImageInfo->ImagePtr); */
|
||||
return pVbiosImageInfo->ImagePtr == NULL ? AGESA_WARNING : AGESA_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ static int is_mrc_cache(struct mrc_data_container *mrc_cache)
|
|||
|
||||
static u32 get_mrc_cache_region(struct mrc_data_container **mrc_region_ptr)
|
||||
{
|
||||
u32 region_size;
|
||||
region_size = CONFIG_MRC_CACHE_SIZE;
|
||||
size_t region_size;
|
||||
*mrc_region_ptr = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
|
||||
"mrc.cache", 0xac);
|
||||
"mrc.cache", 0xac,
|
||||
®ion_size);
|
||||
|
||||
return region_size;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ void sdram_initialize(struct pei_data *pei_data)
|
|||
|
||||
/* Locate and call UEFI System Agent binary. */
|
||||
entry = (unsigned long)cbfs_get_file_content(
|
||||
CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab);
|
||||
CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab, NULL);
|
||||
if (entry) {
|
||||
int rv;
|
||||
asm volatile (
|
||||
|
|
|
@ -66,16 +66,15 @@ static int is_mrc_cache(struct mrc_data_container *mrc_cache)
|
|||
*/
|
||||
static u32 get_mrc_cache_region(struct mrc_data_container **mrc_region_ptr)
|
||||
{
|
||||
u32 region_size;
|
||||
#if CONFIG_CHROMEOS
|
||||
region_size = find_fmap_entry("RW_MRC_CACHE", (void **)mrc_region_ptr);
|
||||
return find_fmap_entry("RW_MRC_CACHE", (void **)mrc_region_ptr);
|
||||
#else
|
||||
region_size = CONFIG_MRC_CACHE_SIZE;
|
||||
size_t region_size;
|
||||
*mrc_region_ptr = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
|
||||
"mrc.cache", 0xac);
|
||||
"mrc.cache", 0xac, ®ion_size);
|
||||
return region_size;
|
||||
#endif
|
||||
|
||||
return region_size;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -253,7 +253,7 @@ void sdram_initialize(struct pei_data *pei_data)
|
|||
/* Locate and call UEFI System Agent binary. */
|
||||
/* TODO make MRC blob (0xab?) defined in cbfs_core.h. */
|
||||
entry = (unsigned long)cbfs_get_file_content(
|
||||
CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab);
|
||||
CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab, NULL);
|
||||
if (entry) {
|
||||
int rv;
|
||||
asm volatile (
|
||||
|
|
|
@ -48,7 +48,7 @@ static void vboot_run_stub(struct vboot_context *context)
|
|||
|
||||
stage = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
|
||||
CONFIG_CBFS_PREFIX "/vboot",
|
||||
CBFS_TYPE_STAGE);
|
||||
CBFS_TYPE_STAGE, NULL);
|
||||
|
||||
if (stage == NULL)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue