util/cbfstool: Fix truncate command error handling and cbfs_image_from_buffer()
Check return value of cbfs_truncate_space() in cbfs_truncate(). Remove return from cbfs_image_from_buffer() to inform about invalid image region when incorrect offset header was provided. Also change header offset provided to mentioned function in cbfs_expand_to_region() and cbfs_truncate_space() from zero to HEADER_OFFSET_UNKNOWN, as they do not support images with cbfs master header. Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Change-Id: Ib009212692fb3594a826436df765860f54837154 Reviewed-on: https://review.coreboot.org/c/coreboot/+/66334 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
77b2d45c9e
commit
aa41563483
|
@ -346,9 +346,8 @@ int cbfs_image_from_buffer(struct cbfs_image *out, struct buffer *in,
|
||||||
out->has_header = true;
|
out->has_header = true;
|
||||||
cbfs_fix_legacy_size(out, header_loc);
|
cbfs_fix_legacy_size(out, header_loc);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (offset != ~0u) {
|
} else if (offset != HEADER_OFFSET_UNKNOWN) {
|
||||||
ERROR("The -H switch is only valid on legacy images having CBFS master headers.\n");
|
ERROR("The -H switch is only valid on legacy images having CBFS master headers.\n");
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
ERROR("Selected image region is not a valid CBFS.\n");
|
ERROR("Selected image region is not a valid CBFS.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -415,7 +414,7 @@ int cbfs_expand_to_region(struct buffer *region)
|
||||||
|
|
||||||
struct cbfs_image image;
|
struct cbfs_image image;
|
||||||
memset(&image, 0, sizeof(image));
|
memset(&image, 0, sizeof(image));
|
||||||
if (cbfs_image_from_buffer(&image, region, 0)) {
|
if (cbfs_image_from_buffer(&image, region, HEADER_OFFSET_UNKNOWN)) {
|
||||||
ERROR("reading CBFS failed!\n");
|
ERROR("reading CBFS failed!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +453,7 @@ int cbfs_truncate_space(struct buffer *region, uint32_t *size)
|
||||||
|
|
||||||
struct cbfs_image image;
|
struct cbfs_image image;
|
||||||
memset(&image, 0, sizeof(image));
|
memset(&image, 0, sizeof(image));
|
||||||
if (cbfs_image_from_buffer(&image, region, 0)) {
|
if (cbfs_image_from_buffer(&image, region, HEADER_OFFSET_UNKNOWN)) {
|
||||||
ERROR("reading CBFS failed!\n");
|
ERROR("reading CBFS failed!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "cbfs.h"
|
#include "cbfs.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define HEADER_OFFSET_UNKNOWN (~0u)
|
||||||
|
|
||||||
/* CBFS image processing */
|
/* CBFS image processing */
|
||||||
|
|
||||||
struct cbfs_image {
|
struct cbfs_image {
|
||||||
|
|
|
@ -113,7 +113,7 @@ static struct param {
|
||||||
.arch = CBFS_ARCHITECTURE_UNKNOWN,
|
.arch = CBFS_ARCHITECTURE_UNKNOWN,
|
||||||
.compression = CBFS_COMPRESS_NONE,
|
.compression = CBFS_COMPRESS_NONE,
|
||||||
.hash = VB2_HASH_INVALID,
|
.hash = VB2_HASH_INVALID,
|
||||||
.headeroffset = ~0,
|
.headeroffset = HEADER_OFFSET_UNKNOWN,
|
||||||
.region_name = SECTION_NAME_PRIMARY_CBFS,
|
.region_name = SECTION_NAME_PRIMARY_CBFS,
|
||||||
.u64val = -1,
|
.u64val = -1,
|
||||||
};
|
};
|
||||||
|
@ -1738,7 +1738,8 @@ static int cbfs_truncate(void)
|
||||||
|
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
int result = cbfs_truncate_space(param.image_region, &size);
|
int result = cbfs_truncate_space(param.image_region, &size);
|
||||||
printf("0x%x\n", size);
|
if (!result)
|
||||||
|
printf("0x%x\n", size);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ int main(int argc, char *argv[])
|
||||||
uint32_t addr = 0;
|
uint32_t addr = 0;
|
||||||
size_t topswap_size = 0;
|
size_t topswap_size = 0;
|
||||||
enum fit_type fit_type = 0;
|
enum fit_type fit_type = 0;
|
||||||
uint32_t headeroffset = ~0u;
|
uint32_t headeroffset = HEADER_OFFSET_UNKNOWN;
|
||||||
|
|
||||||
verbose = 0;
|
verbose = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue