CBFS: Change the signature of cbfs_decompress.
Instead of returning 0 on success and -1 on error, return the decompressed size of the data on success and 0 on error. The decompressed size is useful information to have that was being thrown away in that function. Change-Id: If787201aa61456b1e47feaf3a0071c753fa299a3 Signed-off-by: Gabe Black <gabeblack@chromium.org> Reviewed-on: http://review.coreboot.org/3578 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
parent
f31eacca62
commit
0c605a5a6c
|
@ -217,7 +217,7 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name);
|
||||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||||
int type);
|
int type);
|
||||||
|
|
||||||
/* returns 0 on success, -1 on failure */
|
/* returns decompressed size on success, 0 on failure */
|
||||||
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
||||||
|
|
||||||
/* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS
|
/* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS
|
||||||
|
|
|
@ -120,7 +120,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
|
||||||
if (! dest)
|
if (! dest)
|
||||||
return src;
|
return src;
|
||||||
|
|
||||||
if (cbfs_decompress(ntohl(orom->compression),
|
if (!cbfs_decompress(ntohl(orom->compression),
|
||||||
src,
|
src,
|
||||||
dest,
|
dest,
|
||||||
ntohl(orom->len)))
|
ntohl(orom->len)))
|
||||||
|
@ -146,7 +146,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
stage->entry);
|
stage->entry);
|
||||||
memset((void *) (uint32_t) stage->load, 0, stage->memlen);
|
memset((void *) (uint32_t) stage->load, 0, stage->memlen);
|
||||||
|
|
||||||
if (cbfs_decompress(stage->compression,
|
if (!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,
|
||||||
|
|
|
@ -196,19 +196,16 @@ int cbfs_decompress(int algo, void *src, void *dst, int len)
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case CBFS_COMPRESS_NONE:
|
case CBFS_COMPRESS_NONE:
|
||||||
memcpy(dst, src, len);
|
memcpy(dst, src, len);
|
||||||
return 0;
|
return len;
|
||||||
#ifdef CBFS_CORE_WITH_LZMA
|
#ifdef CBFS_CORE_WITH_LZMA
|
||||||
case CBFS_COMPRESS_LZMA:
|
case CBFS_COMPRESS_LZMA:
|
||||||
if (ulzma(src, dst) != 0) {
|
return ulzma(src, dst);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERROR("tried to decompress %d bytes with algorithm #%x,"
|
ERROR("tried to decompress %d bytes with algorithm #%x,"
|
||||||
"but that algorithm id is unsupported.\n", len,
|
"but that algorithm id is unsupported.\n", len,
|
||||||
algo);
|
algo);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name);
|
||||||
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
||||||
int type);
|
int type);
|
||||||
|
|
||||||
/* returns 0 on success, -1 on failure */
|
/* returns decompressed size on success, 0 on failure */
|
||||||
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
int cbfs_decompress(int algo, void *src, void *dst, int len);
|
||||||
|
|
||||||
/* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS
|
/* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS
|
||||||
|
|
|
@ -112,7 +112,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
|
||||||
if (! dest)
|
if (! dest)
|
||||||
return src;
|
return src;
|
||||||
|
|
||||||
if (cbfs_decompress(ntohl(orom->compression),
|
if (!cbfs_decompress(ntohl(orom->compression),
|
||||||
src,
|
src,
|
||||||
dest,
|
dest,
|
||||||
ntohl(orom->len)))
|
ntohl(orom->len)))
|
||||||
|
@ -204,8 +204,8 @@ static void *load_stage_from_cbfs(struct cbfs_media *media, const char *name,
|
||||||
LOG("Decompressing stage %s @ 0x%p (%d bytes)\n",
|
LOG("Decompressing stage %s @ 0x%p (%d bytes)\n",
|
||||||
name, &ramstage_region[rmodule_offset], stage->memlen);
|
name, &ramstage_region[rmodule_offset], stage->memlen);
|
||||||
|
|
||||||
if (cbfs_decompress(stage->compression, &stage[1],
|
if (!cbfs_decompress(stage->compression, &stage[1],
|
||||||
&ramstage_region[rmodule_offset], stage->len))
|
&ramstage_region[rmodule_offset], stage->len))
|
||||||
return (void *) -1;
|
return (void *) -1;
|
||||||
|
|
||||||
if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage))
|
if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage))
|
||||||
|
@ -259,6 +259,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;
|
||||||
|
@ -270,11 +271,12 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
/* Stages rely the below clearing so that the bss is initialized. */
|
/* Stages rely the below clearing so that the bss is initialized. */
|
||||||
memset((void *) (uint32_t) stage->load, 0, stage->memlen);
|
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;
|
||||||
|
|
||||||
DEBUG("stage loaded.\n");
|
DEBUG("stage loaded.\n");
|
||||||
|
|
|
@ -196,19 +196,16 @@ int cbfs_decompress(int algo, void *src, void *dst, int len)
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case CBFS_COMPRESS_NONE:
|
case CBFS_COMPRESS_NONE:
|
||||||
memmove(dst, src, len);
|
memmove(dst, src, len);
|
||||||
return 0;
|
return len;
|
||||||
#ifdef CBFS_CORE_WITH_LZMA
|
#ifdef CBFS_CORE_WITH_LZMA
|
||||||
case CBFS_COMPRESS_LZMA:
|
case CBFS_COMPRESS_LZMA:
|
||||||
if (ulzma(src, dst) != 0) {
|
return ulzma(src, dst);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERROR("tried to decompress %d bytes with algorithm #%x,"
|
ERROR("tried to decompress %d bytes with algorithm #%x,"
|
||||||
"but that algorithm id is unsupported.\n", len,
|
"but that algorithm id is unsupported.\n", len,
|
||||||
algo);
|
algo);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,8 @@ static void vboot_run_stub(struct vboot_context *context)
|
||||||
|
|
||||||
vboot_region = cbmem_entry_start(vboot_entry);
|
vboot_region = cbmem_entry_start(vboot_entry);
|
||||||
|
|
||||||
if (cbfs_decompress(stage->compression, &stage[1],
|
if (!cbfs_decompress(stage->compression, &stage[1],
|
||||||
&vboot_region[rmodule_offset], stage->len)) {
|
&vboot_region[rmodule_offset], stage->len)) {
|
||||||
printk(BIOS_DEBUG, "Couldn't decompress vboot stub.\n");
|
printk(BIOS_DEBUG, "Couldn't decompress vboot stub.\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -221,8 +221,8 @@ static void vboot_load_ramstage(struct vboot_handoff *vboot_handoff,
|
||||||
printk(BIOS_DEBUG, "Decompressing ramstage @ 0x%p (%d bytes)\n",
|
printk(BIOS_DEBUG, "Decompressing ramstage @ 0x%p (%d bytes)\n",
|
||||||
&ramstage_region[rmodule_offset], stage->memlen);
|
&ramstage_region[rmodule_offset], stage->memlen);
|
||||||
|
|
||||||
if (cbfs_decompress(stage->compression, &stage[1],
|
if (!cbfs_decompress(stage->compression, &stage[1],
|
||||||
&ramstage_region[rmodule_offset], stage->len))
|
&ramstage_region[rmodule_offset], stage->len))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage))
|
if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage))
|
||||||
|
|
Loading…
Reference in New Issue