diff options
-rw-r--r-- | payloads/libpayload/include/cbfs_core.h | 2 | ||||
-rw-r--r-- | payloads/libpayload/libcbfs/cbfs.c | 4 | ||||
-rw-r--r-- | payloads/libpayload/libcbfs/cbfs_core.c | 9 | ||||
-rw-r--r-- | src/include/cbfs_core.h | 2 | ||||
-rw-r--r-- | src/lib/cbfs.c | 18 | ||||
-rw-r--r-- | src/lib/cbfs_core.c | 9 | ||||
-rw-r--r-- | src/vendorcode/google/chromeos/vboot_loader.c | 8 |
7 files changed, 24 insertions, 28 deletions
diff --git a/payloads/libpayload/include/cbfs_core.h b/payloads/libpayload/include/cbfs_core.h index 2dc1992bc7..8be7212210 100644 --- a/payloads/libpayload/include/cbfs_core.h +++ b/payloads/libpayload/include/cbfs_core.h @@ -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, 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); /* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS diff --git a/payloads/libpayload/libcbfs/cbfs.c b/payloads/libpayload/libcbfs/cbfs.c index 2fb91bf2d2..6243473170 100644 --- a/payloads/libpayload/libcbfs/cbfs.c +++ b/payloads/libpayload/libcbfs/cbfs.c @@ -120,7 +120,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor, if (! dest) return src; - if (cbfs_decompress(ntohl(orom->compression), + if (!cbfs_decompress(ntohl(orom->compression), src, dest, ntohl(orom->len))) @@ -146,7 +146,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) stage->entry); memset((void *) (uint32_t) stage->load, 0, stage->memlen); - if (cbfs_decompress(stage->compression, + if (!cbfs_decompress(stage->compression, ((unsigned char *) stage) + sizeof(struct cbfs_stage), (void *) (uint32_t) stage->load, diff --git a/payloads/libpayload/libcbfs/cbfs_core.c b/payloads/libpayload/libcbfs/cbfs_core.c index 48a4b3aaca..1945813bb5 100644 --- a/payloads/libpayload/libcbfs/cbfs_core.c +++ b/payloads/libpayload/libcbfs/cbfs_core.c @@ -196,19 +196,16 @@ int cbfs_decompress(int algo, void *src, void *dst, int len) switch (algo) { case CBFS_COMPRESS_NONE: memcpy(dst, src, len); - return 0; + return len; #ifdef CBFS_CORE_WITH_LZMA case CBFS_COMPRESS_LZMA: - if (ulzma(src, dst) != 0) { - return 0; - } - return -1; + return ulzma(src, dst); #endif default: ERROR("tried to decompress %d bytes with algorithm #%x," "but that algorithm id is unsupported.\n", len, algo); - return -1; + return 0; } } diff --git a/src/include/cbfs_core.h b/src/include/cbfs_core.h index 54e2f60d87..08fe8150ed 100644 --- a/src/include/cbfs_core.h +++ b/src/include/cbfs_core.h @@ -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, 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); /* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index aba1bcccf0..400b8a5f9d 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -112,7 +112,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor, if (! dest) return src; - if (cbfs_decompress(ntohl(orom->compression), + if (!cbfs_decompress(ntohl(orom->compression), src, dest, 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", name, &ramstage_region[rmodule_offset], stage->memlen); - if (cbfs_decompress(stage->compression, &stage[1], - &ramstage_region[rmodule_offset], stage->len)) + if (!cbfs_decompress(stage->compression, &stage[1], + &ramstage_region[rmodule_offset], stage->len)) return (void *) -1; 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. */ /* for now, assume compatible byte order until we solve this. */ uint32_t entry; + uint32_t final_size; if (stage == NULL) 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. */ memset((void *) (uint32_t) stage->load, 0, stage->memlen); - if (cbfs_decompress(stage->compression, - ((unsigned char *) stage) + - sizeof(struct cbfs_stage), - (void *) (uint32_t) stage->load, - stage->len)) + final_size = cbfs_decompress(stage->compression, + ((unsigned char *) stage) + + sizeof(struct cbfs_stage), + (void *) (uint32_t) stage->load, + stage->len); + if (!final_size) return (void *) -1; DEBUG("stage loaded.\n"); diff --git a/src/lib/cbfs_core.c b/src/lib/cbfs_core.c index 39c1ff6008..612fef2a6f 100644 --- a/src/lib/cbfs_core.c +++ b/src/lib/cbfs_core.c @@ -196,19 +196,16 @@ int cbfs_decompress(int algo, void *src, void *dst, int len) switch (algo) { case CBFS_COMPRESS_NONE: memmove(dst, src, len); - return 0; + return len; #ifdef CBFS_CORE_WITH_LZMA case CBFS_COMPRESS_LZMA: - if (ulzma(src, dst) != 0) { - return 0; - } - return -1; + return ulzma(src, dst); #endif default: ERROR("tried to decompress %d bytes with algorithm #%x," "but that algorithm id is unsupported.\n", len, algo); - return -1; + return 0; } } diff --git a/src/vendorcode/google/chromeos/vboot_loader.c b/src/vendorcode/google/chromeos/vboot_loader.c index 10fa52d698..b627af6d3f 100644 --- a/src/vendorcode/google/chromeos/vboot_loader.c +++ b/src/vendorcode/google/chromeos/vboot_loader.c @@ -66,8 +66,8 @@ static void vboot_run_stub(struct vboot_context *context) vboot_region = cbmem_entry_start(vboot_entry); - if (cbfs_decompress(stage->compression, &stage[1], - &vboot_region[rmodule_offset], stage->len)) { + if (!cbfs_decompress(stage->compression, &stage[1], + &vboot_region[rmodule_offset], stage->len)) { printk(BIOS_DEBUG, "Couldn't decompress vboot stub.\n"); 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", &ramstage_region[rmodule_offset], stage->memlen); - if (cbfs_decompress(stage->compression, &stage[1], - &ramstage_region[rmodule_offset], stage->len)) + if (!cbfs_decompress(stage->compression, &stage[1], + &ramstage_region[rmodule_offset], stage->len)) return; if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage)) |