Date:2012-11-09 05:55:57 (11 years 4 months ago)
Author:Xiangfu
Commit:5ade9f115b3aaa86b8df85d85bd4c6dd39946676
Message:Fix compile warnings

Files: jzboot/src/debug.c (1 diff)
usbboot/src/Makefile.am (1 diff)
usbboot/src/cmd.c (33 diffs)
usbboot/src/cmd.h (1 diff)
usbboot/src/command_line.c (5 diffs)
usbboot/src/command_line.h (1 diff)
usbboot/src/ingenic_cfg.c (4 diffs)
usbboot/src/ingenic_cfg.h (1 diff)
usbboot/src/ingenic_usb.c (16 diffs)
usbboot/src/ingenic_usb.h (2 diffs)
usbboot/src/main.c (1 diff)
usbboot/src/usb_boot_defines.h (1 diff)
xbboot/host-app/Makefile.am (1 diff)
xbboot/host-app/host_main.c (1 diff)

Change Details

jzboot/src/debug.c
1818
1919#include <stdarg.h>
2020#include <stdio.h>
21#include <ctype.h>
2122
2223#include "debug.h"
2324
usbboot/src/Makefile.am
1AM_CFLAGS = -pedantic -Wall -W -DCFGDIR=\"$(cfgdir)\" -DDATADIR=\"$(pkgdatadir)\"
1AM_CFLAGS = -DCFGDIR=\"$(cfgdir)\" -DDATADIR=\"$(pkgdatadir)\" \
2    -std=gnu99 \
3    -Wall -Wshadow -Wmissing-prototypes \
4    -Wmissing-declarations -Wno-format-zero-length \
5    -Wno-unused -Wno-implicit-function-declaration \
6    -Wno-missing-prototypes -Wno-missing-declarations
27
38bin_PROGRAMS = usbboot
49usbboot_SOURCES = cmd.c command_line.c ingenic_cfg.c \
usbboot/src/cmd.c
2828#include <ctype.h>
2929#include <byteswap.h>
3030#include "cmd.h"
31#include "command_line.h"
3132#include "ingenic_cfg.h"
3233#include "ingenic_usb.h"
3334#include "ingenic_request.h"
3435#include "usb_boot_defines.h"
3536
36extern int com_argc;
37extern char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
38extern char * stage1;
39
40struct ingenic_dev ingenic_dev;
41struct hand hand;
42struct sdram_in sdram_in;
43struct nand_in nand_in;
44
45unsigned int total_size;
46unsigned char code_buf[4 * 512 * 1024];
47unsigned char check_buf[4 * 512 * 1024];
48unsigned char cs[16];
49unsigned char ret[8];
50
51static const char IMAGE_TYPE[][30] = {
52    "with oob and ecc",
53    "with oob and without ecc",
54    "without oob",
55};
56
57static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path)
37static int load_file(struct ingenic_dev *id, const char *file_path)
5838{
59    struct stat fstat;
39    struct stat fst;
40    struct fw_args *fw_args_copy;
6041    int fd, status, res = -1;
6142
62    status = stat(file_path, &fstat);
43    status = stat(file_path, &fst);
6344
6445    if (status < 0) {
6546        fprintf(stderr, "Error - can't get file size from '%s': %s\n",
...... 
6748        goto out;
6849    }
6950
70    ingenic_dev->file_len = fstat.st_size;
71    ingenic_dev->file_buff = code_buf;
51    id->file_len = fst.st_size;
52    id->file_buff = code_buf;
7253
7354    fd = open(file_path, O_RDONLY);
7455
...... 
7859        goto out;
7960    }
8061
81    status = read(fd, ingenic_dev->file_buff, ingenic_dev->file_len);
62    status = read(fd, id->file_buff, id->file_len);
8263
83    if (status < ingenic_dev->file_len) {
64    if (status < id->file_len) {
8465        fprintf(stderr, "Error - can't read file '%s': %s\n",
8566            file_path, strerror(errno));
8667        goto close;
8768    }
8869
89    struct fw_args *fw_args_copy = malloc(sizeof(struct fw_args));
70    fw_args_copy = malloc(sizeof(struct fw_args));
9071    if (!fw_args_copy)
9172        goto close;
9273
...... 
10081#endif
10182
10283    /* write args to code */
103    memcpy(ingenic_dev->file_buff + 8, fw_args_copy,
84    memcpy(id->file_buff + 8, fw_args_copy,
10485           sizeof(struct fw_args));
10586
10687    free(fw_args_copy);
...... 
145126    return status;
146127}
147128
148/* after upload stage2. must init device */
129/* After upload stage2. we have to init the device */
149130void init_cfg()
150131{
132    struct hand *hand_copy;
151133    int cpu = get_ingenic_cpu();
152134    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
153135        printf(" Device unboot! boot it first!\n");
154136        return;
155137    }
156138
157    struct hand *hand_copy = malloc(sizeof(struct hand));
139    hand_copy = malloc(sizeof(struct hand));
158140    if (!hand_copy)
159141        goto xout;
160142
...... 
184166#endif
185167
186168
187    ingenic_dev.file_buff = hand_copy;
169    ingenic_dev.file_buff = (unsigned char *)hand_copy;
188170    ingenic_dev.file_len = sizeof(struct hand);
189171    if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
190172        goto xout;
...... 
246228    printf(" Comparing %d bytes - ", size);
247229    for (i = 0; i < size; i++) {
248230        if (org[i] != obj[i]) {
249            unsigned int s = (i < 8) ? i : i - 8; // start_dump
231            unsigned int s = (i < 8) ? i : i - 8;
250232            printf("FAIL at off %d, wrote 0x%x, read 0x%x\n", i, org[i], obj[i]);
251233            printf(" off %d write: %02x %02x %02x %02x %02x %02x %02x %02x"
252234                   " %02x %02x %02x %02x %02x %02x %02x %02x\n", s,
...... 
265247    return 1;
266248}
267249
268int nand_markbad(struct nand_in *nand_in)
250int nand_markbad(struct nand_in *ni)
269251{
270252    int cpu = get_ingenic_cpu();
271253    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
272254        printf(" Device unboot! boot it first!\n");
273255        return -1;
274256    }
275    printf(" Mark bad block : %d\n",nand_in->start);
276    usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
257    printf(" Mark bad block : %d\n",ni->start);
258    usb_send_data_address_to_ingenic(&ingenic_dev, ni->start);
277259    usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD);
278260    usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
279261    printf(" Mark bad block at %d\n",((ret[3] << 24) |
...... 
283265    return 0;
284266}
285267
286int nand_program_check(struct nand_in *nand_in, unsigned int *start_page)
268int nand_program_check(struct nand_in *ni, unsigned int *start_page)
287269{
288270    unsigned int i, page_num, cur_page = -1;
289271    unsigned int start_addr;
290272    unsigned short temp;
273    int cpu;
291274    int status = -1;
292275
293    printf(" Writing NAND page %d len %d...\n", nand_in->start, nand_in->length);
294    if (nand_in->length > (unsigned int)MAX_TRANSFER_SIZE) {
276    printf(" Writing NAND page %d len %d...\n", ni->start, ni->length);
277    if (ni->length > (unsigned int)MAX_TRANSFER_SIZE) {
295278        printf(" Buffer size too long!\n");
296279        goto err;
297280    }
298281
299    int cpu = get_ingenic_cpu();
282    cpu = get_ingenic_cpu();
300283    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
301284        printf(" Device unboot! boot it first!\n");
302285        goto err;
303286    }
304287
305    ingenic_dev.file_buff = nand_in->buf;
306    ingenic_dev.file_len = nand_in->length;
288    ingenic_dev.file_buff = ni->buf;
289    ingenic_dev.file_len = ni->length;
307290    usb_send_data_to_ingenic(&ingenic_dev);
308    for (i = 0; i < nand_in->max_chip; i++) {
309        if ((nand_in->cs_map)[i] == 0)
291    for (i = 0; i < ni->max_chip; i++) {
292        if ((ni->cs_map)[i] == 0)
310293            continue;
311        if (nand_in->option == NO_OOB) {
312            page_num = nand_in->length / hand.nand_ps;
313            if ((nand_in->length % hand.nand_ps) !=0)
294        if (ni->option == NO_OOB) {
295            page_num = ni->length / hand.nand_ps;
296            if ((ni->length % hand.nand_ps) !=0)
314297                page_num++;
315298        } else {
316            page_num = nand_in->length /
299            page_num = ni->length /
317300                (hand.nand_ps + hand.nand_os);
318            if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0)
301            if ((ni->length% (hand.nand_ps + hand.nand_os)) !=0)
319302                page_num++;
320303        }
321        temp = ((nand_in->option << 12) & 0xf000) +
304        temp = ((ni->option << 12) & 0xf000) +
322305            ((i<<4) & 0xff0) + NAND_PROGRAM;
323        if (usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start) != 1)
306        if (usb_send_data_address_to_ingenic(&ingenic_dev, ni->start) != 1)
324307            goto err;
325308        if (usb_send_data_length_to_ingenic(&ingenic_dev, page_num) != 1)
326309            goto err;
...... 
330313            goto err;
331314
332315        printf(" Finish! (len %d start_page %d page_num %d)\n",
333               nand_in->length, nand_in->start, page_num);
316               ni->length, ni->start, page_num);
334317
335318        /* Read back to check! */
336        usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
319        usb_send_data_address_to_ingenic(&ingenic_dev, ni->start);
337320        usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
338321
339        switch (nand_in->option) {
322        switch (ni->option) {
340323        case OOB_ECC:
341324            temp = ((OOB_ECC << 12) & 0xf000) +
342325                ((i << 4) & 0xff0) + NAND_READ;
...... 
348331            start_addr = page_num * (hand.nand_ps + hand.nand_os);
349332            break;
350333        case NO_OOB:
334        default:
351335            temp = ((NO_OOB << 12) & 0xf000) +
352336                ((i << 4) & 0xff0) + NAND_READ;
353337            start_addr = page_num * hand.nand_ps;
354338            break;
355        default:
356            ;
357339        }
358340
359        printf(" Checking %d bytes...", nand_in->length);
341        printf(" Checking %d bytes...", ni->length);
360342        usb_ingenic_nand_ops(&ingenic_dev, temp);
361343        usb_read_data_from_ingenic(&ingenic_dev, check_buf, start_addr);
362344        usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
...... 
364346        cur_page = (ret[3] << 24) | (ret[2] << 16) | (ret[1] << 8) |
365347            (ret[0] << 0);
366348
367        if (nand_in->start == 0 && hand.nand_ps == 4096 &&
349        if (ni->start == 0 && hand.nand_ps == 4096 &&
368350            hand.fw_args.cpu_id == 0x4740) {
369351            printf(" No check! end at page: %d\n", cur_page);
370352            fflush(NULL);
371353            continue;
372354        }
373355
374        if (!nand_in->check(nand_in->buf, check_buf, nand_in->length)) {
356        if (!ni->check(ni->buf, check_buf, ni->length)) {
375357            struct nand_in bad;
376            // tbd: doesn't the other side skip bad blocks too? Can we just deduct 1 from cur_page?
377            // tbd: why do we only mark a block as bad if the last page in the block was written?
358            /*
359             * tbd: doesn't the other side skip bad blocks too? Can we just deduct 1 from cur_page?
360             * tbd: why do we only mark a block as bad if the last page in the block was written?
361             */
378362            bad.start = (cur_page - 1) / hand.nand_ppb;
379363            if (cur_page % hand.nand_ppb == 0)
380364                nand_markbad(&bad);
...... 
391375    return status;
392376}
393377
394int nand_erase(struct nand_in *nand_in)
378int nand_erase(struct nand_in *ni)
395379{
396380    unsigned int start_blk, blk_num, end_block;
381    unsigned short temp;
382    int cpu;
397383    int i;
398384
399    start_blk = nand_in->start;
400    blk_num = nand_in->length;
385    start_blk = ni->start;
386    blk_num = ni->length;
401387    if (start_blk > (unsigned int)NAND_MAX_BLK_NUM) {
402388        printf(" Start block number overflow!\n");
403389        return -1;
...... 
407393        return -1;
408394    }
409395
410    int cpu = get_ingenic_cpu();
396    cpu = get_ingenic_cpu();
411397    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
412398        printf(" Device unboot! boot it first!\n");
413399        return -1;
414400    }
415401
416    for (i = 0; i < nand_in->max_chip; i++) {
417        if ((nand_in->cs_map)[i]==0)
402    for (i = 0; i < ni->max_chip; i++) {
403        if ((ni->cs_map)[i]==0)
418404            continue;
419405        printf(" Erasing No.%d device No.%d flash (start_blk %u blk_num %u)......\n",
420               nand_in->dev, i, start_blk, blk_num);
406               ni->dev, i, start_blk, blk_num);
421407
422408        usb_send_data_address_to_ingenic(&ingenic_dev, start_blk);
423409        usb_send_data_length_to_ingenic(&ingenic_dev, blk_num);
424410
425        unsigned short temp = ((i << 4) & 0xff0) + NAND_ERASE;
411        temp = ((i << 4) & 0xff0) + NAND_ERASE;
426412        usb_ingenic_nand_ops(&ingenic_dev, temp);
427413
428414        usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
...... 
446432    return 1;
447433}
448434
449int nand_program_file(struct nand_in *nand_in, char *fname)
435int nand_program_file(struct nand_in *ni, char *fname)
450436{
451437
452438    int flen, m, j, k;
453    unsigned int start_page = 0, page_num, code_len, offset, transfer_size;
439    unsigned int start_page = 0, code_len, offset, transfer_size;
454440    int fd, status;
455    struct stat fstat;
441    struct stat fst;
456442    struct nand_in n_in;
457443
458    status = stat(fname, &fstat);
444    status = stat(fname, &fst);
459445
460446    if (status < 0) {
461447        fprintf(stderr, "Error - can't get file size from '%s': %s\n",
462448            fname, strerror(errno));
463449        return -1;
464450    }
465    flen = fstat.st_size;
451    flen = fst.st_size;
466452
467453    fd = open(fname, O_RDONLY);
468454    if (fd < 0) {
...... 
471457        return -1;
472458    }
473459
474    printf(" Programing No.%d device, flen %d, start page %d...\n",nand_in->dev, flen, nand_in->start);
475    n_in.start = nand_in->start / hand.nand_ppb;
476    if (nand_in->option == NO_OOB) {
460    printf(" Programing No.%d device, flen %d, start page %d...\n",ni->dev, flen, ni->start);
461    n_in.start = ni->start / hand.nand_ppb;
462    if (ni->option == NO_OOB) {
477463        if (flen % (hand.nand_ppb * hand.nand_ps) == 0)
478464            n_in.length = flen / (hand.nand_ps * hand.nand_ppb);
479465        else
...... 
487473                ((hand.nand_ps + hand.nand_os) * hand.nand_ppb)
488474                + 1;
489475    }
490    n_in.cs_map = nand_in->cs_map;
491    n_in.dev = nand_in->dev;
492    n_in.max_chip = nand_in->max_chip;
476    n_in.cs_map = ni->cs_map;
477    n_in.dev = ni->dev;
478    n_in.max_chip = ni->max_chip;
493479    if (nand_erase(&n_in) != 1)
494480        return -1;
495    if (nand_in->option == NO_OOB)
481    if (ni->option == NO_OOB)
496482        transfer_size = (hand.nand_ppb * hand.nand_ps);
497483    else
498484        transfer_size = (hand.nand_ppb * (hand.nand_ps + hand.nand_os));
...... 
500486    m = flen / transfer_size;
501487    j = flen % transfer_size;
502488    printf(" Size to send %d, transfer_size %d\n", flen, transfer_size);
503    printf(" Image type : %s\n", IMAGE_TYPE[nand_in->option]);
489    printf(" Image type : %s\n", IMAGE_TYPE[ni->option]);
504490    printf(" It will cause %d times buffer transfer.\n", j == 0 ? m : m + 1);
505491    fflush(NULL);
506492
507493    offset = 0;
508494    for (k = 0; k < m; k++) {
509        if (nand_in->option == NO_OOB)
510            page_num = transfer_size / hand.nand_ps;
511        else
512            page_num = transfer_size / (hand.nand_ps + hand.nand_os);
513
514495        code_len = transfer_size;
515496        status = read(fd, code_buf, code_len);
516497        if (status < code_len) {
...... 
519500            return -1;
520501        }
521502
522        nand_in->length = code_len; /* code length,not page number! */
523        nand_in->buf = code_buf;
524        if (nand_program_check(nand_in, &start_page) == -1)
503        ni->length = code_len; /* code length,not page number! */
504        ni->buf = code_buf;
505        if (nand_program_check(ni, &start_page) == -1)
525506            return -1;
526507
527        if (start_page - nand_in->start > hand.nand_ppb)
508        if (start_page - ni->start > hand.nand_ppb)
528509            printf(" Info - skip bad block!\n");
529        nand_in->start = start_page;
510        ni->start = start_page;
530511
531512        offset += code_len ;
532513    }
...... 
545526            return -1;
546527        }
547528
548        nand_in->length = j;
549        nand_in->buf = code_buf;
550        if (nand_program_check(nand_in, &start_page) == -1)
529        ni->length = j;
530        ni->buf = code_buf;
531        if (nand_program_check(ni, &start_page) == -1)
551532            return -1;
552533
553        if (start_page - nand_in->start > hand.nand_ppb)
534        if (start_page - ni->start > hand.nand_ppb)
554535            printf(" Info - skip bad block!");
555536
556537    }
...... 
559540    return 1;
560541}
561542
562int nand_program_file_planes(struct nand_in *nand_in, char *fname)
563{
564    printf(" not implement yet !\n");
565    return -1;
566}
567
568543int init_nand_in(void)
569544{
570545    nand_in.buf = code_buf;
...... 
612587    else
613588        printf("%s", help);
614589
615    if (hand.nand_plane > 1)
616        nand_program_file_planes(&nand_in, image_file);
617    else
590    if (hand.nand_plane == 1)
618591        nand_program_file(&nand_in, image_file);
619592
620593    status = 1;
621err:
594
622595    return status;
623596}
624597
625598int nand_query(void)
626599{
627    int i;
600    int cpu, i;
628601    unsigned char csn;
602    unsigned short ops;
629603
630604    if (com_argc < 3) {
631605        printf(" Usage: nquery (1) (2)\n"
...... 
645619    if (i >= nand_in.max_chip)
646620        return -1;
647621
648    int cpu = get_ingenic_cpu();
622    cpu = get_ingenic_cpu();
649623    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
650624        printf(" Device unboot! boot it first!\n");
651625        return -1;
...... 
654628    csn = i;
655629    printf(" ID of No.%d device No.%d flash: \n", nand_in.dev, csn);
656630
657    unsigned short ops = ((csn << 4) & 0xff0) + NAND_QUERY;
631    ops = ((csn << 4) & 0xff0) + NAND_QUERY;
658632    usb_ingenic_nand_ops(&ingenic_dev, ops);
659633    usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
660634    printf(" Vendor ID :0x%x \n",(unsigned char)ret[0]);
...... 
670644
671645int nand_read(int mode)
672646{
673    unsigned int i, j, cpu;
647    unsigned int cpu, j;
674648    unsigned int start_addr, length, page_num;
675649    unsigned char csn;
676650    unsigned short temp = 0;
...... 
752726    return 1;
753727}
754728
755int debug_memory(int obj, unsigned int start, unsigned int size)
729int debug_memory(unsigned int start, unsigned int size)
756730{
757731    unsigned int buffer[8],tmp;
758732
...... 
790764        return -1;
791765
792766    usleep(100);
793    usb_read_data_from_ingenic(&ingenic_dev, buffer, 8);
767    usb_read_data_from_ingenic(&ingenic_dev, (unsigned char *)buffer, 8);
794768    if (buffer[0] != 0)
795769        printf(" Test memory fail! Last error address is 0x%x !\n",
796770               buffer[0]);
...... 
800774    return 1;
801775}
802776
803int debug_gpio(int obj, unsigned char ops, unsigned char pin)
777int debug_gpio(unsigned char ops, unsigned char pin)
804778{
805779    unsigned int tmp;
806780
...... 
847821
848822int debug_go(void)
849823{
850    unsigned int addr,obj;
824    unsigned int addr, obj;
851825    if (com_argc<3) {
852826        printf(" Usage: go (1) (2) \n"
853827               " 1:start SDRAM address\n"
...... 
866840    return 1;
867841}
868842
869int sdram_load(struct sdram_in *sdram_in)
843int sdram_load(struct sdram_in *si)
870844{
871845    int cpu = get_ingenic_cpu();
872846    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
...... 
874848        return -1;
875849    }
876850
877    if (sdram_in->length > (unsigned int) MAX_LOAD_SIZE) {
851    if (si->length > (unsigned int) MAX_LOAD_SIZE) {
878852        printf(" Image length too long!\n");
879853        return -1;
880854    }
881855
882    ingenic_dev.file_buff = sdram_in->buf;
883    ingenic_dev.file_len = sdram_in->length;
856    ingenic_dev.file_buff = si->buf;
857    ingenic_dev.file_len = si->length;
884858    usb_send_data_to_ingenic(&ingenic_dev);
885    usb_send_data_address_to_ingenic(&ingenic_dev, sdram_in->start);
886    usb_send_data_length_to_ingenic(&ingenic_dev, sdram_in->length);
887    usb_ingenic_sdram_ops(&ingenic_dev, sdram_in);
859    usb_send_data_address_to_ingenic(&ingenic_dev, si->start);
860    usb_send_data_length_to_ingenic(&ingenic_dev, si->length);
861    usb_ingenic_sdram_ops(&ingenic_dev, SDRAM_LOAD);
888862
889863    usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
890864    printf(" Load last address at 0x%x\n",
...... 
893867    return 1;
894868}
895869
896int sdram_load_file(struct sdram_in *sdram_in, char *file_path)
870int sdram_load_file(struct sdram_in *si, char *file_path)
897871{
898    struct stat fstat;
899    unsigned int flen,m,j,offset,k;
872    struct stat fst;
873    unsigned int flen, m, j, k;
900874    int fd, status, res = -1;
901875
902    status = stat(file_path, &fstat);
876    status = stat(file_path, &fst);
903877    if (status < 0) {
904878        fprintf(stderr, "Error - can't get file size from '%s': %s\n",
905879            file_path, strerror(errno));
906880        goto out;
907881    }
908    flen = fstat.st_size;
882    flen = fst.st_size;
909883
910884    fd = open(file_path, O_RDONLY);
911885    if (fd < 0) {
...... 
916890
917891    m = flen / MAX_LOAD_SIZE;
918892    j = flen % MAX_LOAD_SIZE;
919    offset = 0;
920893
921894    printf(" Total size to send in byte is :%d\n", flen);
922895    printf(" Loading data to SDRAM :\n");
923896
924897    for (k = 0; k < m; k++) {
925        status = read(fd, sdram_in->buf, MAX_LOAD_SIZE);
898        status = read(fd, si->buf, MAX_LOAD_SIZE);
926899        if (status < MAX_LOAD_SIZE) {
927900            fprintf(stderr, "Error - can't read file '%s': %s\n",
928901                file_path, strerror(errno));
929902            goto close;
930903        }
931904
932        sdram_in->length = MAX_LOAD_SIZE;
933        if (sdram_load(sdram_in) < 1)
905        si->length = MAX_LOAD_SIZE;
906        if (sdram_load(si) < 1)
934907            goto close;
935908
936        sdram_in->start += MAX_LOAD_SIZE;
909        si->start += MAX_LOAD_SIZE;
937910        if ( k % 60 == 0)
938            printf(" 0x%x \n", sdram_in->start);
911            printf(" 0x%x \n", si->start);
939912    }
940913
941914    if (j) {
942915        if (j % 4 !=0)
943916            j += 4 - (j % 4);
944        status = read(fd, sdram_in->buf, j);
917        status = read(fd, si->buf, j);
945918        if (status < j) {
946919            fprintf(stderr, "Error - can't read file '%s': %s\n",
947920                file_path, strerror(errno));
948921            goto close;
949922        }
950923
951        sdram_in->length = j;
952        if (sdram_load(sdram_in) < 1)
924        si->length = j;
925        if (sdram_load(si) < 1)
953926            goto close;
954927    }
955928
usbboot/src/cmd.h
2222#include "usb_boot_defines.h"
2323
2424#define COMMAND_NUM 31
25#define MAX_ARGC 10
26#define MAX_COMMAND_LENGTH 100
25
26struct ingenic_dev ingenic_dev;
27struct hand hand;
28struct sdram_in sdram_in;
29struct nand_in nand_in;
30
31unsigned int total_size;
32unsigned char code_buf[4 * 512 * 1024];
33unsigned char check_buf[4 * 512 * 1024];
34unsigned char cs[16];
35unsigned char ret[8];
36
37static const char IMAGE_TYPE[][30] = {
38    "with oob and ecc",
39    "with oob and without ecc",
40    "without oob",
41};
2742
2843int boot(char *stage1_path, char *stage2_path);
2944int init_nand_in();
45int nand_read(int mode);
3046int nand_prog(void);
3147int nand_query(void);
3248int nand_erase(struct nand_in *nand_in);
33int debug_memory(int obj, unsigned int start, unsigned int size);
34int debug_gpio(int obj, unsigned char ops, unsigned char pin);
49int debug_memory(unsigned int start, unsigned int size);
50int debug_gpio(unsigned char ops, unsigned char pin);
3551int debug_go(void);
3652int device_reset(int ops);
53int nand_markbad(struct nand_in *nand_in);
54int sdram_load_file(struct sdram_in *sdram_in, char *file_path);
3755
3856#endif /* __CMD_H__ */
usbboot/src/command_line.c
2121#include <string.h>
2222#include "usb_boot_defines.h"
2323#include "ingenic_usb.h"
24#include "command_line.h"
2425#include "cmd.h"
2526
26extern struct nand_in nand_in;
27extern struct sdram_in sdram_in;
28extern unsigned char code_buf[4 * 512 * 1024];
29
30int com_argc;
31char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
32char * stage1;
33char * stage2;
34
3527static int handle_help(void)
3628{
3729    printf(
38    " boot boot device and make it in stage2\n"
39    " reset reset device\n"
40    " nprog program NAND flash\n"
41    " nquery query NAND flash info\n"
42    " nerase erase NAND flash\n"
43    " nmark mark a bad block in NAND flash\n"
44    " nread read NAND flash data with checking bad block and ECC\n"
45    " nreadraw read NAND flash data without checking bad block and ECC\n"
46    " nreadoob read NAND flash oob\n"
47    " gpios set one GPIO to high level\n"
48    " gpioc set one GPIO to low level\n"
49    " load load file data to SDRAM\n"
50    " go execute program in SDRAM\n"
51    " memtest memory test\n"
52    " help print this help\n"
53    " exit \n");
30        " boot boot device and make it in stage2\n"
31        " reset reset device\n"
32        " nquery query NAND flash info\n"
33        " nprog program NAND flash\n"
34        " nerase erase NAND flash\n"
35        " nmark mark a bad block in NAND flash\n"
36        " nread read NAND flash data with checking bad block and ECC\n"
37        " nreadraw read NAND flash data without checking bad block and ECC\n"
38        " nreadoob read NAND flash oob\n"
39        " gpios set one GPIO to high level\n"
40        " gpioc set one GPIO to low level\n"
41        " load load file data to SDRAM\n"
42        " go execute program in SDRAM\n"
43        " memtest memory test\n"
44        " help print this help\n"
45        " exit\n");
5446
5547    return 0;
5648}
...... 
128120        size = 0;
129121    }
130122
131    debug_memory(atoi(com_argv[1]), start, size);
123    debug_memory(start, size);
132124    return 0;
133125}
134126
...... 
142134        return -1;
143135    }
144136
145    debug_gpio(atoi(com_argv[2]), mode, atoi(com_argv[1]));
137    debug_gpio(mode, atoi(com_argv[1]));
146138    return 0;
147139}
148140
...... 
175167    com_argc = 0;
176168    strcpy(com_argv[com_argc++], p);
177169
178    while (p = strtok(NULL, "\n "))
170    while ((p = strtok(NULL, "\n ")) != NULL)
179171        strcpy(com_argv[com_argc++], p);
180172
181173    if (!strcmp("boot", com_argv[0]))
...... 
211203    else if (!strcmp("exit", com_argv[0]))
212204        return -1;
213205    else
214        printf(" type `help` show all commands\n", com_argv[0]);
206        printf(" type `help` show all commands\n");
215207
216208    return 0;
217209}
usbboot/src/command_line.h
1919#ifndef __COMMAND_LINE_H__
2020#define __COMMAND_LINE_H__
2121
22#define MAX_ARGC 10
23#define MAX_COMMAND_LENGTH 100
24
25int com_argc;
26char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
27char *stage1;
28char *stage2;
29
2230int command_handle(char *buf);
2331
2432#endif /* __COMMAND_LINE_H__ */
usbboot/src/ingenic_cfg.c
1818
1919#include <errno.h>
2020#include <confuse.h>
21#include <unistd.h>
21#include <unistd.h>
2222#include <string.h>
2323#include "ingenic_cfg.h"
2424#include "usb_boot_defines.h"
2525
2626extern unsigned int total_size;
2727
28int check_dump_cfg(struct hand *hand)
28int check_dump_cfg(struct hand *h)
2929{
3030    printf("Now checking whether all configure args valid:");
3131    /* check PLL */
32    if (hand->fw_args.ext_clk > 27 || hand->fw_args.ext_clk < 12) {
32    if (h->fw_args.ext_clk > 27 || h->fw_args.ext_clk < 12) {
3333        printf(" EXTCLK setting invalid!\n");
3434        return 0;
3535    }
36    if (hand->fw_args.phm_div > 32 || hand->fw_args.ext_clk < 2) {
36    if (h->fw_args.phm_div > 32 || h->fw_args.ext_clk < 2) {
3737        printf(" PHMDIV setting invalid!\n");
3838        return 0;
3939    }
40    if ((hand->fw_args.cpu_speed * hand->fw_args.ext_clk ) % 12 != 0) {
40    if ((h->fw_args.cpu_speed * h->fw_args.ext_clk ) % 12 != 0) {
4141        printf(" CPUSPEED setting invalid!\n");
4242        return 0;
4343    }
4444
4545    /* check SDRAM */
46    if (hand->fw_args.bus_width > 1 ) {
46    if (h->fw_args.bus_width > 1 ) {
4747        printf(" SDRAMWIDTH setting invalid!\n");
4848        return 0;
4949    }
50    if (hand->fw_args.bank_num > 1 ) {
50    if (h->fw_args.bank_num > 1 ) {
5151        printf(" BANKNUM setting invalid!\n");
5252        return 0;
5353    }
54    if (hand->fw_args.row_addr > 13 && hand->fw_args.row_addr < 11 ) {
54    if (h->fw_args.row_addr > 13 && h->fw_args.row_addr < 11 ) {
5555        printf(" ROWADDR setting invalid!\n");
5656        return 0;
5757    }
58    if (hand->fw_args.col_addr > 13 && hand->fw_args.col_addr < 11 ) {
58    if (h->fw_args.col_addr > 13 && h->fw_args.col_addr < 11 ) {
5959        printf(" COLADDR setting invalid!\n");
6060        return 0;
6161    }
6262
6363    /* check NAND */
64    if (hand->nand_ps < 2048 && hand->nand_os > 16) {
64    if (h->nand_ps < 2048 && h->nand_os > 16) {
6565        printf(" PAGESIZE or OOBSIZE setting invalid!\n");
66        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
67               hand->nand_ps, hand->nand_os);
66        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
67               h->nand_ps, h->nand_os);
6868        return 0;
6969    }
70    if (hand->nand_ps < 2048 && hand->nand_ppb > 32) {
70    if (h->nand_ps < 2048 && h->nand_ppb > 32) {
7171        printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
7272        return 0;
7373    }
7474
75    if (hand->nand_ps > 512 && hand->nand_os <= 16) {
75    if (h->nand_ps > 512 && h->nand_os <= 16) {
7676        printf(" PAGESIZE or OOBSIZE setting invalid!\n");
77        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
78               hand->nand_ps, hand->nand_os);
77        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
78               h->nand_ps, h->nand_os);
7979        return 0;
8080    }
81    if (hand->nand_ps > 512 && hand->nand_ppb < 64) {
81    if (h->nand_ps > 512 && h->nand_ppb < 64) {
8282        printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
8383        return 0;
8484    }
...... 
8686
8787    printf("Current device setup information:\n");
8888    printf("Crystal work at %dMHz, the CCLK up to %dMHz and PMH_CLK up to %dMHz\n",
89        hand->fw_args.ext_clk,
90        (unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk,
91        ((unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk) / hand->fw_args.phm_div);
89        h->fw_args.ext_clk,
90        (unsigned int)h->fw_args.cpu_speed * h->fw_args.ext_clk,
91        ((unsigned int)h->fw_args.cpu_speed * h->fw_args.ext_clk) / h->fw_args.phm_div);
9292
9393    printf("SDRAM Total size is %d MB, work in %d bank and %d bit mode\n",
94        total_size / 0x100000, 2 * (hand->fw_args.bank_num + 1),
95           16 * (2 - hand->fw_args.bus_width));
94        total_size / 0x100000, 2 * (h->fw_args.bank_num + 1),
95           16 * (2 - h->fw_args.bus_width));
9696
9797    printf("Nand page per block %d, "
9898           "Nand page size %d, "
...... 
100100           "bad block offset in OOB %d, "
101101           "bad block page %d, "
102102           "use %d plane mode\n",
103           hand->nand_ppb,
104           hand->nand_ps,
105           hand->nand_eccpos,
106           hand->nand_bbpos,
107           hand->nand_bbpage,
108           hand->nand_plane);
103           h->nand_ppb,
104           h->nand_ps,
105           h->nand_eccpos,
106           h->nand_bbpos,
107           h->nand_bbpage,
108           h->nand_plane);
109109    return 1;
110110}
111111
112int parse_configure(struct hand *hand, char * file_path)
112int parse_configure(struct hand *h, char * file_path)
113113{
114    if (access(file_path, F_OK)) {
115        fprintf(stderr, "Error - can't read configure file %s.\n",
116            file_path);
117        return -1;
118    }
119
114    cfg_t *cfg;
120115    cfg_opt_t opts[] = {
121116        CFG_INT("BOUDRATE", 57600, CFGF_NONE),
122117        CFG_INT("EXTCLK", 0, CFGF_NONE),
...... 
153148        CFG_END()
154149    };
155150
156    cfg_t *cfg;
151    if (access(file_path, F_OK)) {
152        fprintf(stderr, "Error - can't read configure file %s.\n",
153            file_path);
154        return -1;
155    }
156
157157    cfg = cfg_init(opts, 0);
158158    if (cfg_parse(cfg, file_path) == CFG_PARSE_ERROR)
159159        return -1;
160160
161    hand->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE");
162    hand->fw_args.ext_clk = cfg_getint(cfg, "EXTCLK");
163    hand->fw_args.cpu_speed = cfg_getint(cfg, "CPUSPEED");
164    hand->fw_args.phm_div = cfg_getint(cfg, "PHMDIV");
165    hand->fw_args.use_uart = cfg_getint(cfg, "USEUART");
166
167    hand->fw_args.bus_width = cfg_getint(cfg, "BUSWIDTH");
168    hand->fw_args.bank_num = cfg_getint(cfg, "BANKS");
169    hand->fw_args.row_addr = cfg_getint(cfg, "ROWADDR");
170    hand->fw_args.col_addr = cfg_getint(cfg, "COLADDR");
171
172    hand->fw_args.is_mobile = cfg_getint(cfg, "ISMOBILE");
173    hand->fw_args.is_busshare = cfg_getint(cfg, "ISBUSSHARE");
174    hand->fw_args.debug_ops = cfg_getint(cfg, "DEBUGOPS");
175    hand->fw_args.pin_num = cfg_getint(cfg, "PINNUM");
176    hand->fw_args.start = cfg_getint(cfg, "START");
177    hand->fw_args.size = cfg_getint(cfg, "SIZE");
178
179    hand->nand_bw = cfg_getint(cfg, "NAND_BUSWIDTH");
180    hand->nand_rc = cfg_getint(cfg, "NAND_ROWCYCLES");
181    hand->nand_ps = cfg_getint(cfg, "NAND_PAGESIZE");
182    hand->nand_ppb = cfg_getint(cfg, "NAND_PAGEPERBLOCK");
183    hand->nand_force_erase = cfg_getint(cfg, "NAND_FORCEERASE");
184    hand->nand_os = cfg_getint(cfg, "NAND_OOBSIZE");
185    hand->nand_eccpos = cfg_getint(cfg, "NAND_ECCPOS");
186    hand->nand_bbpos = cfg_getint(cfg, "NAND_BADBLOCKPOS");
187    hand->nand_bbpage = cfg_getint(cfg, "NAND_BADBLOCKPAGE");
188    hand->nand_plane = cfg_getint(cfg, "NAND_PLANENUM");
189    hand->nand_bchbit = cfg_getint(cfg, "NAND_BCHBIT");
190    hand->nand_wppin = cfg_getint(cfg, "NAND_WPPIN");
191    hand->nand_bpc = cfg_getint(cfg, "NAND_BLOCKPERCHIP");
161    h->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE");
162    h->fw_args.ext_clk = cfg_getint(cfg, "EXTCLK");
163    h->fw_args.cpu_speed = cfg_getint(cfg, "CPUSPEED");
164    h->fw_args.phm_div = cfg_getint(cfg, "PHMDIV");
165    h->fw_args.use_uart = cfg_getint(cfg, "USEUART");
166
167    h->fw_args.bus_width = cfg_getint(cfg, "BUSWIDTH");
168    h->fw_args.bank_num = cfg_getint(cfg, "BANKS");
169    h->fw_args.row_addr = cfg_getint(cfg, "ROWADDR");
170    h->fw_args.col_addr = cfg_getint(cfg, "COLADDR");
171
172    h->fw_args.is_mobile = cfg_getint(cfg, "ISMOBILE");
173    h->fw_args.is_busshare = cfg_getint(cfg, "ISBUSSHARE");
174    h->fw_args.debug_ops = cfg_getint(cfg, "DEBUGOPS");
175    h->fw_args.pin_num = cfg_getint(cfg, "PINNUM");
176    h->fw_args.start = cfg_getint(cfg, "START");
177    h->fw_args.size = cfg_getint(cfg, "SIZE");
178
179    h->nand_bw = cfg_getint(cfg, "NAND_BUSWIDTH");
180    h->nand_rc = cfg_getint(cfg, "NAND_ROWCYCLES");
181    h->nand_ps = cfg_getint(cfg, "NAND_PAGESIZE");
182    h->nand_ppb = cfg_getint(cfg, "NAND_PAGEPERBLOCK");
183    h->nand_force_erase = cfg_getint(cfg, "NAND_FORCEERASE");
184    h->nand_os = cfg_getint(cfg, "NAND_OOBSIZE");
185    h->nand_eccpos = cfg_getint(cfg, "NAND_ECCPOS");
186    h->nand_bbpos = cfg_getint(cfg, "NAND_BADBLOCKPOS");
187    h->nand_bbpage = cfg_getint(cfg, "NAND_BADBLOCKPAGE");
188    h->nand_plane = cfg_getint(cfg, "NAND_PLANENUM");
189    h->nand_bchbit = cfg_getint(cfg, "NAND_BCHBIT");
190    h->nand_wppin = cfg_getint(cfg, "NAND_WPPIN");
191    h->nand_bpc = cfg_getint(cfg, "NAND_BLOCKPERCHIP");
192192
193193    cfg_free(cfg);
194194
195    if (hand->fw_args.bus_width == 32)
196        hand->fw_args.bus_width = 0;
195    if (h->fw_args.bus_width == 32)
196        h->fw_args.bus_width = 0;
197197    else
198        hand->fw_args.bus_width = 1;
199    hand->fw_args.bank_num = hand->fw_args.bank_num / 4;
200    hand->fw_args.cpu_speed = hand->fw_args.cpu_speed / hand->fw_args.ext_clk;
201
198        h->fw_args.bus_width = 1;
199    h->fw_args.bank_num = h->fw_args.bank_num / 4;
200    h->fw_args.cpu_speed = h->fw_args.cpu_speed / h->fw_args.ext_clk;
201
202202    total_size = (unsigned int)
203        (2 << (hand->fw_args.row_addr + hand->fw_args.col_addr - 1)) * 2
204        * (hand->fw_args.bank_num + 1) * 2
205        * (2 - hand->fw_args.bus_width);
203        (2 << (h->fw_args.row_addr + h->fw_args.col_addr - 1)) * 2
204        * (h->fw_args.bank_num + 1) * 2
205        * (2 - h->fw_args.bus_width);
206206
207    if (check_dump_cfg(hand) < 1)
207    if (check_dump_cfg(h) < 1)
208208        return -1;
209209
210210    return 1;
usbboot/src/ingenic_cfg.h
2020#define __INGENIC_CFG_H__
2121
2222#include "usb_boot_defines.h"
23#include "ingenic_usb.h"
2324
2425int hand_init_def(struct hand *hand);
2526int check_dump_cfg(struct hand *hand);
usbboot/src/ingenic_usb.c
22 * Copyright(C) 2009 Qi Hardware Inc.,
33 * Authors: Xiangfu Liu <xiangfu@sharism.cc>
44 * Marek Lindner <lindner_marek@yahoo.de>
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License as published by
88 * the Free Software Foundation, either version 3 of the License, or
...... 
2626
2727extern unsigned int total_size;
2828
29static int get_ingenic_device(struct ingenic_dev *ingenic_dev)
29static int get_ingenic_device(struct ingenic_dev *id)
3030{
31    struct usb_bus *usb_busses, *usb_bus;
31    struct usb_bus *ub, *usb_bus;
3232    struct usb_device *usb_dev;
3333    int count = 0;
3434
35    usb_busses = usb_get_busses();
35    ub = usb_get_busses();
3636
37    for (usb_bus = usb_busses; usb_bus != NULL; usb_bus = usb_bus->next) {
38        for (usb_dev = usb_bus->devices; usb_dev != NULL;
37    for (usb_bus = ub; usb_bus != NULL; usb_bus = usb_bus->next) {
38        for (usb_dev = usb_bus->devices; usb_dev != NULL;
3939             usb_dev = usb_dev->next) {
4040
4141            if ((usb_dev->descriptor.idVendor == VENDOR_ID) &&
4242                (usb_dev->descriptor.idProduct == PRODUCT_ID_4740 ||
4343                usb_dev->descriptor.idProduct == PRODUCT_ID_4760)) {
44                ingenic_dev->usb_dev = usb_dev;
44                id->usb_dev = usb_dev;
4545                count++;
4646            }
4747
...... 
5151    return count;
5252}
5353
54static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
54static int get_ingenic_interface(struct ingenic_dev *id)
5555{
5656    struct usb_config_descriptor *usb_config_desc;
5757    struct usb_interface_descriptor *usb_if_desc;
5858    struct usb_interface *usb_if;
5959    int config_index, if_index, alt_index;
6060
61    for (config_index = 0;
62         config_index < ingenic_dev->usb_dev->descriptor.bNumConfigurations;
61    for (config_index = 0;
62         config_index < id->usb_dev->descriptor.bNumConfigurations;
6363         config_index++) {
64        usb_config_desc = &ingenic_dev->usb_dev->config[config_index];
64        usb_config_desc = &id->usb_dev->config[config_index];
6565
6666        if (!usb_config_desc)
6767            return 0;
6868
69        for (if_index = 0; if_index < usb_config_desc->bNumInterfaces;
69        for (if_index = 0; if_index < usb_config_desc->bNumInterfaces;
7070             if_index++) {
7171            usb_if = &usb_config_desc->interface[if_index];
7272
...... 
8282
8383                if ((usb_if_desc->bInterfaceClass == 0xff) &&
8484                    (usb_if_desc->bInterfaceSubClass == 0)) {
85                    ingenic_dev->interface =
85                    id->interface =
8686                        usb_if_desc->bInterfaceNumber;
8787                    return 1;
8888                }
...... 
9393    return 0;
9494}
9595
96int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
96int usb_ingenic_init(struct ingenic_dev *id)
9797{
9898    int num_ingenic, status = -1;
9999
100    memset(ingenic_dev, 0, sizeof(struct ingenic_dev));
100    memset(id, 0, sizeof(struct ingenic_dev));
101101
102102    usb_init();
103103     /* usb_set_debug(255); */
104104    usb_find_busses();
105105    usb_find_devices();
106106
107    num_ingenic = get_ingenic_device(ingenic_dev);
107    num_ingenic = get_ingenic_device(id);
108108
109109    if (num_ingenic == 0) {
110110        fprintf(stderr, "Error - no XBurst device found\n");
...... 
117117        goto out;
118118    }
119119
120    ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);
121    if (!ingenic_dev->usb_handle) {
120    id->usb_handle = usb_open(id->usb_dev);
121    if (!id->usb_handle) {
122122        fprintf(stderr, "Error - can't open XBurst device: %s\n",
123123            usb_strerror());
124124        goto out;
125125    }
126126
127    if (get_ingenic_interface(ingenic_dev) < 1) {
127    if (get_ingenic_interface(id) < 1) {
128128        fprintf(stderr, "Error - can't find XBurst interface\n");
129129        goto out;
130130    }
131131
132    if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface)
132    if (usb_claim_interface(id->usb_handle, id->interface)
133133        < 0) {
134134        fprintf(stderr, "Error - can't claim XBurst interface: %s\n",
135135            usb_strerror());
...... 
142142    return status;
143143}
144144
145int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
145int usb_get_ingenic_cpu(struct ingenic_dev *id)
146146{
147147    int status;
148148
149    memset(&ingenic_dev->cpu_info_buff, 0,
150           ARRAY_SIZE(ingenic_dev->cpu_info_buff));
149    memset(&id->cpu_info_buff, 0,
150           ARRAY_SIZE(id->cpu_info_buff));
151151
152152    sleep(1);
153    status = usb_control_msg(ingenic_dev->usb_handle,
154          /* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
155          /* bRequest */ VR_GET_CPU_INFO,
156          /* wValue */ 0,
157          /* wIndex */ 0,
158          /* Data */ ingenic_dev->cpu_info_buff,
159          /* wLength */ 8,
160                              USB_TIMEOUT);
161
162    if (status != sizeof(ingenic_dev->cpu_info_buff) - 1 ) {
153    status = usb_control_msg(id->usb_handle,
154      /* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
155      /* bRequest */ VR_GET_CPU_INFO,
156      /* wValue */ 0,
157      /* wIndex */ 0,
158      /* Data */ id->cpu_info_buff,
159      /* wLength */ 8,
160                  USB_TIMEOUT);
161
162    if (status != sizeof(id->cpu_info_buff) - 1 ) {
163163        fprintf(stderr, "Error - "
164164            "can't retrieve XBurst CPU information: %i\n", status);
165165        return status;
166166    }
167167
168    ingenic_dev->cpu_info_buff[8] = '\0';
169    printf(" CPU data: %s\n", ingenic_dev->cpu_info_buff);
168    id->cpu_info_buff[8] = '\0';
169    printf(" CPU data: %s\n", id->cpu_info_buff);
170170
171    if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4740V1")) return JZ4740V1;
172    if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4750V1")) return JZ4750V1;
173    if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4760V1")) return JZ4760V1;
174    if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4740")) return BOOT4740;
175    if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4750")) return BOOT4750;
176    if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4760")) return BOOT4760;
171    if (!strcmp(id->cpu_info_buff,"JZ4740V1")) return JZ4740V1;
172    if (!strcmp(id->cpu_info_buff,"JZ4750V1")) return JZ4750V1;
173    if (!strcmp(id->cpu_info_buff,"JZ4760V1")) return JZ4760V1;
174    if (!strcmp(id->cpu_info_buff,"Boot4740")) return BOOT4740;
175    if (!strcmp(id->cpu_info_buff,"Boot4750")) return BOOT4750;
176    if (!strcmp(id->cpu_info_buff,"Boot4760")) return BOOT4760;
177177
178178    return -1;
179179}
180180
181int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev)
181int usb_ingenic_flush_cache(struct ingenic_dev *id)
182182{
183183    int status;
184184
185    status = usb_control_msg(ingenic_dev->usb_handle,
186          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
187          /* bRequest */ VR_FLUSH_CACHES,
188          /* wValue */ 0,
189          /* wIndex */ 0,
190          /* Data */ 0,
191          /* wLength */ 0,
192                              USB_TIMEOUT);
185    status = usb_control_msg(id->usb_handle,
186      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
187      /* bRequest */ VR_FLUSH_CACHES,
188      /* wValue */ 0,
189      /* wIndex */ 0,
190      /* Data */ 0,
191      /* wLength */ 0,
192                  USB_TIMEOUT);
193193
194194    if (status != 0) {
195195        fprintf(stderr, "Error - can't flush cache: %i\n", status);
...... 
199199    return 1;
200200}
201201
202int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len)
202int usb_send_data_length_to_ingenic(struct ingenic_dev *id, int len)
203203{
204204    int status;
205205    /* tell the device the length of the file to be uploaded */
206    status = usb_control_msg(ingenic_dev->usb_handle,
207          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
208          /* bRequest */ VR_SET_DATA_LENGTH,
209          /* wValue */ STAGE_ADDR_MSB(len),
210          /* wIndex */ STAGE_ADDR_LSB(len),
211          /* Data */ 0,
212          /* wLength */ 0,
213                              USB_TIMEOUT);
206    status = usb_control_msg(id->usb_handle,
207      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
208      /* bRequest */ VR_SET_DATA_LENGTH,
209      /* wValue */ STAGE_ADDR_MSB(len),
210      /* wIndex */ STAGE_ADDR_LSB(len),
211      /* Data */ 0,
212      /* wLength */ 0,
213                  USB_TIMEOUT);
214214
215215    if (status != 0) {
216216        fprintf(stderr, "Error - "
...... 
221221    return 1;
222222}
223223
224int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev,
224int usb_send_data_address_to_ingenic(struct ingenic_dev *id,
225225                     unsigned int stage_addr)
226226{
227227    int status;
228228    /* tell the device the RAM address to store the file */
229    status = usb_control_msg(ingenic_dev->usb_handle,
230          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
231          /* bRequest */ VR_SET_DATA_ADDRESS,
232          /* wValue */ STAGE_ADDR_MSB(stage_addr),
233          /* wIndex */ STAGE_ADDR_LSB(stage_addr),
234          /* Data */ 0,
235          /* wLength */ 0,
236                              USB_TIMEOUT);
229    status = usb_control_msg(id->usb_handle,
230      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
231      /* bRequest */ VR_SET_DATA_ADDRESS,
232      /* wValue */ STAGE_ADDR_MSB(stage_addr),
233      /* wIndex */ STAGE_ADDR_LSB(stage_addr),
234      /* Data */ 0,
235      /* wLength */ 0,
236                  USB_TIMEOUT);
237237
238238    if (status != 0) {
239239        fprintf(stderr, "Error - "
...... 
244244    return 1;
245245}
246246
247int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
247int usb_send_data_to_ingenic(struct ingenic_dev *id)
248248{
249249    int status;
250    status = usb_bulk_write(ingenic_dev->usb_handle,
250    status = usb_bulk_write(id->usb_handle,
251251    /* endpoint */ INGENIC_OUT_ENDPOINT,
252    /* bulk data */ ingenic_dev->file_buff,
253    /* bulk data length */ ingenic_dev->file_len,
254                USB_TIMEOUT);
255    if (status < (int)ingenic_dev->file_len) {
252    /* bulk data */ (char *)id->file_buff,
253    /* bulk data length */ id->file_len,
254                   USB_TIMEOUT);
255    if (status < (int)id->file_len) {
256256        fprintf(stderr, "Error - "
257257            "can't send bulk data to Ingenic CPU: %i %s\n", status, usb_strerror());
258258        return -1;
...... 
261261    return 1;
262262}
263263
264int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,
264int usb_read_data_from_ingenic(struct ingenic_dev *id,
265265                   unsigned char *buff, unsigned int len)
266266{
267267    int status;
268    status = usb_bulk_read(ingenic_dev->usb_handle,
269        /* endpoint */ INGENIC_IN_ENDPOINT,
270    /* bulk data */ buff,
268    status = usb_bulk_read(id->usb_handle,
269    /* endpoint */ INGENIC_IN_ENDPOINT,
270    /* bulk data */ (char *)buff,
271271    /* bulk data length */ len,
272                USB_TIMEOUT);
272                   USB_TIMEOUT);
273273
274274    if (status < (int)len) {
275275        fprintf(stderr, "Error - "
...... 
280280    return 1;
281281}
282282
283int usb_ingenic_start(struct ingenic_dev *ingenic_dev, int rqst, int stage_addr)
283int usb_ingenic_start(struct ingenic_dev *id, int rqst, unsigned int stage_addr)
284284{
285285    int status;
286286
287287    /* tell the device to start the uploaded device */
288    status = usb_control_msg(ingenic_dev->usb_handle,
289          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
288    status = usb_control_msg(id->usb_handle,
289      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
290290      /* bRequest */ rqst,
291          /* wValue */ STAGE_ADDR_MSB(stage_addr),
292          /* wIndex */ STAGE_ADDR_LSB(stage_addr),
293          /* Data */ 0,
294          /* wLength */ 0,
295                              USB_TIMEOUT);
291      /* wValue */ STAGE_ADDR_MSB(stage_addr),
292      /* wIndex */ STAGE_ADDR_LSB(stage_addr),
293      /* Data */ 0,
294      /* wLength */ 0,
295                  USB_TIMEOUT);
296296
297297    if (status != 0) {
298298        fprintf(stderr, "Error - can't start the uploaded binary "
...... 
302302    return 1;
303303}
304304
305int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
305int usb_ingenic_upload(struct ingenic_dev *id, int stage)
306306{
307    int status;
308
307    unsigned int stage_addr;
309308    unsigned int stage2_addr;
310    stage2_addr = total_size + 0x80000000;
311    stage2_addr -= CODE_SIZE;
312
313    unsigned int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
314309    int rqst = VR_PROGRAM_START1;
315310
316    usb_send_data_address_to_ingenic(ingenic_dev, stage_addr);
317    printf(" Download stage %d program and execute at 0x%08x\n",
311    stage2_addr = 0x80000000 + total_size - CODE_SIZE;
312    stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
313
314    usb_send_data_address_to_ingenic(id, stage_addr);
315    printf(" Download stage %d program and execute at 0x%08x\n",
318316           stage, (stage_addr));
319    usb_send_data_to_ingenic(ingenic_dev);
317    usb_send_data_to_ingenic(id);
320318
321319    if (stage == 2) {
322        if (usb_get_ingenic_cpu(ingenic_dev) < 1)
320        if (usb_get_ingenic_cpu(id) < 1)
323321            return -1;
324        usb_ingenic_flush_cache(ingenic_dev);
322        usb_ingenic_flush_cache(id);
325323        rqst = VR_PROGRAM_START2;
326324    }
327325
328326    usleep(100);
329    if (usb_ingenic_start(ingenic_dev, rqst, stage_addr) < 1)
327    if (usb_ingenic_start(id, rqst, stage_addr) < 1)
330328        return -1;
331329    usleep(100);
332    if (usb_get_ingenic_cpu(ingenic_dev) < 1)
330    if (usb_get_ingenic_cpu(id) < 1)
333331        return -1;
334332
335333    return 1;
336334}
337335
338void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev)
336void usb_ingenic_cleanup(struct ingenic_dev *id)
339337{
340    if ((ingenic_dev->usb_handle) && (ingenic_dev->interface))
341        usb_release_interface(ingenic_dev->usb_handle,
342                      ingenic_dev->interface);
338    if ((id->usb_handle) && (id->interface))
339        usb_release_interface(id->usb_handle,
340                      id->interface);
343341
344    if (ingenic_dev->usb_handle)
345        usb_close(ingenic_dev->usb_handle);
342    if (id->usb_handle)
343        usb_close(id->usb_handle);
346344}
347345
348int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops)
346int usb_ingenic_nand_ops(struct ingenic_dev *id, int ops)
349347{
350348    int status;
351    status = usb_control_msg(ingenic_dev->usb_handle,
352          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
353          /* bRequest */ VR_NAND_OPS,
354          /* wValue */ ops & 0xffff,
355          /* wIndex */ 0,
356          /* Data */ 0,
357          /* wLength */ 0,
358                              USB_TIMEOUT);
349    status = usb_control_msg(id->usb_handle,
350      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
351      /* bRequest */ VR_NAND_OPS,
352      /* wValue */ ops & 0xffff,
353      /* wIndex */ 0,
354      /* Data */ 0,
355      /* wLength */ 0,
356                  USB_TIMEOUT);
359357
360358    if (status != 0) {
361359        fprintf(stderr, "Error - "
...... 
366364    return 1;
367365}
368366
369int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops)
367int usb_ingenic_configration(struct ingenic_dev *id, int ops)
370368{
371369    int status;
372    status = usb_control_msg(ingenic_dev->usb_handle,
373          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
374          /* bRequest */ VR_CONFIGRATION,
375          /* wValue */ ops,
376          /* wIndex */ 0,
377          /* Data */ 0,
378          /* wLength */ 0,
379                              USB_TIMEOUT);
370    status = usb_control_msg(id->usb_handle,
371      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
372      /* bRequest */ VR_CONFIGRATION,
373      /* wValue */ ops,
374      /* wIndex */ 0,
375      /* Data */ 0,
376      /* wLength */ 0,
377                  USB_TIMEOUT);
380378
381379    if (status != 0) {
382380        fprintf(stderr, "Error - "
...... 
387385    return 1;
388386}
389387
390int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops)
388int usb_ingenic_sdram_ops(struct ingenic_dev *id, int ops)
391389{
392390    int status;
393    status = usb_control_msg(ingenic_dev->usb_handle,
394          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
395          /* bRequest */ VR_SDRAM_OPS,
396          /* wValue */ ops,
397          /* wIndex */ 0,
398          /* Data */ 0,
399          /* wLength */ 0,
400                              USB_TIMEOUT);
391    status = usb_control_msg(id->usb_handle,
392      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
393      /* bRequest */ VR_SDRAM_OPS,
394      /* wValue */ ops,
395      /* wIndex */ 0,
396      /* Data */ 0,
397      /* wLength */ 0,
398                  USB_TIMEOUT);
401399
402400    if (status != 0) {
403401        fprintf(stderr, "Error - "
...... 
408406    return 1;
409407}
410408
411int usb_ingenic_reset(struct ingenic_dev *ingenic_dev, int ops)
409int usb_ingenic_reset(struct ingenic_dev *id, int ops)
412410{
413411    int status;
414    status = usb_control_msg(ingenic_dev->usb_handle,
415          /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
416          /* bRequest */ VR_RESET,
417          /* wValue */ ops,
418          /* wIndex */ 0,
419          /* Data */ 0,
420          /* wLength */ 0,
421                              USB_TIMEOUT);
412    status = usb_control_msg(id->usb_handle,
413      /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
414      /* bRequest */ VR_RESET,
415      /* wValue */ ops,
416      /* wIndex */ 0,
417      /* Data */ 0,
418      /* wLength */ 0,
419                  USB_TIMEOUT);
422420
423421    if (status != 0) {
424422        fprintf(stderr, "Error - "
usbboot/src/ingenic_usb.h
2121#define __INGENIC_USB_H__
2222
2323#include <stdint.h>
24#include "cmd.h"
2425
2526#define INGENIC_OUT_ENDPOINT 0x01
2627#define INGENIC_IN_ENDPOINT 0x81
...... 
5051    struct usb_dev_handle *usb_handle;
5152    uint8_t interface;
5253    char cpu_info_buff[9];
53    char *file_buff;
54    unsigned char *file_buff;
5455    unsigned int file_len;
5556};
5657
57int usb_ingenic_init(struct ingenic_dev *ingenic_dev);
58int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev);
59int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage);
60void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev);
61int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev,
58int usb_ingenic_init(struct ingenic_dev *id);
59int usb_get_ingenic_cpu(struct ingenic_dev *id);
60int usb_ingenic_upload(struct ingenic_dev *id, int stage);
61void usb_ingenic_cleanup(struct ingenic_dev *id);
62int usb_send_data_address_to_ingenic(struct ingenic_dev *id,
6263                     unsigned int stage_addr);
63int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev);
64int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev,
64int usb_send_data_to_ingenic(struct ingenic_dev *id);
65int usb_send_data_length_to_ingenic(struct ingenic_dev *id,
6566                    int len);
66int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops);
67int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,unsigned char *buff, unsigned int len);
68int usb_ingenic_reset(struct ingenic_dev *ingenic_dev, int ops);
67int usb_ingenic_nand_ops(struct ingenic_dev *id, int ops);
68int usb_ingenic_sdram_ops(struct ingenic_dev *id, int ops);
69int usb_read_data_from_ingenic(struct ingenic_dev *id, unsigned char *buff, unsigned int len);
70int usb_ingenic_reset(struct ingenic_dev *id, int ops);
71int usb_ingenic_start(struct ingenic_dev *id, int rqst, unsigned int stage_addr);
72int usb_ingenic_configration(struct ingenic_dev *id, int ops);
6973
7074#endif /* __INGENIC_USB_H__ */
usbboot/src/main.c
125125        int i, loop = 0;
126126
127127        sub_cmd[loop++] = strtok(cmdpt, ";");
128        while (sub_cmd[loop++] = strtok(NULL, ";"))
128        while ((sub_cmd[loop++] = strtok(NULL, ";")) != NULL)
129129            if (loop >= MAX_COMMANDS) {
130130                printf(" -c only support 10 commands\n");
131131                break;
usbboot/src/usb_boot_defines.h
8383};
8484
8585enum DATA_STRUCTURE_OB {
86    DS_flash_info ,
86    DS_flash_info = 0,
8787    DS_hand
8888};
8989
xbboot/host-app/Makefile.am
1AM_CFLAGS = -pedantic -Wall -W -std=gnu99 -DDATADIR=\"$(pkgdatadir)\"
1AM_CFLAGS = -Wall -W -std=gnu99 -DDATADIR=\"$(pkgdatadir)\"
22
33bin_PROGRAMS = xbboot
44xbboot_SOURCES = host_main.c
xbboot/host-app/host_main.c
7070        return EXIT_SUCCESS;
7171    }
7272
73    xburst_h = NULL;
7374    if (!strcmp(argv[1], "-u") || !strcmp(argv[1], "--upload")) {
7475        if (argc != 4) {
7576            show_help();

Archive Download the corresponding diff file



interactive