usbd: remove yaffs related codes
[kernel/u-boot.git] / common / cmd_usbd.c
1 /*
2  * USB Downloader for SAMSUNG Platform
3  *
4  * Copyright (C) 2007-2008 Samsung Electronics
5  * Minkyu Kang <mk7.kang@samsung.com>
6  *
7  */
8
9 #include <common.h>
10 #include <usbd.h>
11 #include <asm/errno.h>
12 #include <malloc.h>
13
14 /* version of USB Downloader Application */
15 #define APP_VERSION     "1.6.0"
16
17 #define OPS_READ        0
18 #define OPS_WRITE       1
19
20 #ifdef CONFIG_CMD_MTDPARTS
21 #include <jffs2/load_kernel.h>
22 static struct part_info *parts[16];
23 #endif
24
25 #ifdef CONFIG_UBIFS_MK
26 #include <mkfs.ubifs.h>
27 #endif
28
29 #ifdef CONFIG_UBINIZE
30 #include <ubinize.h>
31 #endif
32
33 #include <mbr.h>
34
35 static const char pszMe[] = "usbd: ";
36
37 static struct usbd_ops usbd_ops;
38
39 static unsigned int part_id;
40 static unsigned int write_part = 0;
41 static unsigned int fs_offset = 0x0;
42
43 #define NAND_PAGE_SIZE 2048
44
45 static unsigned long down_ram_addr;
46
47 static int down_mode;
48
49 /* cpu/${CPU} dependent */
50 extern void do_reset(void);
51
52 /* common commands */
53 extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
54 extern int do_run(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
55
56 int mtdparts_init(void);
57 int find_dev_and_part(const char*, struct mtd_device**, u8*, struct part_info**);
58
59 /* common/cmd_jffs2.c */
60 extern struct list_head devices;
61
62 static u8 count_mtdparts(void)
63 {
64         struct list_head *dentry, *pentry;
65         struct mtd_device *dev;
66         u8 part_num = 0;
67
68         list_for_each(dentry, &devices) {
69                 dev = list_entry(dentry, struct mtd_device, link);
70
71                 /* list partitions for given device */
72                 list_for_each(pentry, &dev->parts)
73                         part_num++;
74         }
75
76         return part_num;
77 }
78
79 #ifdef CONFIG_CMD_UBI
80 static int check_ubi_mode(void)
81 {
82         char *env_ubifs;
83         int ubi_mode;
84
85         env_ubifs = getenv("ubi");
86         ubi_mode = !strcmp(env_ubifs, "enabled");
87
88         return ubi_mode;
89 }
90 #else
91 #define check_ubi_mode()                0
92 #endif
93
94 #ifdef CONFIG_MTD_PARTITIONS
95 static int get_part_info(void)
96 {
97         struct mtd_device *dev;
98         u8 out_partnum;
99         char part_name[12];
100         char nand_name[12];
101         int i;
102         int part_num;
103         int ubi_mode = 0;
104
105 #if defined(CONFIG_CMD_NAND)
106         sprintf(nand_name, "nand0");
107 #elif defined(CONFIG_CMD_ONENAND)
108         sprintf(nand_name, "onenand0");
109 #else
110         printf("Configure your NAND sub-system\n");
111         return 0;
112 #endif
113
114         if (mtdparts_init())
115                 return 0;
116
117         ubi_mode = check_ubi_mode();
118
119         part_num = count_mtdparts();
120         for (i = 0; i < part_num; i++) {
121                 sprintf(part_name, "%s,%d", nand_name, i);
122
123                 if (find_dev_and_part(part_name, &dev, &out_partnum, &parts[i]))
124                         return -EINVAL;
125         }
126
127         return 0;
128 }
129
130 static int get_part_id(char *name)
131 {
132         int nparts = count_mtdparts();
133         int i;
134
135         for (i = 0; i < nparts; i++) {
136                 if (strcmp(parts[i]->name, name) == 0)
137                         return i;
138         }
139
140         printf("Error: Unknown partition -> %s\n", name);
141         return -1;
142 }
143 #else
144 static int get_part_info(void)
145 {
146         printf("Error: Can't get patition information\n");
147         return -EINVAL;
148 }
149
150 static int get_part_id(char *name)
151 {
152         return 0;
153 }
154 #endif
155
156 static void boot_cmd(char *addr)
157 {
158         char *argv[] = { "bootm", addr };
159         do_bootm(NULL, 0, 2, argv);
160 }
161
162 #if defined(CONFIG_CMD_NAND)
163 extern int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
164 #elif defined(CONFIG_CMD_ONENAND)
165 extern int do_onenand(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
166 #endif
167
168 /* NAND erase and write using nand command */
169 static int nand_cmd(int type, char *p1, char *p2, char *p3)
170 {
171         int ret = 1;
172         char nand_name[12];
173         int (*nand_func) (cmd_tbl_t *, int, int, char **);
174
175 #if defined(CONFIG_CMD_NAND)
176         sprintf(nand_name, "nand");
177         nand_func = do_nand;
178 #elif defined(CONFIG_CMD_ONENAND)
179         sprintf(nand_name, "onenand");
180         nand_func = do_onenand;
181 #else
182         printf("Configure your NAND sub-system\n");
183         return 0;
184 #endif
185
186         if (type == 0) {
187                 char *argv[] = {nand_name, "erase", p1, p2};
188                 printf("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
189                 ret = nand_func(NULL, 0, 4, argv);
190         } else if (type == 1) {
191                 char *argv[] = {nand_name, "write", p1, p2, p3};
192                 printf("%s %s %s %s %s\n", argv[0], argv[1], argv[2],
193                                 argv[3], argv[4]);
194                 ret = nand_func(NULL, 0, 5, argv);
195         } else if (type == 2) {
196                 char *argv[] = {nand_name, "write.yaffs", p1, p2, p3};
197                 printf("%s %s %s %s %s\n", argv[0], argv[1], argv[2],
198                                 argv[3], argv[4]);
199                 ret = nand_func(NULL, 0, 5, argv);
200         } else if (type == 3) {
201                 char *argv[] = {nand_name, "lock", p1, p2};
202                 printf("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
203                 ret = nand_func(NULL, 0, 4, argv);
204         }
205
206         if (ret)
207                 printf("Error: NAND Command\n");
208
209         return ret;
210 }
211
212 #ifdef CONFIG_CMD_UBI
213 int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
214
215 int ubi_cmd(int part, char *p1, char *p2, char *p3)
216 {
217         int ret = 1;
218
219         if (part == RAMDISK_PART_ID) {
220                 char *argv[] = {"ubi", "write", p1, "rootfs.cramfs", p2, p3};
221                 printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
222                                 argv[3], argv[4], argv[5]);
223                 ret = do_ubi(NULL, 0, 6, argv);
224         } else if (part == FILESYSTEM_PART_ID) {
225                 char *argv[] = {"ubi", "write", p1, "factoryfs.cramfs", p2, p3};
226                 printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
227                                 argv[3], argv[4], argv[5]);
228                 ret = do_ubi(NULL, 0, 6, argv);
229         } else if (part == FILESYSTEM2_PART_ID) {
230                 char *argv[] = {"ubi", "write", p1, "datafs.ubifs", p2, p3};
231                 printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
232                                 argv[3], argv[4], argv[5]);
233                 ret = do_ubi(NULL, 0, 6, argv);
234         }
235
236         return ret;
237 }
238 #endif
239
240 #ifdef CONFIG_CMD_MMC
241 #include <mmc.h>
242 #include <fat.h>
243
244 static struct mmc *mmc;
245
246 static int mmc_cmd(int ops, int dev_num, ulong start, lbaint_t cnt, void *addr)
247 {
248         int ret;
249
250         if (ops) {
251                 printf("mmc write 0x%x 0x%x\n", start, cnt);
252                 ret = mmc->block_dev.block_write(dev_num, start, cnt, addr);
253         } else {
254                 printf("mmc read 0x%x 0x%x\n", start, cnt);
255                 ret = mmc->block_dev.block_read(dev_num, start, cnt, addr);
256         }
257
258         if (ret > 0)
259                 ret = 0;
260         else
261                 ret = 1;
262
263         return ret;
264 }
265
266 #define NORMAL_PARTITION        0
267 #define EXTEND_PARTITION        1
268
269 #define EXTEND_PART_TYPE        5
270
271 #define EXTEND_MAX_PART         32
272
273 static unsigned int cur_blk_offset;
274 static unsigned int cur_part_size;
275 static unsigned int cur_part;
276
277 static unsigned int mmc_parts;
278 static unsigned int mmc_part_write;
279
280 static u8 part_mode = 0;
281
282 struct partition_info {
283         u32 size;
284         u32 checksum;
285         u32 res;
286 } __attribute__((packed));
287
288 struct partition_header {
289         u8                      fat32head[16];  /* RFSHEAD identifier */
290         struct partition_info   partition[EXTEND_MAX_PART];
291         u8                      res[112];       /* only data (without MBR) */
292 } __attribute__((packed));
293
294 struct mul_partition_info {
295         u32 lba_begin;          /* absolute address from 0 block */
296         u32 num_sectors;
297 } __attribute__((packed));
298
299 #define MBR_OFFSET      0x10
300
301 struct partition_header part_info;
302 struct mbr mbr_info;
303 struct mul_partition_info mul_info[EXTEND_MAX_PART];
304
305 static int write_mmc_partition(struct usbd_ops *usbd, u32 *ram_addr, u32 len)
306 {
307         unsigned int blocks;
308         int i;
309         int loop;
310         u32 cnt;
311         int ret;
312
313         if (cur_part_size > len) {
314                 blocks = len / usbd->mmc_blk;
315                 ret = -1;
316         } else {
317                 blocks = cur_part_size / usbd->mmc_blk;
318                 ret = len - cur_part_size;
319         }
320
321         if (len % usbd->mmc_blk)
322                 blocks++;
323
324         loop = blocks / usbd->mmc_max;
325         if (blocks % usbd->mmc_max)
326                 loop++;
327
328         for (i = 0; i < loop; i++) {
329                 if (i == 0) {
330                         cnt = blocks % usbd->mmc_max;
331                         if (cnt == 0)
332                                 cnt = usbd->mmc_max;
333                 } else {
334                         cnt = usbd->mmc_max;
335                 }
336
337                 mmc_cmd(OPS_WRITE, usbd->mmc_dev, cur_blk_offset,
338                                 cnt, (void *)*ram_addr);
339
340                 cur_blk_offset += cnt;
341
342                 *ram_addr += (cnt * usbd->mmc_blk);
343         }
344
345         return ret;
346 }
347
348 static int write_file_mmc(struct usbd_ops *usbd, u32 len)
349 {
350         u32 ram_addr;
351         int i;
352         int ret;
353         struct mbr *mbr;
354
355         if (!usbd->mmc_total) {
356                 printf("MMC is not supported!\n");
357                 return 0;
358         }
359
360         ram_addr = (u32)down_ram_addr;
361
362         if (cur_blk_offset == 0) {
363                 boot_sector *bs;
364                 u32 mbr_blk_size;
365
366                 memcpy(&part_info, (void *)ram_addr,
367                                 sizeof(struct partition_header));
368
369                 ram_addr += sizeof(struct partition_header);
370                 len -= sizeof(struct partition_header);
371                 mbr = (struct mbr *)ram_addr;
372                 mbr_blk_size = mbr->parts[0].lba;
373
374                 if (mbr->parts[0].partition_type != EXTEND_PART_TYPE) {
375                         part_mode = NORMAL_PARTITION;
376
377                         /* modify sectors of p1 */
378                         mbr->parts[0].nsectors = usbd->mmc_total -
379                                         (mbr_blk_size +
380                                         mbr->parts[1].nsectors +
381                                         mbr->parts[2].nsectors +
382                                         mbr->parts[3].nsectors);
383
384                         mmc_parts++;
385
386                         /* modify lba_begin of p2 and p3 and p4 */
387                         for (i = 1; i < 4; i++) {
388                                 if (part_info.partition[i].size == 0)
389                                         break;
390
391                                 mmc_parts++;
392                                 mbr->parts[i].lba =
393                                         mbr->parts[i - 1].lba +
394                                         mbr->parts[i - 1].nsectors;
395                         }
396
397                         /* copy MBR */
398                         memcpy(&mbr_info, mbr, sizeof(struct mbr));
399
400                         printf("Total Size: 0x%08x #parts %d\n",
401                                         (unsigned int)usbd->mmc_total,
402                                         mmc_parts);
403                         for (i = 0; i < mmc_parts; i++) {
404                                 printf("p%d\t0x%08x\t0x%08x\n", i + 1,
405                                         mbr_info.parts[i].lba,
406                                         mbr_info.parts[i].nsectors);
407                         }
408
409                         /* write MBR */
410                         mmc_cmd(OPS_WRITE, usbd->mmc_dev, 0,
411                                         mbr_blk_size, (void *)ram_addr);
412
413                         ram_addr += mbr_blk_size * usbd->mmc_blk;
414                         len -= mbr_blk_size * usbd->mmc_blk;
415
416                         cur_blk_offset = mbr_blk_size;
417                         cur_part = 0;
418                         cur_part_size = part_info.partition[0].size;
419
420                         /* modify p1's total sector */
421                         bs = (boot_sector *)ram_addr;
422                         bs->total_sect = mbr_info.parts[0].nsectors;
423
424                         printf("\nWrite Partition %d.. %d blocks\n",
425                                 cur_part + 1,
426                                 part_info.partition[cur_part].size /
427                                 (int)usbd->mmc_blk);
428                 } else {
429                         part_mode = EXTEND_PARTITION;
430
431                         for (i = 0; i < EXTEND_MAX_PART; i++) {
432                                 if (part_info.partition[i].size == 0)
433                                         break;
434                                 mmc_parts++;
435                         }
436
437                         if (mmc_parts == 0)
438                                 return -1;
439                         else
440                                 printf("found %d partitions\n", mmc_parts);
441
442                         /* build partition table */
443
444                         mul_info[0].num_sectors =
445                                 usbd->mmc_total - mbr_blk_size;
446                         for (i = 1; i < mmc_parts; i++) {
447                                 mul_info[i].num_sectors =
448                                         part_info.partition[i].res +
449                                         mbr_blk_size; /* add MBR */
450                         }
451
452                         for (i = 1; i < mmc_parts; i++) {
453                                 mul_info[0].num_sectors -=
454                                         mul_info[i].num_sectors;
455                         }
456
457                         mul_info[0].lba_begin = mbr_blk_size;
458                         for (i = 1; i < mmc_parts; i++) {
459                                 mul_info[i].lba_begin =
460                                         mul_info[i-1].lba_begin +
461                                         mul_info[i-1].num_sectors;
462                         }
463
464                         /* modify MBR of extended partition: p1 */
465                         mbr->parts[0].nsectors =
466                                 usbd->mmc_total - mbr_blk_size;
467
468                         /* modify MBR of first logical partition: p5 */
469                         mbr = (struct mbr *)
470                                 (ram_addr + mbr_blk_size * usbd->mmc_blk);
471
472                         mbr->parts[0].nsectors =
473                                 mul_info[0].num_sectors - mbr_blk_size;
474                         mbr->parts[1].lba=
475                                 mul_info[1].lba_begin - mbr_blk_size;
476
477                         /* modify BPB data of p5 */
478                         bs = (boot_sector *)
479                                 ((u32)mbr + mbr_blk_size * usbd->mmc_blk);
480                         memset(&bs->sectors, 0, 2);
481                         bs->total_sect = mbr->parts[0].nsectors;
482
483                         printf("Total Size: 0x%08x #parts %d\n",
484                                         (unsigned int)usbd->mmc_total,
485                                         mmc_parts);
486                         for (i = 0; i < mmc_parts; i++) {
487                                 printf("p%d\t0x%08x\t0x%08x\n", i + 1,
488                                         mul_info[i].lba_begin,
489                                         mul_info[i].num_sectors);
490                         }
491
492                         cur_blk_offset = 0;
493                         cur_part = 0;
494                         cur_part_size = part_info.partition[0].size;
495
496                         printf("\nWrite Partition %d.. %d blocks\n",
497                                 cur_part + 1,
498                                 part_info.partition[cur_part].size /
499                                 (int)usbd->mmc_blk);
500                 }
501         }
502
503         for (i = cur_part; i < mmc_parts; i++) {
504                 ret = write_mmc_partition(usbd, &ram_addr, len);
505
506                 if (ret < 0) {
507                         cur_part_size -= len;
508                         break;
509                 } else {
510                         cur_part++;
511                         cur_part_size =
512                                 part_info.partition[cur_part].size;
513
514                         if (part_mode == NORMAL_PARTITION) {
515                                 cur_blk_offset =
516                                         mbr_info.parts[cur_part].lba;
517                         } else {
518                                 cur_blk_offset =
519                                         mul_info[cur_part].lba_begin;
520                                 /* modify MBR */
521                                 if (cur_part < mmc_parts) {
522                                         mbr = (struct mbr *)ram_addr;
523                                         mbr->parts[1].lba=
524                                                 mul_info[cur_part+1].lba_begin -
525                                                 mbr->parts[0].lba;
526                                 }
527                         }
528
529                         if (ret == 0)
530                                 break;
531                         else
532                                 len = ret;
533
534                         printf("\nWrite Partition %d.. %d blocks\n",
535                                 cur_part + 1,
536                                 part_info.partition[cur_part].size /
537                                 (int)usbd->mmc_blk);
538                 }
539         }
540
541         return 0;
542 }
543
544 static int write_file_mmc_part(struct usbd_ops *usbd, u32 len)
545 {
546         u32 ram_addr;
547         u32 ofs;
548         int i;
549         struct mbr *mbr;
550         u32 mbr_blk_size;
551
552         ram_addr = (u32)down_ram_addr;
553         mbr = &mbr_info;
554
555         if (cur_blk_offset == 0) {
556                 /* read MBR */
557                 mmc_cmd(OPS_READ, usbd->mmc_dev, 0,
558                         sizeof(struct mbr)/usbd->mmc_blk, (void *)mbr);
559
560                 mbr_blk_size = mbr->parts[0].lba;
561
562                 if (mbr->parts[0].partition_type != EXTEND_PART_TYPE) {
563                         part_mode = NORMAL_PARTITION;
564
565                         for (i = 0; i < 4; i++) {
566                                 printf("p%d\t0x%08x\t0x%08x\n", i + 1,
567                                         mbr_info.parts[i].lba,
568                                         mbr_info.parts[i].nsectors);
569                         }
570
571                         cur_blk_offset =
572                                 mbr->parts[mmc_part_write - 1].lba;
573                         cur_part = mmc_part_write - 1;
574                         cur_part_size =
575                                 usbd->mmc_blk *
576                                 mbr->parts[mmc_part_write - 1].nsectors;
577
578                         if (mmc_part_write == 1) {
579                                 ram_addr += sizeof(struct mbr);
580                                 cur_blk_offset += sizeof(struct mbr) /
581                                         usbd->mmc_blk;
582                                 len -= sizeof(struct mbr);
583                         }
584                 } else {
585                         part_mode = EXTEND_PARTITION;
586
587                         for (i = 1; i < mmc_part_write; i++) {
588                                 ofs = mbr->parts[0].lba + mbr->parts[1].lba;
589                                 printf("P%d start blk: 0x%x, size: 0x%x\n", i,
590                                         ofs, mbr->parts[1].nsectors);
591                                 mmc_cmd(OPS_READ, usbd->mmc_dev, ofs,
592                                         (sizeof(struct mbr) / usbd->mmc_blk),
593                                         (void *)mbr);
594                         }
595
596                         ofs = mbr->parts[0].lba + mbr->parts[1].lba;
597                         printf("P%d start blk: 0x%x, size: 0x%x\n", i,
598                                 ofs, mbr->parts[1].nsectors);
599
600                         ofs += mbr_blk_size; /* skip MBR */
601                         cur_blk_offset = ofs;
602                         cur_part = mmc_part_write - 1;
603                         cur_part_size =
604                                 usbd->mmc_blk *
605                                 mbr->parts[1].nsectors;
606
607                         if (mmc_part_write == 1) {
608                                 boot_sector *bs;
609                                 u32 total_sect;
610                                 /* modify BPB data of p1 */
611                                 mmc_cmd(OPS_READ, usbd->mmc_dev, cur_blk_offset,
612                                         (sizeof(struct mbr) / usbd->mmc_blk),
613                                         mbr);
614
615                                 bs = (boot_sector *)mbr;
616                                 total_sect = bs->total_sect;
617
618                                 bs = (boot_sector *)ram_addr;
619                                 memset(&bs->sectors, 0, 2);
620                                 bs->total_sect = total_sect;
621                         }
622                 }
623         }
624
625         printf("\nWrite Partition %d.. %d blocks\n",
626                 cur_part + 1,
627                 len / (int)usbd->mmc_blk);
628
629         write_mmc_partition(usbd, &ram_addr, len);
630
631         return 0;
632 }
633 #endif
634
635 static unsigned int mbr_offset[16];
636 static int mbr_parts = 0;
637
638 static unsigned long memsize_parse (const char *const ptr, const char **retptr)
639 {
640         unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
641
642         switch (**retptr) {
643                 case 'G':
644                 case 'g':
645                         ret <<= 10;
646                 case 'M':
647                 case 'm':
648                         ret <<= 10;
649                 case 'K':
650                 case 'k':
651                         ret <<= 10;
652                         (*retptr)++;
653                 default:
654                         break;
655         }
656
657         return ret;
658 }
659
660 static void set_mbr_info(struct usbd_ops *usbd, char *ramaddr, u32 len)
661 {
662         char mbr_str[256];
663         char save[16][16];
664         char *p;
665         char *tok;
666         unsigned int size[16];
667         int i = 0;
668
669         strncpy(mbr_str, ramaddr, len);
670         p = mbr_str;
671
672         for (i = 0; ; i++, p = NULL) {
673                 tok = strtok(p, ",");
674                 if (tok == NULL)
675                         break;
676                 strcpy(save[i], tok);
677                 printf("part%d: %s\n", i, save[i]);
678         }
679
680         mbr_parts = i;
681         printf("find %d partitions\n", mbr_parts);
682
683         for (i = 0; i < mbr_parts; i++) {
684                 p = save[i];
685                 size[i] = memsize_parse(p, (const char **)&p) / 512;
686         }
687
688         puts("save the MBR Table...\n");
689         set_mbr_table(0x800, mbr_parts, size, mbr_offset);
690 }
691
692 static int write_mmc_image(struct usbd_ops *usbd, unsigned int len, int part_num)
693 {
694         int ret = 0;
695
696         if (mbr_parts <= part_num) {
697                 printf("Error: MBR table have %d partitions (request %d)\n",
698                                 mbr_parts, part_num);
699                 return 1;
700         }
701
702 #if 0
703         /* modify size of UMS partition */
704         if (part_num == 4 && fs_offset == 0) {
705                 boot_sector *bs;
706                 bs = (boot_sector *)down_ram_addr;
707                 memset(&bs->sectors, 0, 2);
708                 bs->total_sect = usbd->mmc_total - mbr_offset[part_num];
709         }
710 #endif
711         ret = mmc_cmd(OPS_WRITE, usbd->mmc_dev,
712                         mbr_offset[part_num] + fs_offset,
713                         len / usbd->mmc_blk,
714                         (void *)down_ram_addr);
715
716         fs_offset += (len / usbd->mmc_blk);
717
718         return ret;
719 }
720
721 static int write_fat_file(struct usbd_ops *usbd, char *file_name,
722                         int part_id, int len)
723 {
724 #ifdef CONFIG_FAT_WRITE
725         int ret;
726
727         ret = fat_register_device(&mmc->block_dev, part_id);
728         if (ret < 0) {
729                 printf("error : fat_register_divce\n");
730                 return 0;
731         }
732
733         ret = file_fat_write(file_name, (void *)down_ram_addr, len);
734         if (ret < 0) {
735                 printf("error : writing uImage\n");
736                 return 0;
737         }
738 #else
739         printf("error: doesn't support fat_write\n");
740 #endif
741         return 0;
742 }
743
744 static int write_file_system(char *ramaddr, ulong len, char *offset,
745                 char *length, int part_num, int ubi_update)
746 {
747         int ret = 0;
748
749 #ifdef CONFIG_CMD_UBI
750         /* UBI Update */
751         if (ubi_update) {
752                 sprintf(length, "0x%x", (uint)len);
753                 ret = ubi_cmd(part_id, ramaddr, length, "cont");
754                 return ret;
755         }
756 #endif
757
758         /* Erase entire partition at the first writing */
759         if (write_part == 0 && ubi_update == 0) {
760                 sprintf(offset, "0x%x", (uint)parts[part_num]->offset);
761                 sprintf(length, "0x%x", (uint)parts[part_num]->size);
762                 nand_cmd(0, offset, length, NULL);
763         }
764
765         sprintf(offset, "0x%x", (uint)(parts[part_num]->offset + fs_offset));
766         sprintf(length, "0x%x", (uint)len);
767
768         fs_offset += len;
769         ret = nand_cmd(1, ramaddr, offset, length);
770
771         return ret;
772 }
773
774 static int qboot_erase = 0;
775
776 /* Erase the qboot */
777 static void erase_qboot_area(void)
778 {
779         char offset[12], length[12];
780         int qboot_id;
781
782         if (qboot_erase)
783                 return;
784
785         qboot_id = get_part_id("qboot");
786
787         if (qboot_id != -1) {
788                 printf("\nCOMMAND_ERASE_QBOOT\n");
789                 sprintf(offset, "%x", parts[qboot_id]->offset);
790                 sprintf(length, "%x", parts[qboot_id]->size);
791                 nand_cmd(0, offset, length, NULL);
792                 qboot_erase = 1;
793         }
794 }
795
796 /* Erase the environment */
797 static void erase_env_area(struct usbd_ops *usbd)
798 {
799 #if defined(CONFIG_ENV_IS_IN_NAND) || defined(CONFIG_ENV_IS_IN_ONENAND)
800         int param_id;
801         char offset[12], length[12];
802
803         param_id = get_part_id("params");
804
805         if (param_id == -1) {
806                 sprintf(offset, "%x", CONFIG_ENV_ADDR);
807                 sprintf(length, "%x", CONFIG_ENV_SIZE);
808         } else {
809                 sprintf(offset, "%x", parts[param_id]->offset);
810                 sprintf(length, "%x", parts[param_id]->size);
811         }
812         nand_cmd(0, offset, length, NULL);
813 #elif defined(CONFIG_ENV_IS_IN_MMC)
814         char buf[usbd->mmc_blk];
815
816         memset(buf, 0x0, usbd->mmc_blk);
817         mmc_cmd(OPS_WRITE, CONFIG_SYS_MMC_ENV_DEV,
818                         CONFIG_ENV_OFFSET / usbd->mmc_blk,
819                         1, (void *)buf);
820 #endif
821 }
822
823 static inline void send_ack(struct usbd_ops *usbd, int data)
824 {
825         *((ulong *) usbd->tx_data) = data;
826         usbd->send_data(usbd->tx_data, usbd->tx_len);
827 }
828
829 static inline int check_mmc_device(struct usbd_ops *usbd)
830 {
831         if (usbd->mmc_total)
832                 return 0;
833
834         printf("\nError: Couldn't find the MMC device\n");
835         send_ack(usbd, STATUS_ERROR);
836         return 1;
837 }
838
839 /* Parsing received data packet and Process data */
840 static int process_data(struct usbd_ops *usbd)
841 {
842         unsigned int cmd = 0, arg = 0, ofs = 0, len = 0, flag = 0;
843         char offset[12], length[12], ramaddr[12];
844         int recvlen = 0;
845         unsigned int blocks = 0;
846         int ret = 0;
847         int ubi_update = 0;
848         int ubi_mode = 0;
849         int img_type;
850
851         sprintf(ramaddr, "0x%x", (uint) down_ram_addr);
852
853         /* Parse command */
854         cmd  = *((ulong *) usbd->rx_data + 0);
855         arg  = *((ulong *) usbd->rx_data + 1);
856         len  = *((ulong *) usbd->rx_data + 2);
857         flag = *((ulong *) usbd->rx_data + 3);
858
859         /* Reset tx buffer */
860         memset(usbd->tx_data, 0, sizeof(usbd->tx_data));
861
862         ubi_mode = check_ubi_mode();
863
864         switch (cmd) {
865         case COMMAND_DOWNLOAD_IMAGE:
866                 printf("\nCOMMAND_DOWNLOAD_IMAGE\n");
867
868                 if (arg)
869                         down_ram_addr = usbd->ram_addr + 0x1000000;
870                 else
871                         down_ram_addr = usbd->ram_addr;
872
873                 usbd->recv_setup((char *)down_ram_addr, (int)len);
874                 printf("Download to 0x%08x, %d bytes\n",
875                                 (uint)down_ram_addr, (int)len);
876
877                 /* response */
878                 send_ack(usbd, STATUS_DONE);
879
880                 /* Receive image by using dma */
881                 recvlen = usbd->recv_data();
882                 if (recvlen < len) {
883                         printf("Error: wrong image size -> %d/%d\n",
884                                         (int)recvlen, (int)len);
885
886                         /* Retry this commad */
887                         send_ack(usbd, STATUS_RETRY);
888                 } else
889                         send_ack(usbd, STATUS_DONE);
890
891                 return 1;
892
893         /* Report partition info */
894         case COMMAND_PARTITION_SYNC:
895                 part_id = arg;
896
897 #ifdef CONFIG_CMD_UBI
898                 if (ubi_mode) {
899                         if (part_id == RAMDISK_PART_ID ||
900                             part_id == FILESYSTEM_PART_ID ||
901                             part_id == FILESYSTEM2_PART_ID) {
902                                 /* change to yaffs style */
903                                 get_part_info();
904                         }
905                 } else {
906                         if (part_id == FILESYSTEM3_PART_ID) {
907                                 /* change ubi style */
908                                 get_part_info();
909                         }
910                 }
911 #endif
912
913                 if (part_id == FILESYSTEM3_PART_ID)
914                         part_id = get_part_id("UBI");
915                 else if (part_id == MODEM_PART_ID)
916                         part_id = get_part_id("modem");
917                 else if (part_id == KERNEL_PART_ID)
918                         part_id = get_part_id("kernel");
919                 else if (part_id == BOOT_PART_ID)
920                         part_id = get_part_id("bootloader");
921 #ifdef CONFIG_MIRAGE
922                 if (part_id)
923                         part_id--;
924 #endif
925                 printf("COMMAND_PARTITION_SYNC - Part%d\n", part_id);
926
927                 blocks = parts[part_id]->size / 1024 / 128;
928                 printf("COMMAND_PARTITION_SYNC - Part%d, %d blocks\n",
929                                 part_id, blocks);
930
931                 send_ack(usbd, blocks);
932                 return 1;
933
934         case COMMAND_WRITE_PART_0:
935                 /* Do nothing */
936                 printf("COMMAND_WRITE_PART_0\n");
937                 return 1;
938
939         case COMMAND_WRITE_PART_1:
940                 printf("COMMAND_WRITE_PART_BOOT\n");
941                 part_id = get_part_id("bootloader");
942                 img_type = IMG_BOOT;
943                 break;
944
945         case COMMAND_WRITE_PART_2:
946         case COMMAND_ERASE_PARAMETER:
947                 printf("COMMAND_PARAMETER - not support!\n");
948                 break;
949
950         case COMMAND_WRITE_PART_3:
951                 printf("COMMAND_WRITE_KERNEL\n");
952                 part_id = get_part_id("kernel");
953                 img_type = IMG_KERNEL;
954                 break;
955
956         case COMMAND_WRITE_PART_4:
957                 printf("COMMAND_WRITE_ROOTFS\n");
958                 part_id = get_part_id("Root");
959                 img_type = IMG_FILESYSTEM;
960                 ubi_update = arg;
961                 break;
962
963         case COMMAND_WRITE_PART_5:
964                 printf("COMMAND_WRITE_FACTORYFS\n");
965                 part_id = get_part_id("Fact");
966                 img_type = IMG_FILESYSTEM;
967                 ubi_update = arg;
968                 break;
969
970         case COMMAND_WRITE_PART_6:
971                 printf("COMMAND_WRITE_DATAFS\n");
972                 part_id = get_part_id("Data");
973                 img_type = IMG_FILESYSTEM;
974                 ubi_update = arg;
975                 break;
976
977         case COMMAND_WRITE_PART_7:
978                 printf("COMMAND_WRITE_UBI\n");
979                 part_id = get_part_id("UBI");
980                 img_type = IMG_FILESYSTEM;
981                 ubi_update = 0;
982                 /* someday, it will be deleted */
983                 get_part_info();
984                 break;
985
986         case COMMAND_WRITE_PART_8:
987                 printf("COMMAND_WRITE_MODEM\n");
988                 part_id = get_part_id("modem");
989                 img_type = IMG_MODEM;
990                 break;
991
992 #ifdef CONFIG_CMD_MMC
993         case COMMAND_WRITE_PART_9:
994                 printf("COMMAND_WRITE_MMC\n");
995                 img_type = IMG_MMC;
996                 mmc_part_write = arg;
997                 break;
998 #endif
999
1000         case COMMAND_WRITE_IMG_0:
1001                 printf("COMMAND_WRITE_MBR\n");
1002                 img_type = IMG_MBR;
1003                 break;
1004
1005         case COMMAND_WRITE_IMG_1:
1006                 printf("COMMAND_WRITE_BOOTLOADER\n");
1007                 img_type = IMG_BOOTLOADER;
1008                 break;
1009
1010         case COMMAND_WRITE_IMG_2:
1011                 printf("COMMAND_WRITE_KERNEL\n");
1012                 img_type = IMG_KERNEL_V2;
1013                 part_id = 2;
1014                 break;
1015
1016         case COMMAND_WRITE_IMG_3:
1017                 printf("COMMAND_WRITE_MODEM\n");
1018                 img_type = IMG_MODEM_V2;
1019                 part_id = 2;
1020                 break;
1021
1022         case COMMAND_WRITE_IMG_4:
1023                 printf("COMMAND_WRITE_BOOT_PART\n");
1024                 part_id = 1;
1025                 img_type = IMG_V2;
1026                 break;
1027
1028         case COMMAND_WRITE_IMG_5:
1029                 printf("COMMAND_WRITE_SYSTEM_PART\n");
1030                 part_id = 2;
1031                 img_type = IMG_V2;
1032                 break;
1033
1034         case COMMAND_WRITE_IMG_6:
1035                 printf("COMMAND_WRITE_UMS_PART\n");
1036                 part_id = 4;
1037                 img_type = IMG_V2;
1038                 break;
1039
1040         case COMMAND_WRITE_UBI_INFO:
1041                 printf("COMMAND_WRITE_UBI_INFO\n");
1042
1043                 if (ubi_mode) {
1044 #ifdef CONFIG_CMD_UBI
1045                         part_id = arg-1;
1046                         sprintf(length, "0x%x", (uint)len);
1047                         ret = ubi_cmd(part_id, ramaddr, length, "begin");
1048                 } else {
1049 #endif
1050                         printf("Error: Not UBI mode\n");
1051                         ret = 1;
1052                 }
1053
1054                 /* Write image success -> Report status */
1055                 send_ack(usbd, ret);
1056
1057                 return !ret;
1058         /* Download complete -> reset */
1059         case COMMAND_RESET_PDA:
1060                 printf("\nDownload finished and Auto reset!\nWait........\n");
1061
1062                 /* Stop USB */
1063                 usbd->usb_stop();
1064
1065                 if (usbd->cpu_reset)
1066                         usbd->cpu_reset();
1067                 else
1068                         do_reset();
1069
1070                 return 0;
1071
1072         /* Error */
1073         case COMMAND_RESET_USB:
1074                 printf("\nError is occured!(maybe previous step)->\
1075                                 Turn off and restart!\n");
1076
1077                 /* Stop USB */
1078                 usbd->usb_stop();
1079                 return 0;
1080
1081         case COMMAND_RAM_BOOT:
1082                 usbd->usb_stop();
1083                 boot_cmd(ramaddr);
1084                 return 0;
1085
1086         case COMMAND_RAMDISK_MODE:
1087                 printf("COMMAND_RAMDISK_MODE\n");
1088 #ifdef CONFIG_RAMDISK_ADDR
1089                 if (arg) {
1090                         down_ram_addr = usbd->ram_addr;
1091                 } else {
1092                         down_ram_addr = CONFIG_RAMDISK_ADDR;
1093                         run_command("run ramboot", 0);
1094                 }
1095 #endif
1096                 return 1;
1097
1098 #ifdef CONFIG_DOWN_PHONE
1099         case COMMAND_DOWN_PHONE:
1100                 printf("COMMAND_RESET_PHONE\n");
1101
1102                 usbd_phone_down();
1103
1104                 send_ack(usbd, STATUS_DONE);
1105                 return 1;
1106
1107         case COMMAND_CHANGE_USB:
1108                 printf("COMMAND_CHANGE_USB\n");
1109
1110                 /* Stop USB */
1111                 usbd->usb_stop();
1112
1113                 usbd_path_change();
1114
1115                 do_reset();
1116                 return 0;
1117 #endif
1118         case COMMAND_CSA_CLEAR:
1119                 printf("COMMAND_CSA_CLEAR\n");
1120                 part_id = get_part_id("csa");
1121                 img_type = IMG_MODEM;
1122                 break;
1123
1124         case COMMAND_PROGRESS:
1125                 if (usbd->set_progress)
1126                         usbd->set_progress(arg);
1127                 return 1;
1128
1129         default:
1130                 printf("Error: Unknown command -> (%d)\n", (int)cmd);
1131                 return 1;
1132         }
1133
1134         /* Erase and Write to NAND */
1135         switch (img_type) {
1136         case IMG_BOOT:
1137                 ofs = parts[part_id]->offset;
1138 #ifdef CONFIG_S5PC1XX
1139                 /* Workaround: for prevent revision mismatch */
1140                 if (cpu_is_s5pc110() && (down_mode != MODE_FORCE)) {
1141                         int img_rev = 1;
1142                         long *img_header = (long *)down_ram_addr;
1143
1144                         if (*img_header == 0xea000012)
1145                                 img_rev = 0;
1146                         else if (*(img_header + 0x400) == 0xea000012)
1147                                 img_rev = 2;
1148
1149                         if (img_rev != s5p_get_cpu_rev()) {
1150                                 printf("CPU revision mismatch!\n"
1151                                         "bootloader is %s%s\n"
1152                                         "download image is %s%s\n",
1153                                         s5p_get_cpu_rev() ? "EVT1" : "EVT0",
1154                                         s5p_get_cpu_rev() == 2 ? "-Fused" : "",
1155                                         img_rev ? "EVT1" : "EVT0",
1156                                         img_rev == 2 ? "-Fused" : "");
1157                                 send_ack(usbd, STATUS_ERROR);
1158                                 return 0;
1159                         }
1160                 }
1161 #endif
1162 #ifdef CONFIG_SBOOT
1163                 /* Only u-boot.bin is allowed */
1164                 {
1165                         long *img_header = (long *)down_ram_addr;
1166
1167                         if (*img_header != 0xea000018) {
1168                                 printf("\n!!! ERROR !!!\n"
1169                                         "Please download the u-boot.bin.\n"
1170                                         "Other images are not allowed.\n\n");
1171                                 send_ack(usbd, STATUS_ERROR);
1172                                 return 0;
1173                         }
1174                 }
1175 #endif
1176
1177                 erase_env_area(usbd);
1178
1179                 sprintf(offset, "%x", (uint)ofs);
1180                 if (ofs != 0)
1181                         sprintf(length, "%x", parts[part_id]->size - (uint)ofs);
1182                 else
1183                         sprintf(length, "%x", parts[part_id]->size);
1184
1185                 /* Erase */
1186                 nand_cmd(0, offset, length, NULL);
1187                 /* Write */
1188                 sprintf(length, "%x", (unsigned int) len);
1189                 ret = nand_cmd(1, ramaddr, offset, length);
1190                 break;
1191
1192         case IMG_KERNEL:
1193                 sprintf(offset, "%x", parts[part_id]->offset);
1194                 sprintf(length, "%x", parts[part_id]->size);
1195
1196                 /* Erase */
1197                 nand_cmd(0, offset, length, NULL);
1198                 /* Write */
1199                 sprintf(length, "%x", (unsigned int) len);
1200                 ret = nand_cmd(1, ramaddr, offset, length);
1201
1202                 erase_qboot_area();
1203                 break;
1204
1205         /* File Systems */
1206         case IMG_FILESYSTEM:
1207                 ret = write_file_system(ramaddr, len, offset, length,
1208                                 part_id, ubi_update);
1209
1210                 erase_qboot_area();
1211                 break;
1212
1213         case IMG_MODEM:
1214                 sprintf(offset, "%x", parts[part_id]->offset);
1215                 sprintf(length, "%x", parts[part_id]->size);
1216
1217                 /* Erase */
1218                 if (!arg)
1219                         nand_cmd(0, offset, length, NULL);
1220                 else
1221                         printf("CSA Clear will be skipped temporary\n");
1222
1223                 /* Check ubi image, 0x23494255 is UBI# */
1224                 {
1225                         long *img_header = (long *)down_ram_addr;
1226
1227                         if (*img_header == 0x23494255)
1228                                 goto ubi_img;
1229                 }
1230
1231 #ifdef CONFIG_UBIFS_MK
1232                 void *dest_addr = (void *) down_ram_addr + 0xc00000;
1233                 void *src_addr = (void *) down_ram_addr;
1234                 int leb_size, max_leb_cnt, mkfs_min_io_size;
1235                 unsigned long ubifs_dest_size, ubi_dest_size;
1236 #ifdef CONFIG_S5PC110
1237                 mkfs_min_io_size = 4096;
1238                 leb_size = 248 * 1024;
1239                 max_leb_cnt = 4096;
1240 #elif CONFIG_S5PC210
1241                 mkfs_min_io_size = 2048;
1242                 leb_size = 126 * 1024;
1243                 max_leb_cnt = 4096;
1244 #endif
1245                 printf("Start making ubifs\n");
1246                 ret = mkfs(src_addr, len, dest_addr, &ubifs_dest_size,
1247                            mkfs_min_io_size, leb_size, max_leb_cnt);
1248                 if (ret) {
1249                         printf("Error : making ubifs failed\n");
1250                         goto out;
1251                 }
1252                 printf("Complete making ubifs\n");
1253 #endif
1254
1255 #ifdef CONFIG_UBINIZE
1256                 int peb_size, ubi_min_io_size, subpage_size, vid_hdr_offs;
1257 #ifdef CONFIG_S5PC110
1258                 ubi_min_io_size = 4096;
1259                 peb_size = 256 * 1024;
1260                 subpage_size = 4096;
1261                 vid_hdr_offs = 0;
1262 #elif CONFIG_S5PC210
1263                 ubi_min_io_size = 2048;
1264                 peb_size = 128 * 1024;
1265                 subpage_size = 512;
1266                 vid_hdr_offs = 512;
1267 #endif
1268                 printf("Start ubinizing\n");
1269                 ret = ubinize(dest_addr, ubifs_dest_size,
1270                               src_addr, &ubi_dest_size,
1271                               peb_size, ubi_min_io_size,
1272                               subpage_size, vid_hdr_offs);
1273                 if (ret) {
1274                         printf("Error : ubinizing failed\n");
1275                         goto out;
1276                 }
1277                 printf("Complete ubinizing\n");
1278
1279                 len = (unsigned int) ubi_dest_size;
1280 #endif
1281
1282 ubi_img:
1283                 /* Write : arg (0 Modem) / (1 CSA) */
1284                 if (!arg) {
1285                         sprintf(length, "%x", (unsigned int) len);
1286                         ret = nand_cmd(1, ramaddr, offset, length);
1287                 }
1288 out:
1289                 break;
1290
1291 #ifdef CONFIG_CMD_MMC
1292         case IMG_MMC:
1293                 if (check_mmc_device(usbd))
1294                         return 0;
1295
1296                 if (mmc_part_write)
1297                         ret = write_file_mmc_part(usbd, len);
1298                 else
1299                         ret = write_file_mmc(usbd, len);
1300
1301                 erase_qboot_area();
1302                 break;
1303 #endif
1304         case IMG_V2:
1305                 if (check_mmc_device(usbd))
1306                         return 0;
1307
1308                 ret = write_mmc_image(usbd, len, part_id);
1309                 break;
1310
1311         case IMG_MBR:
1312                 if (check_mmc_device(usbd))
1313                         return 0;
1314
1315 #ifdef CONFIG_CMD_MBR
1316                 set_mbr_info(usbd, (char *)down_ram_addr, len);
1317 #endif
1318                 break;
1319
1320         case IMG_BOOTLOADER:
1321                 if (check_mmc_device(usbd))
1322                         return 0;
1323
1324 #ifdef CONFIG_BOOTLOADER_SECTOR
1325                 erase_env_area(usbd);
1326
1327                 ret = mmc_cmd(OPS_WRITE, usbd->mmc_dev,
1328                                 CONFIG_BOOTLOADER_SECTOR,
1329                                 len / usbd->mmc_blk + 1,
1330                                 (void *)down_ram_addr);
1331 #endif
1332                 break;
1333
1334         case IMG_KERNEL_V2:
1335                 if (check_mmc_device(usbd))
1336                         return 0;
1337
1338                 ret = write_fat_file(usbd, "uImage", part_id, len);
1339                 break;
1340
1341         case IMG_MODEM_V2:
1342                 if (check_mmc_device(usbd))
1343                         return 0;
1344
1345                 ret = write_fat_file(usbd, "modem.bin", part_id, len);
1346                 break;
1347
1348         default:
1349                 /* Retry? */
1350                 write_part--;
1351         }
1352
1353         if (ret) {
1354                 /* Retry this commad */
1355                 send_ack(usbd, STATUS_RETRY);
1356                 return 1;
1357         } else
1358                 send_ack(usbd, STATUS_DONE);
1359
1360         write_part++;
1361
1362         /* Reset write count for another image */
1363         if (flag) {
1364                 write_part = 0;
1365                 fs_offset = 0;
1366         }
1367
1368         return 1;
1369 }
1370
1371 static const char *recv_key = "SAMSUNG";
1372 static const char *tx_key = "MPL";
1373
1374 int do_usbd_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1375 {
1376         struct usbd_ops *usbd;
1377         int err;
1378
1379         if (argc > 1)
1380                 down_mode = simple_strtoul(argv[1], NULL, 10);
1381         else
1382                 down_mode = MODE_NORMAL;
1383
1384         printf("USB Downloader v%s\n", APP_VERSION);
1385
1386         /* get partition info */
1387         err = get_part_info();
1388         if (err)
1389                 return err;
1390
1391         /* interface setting */
1392         usbd = usbd_set_interface(&usbd_ops);
1393         down_ram_addr = usbd->ram_addr;
1394
1395 #ifdef CONFIG_CMD_MBR
1396         /* get mbr info */
1397         mbr_parts = get_mbr_table(mbr_offset);
1398         if (!mbr_parts) {
1399                 char *mbrparts;
1400
1401                 puts("using default MBR\n");
1402
1403                 mbrparts = getenv("mbrparts");
1404                 set_mbr_info(usbd, mbrparts, strlen(mbrparts));
1405         }
1406 #endif
1407
1408         /* init the usb controller */
1409         if (!usbd->usb_init()) {
1410                 usbd->down_cancel();
1411                 return 0;
1412         }
1413         mmc = find_mmc_device(usbd->mmc_dev);
1414         mmc_init(mmc);
1415
1416         /* receive setting */
1417         usbd->recv_setup(usbd->rx_data, usbd->rx_len);
1418
1419         /* detect the download request from Host PC */
1420         if (usbd->recv_data()) {
1421                 if (strncmp(usbd->rx_data, recv_key, strlen(recv_key)) == 0) {
1422                         printf("Download request from the Host PC\n");
1423                         msleep(30);
1424
1425                         strcpy(usbd->tx_data, tx_key);
1426                         usbd->send_data(usbd->tx_data, usbd->tx_len);
1427                 } else {
1428                         printf("No download request from the Host PC!! 1\n");
1429                         return 0;
1430                 }
1431         } else {
1432                 usbd->down_cancel();
1433                 return 0;
1434         }
1435
1436         usbd->down_start();
1437         printf("Receive the packet\n");
1438
1439         /* receive the data from Host PC */
1440         while (1) {
1441                 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
1442
1443                 if (usbd->recv_data()) {
1444                         if (process_data(usbd) == 0)
1445                                 return 0;
1446                 }
1447         }
1448
1449         return 0;
1450 }
1451
1452 U_BOOT_CMD(usbdown, CONFIG_SYS_MAXARGS, 1, do_usbd_down,
1453         "Initialize USB device and Run USB Downloader (specific)",
1454         "- normal mode\n"
1455         "usbdown mode - specific mode (0: NORAML, 1: FORCE)"
1456 );