Date:2011-05-27 15:12:02 (3 years 5 months ago)
Author:Xiangfu Liu
Commit:1d7a2f3f5610518f67bf789401764a2628acf02f
Message:usbboot: fix hand.fw_args.cpu_id have wrong value when there is no 'boot' in commands

Files: usbboot/src/cmd.c (30 diffs)

Change Details

usbboot/src/cmd.c
7272    fd = open(file_path, O_RDONLY);
7373
7474    if (fd < 0) {
75        fprintf(stderr, "Error - can't open file '%s': %s\n",
75        fprintf(stderr, "Error - can't open file '%s': %s\n",
7676            file_path, strerror(errno));
7777        goto out;
7878    }
...... 
8080    status = read(fd, ingenic_dev->file_buff, ingenic_dev->file_len);
8181
8282    if (status < ingenic_dev->file_len) {
83        fprintf(stderr, "Error - can't read file '%s': %s\n",
83        fprintf(stderr, "Error - can't read file '%s': %s\n",
8484            file_path, strerror(errno));
8585        goto close;
8686    }
8787
8888    /* write args to code */
89    memcpy(ingenic_dev->file_buff + 8, &hand.fw_args,
89    memcpy(ingenic_dev->file_buff + 8, &hand.fw_args,
9090           sizeof(struct fw_args));
9191
9292    res = 1;
...... 
9797    return res;
9898}
9999
100/* after upload stage2. must init device */
101void init_cfg()
100int get_ingenic_cpu()
102101{
103    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
104        printf(" XBurst CPU not booted yet, boot it first!\n");
105        return;
106    }
107
108    ingenic_dev.file_buff = &hand;
109    ingenic_dev.file_len = sizeof(hand);
110    if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
111        goto xout;
112
113    sleep(1);
114    if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1)
115        goto xout;
116
117    if (usb_read_data_from_ingenic(&ingenic_dev, ret, 8) != 1)
118        goto xout;
119
120    printf(" Configuring XBurst CPU succeeded.\n");
121    return;
122xout:
123    printf(" Configuring XBurst CPU failed.\n");
124}
125
126int boot(char *stage1_path, char *stage2_path){
127102    int status;
128103
129104    status = usb_get_ingenic_cpu(&ingenic_dev);
105
130106    switch (status) {
131107    case JZ4740V1:
132        status = 0;
133108        hand.fw_args.cpu_id = 0x4740;
134109        break;
135110    case JZ4750V1:
136        status = 0;
137111        hand.fw_args.cpu_id = 0x4750;
138112        break;
139113    case JZ4760V1:
140        status = 0;
141114        hand.fw_args.cpu_id = 0x4760;
142115        break;
143116    case BOOT4740:
144        status = 1;
145117        hand.fw_args.cpu_id = 0x4740;
146118        break;
147119    case BOOT4750:
148        status = 1;
149120        hand.fw_args.cpu_id = 0x4750;
150121        break;
151122    case BOOT4760:
152        status = 1;
153123        hand.fw_args.cpu_id = 0x4760;
154124        break;
155125    default:
156        return 1;
126        hand.fw_args.cpu_id = 0;
157127    }
158128
159    if (status) {
129    return status;
130}
131
132/* after upload stage2. must init device */
133void init_cfg()
134{
135    int cpu = get_ingenic_cpu();
136    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
137        printf(" Device unboot! Boot it first!\n");
138        return;
139    }
140
141    ingenic_dev.file_buff = &hand;
142    ingenic_dev.file_len = sizeof(hand);
143    if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
144        goto xout;
145
146    sleep(1);
147    if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1)
148        goto xout;
149
150    if (usb_read_data_from_ingenic(&ingenic_dev, ret, 8) != 1)
151        goto xout;
152
153    printf(" Configuring XBurst CPU succeeded.\n");
154    return;
155xout:
156    printf(" Configuring XBurst CPU failed.\n");
157}
158
159int boot(char *stage1_path, char *stage2_path){
160    int status = get_ingenic_cpu();
161
162    if (status == BOOT4740 || status == BOOT4750 || status == BOOT4760) {
160163        printf(" Already booted.\n");
161164        return 1;
162165    } else {
...... 
181184
182185        printf(" Booted successfully!\n");
183186    }
187
184188    usleep(100);
185189    init_cfg();
190
186191    return 1;
187192}
188193
...... 
214219
215220int nand_markbad(struct nand_in *nand_in)
216221{
217    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
222    int cpu = get_ingenic_cpu();
223    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
218224        printf(" Device unboot! Boot it first!\n");
219225        return -1;
220226    }
...... 
222228    usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
223229    usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD);
224230    usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
225    printf(" Mark bad block at %d\n",((ret[3] << 24) |
226                       (ret[2] << 16) |
227                       (ret[1] << 8) |
231    printf(" Mark bad block at %d\n",((ret[3] << 24) |
232                       (ret[2] << 16) |
233                       (ret[1] << 8) |
228234                       (ret[0] << 0)) / hand.nand_ppb);
229235    return 0;
230236}
...... 
242248        goto err;
243249    }
244250
245    int cpu = usb_get_ingenic_cpu(&ingenic_dev);
251    int cpu = get_ingenic_cpu();
246252    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
247253        printf(" Device unboot! Boot it first!\n");
248254        goto err;
...... 
252258    ingenic_dev.file_len = nand_in->length;
253259    usb_send_data_to_ingenic(&ingenic_dev);
254260    for (i = 0; i < nand_in->max_chip; i++) {
255        if ((nand_in->cs_map)[i] == 0)
261        if ((nand_in->cs_map)[i] == 0)
256262            continue;
257263        if (nand_in->option == NO_OOB) {
258264            page_num = nand_in->length / hand.nand_ps;
259            if ((nand_in->length % hand.nand_ps) !=0)
265            if ((nand_in->length % hand.nand_ps) !=0)
260266                page_num++;
261267        } else {
262            page_num = nand_in->length /
268            page_num = nand_in->length /
263269                (hand.nand_ps + hand.nand_os);
264270            if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0)
265271                page_num++;
266272        }
267        temp = ((nand_in->option << 12) & 0xf000) +
268            ((i<<4) & 0xff0) + NAND_PROGRAM;
273        temp = ((nand_in->option << 12) & 0xf000) +
274            ((i<<4) & 0xff0) + NAND_PROGRAM;
269275        if (usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start) != 1)
270276            goto err;
271277        if (usb_send_data_length_to_ingenic(&ingenic_dev, page_num) != 1)
...... 
275281        if (usb_read_data_from_ingenic(&ingenic_dev, ret, 8) != 1)
276282            goto err;
277283
278        printf(" Finish! (len %d start_page %d page_num %d)\n",
284        printf(" Finish! (len %d start_page %d page_num %d)\n",
279285               nand_in->length, nand_in->start, page_num);
280286
281287        /* Read back to check! */
...... 
289295            start_addr = page_num * (hand.nand_ps + hand.nand_os);
290296            break;
291297        case OOB_NO_ECC: /* do not support data verify */
292            temp = ((OOB_NO_ECC << 12) & 0xf000) +
298            temp = ((OOB_NO_ECC << 12) & 0xf000) +
293299                ((i << 4) & 0xff0) + NAND_READ;
294300            start_addr = page_num * (hand.nand_ps + hand.nand_os);
295301            break;
296302        case NO_OOB:
297            temp = ((NO_OOB << 12) & 0xf000) +
303            temp = ((NO_OOB << 12) & 0xf000) +
298304                ((i << 4) & 0xff0) + NAND_READ;
299305            start_addr = page_num * hand.nand_ps;
300306            break;
...... 
307313        usb_read_data_from_ingenic(&ingenic_dev, check_buf, start_addr);
308314        usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
309315
310        cur_page = (ret[3] << 24) | (ret[2] << 16) | (ret[1] << 8) |
316        cur_page = (ret[3] << 24) | (ret[2] << 16) | (ret[1] << 8) |
311317            (ret[0] << 0);
312318
313319        if (nand_in->start == 0 && hand.nand_ps == 4096 &&
...... 
353359        return -1;
354360    }
355361
356    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
362    int cpu = get_ingenic_cpu();
363    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
357364        printf(" Device unboot! Boot it first!\n");
358365        return -1;
359366    }
360367
361368    for (i = 0; i < nand_in->max_chip; i++) {
362        if ((nand_in->cs_map)[i]==0)
369        if ((nand_in->cs_map)[i]==0)
363370            continue;
364371        printf(" Erasing No.%d device No.%d flash (start_blk %u blk_num %u)......\n",
365372               nand_in->dev, i, start_blk, blk_num);
...... 
375382    }
376383    end_block = ((ret[3] << 24) |
377384             (ret[2] << 16) |
378             (ret[1] << 8) |
385             (ret[1] << 8) |
379386             (ret[0] << 0)) / hand.nand_ppb;
380    printf(" Return: %02x %02x %02x %02x %02x %02x %02x %02x (position %d)\n",
387    printf(" Return: %02x %02x %02x %02x %02x %02x %02x %02x (position %d)\n",
381388           ret[0], ret[1], ret[2], ret[3], ret[4], ret[5], ret[6], ret[7], end_block);
382    if (!hand.nand_force_erase) {
389    if (!hand.nand_force_erase) {
383390    /* not force erase, show bad block infomation */
384        printf(" There are marked bad blocks: %d\n",
391        printf(" There are marked bad blocks: %d\n",
385392               end_block - start_blk - blk_num );
386393    } else {
387394    /* force erase, no bad block infomation can show */
...... 
411418
412419    fd = open(fname, O_RDONLY);
413420    if (fd < 0) {
414        fprintf(stderr, "Error - can't open file '%s': %s\n",
421        fprintf(stderr, "Error - can't open file '%s': %s\n",
415422            fname, strerror(errno));
416423        return -1;
417424    }
418425
419426    printf(" Programing No.%d device, flen %d, start page %d...\n",nand_in->dev, flen, nand_in->start);
420    n_in.start = nand_in->start / hand.nand_ppb;
427    n_in.start = nand_in->start / hand.nand_ppb;
421428    if (nand_in->option == NO_OOB) {
422        if (flen % (hand.nand_ppb * hand.nand_ps) == 0)
429        if (flen % (hand.nand_ppb * hand.nand_ps) == 0)
423430            n_in.length = flen / (hand.nand_ps * hand.nand_ppb);
424431        else
425432            n_in.length = flen / (hand.nand_ps * hand.nand_ppb) + 1;
426433    } else {
427        if (flen % (hand.nand_ppb * (hand.nand_ps + hand.nand_os)) == 0)
428            n_in.length = flen /
434        if (flen % (hand.nand_ppb * (hand.nand_ps + hand.nand_os)) == 0)
435            n_in.length = flen /
429436                ((hand.nand_ps + hand.nand_os) * hand.nand_ppb);
430437        else
431            n_in.length = flen /
438            n_in.length = flen /
432439                ((hand.nand_ps + hand.nand_os) * hand.nand_ppb)
433440                + 1;
434441    }
...... 
449456    printf(" It will cause %d times buffer transfer.\n", j == 0 ? m : m + 1);
450457    fflush(NULL);
451458
452    offset = 0;
459    offset = 0;
453460    for (k = 0; k < m; k++) {
454461        if (nand_in->option == NO_OOB)
455462            page_num = transfer_size / hand.nand_ps;
...... 
459466        code_len = transfer_size;
460467        status = read(fd, code_buf, code_len);
461468        if (status < code_len) {
462            fprintf(stderr, "Error - can't read file '%s': %s\n",
469            fprintf(stderr, "Error - can't read file '%s': %s\n",
463470                fname, strerror(errno));
464471            return -1;
465472        }
...... 
485492        status = read(fd, code_buf, code_len);
486493
487494        if (status < code_len) {
488            fprintf(stderr, "Error - can't read file '%s': %s\n",
495            fprintf(stderr, "Error - can't read file '%s': %s\n",
489496                fname, strerror(errno));
490497            return -1;
491498        }
...... 
499506            printf(" Info - skip bad block!");
500507
501508    }
502
509
503510    close(fd);
504511    return 1;
505512}
...... 
548555    nand_in.dev = atoi(com_argv[3]);
549556
550557    (nand_in.cs_map)[atoi(com_argv[4])] = 1;
551    if (!strcmp(com_argv[5], "-e"))
558    if (!strcmp(com_argv[5], "-e"))
552559        nand_in.option = OOB_ECC;
553    else if (!strcmp(com_argv[5], "-o"))
560    else if (!strcmp(com_argv[5], "-o"))
554561        nand_in.option = OOB_NO_ECC;
555    else if (!strcmp(com_argv[5], "-n"))
562    else if (!strcmp(com_argv[5], "-n"))
556563        nand_in.option = NO_OOB;
557564    else
558565        printf("%s", help);
...... 
575582    if (com_argc < 3) {
576583        printf(" Usage: nquery (1) (2)\n"
577584               " (1):device index number\n"
578               " (2):flash index number\n");
585               " (2):flash index number\n");
579586        return -1;
580587    }
581588    init_nand_in();
...... 
584591    (nand_in.cs_map)[atoi(com_argv[2])] = 1;
585592
586593    for (i = 0; i < nand_in.max_chip; i++) {
587        if ((nand_in.cs_map)[i] != 0)
594        if ((nand_in.cs_map)[i] != 0)
588595            break;
589596    }
590    if (i >= nand_in.max_chip)
597    if (i >= nand_in.max_chip)
591598        return -1;
592599
593    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
600    int cpu = get_ingenic_cpu();
601    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
594602        printf(" Device unboot! Boot it first!\n");
595603        return -1;
596604    }
...... 
651659        printf(" Page number overflow!\n");
652660        return -1;
653661    }
654    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
662    int cpu = get_ingenic_cpu();
663    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
655664        printf(" Device unboot! Boot it first!\n");
656665        return -1;
657666    }
658    for (i = 0; i < nand_in.max_chip; i++)
659        if ((nand_in.cs_map)[i] != 0)
667    for (i = 0; i < nand_in.max_chip; i++)
668        if ((nand_in.cs_map)[i] != 0)
660669            break;
661670    if (i >= nand_in.max_chip) return 1;
662671    csn = i;
...... 
672681        temp = ((csn<<4) & 0xff0) + NAND_READ_OOB;
673682        break;
674683    case NAND_READ_RAW:
675        temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
684        temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
676685            NAND_READ_RAW;
677686        break;
678687    case NAND_READ_TO_RAM:
679        temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
688        temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
680689            NAND_READ_TO_RAM;
681690        printf(" Reading nand to RAM: 0x%x\n", ram_addr);
682691        usb_ingenic_start(&ingenic_dev, VR_PROGRAM_START1, ram_addr);
...... 
711720{
712721    unsigned int buffer[8],tmp;
713722
714    tmp = usb_get_ingenic_cpu(&ingenic_dev);
715    if (tmp > 2) {
723    tmp = get_ingenic_cpu();
724    if (tmp == BOOT4740 || tmp == BOOT4750 || tmp == BOOT4760) {
716725        printf(" This command only run under UNBOOT state!\n");
717726        return -1;
718727    }
...... 
759768{
760769    unsigned int tmp;
761770
762    tmp = usb_get_ingenic_cpu(&ingenic_dev);
763    if (tmp > 2) {
771    tmp = get_ingenic_cpu();
772    if (tmp == BOOT4740 || tmp == BOOT4750 || tmp == BOOT4760) {
764773        printf(" This command only run under UNBOOT state!\n");
765774        return -1;
766775    }
...... 
823832
824833int sdram_load(struct sdram_in *sdram_in)
825834{
826    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
835    int cpu = get_ingenic_cpu();
836    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
827837        printf(" Device unboot! Boot it first!\n");
828838        return -1;
829839    }
...... 
863873
864874    fd = open(file_path, O_RDONLY);
865875    if (fd < 0) {
866        fprintf(stderr, "Error - can't open file '%s': %s\n",
876        fprintf(stderr, "Error - can't open file '%s': %s\n",
867877            file_path, strerror(errno));
868878        goto out;
869879    }
...... 
878888    for (k = 0; k < m; k++) {
879889        status = read(fd, sdram_in->buf, MAX_LOAD_SIZE);
880890        if (status < MAX_LOAD_SIZE) {
881            fprintf(stderr, "Error - can't read file '%s': %s\n",
891            fprintf(stderr, "Error - can't read file '%s': %s\n",
882892                file_path, strerror(errno));
883893            goto close;
884894        }
...... 
888898            goto close;
889899
890900        sdram_in->start += MAX_LOAD_SIZE;
891        if ( k % 60 == 0)
901        if ( k % 60 == 0)
892902            printf(" 0x%x \n", sdram_in->start);
893903    }
894904
895905    if (j) {
896        if (j % 4 !=0)
906        if (j % 4 !=0)
897907            j += 4 - (j % 4);
898908        status = read(fd, sdram_in->buf, j);
899909        if (status < j) {
900            fprintf(stderr, "Error - can't read file '%s': %s\n",
910            fprintf(stderr, "Error - can't read file '%s': %s\n",
901911                file_path, strerror(errno));
902912            goto close;
903913        }
...... 
917927
918928int device_reset(int ops)
919929{
920    if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
930    int cpu = get_ingenic_cpu();
931    if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) {
921932        printf(" Device unboot! Boot it first!\n");
922933        return -1;
923934    }

Archive Download the corresponding diff file



interactive