summaryrefslogtreecommitdiffstats
path: root/rbutil/mkimxboot
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-01-29 11:50:46 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2013-01-29 11:53:07 +0000
commit42a725f7ecd1e6779d24f1a66eb13652de467de9 (patch)
tree1727364077a26e2e77b1ac78a2160508c2c88395 /rbutil/mkimxboot
parentd73c20933b5a7428c8f30442a6e0b90b34ece291 (diff)
downloadrockbox-42a725f7ecd1e6779d24f1a66eb13652de467de9.tar.gz
rockbox-42a725f7ecd1e6779d24f1a66eb13652de467de9.tar.bz2
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/mkimxboot')
-rw-r--r--rbutil/mkimxboot/main.c8
-rw-r--r--rbutil/mkimxboot/mkimxboot.c59
-rw-r--r--rbutil/mkimxboot/mkimxboot.h1
3 files changed, 65 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)
printf(" -v <v>\tSet variant\n");
printf(" -x\t\tDump device informations\n");
printf(" -w\tExtract the original firmware\n");
+ printf(" -p <ver>\tForce product and component version\n");
printf("Supported variants: (default is standard)\n");
printf(" ");
for(size_t i = 0; i < NR_VARIANTS; i++)
@@ -77,6 +78,7 @@ int main(int argc, char *argv[])
enum imx_output_type_t type = IMX_DUALBOOT;
bool debug = false;
bool extract_of = false;
+ const char *force_version = NULL;
if(argc == 1)
usage();
@@ -96,7 +98,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0}
};
- int c = getopt_long(argc, argv, "?di:o:b:t:v:xw", long_options, NULL);
+ int c = getopt_long(argc, argv, "?di:o:b:t:v:xwp:", long_options, NULL);
if(c == -1)
break;
switch(c)
@@ -156,6 +158,9 @@ int main(int argc, char *argv[])
case 'w':
extract_of = true;
break;
+ case 'p':
+ force_version = optarg;
+ break;
default:
abort();
}
@@ -194,6 +199,7 @@ int main(int argc, char *argv[])
opt.debug = debug;
opt.output = type;
opt.fw_variant = variant;
+ opt.force_version = force_version;
enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt);
printf("Result: %d\n", err);
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 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
#include "mkimxboot.h"
#include "sb.h"
#include "dualboot.h"
@@ -279,10 +281,62 @@ static enum imx_error_t patch_std_zero_host_play(int jump_before, int model,
}
}
+static enum imx_error_t parse_subversion(const char *s, const char *end, uint16_t *ver)
+{
+ int len = (end == NULL) ? strlen(s) : end - s;
+ if(len > 4)
+ {
+ printf("[ERR] Bad subversion override '%s' (too long)\n", s);
+ return IMX_ERROR;
+ }
+ *ver = 0;
+ for(int i = 0; i < len; i++)
+ {
+ if(!isdigit(s[i]))
+ {
+ printf("[ERR] Bad subversion override '%s' (not a digit)\n", s);
+ return IMX_ERROR;
+ }
+ *ver = *ver << 4 | (s[i] - '0');
+ }
+ return IMX_SUCCESS;
+}
+
+static enum imx_error_t parse_version(const char *s, struct sb_version_t *ver)
+{
+ const char *dot1 = strchr(s, '.');
+ if(dot1 == NULL)
+ {
+ printf("[ERR] Bad version override '%s' (missing dot)\n", s);
+ return IMX_ERROR;
+ }
+ const char *dot2 = strchr(dot1 + 1, '.');
+ if(dot2 == NULL)
+ {
+ printf("[ERR] Bad version override '%s' (missing second dot)\n", s);
+ return IMX_ERROR;
+ }
+ enum imx_error_t ret = parse_subversion(s, dot1, &ver->major);
+ if(ret != IMX_SUCCESS) return ret;
+ ret = parse_subversion(dot1 + 1, dot2, &ver->minor);
+ if(ret != IMX_SUCCESS) return ret;
+ ret = parse_subversion(dot2 + 1, NULL, &ver->revision);
+ if(ret != IMX_SUCCESS) return ret;
+ return IMX_SUCCESS;
+}
+
static enum imx_error_t patch_firmware(enum imx_model_t model,
enum imx_firmware_variant_t variant, enum imx_output_type_t type,
- struct sb_file_t *sb_file, void *boot, size_t boot_sz)
+ struct sb_file_t *sb_file, void *boot, size_t boot_sz,
+ const char *force_version)
{
+ if(force_version)
+ {
+ enum imx_error_t err = parse_version(force_version, &sb_file->product_ver);
+ if(err != IMX_SUCCESS) return err;
+ err = parse_version(force_version, &sb_file->component_ver);
+ if(err != IMX_SUCCESS) return err;
+ }
switch(model)
{
case MODEL_FUZEPLUS:
@@ -511,7 +565,8 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
}
}while(0);
/* produce file */
- enum imx_error_t ret = patch_firmware(model, opt.fw_variant, opt.output, sb_file, boot + 8, boot_size - 8);
+ enum imx_error_t ret = patch_firmware(model, opt.fw_variant, opt.output,
+ sb_file, boot + 8, boot_size - 8, opt.force_version);
if(ret == IMX_SUCCESS)
ret = sb_write_file(sb_file, outfile);
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
bool debug;
enum imx_output_type_t output;
enum imx_firmware_variant_t fw_variant;
+ const char *force_version; // set to NULL to ignore
};
void dump_imx_dev_info(const char *prefix);