diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-01-29 11:50:46 +0000 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-01-29 11:53:07 +0000 |
commit | 42a725f7ecd1e6779d24f1a66eb13652de467de9 (patch) | |
tree | 1727364077a26e2e77b1ac78a2160508c2c88395 /rbutil | |
parent | d73c20933b5a7428c8f30442a6e0b90b34ece291 (diff) | |
download | rockbox-42a725f7ecd1e6779d24f1a66eb13652de467de9.tar.gz rockbox-42a725f7ecd1e6779d24f1a66eb13652de467de9.zip |
mkimxboot: add a switch to force version
Add a switch to override the product and component version of the
sb file. This can usually for target like the Zen X-Fi2 where the
upader allows to drop any file named firmware.sb and prints the
version: by using a funky version the users can check they got it
right. This should not be used on the fuze+ or zenxfi3 because the
OF prevents downgrade.
Also make rbutil always zero out the option structure passed to
mkimxboot, this has already created bugs in the past.
Change-Id: I175c5def52c40c2132e11300e2f037d60a4f040e
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/mkimxboot/main.c | 8 | ||||
-rw-r--r-- | rbutil/mkimxboot/mkimxboot.c | 59 | ||||
-rw-r--r-- | rbutil/mkimxboot/mkimxboot.h | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallimx.cpp | 1 |
4 files changed, 66 insertions, 3 deletions
diff --git a/rbutil/mkimxboot/main.c b/rbutil/mkimxboot/main.c index b775242b10..3299d748d5 100644 --- a/rbutil/mkimxboot/main.c +++ b/rbutil/mkimxboot/main.c | |||
@@ -55,6 +55,7 @@ static void usage(void) | |||
55 | printf(" -v <v>\tSet variant\n"); | 55 | printf(" -v <v>\tSet variant\n"); |
56 | printf(" -x\t\tDump device informations\n"); | 56 | printf(" -x\t\tDump device informations\n"); |
57 | printf(" -w\tExtract the original firmware\n"); | 57 | printf(" -w\tExtract the original firmware\n"); |
58 | printf(" -p <ver>\tForce product and component version\n"); | ||
58 | printf("Supported variants: (default is standard)\n"); | 59 | printf("Supported variants: (default is standard)\n"); |
59 | printf(" "); | 60 | printf(" "); |
60 | for(size_t i = 0; i < NR_VARIANTS; i++) | 61 | for(size_t i = 0; i < NR_VARIANTS; i++) |
@@ -77,6 +78,7 @@ int main(int argc, char *argv[]) | |||
77 | enum imx_output_type_t type = IMX_DUALBOOT; | 78 | enum imx_output_type_t type = IMX_DUALBOOT; |
78 | bool debug = false; | 79 | bool debug = false; |
79 | bool extract_of = false; | 80 | bool extract_of = false; |
81 | const char *force_version = NULL; | ||
80 | 82 | ||
81 | if(argc == 1) | 83 | if(argc == 1) |
82 | usage(); | 84 | usage(); |
@@ -96,7 +98,7 @@ int main(int argc, char *argv[]) | |||
96 | {0, 0, 0, 0} | 98 | {0, 0, 0, 0} |
97 | }; | 99 | }; |
98 | 100 | ||
99 | int c = getopt_long(argc, argv, "?di:o:b:t:v:xw", long_options, NULL); | 101 | int c = getopt_long(argc, argv, "?di:o:b:t:v:xwp:", long_options, NULL); |
100 | if(c == -1) | 102 | if(c == -1) |
101 | break; | 103 | break; |
102 | switch(c) | 104 | switch(c) |
@@ -156,6 +158,9 @@ int main(int argc, char *argv[]) | |||
156 | case 'w': | 158 | case 'w': |
157 | extract_of = true; | 159 | extract_of = true; |
158 | break; | 160 | break; |
161 | case 'p': | ||
162 | force_version = optarg; | ||
163 | break; | ||
159 | default: | 164 | default: |
160 | abort(); | 165 | abort(); |
161 | } | 166 | } |
@@ -194,6 +199,7 @@ int main(int argc, char *argv[]) | |||
194 | opt.debug = debug; | 199 | opt.debug = debug; |
195 | opt.output = type; | 200 | opt.output = type; |
196 | opt.fw_variant = variant; | 201 | opt.fw_variant = variant; |
202 | opt.force_version = force_version; | ||
197 | enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt); | 203 | enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt); |
198 | printf("Result: %d\n", err); | 204 | printf("Result: %d\n", err); |
199 | return 0; | 205 | return 0; |
diff --git a/rbutil/mkimxboot/mkimxboot.c b/rbutil/mkimxboot/mkimxboot.c index 7a9d05fe69..d420afce5d 100644 --- a/rbutil/mkimxboot/mkimxboot.c +++ b/rbutil/mkimxboot/mkimxboot.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <stdarg.h> | 23 | #include <stdarg.h> |
24 | #include <string.h> | ||
25 | #include <ctype.h> | ||
24 | #include "mkimxboot.h" | 26 | #include "mkimxboot.h" |
25 | #include "sb.h" | 27 | #include "sb.h" |
26 | #include "dualboot.h" | 28 | #include "dualboot.h" |
@@ -279,10 +281,62 @@ static enum imx_error_t patch_std_zero_host_play(int jump_before, int model, | |||
279 | } | 281 | } |
280 | } | 282 | } |
281 | 283 | ||
284 | static enum imx_error_t parse_subversion(const char *s, const char *end, uint16_t *ver) | ||
285 | { | ||
286 | int len = (end == NULL) ? strlen(s) : end - s; | ||
287 | if(len > 4) | ||
288 | { | ||
289 | printf("[ERR] Bad subversion override '%s' (too long)\n", s); | ||
290 | return IMX_ERROR; | ||
291 | } | ||
292 | *ver = 0; | ||
293 | for(int i = 0; i < len; i++) | ||
294 | { | ||
295 | if(!isdigit(s[i])) | ||
296 | { | ||
297 | printf("[ERR] Bad subversion override '%s' (not a digit)\n", s); | ||
298 | return IMX_ERROR; | ||
299 | } | ||
300 | *ver = *ver << 4 | (s[i] - '0'); | ||
301 | } | ||
302 | return IMX_SUCCESS; | ||
303 | } | ||
304 | |||
305 | static enum imx_error_t parse_version(const char *s, struct sb_version_t *ver) | ||
306 | { | ||
307 | const char *dot1 = strchr(s, '.'); | ||
308 | if(dot1 == NULL) | ||
309 | { | ||
310 | printf("[ERR] Bad version override '%s' (missing dot)\n", s); | ||
311 | return IMX_ERROR; | ||
312 | } | ||
313 | const char *dot2 = strchr(dot1 + 1, '.'); | ||
314 | if(dot2 == NULL) | ||
315 | { | ||
316 | printf("[ERR] Bad version override '%s' (missing second dot)\n", s); | ||
317 | return IMX_ERROR; | ||
318 | } | ||
319 | enum imx_error_t ret = parse_subversion(s, dot1, &ver->major); | ||
320 | if(ret != IMX_SUCCESS) return ret; | ||
321 | ret = parse_subversion(dot1 + 1, dot2, &ver->minor); | ||
322 | if(ret != IMX_SUCCESS) return ret; | ||
323 | ret = parse_subversion(dot2 + 1, NULL, &ver->revision); | ||
324 | if(ret != IMX_SUCCESS) return ret; | ||
325 | return IMX_SUCCESS; | ||
326 | } | ||
327 | |||
282 | static enum imx_error_t patch_firmware(enum imx_model_t model, | 328 | static enum imx_error_t patch_firmware(enum imx_model_t model, |
283 | enum imx_firmware_variant_t variant, enum imx_output_type_t type, | 329 | enum imx_firmware_variant_t variant, enum imx_output_type_t type, |
284 | struct sb_file_t *sb_file, void *boot, size_t boot_sz) | 330 | struct sb_file_t *sb_file, void *boot, size_t boot_sz, |
331 | const char *force_version) | ||
285 | { | 332 | { |
333 | if(force_version) | ||
334 | { | ||
335 | enum imx_error_t err = parse_version(force_version, &sb_file->product_ver); | ||
336 | if(err != IMX_SUCCESS) return err; | ||
337 | err = parse_version(force_version, &sb_file->component_ver); | ||
338 | if(err != IMX_SUCCESS) return err; | ||
339 | } | ||
286 | switch(model) | 340 | switch(model) |
287 | { | 341 | { |
288 | case MODEL_FUZEPLUS: | 342 | case MODEL_FUZEPLUS: |
@@ -511,7 +565,8 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile, | |||
511 | } | 565 | } |
512 | }while(0); | 566 | }while(0); |
513 | /* produce file */ | 567 | /* produce file */ |
514 | enum imx_error_t ret = patch_firmware(model, opt.fw_variant, opt.output, sb_file, boot + 8, boot_size - 8); | 568 | enum imx_error_t ret = patch_firmware(model, opt.fw_variant, opt.output, |
569 | sb_file, boot + 8, boot_size - 8, opt.force_version); | ||
515 | if(ret == IMX_SUCCESS) | 570 | if(ret == IMX_SUCCESS) |
516 | ret = sb_write_file(sb_file, outfile); | 571 | ret = sb_write_file(sb_file, outfile); |
517 | 572 | ||
diff --git a/rbutil/mkimxboot/mkimxboot.h b/rbutil/mkimxboot/mkimxboot.h index 9551b11f4c..748742f523 100644 --- a/rbutil/mkimxboot/mkimxboot.h +++ b/rbutil/mkimxboot/mkimxboot.h | |||
@@ -83,6 +83,7 @@ struct imx_option_t | |||
83 | bool debug; | 83 | bool debug; |
84 | enum imx_output_type_t output; | 84 | enum imx_output_type_t output; |
85 | enum imx_firmware_variant_t fw_variant; | 85 | enum imx_firmware_variant_t fw_variant; |
86 | const char *force_version; // set to NULL to ignore | ||
86 | }; | 87 | }; |
87 | 88 | ||
88 | void dump_imx_dev_info(const char *prefix); | 89 | void dump_imx_dev_info(const char *prefix); |
diff --git a/rbutil/rbutilqt/base/bootloaderinstallimx.cpp b/rbutil/rbutilqt/base/bootloaderinstallimx.cpp index c085b30346..e12849e856 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallimx.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallimx.cpp | |||
@@ -47,6 +47,7 @@ void BootloaderThreadImx::run(void) | |||
47 | { | 47 | { |
48 | qDebug() << "[BootloaderThreadImx] Thread started."; | 48 | qDebug() << "[BootloaderThreadImx] Thread started."; |
49 | struct imx_option_t opt; | 49 | struct imx_option_t opt; |
50 | memset(&opt, 0, sizeof(opt)); | ||
50 | opt.debug = false; | 51 | opt.debug = false; |
51 | opt.output = IMX_DUALBOOT; | 52 | opt.output = IMX_DUALBOOT; |
52 | opt.fw_variant = VARIANT_DEFAULT; | 53 | opt.fw_variant = VARIANT_DEFAULT; |