summaryrefslogtreecommitdiffstats
path: root/utils/imxtools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-09-07 12:12:09 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-07 17:47:00 +0200
commit3c558127b83d162636fb27d2ded1f02c88413e37 (patch)
tree06440e649a657da8821f0e01de1a514bba2326b6 /utils/imxtools
parent6957966c861498861008b27349dfbe209973a02f (diff)
downloadrockbox-3c558127b83d162636fb27d2ded1f02c88413e37.tar.gz
rockbox-3c558127b83d162636fb27d2ded1f02c88413e37.tar.bz2
rockbox-3c558127b83d162636fb27d2ded1f02c88413e37.zip
sbtools: add option to ignore sha1 errors
Change-Id: I6bf9e4671e57f8ff3f436660e8ecb561027a036c
Diffstat (limited to 'utils/imxtools')
-rw-r--r--utils/imxtools/sbtools/sb.c22
-rw-r--r--utils/imxtools/sbtools/sb.h11
-rw-r--r--utils/imxtools/sbtools/sbtoelf.c11
3 files changed, 30 insertions, 14 deletions
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c
index bea0438cca..385c5e5ded 100644
--- a/utils/imxtools/sbtools/sb.c
+++ b/utils/imxtools/sbtools/sb.c
@@ -646,14 +646,14 @@ static uint32_t guess_alignment(uint32_t off)
return a;
}
-struct sb_file_t *sb_read_file(const char *filename, bool raw_mode, void *u,
+struct sb_file_t *sb_read_file(const char *filename, unsigned flags, void *u,
generic_printf_t cprintf, enum sb_error_t *err)
{
- return sb_read_file_ex(filename, 0, -1, raw_mode, u, cprintf, err);
+ return sb_read_file_ex(filename, 0, -1, flags, 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,
- generic_printf_t cprintf, enum sb_error_t *err)
+struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t size,
+ unsigned flags, void *u, generic_printf_t cprintf, enum sb_error_t *err)
{
#define fatal(e, ...) \
do { if(err) *err = e; \
@@ -678,7 +678,7 @@ struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t si
}
fclose(f);
- struct sb_file_t *ret = sb_read_memory(buf, read_size, raw_mode, u, cprintf, err);
+ struct sb_file_t *ret = sb_read_memory(buf, read_size, flags, u, cprintf, err);
free(buf);
return ret;
@@ -704,7 +704,7 @@ static void sb_printer(void *user, const char *fmt, ...)
va_end(args);
}
-struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, void *u,
+struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, void *u,
generic_printf_t cprintf, enum sb_error_t *err)
{
struct sb_file_t *sb_file = NULL;
@@ -935,7 +935,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
}
/* sections */
- if(!raw_mode)
+ if(!(flags & SB_RAW_MODE))
{
sb_file->nr_sections = sb_header->nr_sections;
sb_file->sections = xmalloc(sb_file->nr_sections * sizeof(struct sb_section_t));
@@ -1132,6 +1132,14 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
sha_1_output(&sha_1_params, computed_sha1);
if(memcmp(decrypted_block, computed_sha1, 20) == 0)
printf(RED, " Ok\n");
+ else if(flags & SB_IGNORE_SHA1)
+ {
+ /* some weird images produced by some buggy tools have wrong SHA-1,
+ * this probably gone unnoticed because the bootloader ignores the SH1-1
+ * anyway */
+ printf(RED, " Failed\n");
+ cprintf(u, true, GREY, "Warning: SHA-1 mismatch ignored per flags\n");
+ }
else
{
printf(RED, " Failed\n");
diff --git a/utils/imxtools/sbtools/sb.h b/utils/imxtools/sbtools/sb.h
index 67d0d8c423..cf826362de 100644
--- a/utils/imxtools/sbtools/sb.h
+++ b/utils/imxtools/sbtools/sb.h
@@ -234,14 +234,17 @@ enum sb_error_t
SB_LAST_CRYPTO_ERROR = SB_FIRST_CRYPTO_ERROR - CRYPTO_NUM_ERRORS,
};
+#define SB_RAW_MODE (1 << 0) /* read image in raw mode (aka bootloader-like) */
+#define SB_IGNORE_SHA1 (1 << 1) /* ignore SHA-1 mismatch */
+
enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *u,
generic_printf_t printf);
-struct sb_file_t *sb_read_file(const char *filename, bool raw_mode, void *u,
+struct sb_file_t *sb_read_file(const char *filename, unsigned flags, void *u,
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,
- 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,
+struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t size,
+ unsigned flags, void *u, generic_printf_t printf, enum sb_error_t *err);
+struct sb_file_t *sb_read_memory(void *buffer, size_t size, unsigned flags, void *u,
generic_printf_t printf, enum sb_error_t *err);
uint64_t sb_generate_timestamp(void);
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c
index 578135d7ca..86c37f3e4c 100644
--- a/utils/imxtools/sbtools/sbtoelf.c
+++ b/utils/imxtools/sbtools/sbtoelf.c
@@ -263,13 +263,14 @@ static void usage(void)
printf(" -s/--no-simpl Prevent elf files from being simplified*\n");
printf(" -x Use default sb1 key\n");
printf(" -b Brute force key\n");
+ printf(" --ignore-sha1 Ignore SHA-1 mismatch*\n");
printf("Options marked with a * are for debug purpose only\n");
exit(1);
}
int main(int argc, char **argv)
{
- bool raw_mode = false;
+ unsigned flags = 0;
const char *loopback = NULL;
bool force_sb1 = false;
bool force_sb2 = false;
@@ -288,6 +289,7 @@ int main(int argc, char **argv)
{"v1", no_argument, 0, '1'},
{"v2", no_argument, 0, '2'},
{"no-simpl", no_argument, 0, 's'},
+ {"ignore-sha1", no_argument, 0, 254},
{0, 0, 0, 0}
};
@@ -339,7 +341,7 @@ int main(int argc, char **argv)
break;
}
case 'r':
- raw_mode = true;
+ flags |= SB_RAW_MODE;
break;
case 'a':
{
@@ -364,6 +366,9 @@ int main(int argc, char **argv)
case 'b':
brute_force = true;
break;
+ case 254:
+ flags |= SB_IGNORE_SHA1;
+ break;
default:
bug("Internal error: unknown option '%c'\n", c);
}
@@ -390,7 +395,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, generic_std_printf, &err);
+ struct sb_file_t *file = sb_read_file(sb_filename, flags, NULL, generic_std_printf, &err);
if(file == NULL)
{
color(OFF);