summaryrefslogtreecommitdiff
path: root/rbutil/mkimxboot/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/mkimxboot/main.c')
-rw-r--r--rbutil/mkimxboot/main.c86
1 files changed, 85 insertions, 1 deletions
diff --git a/rbutil/mkimxboot/main.c b/rbutil/mkimxboot/main.c
index bcc443d7f2..611715f7c1 100644
--- a/rbutil/mkimxboot/main.c
+++ b/rbutil/mkimxboot/main.c
@@ -43,6 +43,26 @@ static struct imx_variant_t imx_variants[] =
43 43
44#define NR_VARIANTS sizeof(imx_variants) / sizeof(imx_variants[0]) 44#define NR_VARIANTS sizeof(imx_variants) / sizeof(imx_variants[0])
45 45
46struct model_t
47{
48 const char *name;
49 enum imx_model_t model;
50};
51
52struct model_t imx_models[] =
53{
54 { "unknown", MODEL_UNKNOWN },
55 { "fuzeplus", MODEL_FUZEPLUS },
56 { "zenxfi2", MODEL_ZENXFI2 },
57 { "zenxfi3", MODEL_ZENXFI3 },
58 { "zenxfistyle", MODEL_ZENXFISTYLE },
59 { "zenstyle", MODEL_ZENSTYLE },
60 { "nwze370", MODEL_NWZE370 },
61 { "nwze360", MODEL_NWZE360 },
62};
63
64#define NR_MODELS sizeof(imx_models) / sizeof(imx_models[0])
65
46static void usage(void) 66static void usage(void)
47{ 67{
48 printf("Usage: mkimxboot [options | file]...\n"); 68 printf("Usage: mkimxboot [options | file]...\n");
@@ -57,6 +77,8 @@ static void usage(void)
57 printf(" -x Dump device informations\n"); 77 printf(" -x Dump device informations\n");
58 printf(" -w Extract the original firmware\n"); 78 printf(" -w Extract the original firmware\n");
59 printf(" -p <ver> Force product and component version\n"); 79 printf(" -p <ver> Force product and component version\n");
80 printf(" -5 <type> Compute <type> MD5 sum of the input file\n");
81 printf(" -m <model> Specify model (useful for soft MD5 sum)\n");
60 printf("Supported variants: (default is standard)\n"); 82 printf("Supported variants: (default is standard)\n");
61 printf(" "); 83 printf(" ");
62 for(size_t i = 0; i < NR_VARIANTS; i++) 84 for(size_t i = 0; i < NR_VARIANTS; i++)
@@ -66,15 +88,51 @@ static void usage(void)
66 printf("%s", imx_variants[i].name); 88 printf("%s", imx_variants[i].name);
67 } 89 }
68 printf("\n"); 90 printf("\n");
91 printf("Supported models: (default is unknown)\n");
92 for(size_t i = 0; i < NR_MODELS; i++)
93 {
94 if(i != 0)
95 printf(", ");
96 printf("%s", imx_models[i].name);
97 }
98 printf("\n");
69 printf("By default a dualboot image is built\n"); 99 printf("By default a dualboot image is built\n");
70 printf("This tools supports the following format for the boot file:\n"); 100 printf("This tools supports the following format for the boot file:\n");
71 printf("- rockbox scramble format\n"); 101 printf("- rockbox scramble format\n");
72 printf("- elf format\n"); 102 printf("- elf format\n");
73 printf("Additional checks will be performed on rockbox scramble format to\n"); 103 printf("Additional checks will be performed on rockbox scramble format to\n");
74 printf("ensure soundness of operation.\n"); 104 printf("ensure soundness of operation.\n");
105 printf("There are two types of MD5 sums: 'full' or 'soft'.\n");
106 printf("- full MD5 sum applies to the whole file\n");
107 printf("- soft MD5 sum for SB files accounts for relevant parts only\n");
75 exit(1); 108 exit(1);
76} 109}
77 110
111static int print_md5(const char *file, enum imx_model_t model, const char *type)
112{
113 uint8_t md5sum[16];
114 enum imx_error_t err;
115 if(strcmp(type, "full") == 0)
116 err = compute_md5sum(file, md5sum);
117 else if(strcmp(type, "soft") == 0)
118 err = compute_soft_md5sum(file, model, md5sum);
119 else
120 {
121 printf("Invalid md5sum type '%s'\n", type);
122 return 1;
123 }
124 if(err != IMX_SUCCESS)
125 {
126 printf("There was an error when computing the MD5 sum: %d\n", err);
127 return 2;
128 }
129 printf("%s MD5 sum: ", type);
130 for(int i = 0; i < 16; i++)
131 printf("%02x", md5sum[i]);
132 printf("\n");
133 return 0;
134}
135
78int main(int argc, char *argv[]) 136int main(int argc, char *argv[])
79{ 137{
80 char *infile = NULL; 138 char *infile = NULL;
@@ -82,8 +140,10 @@ int main(int argc, char *argv[])
82 char *bootfile = NULL; 140 char *bootfile = NULL;
83 enum imx_firmware_variant_t variant = VARIANT_DEFAULT; 141 enum imx_firmware_variant_t variant = VARIANT_DEFAULT;
84 enum imx_output_type_t type = IMX_DUALBOOT; 142 enum imx_output_type_t type = IMX_DUALBOOT;
143 enum imx_model_t model = MODEL_UNKNOWN;
85 bool debug = false; 144 bool debug = false;
86 bool extract_of = false; 145 bool extract_of = false;
146 const char *md5type = NULL;
87 const char *force_version = NULL; 147 const char *force_version = NULL;
88 148
89 if(argc == 1) 149 if(argc == 1)
@@ -101,10 +161,12 @@ int main(int argc, char *argv[])
101 {"type", required_argument, 0, 't'}, 161 {"type", required_argument, 0, 't'},
102 {"variant", required_argument, 0, 'v'}, 162 {"variant", required_argument, 0, 'v'},
103 {"dev-info", no_argument, 0, 'x'}, 163 {"dev-info", no_argument, 0, 'x'},
164 {"model", required_argument, 0, 'm'},
165 {"md5", required_argument, 0, '5'},
104 {0, 0, 0, 0} 166 {0, 0, 0, 0}
105 }; 167 };
106 168
107 int c = getopt_long(argc, argv, "?di:o:b:t:v:xwp:", long_options, NULL); 169 int c = getopt_long(argc, argv, "?di:o:b:t:v:xwp:m:5:", long_options, NULL);
108 if(c == -1) 170 if(c == -1)
109 break; 171 break;
110 switch(c) 172 switch(c)
@@ -167,6 +229,24 @@ int main(int argc, char *argv[])
167 case 'p': 229 case 'p':
168 force_version = optarg; 230 force_version = optarg;
169 break; 231 break;
232 case '5':
233 md5type = optarg;
234 break;
235 case 'm':
236 if(model != MODEL_UNKNOWN)
237 {
238 printf("You cannot specify two models\n");
239 return 1;
240 }
241 for(int i = 0; i < NR_MODELS; i++)
242 if(strcmp(optarg, imx_models[i].name) == 0)
243 {
244 model = imx_models[i].model;
245 break;
246 }
247 if(model == MODEL_UNKNOWN)
248 printf("Unknown model '%s'\n", optarg);
249 break;
170 default: 250 default:
171 abort(); 251 abort();
172 } 252 }
@@ -177,6 +257,10 @@ int main(int argc, char *argv[])
177 printf("You must specify an input file\n"); 257 printf("You must specify an input file\n");
178 return 1; 258 return 1;
179 } 259 }
260
261 if(md5type)
262 return print_md5(infile, md5type);
263
180 if(!outfile) 264 if(!outfile)
181 { 265 {
182 printf("You must specify an output file\n"); 266 printf("You must specify an output file\n");