summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-08-21 22:20:53 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-08-21 22:20:53 +0200
commit99f3ca174e3e6a3e6a55931b012208be64d8be39 (patch)
tree2a8a1a6ab55f44be85d287c06f9f35e0a5bd92fc
parent1357e0a4f1567e4bf5f3ecb27c28457d1dfc1ab4 (diff)
downloadrockbox-99f3ca1.tar.gz
rockbox-99f3ca1.tar.bz2
rockbox-99f3ca1.zip
sbtools: more code refactoring
Factor all printf method with a unique one defined in misc.h Change-Id: I58fbf8916b76e873a2e6678506d2c8aece7834ec
-rw-r--r--rbutil/mkimxboot/mkimxboot.c28
-rw-r--r--utils/imxtools/sbtools/elf.c35
-rw-r--r--utils/imxtools/sbtools/elf.h8
-rw-r--r--utils/imxtools/sbtools/elftosb.c4
-rw-r--r--utils/imxtools/sbtools/elftosb1.c20
-rw-r--r--utils/imxtools/sbtools/misc.c12
-rw-r--r--utils/imxtools/sbtools/misc.h4
-rw-r--r--utils/imxtools/sbtools/sb.c30
-rw-r--r--utils/imxtools/sbtools/sb.h15
-rw-r--r--utils/imxtools/sbtools/sb1.c10
-rw-r--r--utils/imxtools/sbtools/sb1.h11
-rw-r--r--utils/imxtools/sbtools/sbtoelf.c15
12 files changed, 69 insertions, 123 deletions
diff --git a/rbutil/mkimxboot/mkimxboot.c b/rbutil/mkimxboot/mkimxboot.c
index 47035bbc4d..511b3a1b7e 100644
--- a/rbutil/mkimxboot/mkimxboot.c
+++ b/rbutil/mkimxboot/mkimxboot.c
@@ -540,7 +540,7 @@ static enum imx_error_t load_sb_file(const char *file, int md5_idx,
clear_keys();
add_keys(imx_models[model].keys, imx_models[model].nr_keys);
*sb_file = sb_read_file_ex(file, imx_sums[md5_idx].fw_variants[opt.fw_variant].offset,
- imx_sums[md5_idx].fw_variants[opt.fw_variant].size, false, NULL, &sb_std_printf, &err);
+ imx_sums[md5_idx].fw_variants[opt.fw_variant].size, false, NULL, generic_std_printf, &err);
if(*sb_file == NULL)
{
clear_keys();
@@ -595,28 +595,6 @@ struct elf_user_t
size_t sz;
};
-static bool elf_read(void *user, uint32_t addr, void *buf, size_t count)
-{
- struct elf_user_t *u = user;
- if(addr + count <= u->sz)
- {
- memcpy(buf, u->buf + addr, count);
- return true;
- }
- else
- return false;
-}
-
-static void elf_printf(void *user, bool error, const char *fmt, ...)
-{
- if(!g_debug && !error)
- return;
- (void) user;
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
/* Load a rockbox firwmare from a buffer. Data is copied. Assume firmware is
* using ELF format. */
static enum imx_error_t rb_fw_load_buf_elf(struct rb_fw_t *fw, uint8_t *buf,
@@ -627,7 +605,7 @@ static enum imx_error_t rb_fw_load_buf_elf(struct rb_fw_t *fw, uint8_t *buf,
user.buf = buf;
user.sz = sz;
elf_init(&elf);
- if(!elf_read_file(&elf, &elf_read, &elf_printf, &user))
+ if(!elf_read_file(&elf, elf_std_read, generic_std_printf, &user))
{
elf_release(&elf);
printf("[ERR] Error parsing ELF file\n");
@@ -744,7 +722,7 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
ret = patch_firmware(model, opt.fw_variant, opt.output,
sb_file, boot_fw, opt.force_version);
if(ret == IMX_SUCCESS)
- ret = sb_write_file(sb_file, outfile, NULL, sb_std_printf);
+ ret = sb_write_file(sb_file, outfile, NULL, generic_std_printf);
clear_keys();
rb_fw_free(&boot_fw);
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c
index 5017251da3..c875cc7963 100644
--- a/utils/imxtools/sbtools/elf.c
+++ b/utils/imxtools/sbtools/elf.c
@@ -430,7 +430,7 @@ void elf_sort_by_address(struct elf_params_t *params)
}
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
- elf_printf_fn_t printf, void *user)
+ generic_printf_t printf, void *user)
{
(void) printf;
@@ -607,13 +607,13 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
free(strtbl_content);
}
-static void *elf_load_section(Elf32_Shdr *sh, elf_read_fn_t read, elf_printf_fn_t printf, void *user)
+static void *elf_load_section(Elf32_Shdr *sh, elf_read_fn_t read, generic_printf_t printf, void *user)
{
void *data = xmalloc(sh->sh_size);
if(!read(user, sh->sh_offset, data, sh->sh_size))
{
free(data);
- printf(user, true, "error reading elf section data\n");
+ printf(user, true, OFF, "error reading elf section data\n");
return NULL;
}
return data;
@@ -633,15 +633,15 @@ bool elf_guess(elf_read_fn_t read, void *user)
}
bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
- elf_printf_fn_t printf, void *user)
+ generic_printf_t printf, void *user)
{
- #define error_printf(...) ({printf(user, true, __VA_ARGS__); return false;})
+ #define error_printf(...) ({printf(user, true, GREY, __VA_ARGS__); return false;})
/* read header */
Elf32_Ehdr ehdr;
if(!read(user, 0, &ehdr, sizeof(ehdr)))
{
- printf(user, true, "error reading elf header\n");
+ printf(user, true, GREY, "error reading elf header\n");
return false;
}
/* basic checks */
@@ -667,16 +667,16 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
elf_set_start_addr(params, ehdr.e_entry);
/* run through sections */
- printf(user, false, "ELF file:\n");
+ printf(user, false, OFF, "ELF file:\n");
Elf32_Shdr *shdr = xmalloc(sizeof(Elf32_Shdr) * ehdr.e_shnum);
if(!read(user, ehdr.e_shoff, shdr, sizeof(Elf32_Shdr) * ehdr.e_shnum))
{
- printf(user, true, "cannot read elf section headers\n");
+ printf(user, true, GREY, "cannot read elf section headers\n");
return false;
}
char *strtab = elf_load_section(&shdr[ehdr.e_shstrndx], read, printf, user);
if(!strtab)
- printf(user, false, "elf file has no valid section string table\n");
+ printf(user, false, OFF, "elf file has no valid section string table\n");
for(int i = 1; i < ehdr.e_shnum; i++)
{
const char *sec_name = &strtab[shdr[i].sh_name];
@@ -688,7 +688,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
void *data = elf_load_section(&shdr[i], read, printf, user);
if(!data)
{
- printf(user, true, "cannot read elf section %s\n", sec_name);
+ printf(user, true, GREY, "cannot read elf section %s\n", sec_name);
goto Lerr;
}
elf_add_load_section(params, shdr[i].sh_addr, shdr[i].sh_size, data, sec_name);
@@ -707,7 +707,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
char *symstrtab = elf_load_section(&shdr[shdr[i].sh_link], read, printf, user);
if(!symstrtab)
{
- printf(user, true, "cannot load string table for symbol table %s\n", sec_name);
+ printf(user, true, GREY, "cannot load string table for symbol table %s\n", sec_name);
goto Lerr;
}
// load symbol table data
@@ -772,7 +772,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
seg->paddr = phdr.p_paddr;
seg->vsize = phdr.p_memsz;
seg->psize = phdr.p_filesz;
- printf(user, false, "create segment [%#x,+%#x[ -> [%#x,+%#x[\n",
+ printf(user, false, OFF, "create segment [%#x,+%#x[ -> [%#x,+%#x[\n",
seg->vaddr, seg->vsize, seg->paddr, seg->psize);
}
@@ -855,17 +855,6 @@ void elf_release(struct elf_params_t *params)
}
}
-void elf_std_printf(void *user, bool error, const char *fmt, ...)
-{
- if(!g_debug && !error)
- return;
- (void) user;
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count)
{
FILE *f = user;
diff --git a/utils/imxtools/sbtools/elf.h b/utils/imxtools/sbtools/elf.h
index 4200850e74..bc2971c4f1 100644
--- a/utils/imxtools/sbtools/elf.h
+++ b/utils/imxtools/sbtools/elf.h
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
+#include "misc.h"
/**
* API
@@ -93,7 +94,6 @@ struct elf_params_t
typedef bool (*elf_read_fn_t)(void *user, uint32_t addr, void *buf, size_t count);
/* write function manages it's own error state */
typedef void (*elf_write_fn_t)(void *user, uint32_t addr, const void *buf, size_t count);
-typedef void (*elf_printf_fn_t)(void *user, bool error, const char *fmt, ...);
void elf_init(struct elf_params_t *params);
void elf_add_load_section(struct elf_params_t *params,
@@ -103,9 +103,8 @@ void elf_add_fill_section(struct elf_params_t *params,
uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
void elf_simplify(struct elf_params_t *params);
void elf_sort_by_address(struct elf_params_t *params);
-void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user);
-bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
- void *user);
+void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, generic_printf_t printf, void *user);
+bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, generic_printf_t printf, void *user);
bool elf_is_empty(struct elf_params_t *params);
void elf_set_start_addr(struct elf_params_t *params, uint32_t addr);
bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr);
@@ -116,7 +115,6 @@ bool elf_guess(elf_read_fn_t read, void *user);
/* standard implementation of read/write/printf functions
* with user being a FILE* pointer */
-void elf_std_printf(void *user, bool error, const char *fmt, ...);
void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count);
bool elf_std_read(void *user, uint32_t addr, void *buf, size_t count);
diff --git a/utils/imxtools/sbtools/elftosb.c b/utils/imxtools/sbtools/elftosb.c
index 4df35ae6e6..c904e42f79 100644
--- a/utils/imxtools/sbtools/elftosb.c
+++ b/utils/imxtools/sbtools/elftosb.c
@@ -84,7 +84,7 @@ static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id)
if(g_debug)
printf("Loading ELF file '%s'...\n", src->filename);
elf_init(&src->elf);
- src->loaded = elf_read_file(&src->elf, elf_std_read, elf_std_printf, fd);
+ src->loaded = elf_read_file(&src->elf, elf_std_read, generic_std_printf, fd);
fclose(fd);
if(!src->loaded)
bug("error loading elf file '%s' (id '%s')\n", src->filename, id);
@@ -430,7 +430,7 @@ int main(int argc, char **argv)
sb_file->flags = 0;
sb_file->minor_version = 1;
- sb_write_file(sb_file, output_filename);
+ sb_write_file(sb_file, output_filename, 0, generic_std_printf);
sb_free(sb_file);
clear_keys();
diff --git a/utils/imxtools/sbtools/elftosb1.c b/utils/imxtools/sbtools/elftosb1.c
index 43f9b1e9be..83e1c175bc 100644
--- a/utils/imxtools/sbtools/elftosb1.c
+++ b/utils/imxtools/sbtools/elftosb1.c
@@ -68,24 +68,6 @@ static char *cmd_line_next_arg(void *user)
return *(uu->argv - 1);
}
-static bool elf_read(void *user, uint32_t addr, void *buf, size_t count)
-{
- if(fseek((FILE *)user, addr, SEEK_SET) == -1)
- return false;
- return fread(buf, 1, count, (FILE *)user) == count;
-}
-
-static void elf_printf(void *user, bool error, const char *fmt, ...)
-{
- if(!g_debug && !error)
- return;
- (void) user;
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
static int sb1_add_inst(struct sb1_file_t *sb, struct sb1_inst_t *insts, int nr_insts)
{
sb->insts = augment_array(sb->insts, sizeof(struct sb1_inst_t), sb->nr_insts,
@@ -402,7 +384,7 @@ static int load_elf(struct sb1_file_t *sb, const char *filename, int act)
if(g_debug)
printf("Loading elf file '%s'...\n", filename);
elf_init(&elf);
- bool loaded = elf_read_file(&elf, elf_read, elf_printf, fd);
+ bool loaded = elf_read_file(&elf, elf_std_read, generic_std_printf, fd);
fclose(fd);
if(!loaded)
bug("error loading elf file '%s'\n", filename);
diff --git a/utils/imxtools/sbtools/misc.c b/utils/imxtools/sbtools/misc.c
index 58e9609909..b36ab7902f 100644
--- a/utils/imxtools/sbtools/misc.c
+++ b/utils/imxtools/sbtools/misc.c
@@ -316,6 +316,18 @@ void color(color_t c)
printf("%s", (char *)c);
}
+void generic_std_printf(void *u, bool err, color_t c, const char *f, ...)
+{
+ (void)u;
+ if(!g_debug && !err)
+ return;
+ va_list args;
+ va_start(args, f);
+ color(c);
+ vprintf(f, args);
+ va_end(args);
+}
+
enum sb_version_guess_t guess_sb_version(const char *filename)
{
#define ret(x) do { if(f) fclose(f); return x; } while(0)
diff --git a/utils/imxtools/sbtools/misc.h b/utils/imxtools/sbtools/misc.h
index 624cd5a9c0..01e77c80c1 100644
--- a/utils/imxtools/sbtools/misc.h
+++ b/utils/imxtools/sbtools/misc.h
@@ -67,6 +67,10 @@ extern color_t OFF, GREY, RED, GREEN, YELLOW, BLUE;
void color(color_t c);
void enable_color(bool enable);
+typedef void (*generic_printf_t)(void *u, bool err, color_t c, const char *f, ...);
+
+void generic_std_printf(void *u, bool err, color_t c, const char *f, ...);
+
enum sb_version_guess_t
{
SB_VERSION_1,
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c
index 33961d41bc..a642af5945 100644
--- a/utils/imxtools/sbtools/sb.c
+++ b/utils/imxtools/sbtools/sb.c
@@ -45,7 +45,7 @@ static void fill_gaps(struct sb_file_t *sb)
}
}
-static void compute_sb_offsets(struct sb_file_t *sb, void *u, sb_color_printf cprintf)
+static void compute_sb_offsets(struct sb_file_t *sb, void *u, generic_printf_t cprintf)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
sb->image_size = 0;
@@ -283,7 +283,7 @@ static void produce_section_tag_cmd(struct sb_section_t *sec,
}
void produce_sb_instruction(struct sb_inst_t *inst,
- struct sb_instruction_common_t *cmd, void *u, sb_color_printf cprintf)
+ struct sb_instruction_common_t *cmd, void *u, generic_printf_t cprintf)
{
memset(cmd, 0, sizeof(struct sb_instruction_common_t));
cmd->hdr.opcode = inst->inst;
@@ -318,7 +318,7 @@ void produce_sb_instruction(struct sb_inst_t *inst,
}
enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *u,
- sb_color_printf cprintf)
+ generic_printf_t cprintf)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
struct crypto_key_t real_key;
@@ -475,7 +475,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
}
static struct sb_section_t *read_section(bool data_sec, uint32_t id, byte *buf,
- int size, const char *indent, void *u, sb_color_printf cprintf, enum sb_error_t *err)
+ int size, const char *indent, void *u, generic_printf_t cprintf, enum sb_error_t *err)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
#define fatal(e, ...) \
@@ -640,13 +640,13 @@ static uint32_t guess_alignment(uint32_t off)
}
struct sb_file_t *sb_read_file(const char *filename, bool raw_mode, void *u,
- sb_color_printf cprintf, enum sb_error_t *err)
+ generic_printf_t cprintf, enum sb_error_t *err)
{
return sb_read_file_ex(filename, 0, -1, raw_mode, u, cprintf, err);
}
struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t size, bool raw_mode, void *u,
- sb_color_printf cprintf, enum sb_error_t *err)
+ generic_printf_t cprintf, enum sb_error_t *err)
{
#define fatal(e, ...) \
do { if(err) *err = e; \
@@ -681,7 +681,7 @@ struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t si
struct printer_t
{
void *user;
- sb_color_printf cprintf;
+ generic_printf_t cprintf;
const char *color;
bool error;
};
@@ -698,7 +698,7 @@ static void sb_printer(void *user, const char *fmt, ...)
}
struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, void *u,
- sb_color_printf cprintf, enum sb_error_t *err)
+ generic_printf_t cprintf, enum sb_error_t *err)
{
struct sb_file_t *sb_file = NULL;
uint8_t *buf = _buf;
@@ -1158,7 +1158,7 @@ void sb_free(struct sb_file_t *file)
free(file);
}
-void sb_dump(struct sb_file_t *file, void *u, sb_color_printf cprintf)
+void sb_dump(struct sb_file_t *file, void *u, generic_printf_t cprintf)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
struct printer_t printer = {.user = u, .cprintf = cprintf, .color = OFF, .error = false };
@@ -1284,15 +1284,3 @@ void sb_get_zero_key(struct crypto_key_t *key)
key->method = CRYPTO_KEY;
memset(key->u.key, 0, sizeof(key->u.key));
}
-
-void sb_std_printf(void *user, bool error, color_t c, const char *fmt, ...)
-{
- (void)user;
- if(!g_debug && !error)
- return;
- va_list args;
- va_start(args, fmt);
- color(c);
- vprintf(fmt, args);
- va_end(args);
-}
diff --git a/utils/imxtools/sbtools/sb.h b/utils/imxtools/sbtools/sb.h
index 259ac7369b..4f725da750 100644
--- a/utils/imxtools/sbtools/sb.h
+++ b/utils/imxtools/sbtools/sb.h
@@ -231,26 +231,21 @@ enum sb_error_t
SB_LAST_CRYPTO_ERROR = SB_FIRST_CRYPTO_ERROR - CRYPTO_NUM_ERRORS,
};
-typedef void (*sb_color_printf)(void *u, bool err, color_t c, const char *f, ...);
-
enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *u,
- sb_color_printf printf);
+ generic_printf_t printf);
struct sb_file_t *sb_read_file(const char *filename, bool raw_mode, void *u,
- sb_color_printf printf, enum sb_error_t *err);
+ generic_printf_t printf, enum sb_error_t *err);
/* use size_t(-1) to use maximum size */
struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t size, bool raw_mode, void *u,
- sb_color_printf printf, enum sb_error_t *err);
+ generic_printf_t printf, enum sb_error_t *err);
struct sb_file_t *sb_read_memory(void *buffer, size_t size, bool raw_mode, void *u,
- sb_color_printf printf, enum sb_error_t *err);
+ generic_printf_t printf, enum sb_error_t *err);
void sb_fill_section_name(char name[5], uint32_t identifier);
-void sb_dump(struct sb_file_t *file, void *u, sb_color_printf printf);
+void sb_dump(struct sb_file_t *file, void *u, generic_printf_t printf);
void sb_free_instruction(struct sb_inst_t inst);
void sb_free_section(struct sb_section_t file);
void sb_free(struct sb_file_t *file);
void sb_get_zero_key(struct crypto_key_t *key);
-/* standard implementation: user is unused*/
-void sb_std_printf(void *user, bool error, color_t c, const char *fmt, ...);
-
#endif /* __SB_H__ */
diff --git a/utils/imxtools/sbtools/sb1.c b/utils/imxtools/sbtools/sb1.c
index ca7b7fdc8c..ed5893f454 100644
--- a/utils/imxtools/sbtools/sb1.c
+++ b/utils/imxtools/sbtools/sb1.c
@@ -189,13 +189,13 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
}
struct sb1_file_t *sb1_read_file(const char *filename, void *u,
- sb1_color_printf cprintf, enum sb1_error_t *err)
+ generic_printf_t cprintf, enum sb1_error_t *err)
{
return sb1_read_file_ex(filename, 0, -1, u, cprintf, err);
}
struct sb1_file_t *sb1_read_file_ex(const char *filename, size_t offset, size_t size, void *u,
- sb1_color_printf cprintf, enum sb1_error_t *err)
+ generic_printf_t cprintf, enum sb1_error_t *err)
{
#define fatal(e, ...) \
do { if(err) *err = e; \
@@ -270,7 +270,7 @@ bool sb1_is_key_valid_fast(void *buffer, union xorcrypt_key_t _key[2])
return mark == *(uint32_t *)&sector[SECTOR_SIZE - 4 - header->header_size];
}
-bool sb1_brute_force(const char *filename, void *u, sb1_color_printf cprintf,
+bool sb1_brute_force(const char *filename, void *u, generic_printf_t cprintf,
enum sb1_error_t *err, struct crypto_key_t *key)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
@@ -358,7 +358,7 @@ bool sb1_brute_force(const char *filename, void *u, sb1_color_printf cprintf,
}
struct sb1_file_t *sb1_read_memory(void *_buf, size_t filesize, void *u,
- sb1_color_printf cprintf, enum sb1_error_t *err)
+ generic_printf_t cprintf, enum sb1_error_t *err)
{
struct sb1_file_t *file = NULL;
uint8_t *buf = _buf;
@@ -606,7 +606,7 @@ void sb1_free(struct sb1_file_t *file)
free(file);
}
-void sb1_dump(struct sb1_file_t *file, void *u, sb1_color_printf cprintf)
+void sb1_dump(struct sb1_file_t *file, void *u, generic_printf_t cprintf)
{
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
#define print_hex(c, p, len, nl) \
diff --git a/utils/imxtools/sbtools/sb1.h b/utils/imxtools/sbtools/sb1.h
index d5ab042c95..f2dec509b7 100644
--- a/utils/imxtools/sbtools/sb1.h
+++ b/utils/imxtools/sbtools/sb1.h
@@ -145,24 +145,23 @@ enum sb1_error_t
enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename);
-typedef void (*sb1_color_printf)(void *u, bool err, color_t c, const char *f, ...);
struct sb1_file_t *sb1_read_file(const char *filename, void *u,
- sb1_color_printf printf, enum sb1_error_t *err);
+ generic_printf_t printf, enum sb1_error_t *err);
/* use size_t(-1) to use maximum size */
struct sb1_file_t *sb1_read_file_ex(const char *filename, size_t offset, size_t size,
- void *u, sb1_color_printf printf, enum sb1_error_t *err);
+ void *u, generic_printf_t printf, enum sb1_error_t *err);
struct sb1_file_t *sb1_read_memory(void *buffer, size_t size, void *u,
- sb1_color_printf printf, enum sb1_error_t *err);
+ generic_printf_t printf, enum sb1_error_t *err);
/* do as little checks as possible, make sure the image is valid (advance use only).
* Buffer should be of size SECTOR_SIZE at least. */
bool sb1_is_key_valid_fast(void *buffer, union xorcrypt_key_t key[2]);
-bool sb1_brute_force(const char *filename, void *u, sb1_color_printf printf,
+bool sb1_brute_force(const char *filename, void *u, generic_printf_t printf,
enum sb1_error_t *err, struct crypto_key_t *key);
void sb1_get_default_key(struct crypto_key_t *key);
-void sb1_dump(struct sb1_file_t *file, void *u, sb1_color_printf printf);
+void sb1_dump(struct sb1_file_t *file, void *u, generic_printf_t printf);
void sb1_free(struct sb1_file_t *file);
#endif /* __SB1_H__ */
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c
index 95fc7381a9..cf1744b086 100644
--- a/utils/imxtools/sbtools/sbtoelf.c
+++ b/utils/imxtools/sbtools/sbtoelf.c
@@ -27,6 +27,7 @@
*/
#define _ISOC99_SOURCE /* snprintf() */
+#define _POSIX_C_SOURCE 200809L /* for strdup */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@@ -161,7 +162,7 @@ static void extract_elf(struct elf_params_t *elf, int count)
return;
if(g_elf_simplify)
elf_simplify(elf);
- elf_write_file(elf, elf_std_write, elf_std_printf, fd);
+ elf_write_file(elf, elf_std_write, generic_std_printf, fd);
fclose(fd);
}
@@ -350,7 +351,7 @@ int main(int argc, char **argv)
if(force_sb2 || ver == SB_VERSION_2)
{
enum sb_error_t err;
- struct sb_file_t *file = sb_read_file(sb_filename, raw_mode, NULL, sb_std_printf, &err);
+ struct sb_file_t *file = sb_read_file(sb_filename, raw_mode, NULL, generic_std_printf, &err);
if(file == NULL)
{
color(OFF);
@@ -365,7 +366,7 @@ int main(int argc, char **argv)
{
color(GREY);
printf("[Debug output]\n");
- sb_dump(file, NULL, sb_std_printf);
+ sb_dump(file, NULL, generic_std_printf);
}
if(loopback)
{
@@ -374,7 +375,7 @@ int main(int argc, char **argv)
* garbage */
file->override_real_key = false;
file->override_crypto_iv = false;
- sb_write_file(file, loopback);
+ sb_write_file(file, loopback, 0, generic_std_printf);
}
sb_free(file);
}
@@ -384,7 +385,7 @@ int main(int argc, char **argv)
{
struct crypto_key_t key;
enum sb1_error_t err;
- if(!sb1_brute_force(sb_filename, NULL, sb_std_printf, &err, &key))
+ if(!sb1_brute_force(sb_filename, NULL, generic_std_printf, &err, &key))
{
color(OFF);
printf("Brute force failed: %d\n", err);
@@ -408,7 +409,7 @@ int main(int argc, char **argv)
}
enum sb1_error_t err;
- struct sb1_file_t *file = sb1_read_file(sb_filename, NULL, sb_std_printf, &err);
+ struct sb1_file_t *file = sb1_read_file(sb_filename, NULL, generic_std_printf, &err);
if(file == NULL)
{
color(OFF);
@@ -423,7 +424,7 @@ int main(int argc, char **argv)
{
color(GREY);
printf("[Debug output]\n");
- sb1_dump(file, NULL, sb_std_printf);
+ sb1_dump(file, NULL, generic_std_printf);
}
if(loopback)
sb1_write_file(file, loopback);