summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 13:55:33 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:10:52 +0200
commite09c1e3d43665d04ae0ce2f288ba695b5abc3622 (patch)
tree7b89d6f4aabb847002004a65686b363859af0a33
parentb62ec2ba809f093f299111cf263ce51ca4d4a665 (diff)
downloadrockbox-e09c1e3d43665d04ae0ce2f288ba695b5abc3622.tar.gz
rockbox-e09c1e3d43665d04ae0ce2f288ba695b5abc3622.zip
mkimxboot: add support for more target and variants
Add creative zen x-fi 2/3 and add a variant mechanism Change-Id: Ic2ee82a4238a87c2eb5d72b8309650d9a280325f
-rw-r--r--rbutil/mkimxboot/Makefile2
-rw-r--r--rbutil/mkimxboot/dualboot.c10
-rw-r--r--rbutil/mkimxboot/dualboot.h2
-rw-r--r--rbutil/mkimxboot/dualboot/Makefile10
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.S20
-rw-r--r--rbutil/mkimxboot/main.c56
-rw-r--r--rbutil/mkimxboot/mkimxboot.c134
-rw-r--r--rbutil/mkimxboot/mkimxboot.h29
8 files changed, 228 insertions, 35 deletions
diff --git a/rbutil/mkimxboot/Makefile b/rbutil/mkimxboot/Makefile
index 942ceb9ca7..41581c312d 100644
--- a/rbutil/mkimxboot/Makefile
+++ b/rbutil/mkimxboot/Makefile
@@ -8,7 +8,7 @@
8# We use the SB code available in the Rockbox utils/sbtools directory 8# We use the SB code available in the Rockbox utils/sbtools directory
9IMXTOOLS_DIR=../../utils/imxtools/ 9IMXTOOLS_DIR=../../utils/imxtools/
10CFLAGS += -I$(IMXTOOLS_DIR) -Wall 10CFLAGS += -I$(IMXTOOLS_DIR) -Wall
11CFLAGS += -std=c99 11CFLAGS += -std=c99 -g
12 12
13OUTPUT = mkimxboot 13OUTPUT = mkimxboot
14 14
diff --git a/rbutil/mkimxboot/dualboot.c b/rbutil/mkimxboot/dualboot.c
index 67ab56d302..29e18eddf7 100644
--- a/rbutil/mkimxboot/dualboot.c
+++ b/rbutil/mkimxboot/dualboot.c
@@ -14,3 +14,13 @@ unsigned char dualboot_fuzeplus[152] = {
14 0x10, 0x86, 0x01, 0x80, 0xc0, 0x40, 0x04, 0x80, 0x70, 0x64, 0x08, 0x00, 0x80, 0x1a, 0x06, 0x00, 14 0x10, 0x86, 0x01, 0x80, 0xc0, 0x40, 0x04, 0x80, 0x70, 0x64, 0x08, 0x00, 0x80, 0x1a, 0x06, 0x00,
15 0x00, 0x41, 0x04, 0x80, 0x01, 0x00, 0x77, 0x3e 15 0x00, 0x41, 0x04, 0x80, 0x01, 0x00, 0x77, 0x3e
16}; 16};
17unsigned char dualboot_zenxfi2[36] = {
18 0x18, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x01, 0x09, 0x12, 0xe3, 0x00, 0x00, 0xa0, 0x03,
19 0x1e, 0xff, 0x2f, 0x01, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 0x1e, 0xff, 0x2f, 0xe1,
20 0x00, 0x86, 0x01, 0x80
21};
22unsigned char dualboot_zenxfi3[36] = {
23 0x18, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x80, 0x00, 0x12, 0xe3, 0x00, 0x00, 0xa0, 0x03,
24 0x1e, 0xff, 0x2f, 0x01, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 0x1e, 0xff, 0x2f, 0xe1,
25 0x20, 0x86, 0x01, 0x80
26};
diff --git a/rbutil/mkimxboot/dualboot.h b/rbutil/mkimxboot/dualboot.h
index 78efb8170d..272e257996 100644
--- a/rbutil/mkimxboot/dualboot.h
+++ b/rbutil/mkimxboot/dualboot.h
@@ -1,3 +1,5 @@
1/* Generated by bin2c */ 1/* Generated by bin2c */
2 2
3extern unsigned char dualboot_fuzeplus[152]; 3extern unsigned char dualboot_fuzeplus[152];
4extern unsigned char dualboot_zenxfi2[36];
5extern unsigned char dualboot_zenxfi3[36];
diff --git a/rbutil/mkimxboot/dualboot/Makefile b/rbutil/mkimxboot/dualboot/Makefile
index fa5f341b6d..6386b7c622 100644
--- a/rbutil/mkimxboot/dualboot/Makefile
+++ b/rbutil/mkimxboot/dualboot/Makefile
@@ -4,8 +4,8 @@ CROSS_PREFIX=arm-elf-eabi
4# adding a new target. mkimxboot.c also needs to be edited to refer to these 4# adding a new target. mkimxboot.c also needs to be edited to refer to these
5# new images. 5# new images.
6 6
7BOOTOBJS = dualboot_fuzeplus.o 7BOOTOBJS = dualboot_fuzeplus.o dualboot_zenxfi2.o dualboot_zenxfi3.o
8BOOTBINS = dualboot_fuzeplus.arm-bin 8BOOTBINS = dualboot_fuzeplus.arm-bin dualboot_zenxfi2.arm-bin dualboot_zenxfi3.arm-bin
9 9
10all: ../dualboot.h ../dualboot.c 10all: ../dualboot.h ../dualboot.c
11 11
@@ -14,6 +14,12 @@ all: ../dualboot.h ../dualboot.c
14dualboot_fuzeplus.o: dualboot.S 14dualboot_fuzeplus.o: dualboot.S
15 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DSANSA_FUZEPLUS -c -o dualboot_fuzeplus.o dualboot.S 15 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DSANSA_FUZEPLUS -c -o dualboot_fuzeplus.o dualboot.S
16 16
17dualboot_zenxfi2.o: dualboot.S
18 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DCREATIVE_ZENXFI2 -c -o dualboot_zenxfi2.o dualboot.S
19
20dualboot_zenxfi3.o: dualboot.S
21 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DCREATIVE_ZENXFI3 -c -o dualboot_zenxfi3.o dualboot.S
22
17# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract 23# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract
18# the binary code and finally convert to .h for building in mkamsboot 24# the binary code and finally convert to .h for building in mkamsboot
19 25
diff --git a/rbutil/mkimxboot/dualboot/dualboot.S b/rbutil/mkimxboot/dualboot/dualboot.S
index 4002167929..ed91012199 100644
--- a/rbutil/mkimxboot/dualboot/dualboot.S
+++ b/rbutil/mkimxboot/dualboot/dualboot.S
@@ -65,6 +65,26 @@ power_down:
65 ldr r1, =0x3E770001 @ unlock key + power down 65 ldr r1, =0x3E770001 @ unlock key + power down
66 str r1, [r0] 66 str r1, [r0]
67 b power_down 67 b power_down
68#elif defined(CREATIVE_ZENXFI2)
69 /* If select key is hold, return so that the OF can boot */
70 ldr r2, =0x80018600 @ HW_PINCTRL_DIN0
71 ldr r2, [r2]
72 tst r2, #0x4000 @ bit 14, active low
73 moveq r0, #0 @ return 0, continue boot
74 bxeq lr
75 str r0, [r1]
76 mov r0, #1
77 bx lr
78#elif defined(CREATIVE_ZENXFI3)
79 /* If volume down key is hold, return so that the OF can boot */
80 ldr r2, =0x80018620 @ HW_PINCTRL_DIN2
81 ldr r2, [r2]
82 tst r2, #0x80 @ bit 7, active low
83 moveq r0, #0 @ return 0, continue boot
84 bxeq lr
85 str r0, [r1]
86 mov r0, #1
87 bx lr
68#else 88#else
69#error No target defined ! 89#error No target defined !
70#endif 90#endif
diff --git a/rbutil/mkimxboot/main.c b/rbutil/mkimxboot/main.c
index 95fc226db1..68387c25c0 100644
--- a/rbutil/mkimxboot/main.c
+++ b/rbutil/mkimxboot/main.c
@@ -25,6 +25,22 @@
25#include <string.h> 25#include <string.h>
26#include "mkimxboot.h" 26#include "mkimxboot.h"
27 27
28struct imx_variant_t
29{
30 const char *name;
31 enum imx_firmware_variant_t variant;
32};
33
34struct imx_variant_t imx_variants[] =
35{
36 { "default", VARIANT_DEFAULT },
37 { "zenxfi2-recovery", VARIANT_ZENXFI2_RECOVERY },
38 { "zenxfi2-nand", VARIANT_ZENXFI2_NAND },
39 { "zenxfi2-sd", VARIANT_ZENXFI2_SD },
40};
41
42#define NR_VARIANTS sizeof(imx_variants) / sizeof(imx_variants[0])
43
28static void usage(void) 44static void usage(void)
29{ 45{
30 printf("Usage: elftosb [options | file]...\n"); 46 printf("Usage: elftosb [options | file]...\n");
@@ -35,6 +51,17 @@ static void usage(void)
35 printf(" -b <file>\tSet boot file\n"); 51 printf(" -b <file>\tSet boot file\n");
36 printf(" -d/--debug\tEnable debug output\n"); 52 printf(" -d/--debug\tEnable debug output\n");
37 printf(" -t <type>\tSet type (dualboot, singleboot, recovery)\n"); 53 printf(" -t <type>\tSet type (dualboot, singleboot, recovery)\n");
54 printf(" -v <v>\tSet variant\n");
55 printf(" -x\t\tDump device informations\n");
56 printf("Supported variants: (default is standard)\n");
57 printf(" ");
58 for(size_t i = 0; i < NR_VARIANTS; i++)
59 {
60 if(i != 0)
61 printf(", ");
62 printf("%s", imx_variants[i].name);
63 }
64 printf("\n");
38 printf("By default a dualboot image is built\n"); 65 printf("By default a dualboot image is built\n");
39 exit(1); 66 exit(1);
40} 67}
@@ -44,6 +71,7 @@ int main(int argc, char *argv[])
44 char *infile = NULL; 71 char *infile = NULL;
45 char *outfile = NULL; 72 char *outfile = NULL;
46 char *bootfile = NULL; 73 char *bootfile = NULL;
74 enum imx_firmware_variant_t variant = VARIANT_DEFAULT;
47 enum imx_output_type_t type = IMX_DUALBOOT; 75 enum imx_output_type_t type = IMX_DUALBOOT;
48 bool debug = false; 76 bool debug = false;
49 77
@@ -60,10 +88,12 @@ int main(int argc, char *argv[])
60 {"boot-file", required_argument, 0, 'b'}, 88 {"boot-file", required_argument, 0, 'b'},
61 {"debug", no_argument, 0, 'd'}, 89 {"debug", no_argument, 0, 'd'},
62 {"type", required_argument, 0, 't'}, 90 {"type", required_argument, 0, 't'},
91 {"variant", required_argument, 0, 'v'},
92 {"dev-info", no_argument, 0, 'x'},
63 {0, 0, 0, 0} 93 {0, 0, 0, 0}
64 }; 94 };
65 95
66 int c = getopt_long(argc, argv, "?di:o:b:t:", long_options, NULL); 96 int c = getopt_long(argc, argv, "?di:o:b:t:v:x", long_options, NULL);
67 if(c == -1) 97 if(c == -1)
68 break; 98 break;
69 switch(c) 99 switch(c)
@@ -98,6 +128,28 @@ int main(int argc, char *argv[])
98 return 1; 128 return 1;
99 } 129 }
100 break; 130 break;
131 case 'v':
132 {
133 for(size_t i = 0; i < NR_VARIANTS; i++)
134 {
135 if(strcmp(optarg, imx_variants[i].name) == 0)
136 {
137 variant = imx_variants[i].variant;
138 goto Lok;
139 }
140 }
141 printf("Invalid variant '%s'\n", optarg);
142 return 1;
143
144 Lok:
145 break;
146 }
147 case 'x':
148 dump_imx_dev_info("");
149 printf("variant mapping:\n");
150 for(int i = 0; i < sizeof(imx_variants) / sizeof(imx_variants[0]); i++)
151 printf(" %s -> variant=%d\n", imx_variants[i].name, imx_variants[i].variant);
152 break;
101 default: 153 default:
102 abort(); 154 abort();
103 } 155 }
@@ -125,8 +177,10 @@ int main(int argc, char *argv[])
125 } 177 }
126 178
127 struct imx_option_t opt; 179 struct imx_option_t opt;
180 memset(&opt, 0, sizeof(opt));
128 opt.debug = debug; 181 opt.debug = debug;
129 opt.output = type; 182 opt.output = type;
183 opt.fw_variant = variant;
130 enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt); 184 enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt);
131 printf("Result: %d\n", err); 185 printf("Result: %d\n", err);
132 return 0; 186 return 0;
diff --git a/rbutil/mkimxboot/mkimxboot.c b/rbutil/mkimxboot/mkimxboot.c
index 6f90924c9a..8806167078 100644
--- a/rbutil/mkimxboot/mkimxboot.c
+++ b/rbutil/mkimxboot/mkimxboot.c
@@ -26,20 +26,22 @@
26#include "dualboot.h" 26#include "dualboot.h"
27#include "md5.h" 27#include "md5.h"
28 28
29/* Supported models */ 29struct imx_fw_variant_desc_t
30enum imx_model_t
31{ 30{
32 MODEL_UNKNOWN = -1, 31 /* Offset within file */
33 MODEL_FUZEPLUS = 0, 32 size_t offset;
34 /* new models go here */ 33 /* Total size of the firmware */
35 34 size_t size;
36 NUM_MODELS
37}; 35};
38 36
39struct imx_md5sum_t 37struct imx_md5sum_t
40{ 38{
41 int model; 39 /* Device model */
40 enum imx_model_t model;
41 /* md5sum of the file */
42 char *md5sum; 42 char *md5sum;
43 /* Variant descriptions */
44 struct imx_fw_variant_desc_t fw_variants[VARIANT_COUNT];
43}; 45};
44 46
45struct imx_model_desc_t 47struct imx_model_desc_t
@@ -66,9 +68,38 @@ struct imx_model_desc_t
66 uint32_t bootloader_addr; 68 uint32_t bootloader_addr;
67}; 69};
68 70
71static const char *imx_fw_variant[] =
72{
73 [VARIANT_DEFAULT] = "default",
74 [VARIANT_ZENXFI2_RECOVERY] = "ZEN X-Fi2 Recovery",
75 [VARIANT_ZENXFI2_NAND] = "ZEN X-Fi2 NAND",
76 [VARIANT_ZENXFI2_SD] = "ZEN X-Fi2 eMMC/SD",
77};
78
69static const struct imx_md5sum_t imx_sums[] = 79static const struct imx_md5sum_t imx_sums[] =
70{ 80{
71 { MODEL_FUZEPLUS, "c3e27620a877dc6b200b97dcb3e0ecc7" }, /* Version 2.38.6 */ 81 {
82 /* Version 2.38.6 */
83 MODEL_FUZEPLUS, "c3e27620a877dc6b200b97dcb3e0ecc7",
84 { [VARIANT_DEFAULT] = { 0, 34652624 } }
85 },
86 {
87 /* Version 1.23.01e */
88 MODEL_ZENXFI2, "e37e2c24abdff8e624d0a29f79157850",
89 },
90 {
91 /* Version 1.23.01e */
92 MODEL_ZENXFI2, "2beff2168212d332f13cfc36ca46989d",
93 { [VARIANT_ZENXFI2_RECOVERY] = { 0x93010, 684192},
94 [VARIANT_ZENXFI2_NAND] = { 0x13a0b0, 42410704 },
95 [VARIANT_ZENXFI2_SD] = { 0x29ac380, 42304208 }
96 }
97 },
98 {
99 /* Version 1.00.22e */
100 MODEL_ZENXFI3, "658a24eeef5f7186ca731085d8822a87",
101 { [VARIANT_DEFAULT] = {0, 18110576} }
102 },
72}; 103};
73 104
74static struct crypto_key_t zero_key = 105static struct crypto_key_t zero_key =
@@ -79,8 +110,12 @@ static struct crypto_key_t zero_key =
79 110
80static const struct imx_model_desc_t imx_models[] = 111static const struct imx_model_desc_t imx_models[] =
81{ 112{
82 [MODEL_FUZEPLUS] = { "Fuze+", dualboot_fuzeplus, sizeof(dualboot_fuzeplus), "fuz+", 72, 113 [MODEL_FUZEPLUS] = { "Fuze+", dualboot_fuzeplus, sizeof(dualboot_fuzeplus), "fuz+", 72,
83 1, &zero_key, 0, 0x40000000 }, 114 1, &zero_key, 0, 0x40000000 },
115 [MODEL_ZENXFI2] = {"Zen X-Fi2", dualboot_zenxfi2, sizeof(dualboot_zenxfi2), "zxf2", 82,
116 1, &zero_key, 0, 0x40000000 },
117 [MODEL_ZENXFI3] = {"Zen X-Fi3", dualboot_zenxfi3, sizeof(dualboot_zenxfi3), "zxf3", 83,
118 1, &zero_key, 0, 0x40000000 },
84}; 119};
85 120
86#define NR_IMX_SUMS (sizeof(imx_sums) / sizeof(imx_sums[0])) 121#define NR_IMX_SUMS (sizeof(imx_sums) / sizeof(imx_sums[0]))
@@ -212,7 +247,8 @@ static enum imx_error_t patch_std_zero_host_play(int jump_before, int model,
212 } 247 }
213} 248}
214 249
215static enum imx_error_t patch_firmware(int model, enum imx_output_type_t type, 250static enum imx_error_t patch_firmware(enum imx_model_t model,
251 enum imx_firmware_variant_t variant, enum imx_output_type_t type,
216 struct sb_file_t *sb_file, void *boot, size_t boot_sz) 252 struct sb_file_t *sb_file, void *boot, size_t boot_sz)
217{ 253{
218 switch(model) 254 switch(model)
@@ -221,6 +257,23 @@ static enum imx_error_t patch_firmware(int model, enum imx_output_type_t type,
221 /* The Fuze+ uses the standard ____, host, play sections, patch after third 257 /* The Fuze+ uses the standard ____, host, play sections, patch after third
222 * call in ____ section */ 258 * call in ____ section */
223 return patch_std_zero_host_play(3, model, type, sb_file, boot, boot_sz); 259 return patch_std_zero_host_play(3, model, type, sb_file, boot, boot_sz);
260 case MODEL_ZENXFI3:
261 /* The ZEN X-Fi3 uses the standard ____, hSst, pSay sections, patch after third
262 * call in ____ section. Although sections names use the S variant, they are standard. */
263 return patch_std_zero_host_play(3, model, type, sb_file, boot, boot_sz);
264 case MODEL_ZENXFI2:
265 /* The ZEN X-Fi2 has two types of firmware: recovery and normal.
266 * Normal uses the standard ___, host, play sections and recovery only ____ */
267 switch(variant)
268 {
269 case VARIANT_ZENXFI2_RECOVERY:
270 case VARIANT_ZENXFI2_NAND:
271 case VARIANT_ZENXFI2_SD:
272 return patch_std_zero_host_play(1, model, type, sb_file, boot, boot_sz);
273 default:
274 return IMX_DONT_KNOW_HOW_TO_PATCH;
275 }
276 break;
224 default: 277 default:
225 return IMX_DONT_KNOW_HOW_TO_PATCH; 278 return IMX_DONT_KNOW_HOW_TO_PATCH;
226 } 279 }
@@ -247,26 +300,38 @@ static uint32_t get_uint32be(unsigned char *p)
247 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 300 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
248} 301}
249 302
303void dump_imx_dev_info(const char *prefix)
304{
305 printf("%smkimxboot models:\n", prefix);
306 for(int i = 0; i < NR_IMX_MODELS; i++)
307 {
308 printf("%s %s: idx=%d rb_model=%s rb_num=%d\n", prefix,
309 imx_models[i].model_name, i, imx_models[i].rb_model_name,
310 imx_models[i].rb_model_num);
311 }
312 printf("%smkimxboot variants:\n", prefix);
313 for(int i = 0; i < VARIANT_COUNT; i++)
314 {
315 printf("%s %d: %s\n", prefix, i, imx_fw_variant[i]);
316 }
317 printf("%smkimxboot mapping:\n", prefix);
318 for(int i = 0; i < NR_IMX_SUMS; i++)
319 {
320 printf("%s md5sum=%s -> idx=%d\n", prefix, imx_sums[i].md5sum,
321 imx_sums[i].model);
322 for(int j = 0; j < VARIANT_COUNT; j++)
323 if(imx_sums[i].fw_variants[j].size)
324 printf("%s variant=%d -> offset=%#x size=%#x\n", prefix,
325 j, (unsigned)imx_sums[i].fw_variants[j].offset,
326 (unsigned)imx_sums[i].fw_variants[j].size);
327 }
328}
329
250enum imx_error_t mkimxboot(const char *infile, const char *bootfile, 330enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
251 const char *outfile, struct imx_option_t opt) 331 const char *outfile, struct imx_option_t opt)
252{ 332{
253 /* Dump tables */ 333 /* Dump tables */
254 do 334 dump_imx_dev_info("[INFO] ");
255 {
256 printf("[INFO] mkimxboot models:\n");
257 for(int i = 0; i < NR_IMX_MODELS; i++)
258 {
259 printf("[INFO] %s: idx=%d rb_model=%s rb_num=%d\n",
260 imx_models[i].model_name, i, imx_models[i].rb_model_name,
261 imx_models[i].rb_model_num);
262 }
263 printf("[INFO] mkimxboot mapping:\n");
264 for(int i = 0; i < NR_IMX_SUMS; i++)
265 {
266 printf("[INFO] md5sum=%s -> idx=%d\n", imx_sums[i].md5sum,
267 imx_sums[i].model);
268 }
269 }while(0);
270 /* compute MD5 sum of the file */ 335 /* compute MD5 sum of the file */
271 uint8_t file_md5sum[16]; 336 uint8_t file_md5sum[16];
272 do 337 do
@@ -298,7 +363,8 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
298 printf("[INFO] MD5 sum of the file: "); 363 printf("[INFO] MD5 sum of the file: ");
299 print_hex(file_md5sum, 16, true); 364 print_hex(file_md5sum, 16, true);
300 /* find model */ 365 /* find model */
301 int model; 366 enum imx_model_t model;
367 int md5_idx;
302 do 368 do
303 { 369 {
304 int i = 0; 370 int i = 0;
@@ -327,6 +393,7 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
327 return IMX_NO_MATCH; 393 return IMX_NO_MATCH;
328 } 394 }
329 model = imx_sums[i].model; 395 model = imx_sums[i].model;
396 md5_idx = i;
330 }while(0); 397 }while(0);
331 printf("[INFO] File is for model %d (%s)\n", model, imx_models[model].model_name); 398 printf("[INFO] File is for model %d (%s)\n", model, imx_models[model].model_name);
332 /* load rockbox file */ 399 /* load rockbox file */
@@ -385,11 +452,18 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
385 struct sb_file_t *sb_file; 452 struct sb_file_t *sb_file;
386 do 453 do
387 { 454 {
455 if(imx_sums[md5_idx].fw_variants[opt.fw_variant].size == 0)
456 {
457 printf("[ERR] Input file does not contain variant '%s'\n", imx_fw_variant[opt.fw_variant]);
458 free(boot);
459 return IMX_VARIANT_MISMATCH;
460 }
388 enum sb_error_t err; 461 enum sb_error_t err;
389 g_debug = opt.debug; 462 g_debug = opt.debug;
390 clear_keys(); 463 clear_keys();
391 add_keys(imx_models[model].keys, imx_models[model].nr_keys); 464 add_keys(imx_models[model].keys, imx_models[model].nr_keys);
392 sb_file = sb_read_file(infile, false, NULL, &imx_printf, &err); 465 sb_file = sb_read_file_ex(infile, imx_sums[md5_idx].fw_variants[opt.fw_variant].offset,
466 imx_sums[md5_idx].fw_variants[opt.fw_variant].size, false, NULL, &imx_printf, &err);
393 if(sb_file == NULL) 467 if(sb_file == NULL)
394 { 468 {
395 clear_keys(); 469 clear_keys();
@@ -398,7 +472,7 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
398 } 472 }
399 }while(0); 473 }while(0);
400 /* produce file */ 474 /* produce file */
401 enum imx_error_t ret = patch_firmware(model, opt.output, sb_file, boot + 8, boot_size - 8); 475 enum imx_error_t ret = patch_firmware(model, opt.fw_variant, opt.output, sb_file, boot + 8, boot_size - 8);
402 if(ret == IMX_SUCCESS) 476 if(ret == IMX_SUCCESS)
403 ret = sb_write_file(sb_file, outfile); 477 ret = sb_write_file(sb_file, outfile);
404 478
diff --git a/rbutil/mkimxboot/mkimxboot.h b/rbutil/mkimxboot/mkimxboot.h
index 4ee1ca20cf..5be87b31e0 100644
--- a/rbutil/mkimxboot/mkimxboot.h
+++ b/rbutil/mkimxboot/mkimxboot.h
@@ -40,7 +40,8 @@ enum imx_error_t
40 IMX_BOOT_MISMATCH = -6, 40 IMX_BOOT_MISMATCH = -6,
41 IMX_BOOT_CHECKSUM_ERROR = -7, 41 IMX_BOOT_CHECKSUM_ERROR = -7,
42 IMX_DONT_KNOW_HOW_TO_PATCH = -8, 42 IMX_DONT_KNOW_HOW_TO_PATCH = -8,
43 IMX_FIRST_SB_ERROR = -9, 43 IMX_VARIANT_MISMATCH = -9,
44 IMX_FIRST_SB_ERROR = -10,
44}; 45};
45 46
46enum imx_output_type_t 47enum imx_output_type_t
@@ -50,12 +51,38 @@ enum imx_output_type_t
50 IMX_SINGLEBOOT = 2, 51 IMX_SINGLEBOOT = 2,
51}; 52};
52 53
54/* Supported models */
55enum imx_model_t
56{
57 MODEL_UNKNOWN = -1,
58 MODEL_FUZEPLUS = 0,
59 MODEL_ZENXFI2 = 1,
60 MODEL_ZENXFI3 = 2,
61 /* new models go here */
62
63 NUM_MODELS
64};
65
66/* Supported firmware variants */
67enum imx_firmware_variant_t
68{
69 VARIANT_DEFAULT = 0,
70 /* For the Creative ZEN X-Fi2 */
71 VARIANT_ZENXFI2_NAND,
72 VARIANT_ZENXFI2_SD,
73 VARIANT_ZENXFI2_RECOVERY,
74 /* Last */
75 VARIANT_COUNT
76};
77
53struct imx_option_t 78struct imx_option_t
54{ 79{
55 bool debug; 80 bool debug;
56 enum imx_output_type_t output; 81 enum imx_output_type_t output;
82 enum imx_firmware_variant_t fw_variant;
57}; 83};
58 84
85void dump_imx_dev_info(const char *prefix);
59enum imx_error_t mkimxboot(const char *infile, const char *bootfile, 86enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
60 const char *outfile, struct imx_option_t opt); 87 const char *outfile, struct imx_option_t opt);
61 88