summaryrefslogtreecommitdiff
path: root/util/cbfstool
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool')
-rw-r--r--util/cbfstool/cbfs-mkpayload.c4
-rw-r--r--util/cbfstool/cbfs-mkstage.c10
-rw-r--r--util/cbfstool/cbfstool.c109
-rw-r--r--util/cbfstool/common.c79
-rw-r--r--util/cbfstool/common.h8
-rw-r--r--util/cbfstool/compress.c2
6 files changed, 108 insertions, 104 deletions
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c
index 7f01024bae..da04a75785 100644
--- a/util/cbfstool/cbfs-mkpayload.c
+++ b/util/cbfstool/cbfs-mkpayload.c
@@ -44,13 +44,13 @@ int parse_elf_to_payload(unsigned char *input, unsigned char **output,
int i;
if(!iself(input)){
- fprintf(stderr, "E: The payload file is not in ELF format!\n");
+ ERROR("The payload file is not in ELF format!\n");
return -1;
}
if (!((ehdr->e_machine == EM_ARM) && (arch == CBFS_ARCHITECTURE_ARMV7)) &&
!((ehdr->e_machine == EM_386) && (arch == CBFS_ARCHITECTURE_X86))) {
- fprintf(stderr, "E: The payload file has the wrong architecture\n");
+ ERROR("The payload file has the wrong architecture\n");
return -1;
}
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index b54af1013f..ef5182aae3 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -64,13 +64,13 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
return -1;
if (!iself(input)) {
- fprintf(stderr, "E: The stage file is not in ELF format!\n");
+ ERROR("The stage file is not in ELF format!\n");
return -1;
}
if (!((ehdr->e_machine == EM_ARM) && (arch == CBFS_ARCHITECTURE_ARMV7)) &&
!((ehdr->e_machine == EM_386) && (arch == CBFS_ARCHITECTURE_X86))) {
- fprintf(stderr, "E: The stage file has the wrong architecture\n");
+ ERROR("The stage file has the wrong architecture\n");
return -1;
}
@@ -126,7 +126,7 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
}
if (data_end <= data_start) {
- fprintf(stderr, "E: data ends before it starts. Make sure the "
+ ERROR("data ends before it starts. Make sure the "
"ELF file is correct and resides in ROM space.\n");
exit(1);
}
@@ -135,7 +135,7 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
buffer = calloc(data_end - data_start, 1);
if (buffer == NULL) {
- fprintf(stderr, "E: Unable to allocate memory: %m\n");
+ ERROR("Unable to allocate memory: %m\n");
return -1;
}
@@ -165,7 +165,7 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
out = calloc(sizeof(struct cbfs_stage) + data_end - data_start, 1);
if (out == NULL) {
- fprintf(stderr, "E: Unable to allocate memory: %m\n");
+ ERROR("Unable to allocate memory: %m\n");
return -1;
}
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index cbf1d5e91a..2857264d26 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -59,30 +59,30 @@ static int cbfs_add(void)
void *rom, *filedata, *cbfsfile;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
if (param.type == 0) {
- fprintf(stderr, "E: You need to specify a valid -t/--type.\n");
+ ERROR("You need to specify a valid -t/--type.\n");
return 1;
}
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
filedata = loadfile(param.filename, &filesize, 0, SEEK_SET);
if (filedata == NULL) {
- fprintf(stderr, "E: Could not load file '%s'.\n",
+ ERROR("Could not load file '%s'.\n",
param.filename);
free(rom);
return 1;
@@ -93,7 +93,7 @@ static int cbfs_add(void)
free(filedata);
if (add_file_to_cbfs(cbfsfile, filesize, param.baseaddress)) {
- fprintf(stderr, "E: Adding file '%s' failed.\n", param.filename);
+ ERROR("Adding file '%s' failed.\n", param.filename);
free(cbfsfile);
free(rom);
return 1;
@@ -116,25 +116,25 @@ static int cbfs_add_payload(void)
unsigned char *payload;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
filedata = loadfile(param.filename, &filesize, 0, SEEK_SET);
if (filedata == NULL) {
- fprintf(stderr, "E: Could not load file '%s'.\n",
+ ERROR("Could not load file '%s'.\n",
param.filename);
free(rom);
return 1;
@@ -142,7 +142,7 @@ static int cbfs_add_payload(void)
filesize = parse_elf_to_payload(filedata, &payload, param.algo);
if (filesize <= 0) {
- fprintf(stderr, "E: Adding payload '%s' failed.\n",
+ ERROR("Adding payload '%s' failed.\n",
param.filename);
free(rom);
return 1;
@@ -155,7 +155,7 @@ static int cbfs_add_payload(void)
free(payload);
if (add_file_to_cbfs(cbfsfile, filesize, param.baseaddress)) {
- fprintf(stderr, "E: Adding payload '%s' failed.\n",
+ ERROR("Adding payload '%s' failed.\n",
param.filename);
free(cbfsfile);
free(rom);
@@ -180,25 +180,25 @@ static int cbfs_add_stage(void)
unsigned char *stage;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
filedata = loadfile(param.filename, &filesize, 0, SEEK_SET);
if (filedata == NULL) {
- fprintf(stderr, "E: Could not load file '%s'.\n",
+ ERROR("Could not load file '%s'.\n",
param.filename);
free(rom);
return 1;
@@ -213,7 +213,7 @@ static int cbfs_add_stage(void)
free(stage);
if (add_file_to_cbfs(cbfsfile, filesize, param.baseaddress)) {
- fprintf(stderr, "E: Adding stage '%s' failed.\n",
+ ERROR("Adding stage '%s' failed.\n",
param.filename);
free(cbfsfile);
free(rom);
@@ -242,23 +242,23 @@ static int cbfs_add_flat_binary(void)
int doffset, len = 0;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
if (param.loadaddress == 0) {
- fprintf(stderr, "E: You need to specify a valid "
+ ERROR("You need to specify a valid "
"-l/--load-address.\n");
return 1;
}
if (param.entrypoint == 0) {
- fprintf(stderr, "E: You need to specify a valid "
+ ERROR("You need to specify a valid "
"-e/--entry-point.\n");
return 1;
}
@@ -269,14 +269,14 @@ static int cbfs_add_flat_binary(void)
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
filedata = loadfile(param.filename, &filesize, 0, SEEK_SET);
if (filedata == NULL) {
- fprintf(stderr, "E: Could not load file '%s'.\n",
+ ERROR("Could not load file '%s'.\n",
param.filename);
free(rom);
return 1;
@@ -285,7 +285,7 @@ static int cbfs_add_flat_binary(void)
/* FIXME compressed file size might be bigger than original file */
payload = calloc((2 * sizeof(struct cbfs_payload_segment)) + filesize, 1);
if (payload == NULL) {
- fprintf(stderr, "E: Could not allocate memory.\n");
+ ERROR("Could not allocate memory.\n");
free(filedata);
free(rom);
return 1;
@@ -323,7 +323,7 @@ static int cbfs_add_flat_binary(void)
free(payload);
if (add_file_to_cbfs(cbfsfile, final_size, param.baseaddress)) {
- fprintf(stderr, "E: Adding payload '%s' failed.\n",
+ ERROR("Adding payload '%s' failed.\n",
param.filename);
free(cbfsfile);
free(rom);
@@ -345,19 +345,19 @@ static int cbfs_remove(void)
void *rom;
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
if (remove_file_from_cbfs(param.name)) {
- fprintf(stderr, "E: Removing file '%s' failed.\n",
+ ERROR("Removing file '%s' failed.\n",
param.name);
free(rom);
return 1;
@@ -375,17 +375,17 @@ static int cbfs_remove(void)
static int cbfs_create(void)
{
if (param.size == 0) {
- fprintf(stderr, "E: You need to specify a valid -s/--size.\n");
+ ERROR("You need to specify a valid -s/--size.\n");
return 1;
}
if (!param.bootblock) {
- fprintf(stderr, "E: You need to specify -b/--bootblock.\n");
+ ERROR("You need to specify -b/--bootblock.\n");
return 1;
}
if (arch == CBFS_ARCHITECTURE_UNKNOWN) {
- fprintf(stderr, "E: You need to specify -m/--machine arch\n");
+ ERROR("You need to specify -m/--machine arch\n");
return 1;
}
@@ -398,12 +398,12 @@ static int cbfs_locate(void)
uint32_t filesize, location;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
@@ -422,7 +422,7 @@ static int cbfs_print(void)
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
@@ -439,18 +439,18 @@ static int cbfs_extract(void)
int ret;
if (!param.filename) {
- fprintf(stderr, "E: You need to specify -f/--filename.\n");
+ ERROR("You need to specify -f/--filename.\n");
return 1;
}
if (!param.name) {
- fprintf(stderr, "E: You need to specify -n/--name.\n");
+ ERROR("You need to specify -n/--name.\n");
return 1;
}
rom = loadrom(param.cbfs_name);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
+ ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
@@ -462,15 +462,15 @@ static int cbfs_extract(void)
}
static const struct command commands[] = {
- {"add", "f:n:t:b:h?", cbfs_add},
- {"add-payload", "f:n:t:c:b:h?", cbfs_add_payload},
- {"add-stage", "f:n:t:c:b:h?", cbfs_add_stage},
- {"add-flat-binary", "f:n:l:e:c:b:h?", cbfs_add_flat_binary},
- {"remove", "n:h?", cbfs_remove},
- {"create", "s:B:a:o:m:h?", cbfs_create},
- {"locate", "f:n:a:h?", cbfs_locate},
- {"print", "h?", cbfs_print},
- {"extract", "n:f:h?", cbfs_extract},
+ {"add", "f:n:t:b:vh?", cbfs_add},
+ {"add-payload", "f:n:t:c:b:vh?", cbfs_add_payload},
+ {"add-stage", "f:n:t:c:b:vh?", cbfs_add_stage},
+ {"add-flat-binary", "f:n:l:e:c:b:vh?", cbfs_add_flat_binary},
+ {"remove", "n:vh?", cbfs_remove},
+ {"create", "s:B:a:o:m:vh?", cbfs_create},
+ {"locate", "f:n:a:vh?", cbfs_locate},
+ {"print", "vh?", cbfs_print},
+ {"extract", "n:f:vh?", cbfs_extract},
};
static struct option long_options[] = {
@@ -496,8 +496,9 @@ static void usage(char *name)
printf
("cbfstool: Management utility for CBFS formatted ROM images\n\n"
"USAGE:\n" " %s [-h]\n"
- " %s FILE COMMAND [PARAMETERS]...\n\n" "OPTIONs:\n"
- " -h Display this help message\n\n"
+ " %s FILE COMMAND [-v] [PARAMETERS]...\n\n" "OPTIONs:\n"
+ " -v Provide verbose output\n"
+ " -h Display this help message\n\n"
"COMMANDs:\n"
" add -f FILE -n NAME -t TYPE [-b base-address] "
"Add a component\n"
@@ -570,8 +571,8 @@ int main(int argc, char **argv)
/* filter out illegal long options */
if (strchr(commands[i].optstring, c) == NULL) {
/* TODO maybe print actual long option instead */
- printf("%s: invalid option -- '%c'\n",
- argv[0], c);
+ ERROR("%s: invalid option -- '%c'\n",
+ argv[0], c);
c = '?';
}
@@ -585,7 +586,7 @@ int main(int argc, char **argv)
else
param.type = strtoul(optarg, NULL, 0);
if (param.type == 0)
- printf("W: Unknown type '%s' ignored\n",
+ WARN("Unknown type '%s' ignored\n",
optarg);
break;
case 'c':
@@ -594,8 +595,8 @@ int main(int argc, char **argv)
else if (!strncasecmp(optarg, "none", 5))
param.algo = CBFS_COMPRESS_NONE;
else
- printf("W: Unknown compression '%s'"
- " ignored.\n", optarg);
+ WARN("Unknown compression '%s'"
+ " ignored.\n", optarg);
break;
case 'b':
param.baseaddress = strtoul(optarg, NULL, 0);
@@ -645,7 +646,7 @@ int main(int argc, char **argv)
return commands[i].function();
}
- printf("Unknown command '%s'.\n", cmd);
+ ERROR("Unknown command '%s'.\n", cmd);
usage(argv[0]);
return 1;
}
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 137aeb7bb8..3394b7b536 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -27,8 +27,6 @@
#include "cbfs.h"
#include "elf.h"
-#define dprintf(x...)
-
size_t getfilesize(const char *filename)
{
size_t size;
@@ -55,15 +53,15 @@ void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
if (!content) {
content = malloc(*romsize_p);
if (!content) {
- fprintf(stderr, "E: Could not get %d bytes for file %s\n",
- *romsize_p, filename);
+ ERROR("Could not get %d bytes for file %s\n",
+ *romsize_p, filename);
exit(1);
}
} else if (place == SEEK_END)
content -= *romsize_p;
if (!fread(content, *romsize_p, 1, file)) {
- fprintf(stderr, "E: Failed to read %s\n", filename);
+ ERROR("Failed to read %s\n", filename);
return NULL;
}
fclose(file);
@@ -138,14 +136,14 @@ int find_master_header(void *romarea, size_t size)
void recalculate_rom_geometry(void *romarea)
{
if (find_master_header(romarea, romsize)) {
- fprintf(stderr, "E: Cannot find master header\n");
+ ERROR("Cannot find master header\n");
exit(1);
}
/* Update old headers */
if (master_header->version == CBFS_HEADER_VERSION1 &&
ntohl(master_header->architecture) == CBFS_ARCHITECTURE_UNKNOWN) {
- dprintf("Updating CBFS master header to version 2\n");
+ DEBUG("Updating CBFS master header to version 2\n");
master_header->architecture = htonl(CBFS_ARCHITECTURE_X86);
}
@@ -165,7 +163,7 @@ void recalculate_rom_geometry(void *romarea)
sizeof(struct cbfs_header)) & 0xffffffff;
break;
default:
- fprintf(stderr, "E: Unknown architecture\n");
+ ERROR("Unknown architecture\n");
exit(1);
}
@@ -185,13 +183,13 @@ int writerom(const char *filename, void *start, uint32_t size)
{
FILE *file = fopen(filename, "wb");
if (!file) {
- fprintf(stderr, "Could not open '%s' for writing: ", filename);
+ ERROR("Could not open '%s' for writing: ", filename);
perror("");
return 1;
}
if (fwrite(start, size, 1, file) != 1) {
- fprintf(stderr, "Could not write to '%s': ", filename);
+ ERROR("Could not write to '%s': ", filename);
perror("");
return 1;
}
@@ -247,9 +245,9 @@ void print_supported_filetypes(void)
int i, number = ARRAY_SIZE(filetypes);
for (i=0; i<number; i++) {
- printf(" %s%c", filetypes[i].name, (i==(number-1))?'\n':',');
+ LOG(" %s%c", filetypes[i].name, (i==(number-1))?'\n':',');
if ((i%8) == 7)
- printf("\n");
+ LOG("\n");
}
}
@@ -303,7 +301,7 @@ void print_cbfs_directory(const char *filename)
case CBFS_COMPONENT_STAGE:
{
struct cbfs_stage *stage = CBFS_SUBHEADER(thisfile);
- dprintf(" %s compression, entry: 0x%llx, load: 0x%llx, length: %d/%d\n",
+ INFO(" %s compression, entry: 0x%llx, load: 0x%llx, length: %d/%d\n",
stage->compression == CBFS_COMPRESS_LZMA ? "LZMA" : "no",
(unsigned long long)stage->entry,
(unsigned long long)stage->load,
@@ -318,7 +316,7 @@ void print_cbfs_directory(const char *filename)
switch(payload->type) {
case PAYLOAD_SEGMENT_CODE:
case PAYLOAD_SEGMENT_DATA:
- dprintf(" %s (%s compression, offset: 0x%x, load: 0x%llx, length: %d/%d)\n",
+ INFO(" %s (%s compression, offset: 0x%x, load: 0x%llx, length: %d/%d)\n",
payload->type == PAYLOAD_SEGMENT_CODE ? "code " : "data" ,
payload->compression == CBFS_COMPRESS_LZMA ? "LZMA" : "no",
ntohl(payload->offset),
@@ -326,16 +324,16 @@ void print_cbfs_directory(const char *filename)
ntohl(payload->len), ntohl(payload->mem_len));
break;
case PAYLOAD_SEGMENT_ENTRY:
- dprintf(" entry (0x%llx)\n", (unsigned long long)ntohll(payload->load_addr));
+ INFO(" entry (0x%llx)\n", (unsigned long long)ntohll(payload->load_addr));
break;
case PAYLOAD_SEGMENT_BSS:
- dprintf(" BSS (address 0x%016llx, length 0x%x)\n", (unsigned long long)ntohll(payload->load_addr), ntohl(payload->len));
+ INFO(" BSS (address 0x%016llx, length 0x%x)\n", (unsigned long long)ntohll(payload->load_addr), ntohl(payload->len));
break;
case PAYLOAD_SEGMENT_PARAMS:
- dprintf(" parameters\n");
+ INFO(" parameters\n");
break;
default:
- dprintf(" %x (%s compression, offset: 0x%x, load: 0x%llx, length: %d/%d\n",
+ INFO(" %x (%s compression, offset: 0x%x, load: 0x%llx, length: %d/%d\n",
payload->type,
payload->compression == CBFS_COMPRESS_LZMA ? "LZMA" : "no",
ntohl(payload->offset),
@@ -389,7 +387,7 @@ int extract_file_from_cbfs(const char *filename, const char *payloadname, const
}
// Else, it's our file.
- printf("Found file %.30s at 0x%x, type %.12s, size %d\n", fname,
+ LOG("Found file %.30s at 0x%x, type %.12s, size %d\n", fname,
current - phys_start, strfiletype(ntohl(thisfile->type)),
length);
@@ -397,25 +395,25 @@ int extract_file_from_cbfs(const char *filename, const char *payloadname, const
outfile = fopen(outpath, "wb");
if (!outfile)
{
- fprintf(stderr, "E: Could not open the file %s for writing.\n", outpath);
+ ERROR("Could not open the file %s for writing.\n", outpath);
return 1;
}
if (ntohl(thisfile->type) != CBFS_COMPONENT_RAW)
{
- fprintf(stderr, "W: Only 'raw' files are safe to extract.\n");
+ WARN("Only 'raw' files are safe to extract.\n");
}
fwrite(((char *)thisfile)
+ ntohl(thisfile->offset), length, 1, outfile);
fclose(outfile);
- printf("Successfully dumped the file.\n");
+ LOG("Successfully dumped the file.\n");
// We'll only dump one file.
return 0;
}
- fprintf(stderr, "E: File %s not found.\n", payloadname);
+ ERROR("File %s not found.\n", payloadname);
return 1;
}
@@ -432,18 +430,17 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
(struct cbfs_file *)phys_to_virt(current);
uint32_t length = ntohl(thisfile->len);
- dprintf("at %x, %x bytes\n", current, length);
+ DEBUG("at %x, %x bytes\n", current, length);
/* Is this a free chunk? */
if ((thisfile->type == CBFS_COMPONENT_DELETED)
|| (thisfile->type == CBFS_COMPONENT_NULL)) {
- dprintf("null||deleted at %x, %x bytes\n", current,
+ DEBUG("null||deleted at %x, %x bytes\n", current,
length);
/* if this is the right size, and if specified, the right location, use it */
if ((contentsize <= length)
&& ((location == 0) || (current == location))) {
if (contentsize < length) {
- dprintf
- ("this chunk is %x bytes, we need %x. create a new chunk at %x with %x bytes\n",
+ DEBUG("this chunk is %x bytes, we need %x. create a new chunk at %x with %x bytes\n",
length, contentsize,
ALIGN(current + contentsize,
align),
@@ -456,7 +453,7 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
sizeof(struct cbfs_file);
cbfs_create_empty_file(start, size);
}
- dprintf("copying data\n");
+ DEBUG("copying data\n");
memcpy(phys_to_virt(current), content,
contentsize);
return 0;
@@ -465,8 +462,7 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
/* CBFS has the constraint that the chain always moves up in memory. so once
we're past the place we seek, we don't need to look any further */
if (current > location) {
- fprintf
- (stderr, "E: The requested space is not available\n");
+ ERROR("The requested space is not available\n");
return 1;
}
@@ -475,7 +471,7 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
&& ((location + contentsize) <=
(current + length))) {
/* Split it up. In the next iteration the code will be at the right place. */
- dprintf("split up. new length: %x\n",
+ DEBUG("split up. new length: %x\n",
location - current -
ntohl(thisfile->offset));
thisfile->len =
@@ -492,8 +488,8 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
ALIGN(current + ntohl(thisfile->len) +
ntohl(thisfile->offset), align);
}
- fprintf(stderr, "E: Could not add the file to CBFS, it's probably too big.\n");
- fprintf(stderr, "E: File size: %d bytes (%d KB).\n", contentsize, contentsize/1024);
+ ERROR("Could not add the file to CBFS, it's probably too big.\n");
+ ERROR("File size: %d bytes (%d KB).\n", contentsize, contentsize/1024);
return 1;
}
@@ -548,7 +544,7 @@ int remove_file_from_cbfs(const char *filename)
return 0;
}
- fprintf(stderr, "E: CBFS file %s not found.\n", filename);
+ ERROR("CBFS file %s not found.\n", filename);
return 1;
}
@@ -574,7 +570,7 @@ void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
}
void *newdata = malloc(*datasize + headersize);
if (!newdata) {
- fprintf(stderr, "E: Could not get %d bytes for CBFS file.\n", *datasize +
+ ERROR("Could not get %d bytes for CBFS file.\n", *datasize +
headersize);
exit(1);
}
@@ -601,7 +597,7 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
romsize = _romsize;
romarea = malloc(romsize);
if (!romarea) {
- fprintf(stderr, "E: Could not get %d bytes of memory"
+ ERROR("Could not get %d bytes of memory"
" for CBFS image.\n", romsize);
exit(1);
}
@@ -613,7 +609,7 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
bootblk = loadfile(bootblock, &bootblocksize,
romarea + romsize, SEEK_END);
if (!bootblk) {
- fprintf(stderr, "E: Could not load bootblock %s.\n",
+ ERROR("Could not load bootblock %s.\n",
bootblock);
free(romarea);
return 1;
@@ -643,8 +639,8 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
if (*(uint32_t *)p == 0xdeadbeef)
break;
if (p >= (romarea + _romsize)) {
- fprintf(stderr, "E: Could not determine CBFS "
- "header location.\n", bootblock);
+ ERROR("Could not determine CBFS "
+ "header location.\n");
return 1;
}
p += (sizeof(unsigned int));
@@ -702,7 +698,7 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
default:
// Should not happen.
- fprintf(stderr, "E: You found a bug in cbfstool.\n");
+ ERROR("You found a bug in cbfstool.\n");
exit(1);
}
@@ -726,8 +722,7 @@ uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
rom = loadrom(romfile);
if (rom == NULL) {
- fprintf(stderr, "E: Could not load ROM image '%s'.\n",
- romfile);
+ ERROR("Could not load ROM image '%s'.\n", romfile);
return 0;
}
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 853e5298a4..bb18ee1b9d 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -29,6 +29,14 @@
#define ntohll(x) (host_bigendian?(x):swab64(x))
#define htonll(x) (host_bigendian?(x):swab64(x))
+/* Message output */
+extern int verbose;
+#define ERROR(x...) { fprintf(stderr, "E: " x); }
+#define WARN(x...) { fprintf(stderr, "W: " x); }
+#define LOG(x...) { fprintf(stderr, x); }
+#define INFO(x...) { if (verbose > 0) fprintf(stderr, "INFO: " x); }
+#define DEBUG(x...) { if (verbose > 1) fprintf(stderr, "DEBUG: " x); }
+
extern void *offset;
extern uint32_t romsize;
extern int host_bigendian;
diff --git a/util/cbfstool/compress.c b/util/cbfstool/compress.c
index 2222dab112..22f302067f 100644
--- a/util/cbfstool/compress.c
+++ b/util/cbfstool/compress.c
@@ -50,7 +50,7 @@ comp_func_ptr compression_function(comp_algo algo)
compress = lzma_compress;
break;
default:
- fprintf(stderr, "E: Unknown compression algorithm %d!\n", algo);
+ ERROR("Unknown compression algorithm %d!\n", algo);
return NULL;
}
return compress;