Changeset 12 for tt-loader/main.c
- Timestamp:
- May 23, 2008, 12:59:00 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tt-loader/main.c
r11 r12 33 33 #include <errno.h> 34 34 35 extern unsigned long crc32( unsigned long crc, char* buf, unsigned int len); 36 35 37 /* 36 38 * Here Vendor/Product detected for the target device … … 43 45 44 46 /* 45 * Length of memory dump done by 2nd.bin47 * Length of memory dump lines 46 48 */ 47 #define MEM_READ_SIZE 3249 #define DUMP_LINE_SIZE 32 48 50 49 51 struct mem_file { 50 52 void *content ; 51 53 int size ; 54 char *filename ; 52 55 }; 53 56 57 /* 58 * MAX_SIZE is the maximum size of the 2nd.bin program 59 */ 54 60 #define MAX_SIZE 65536 61 #define CHUNK_SIZE 8192 55 62 static char buffer[MAX_SIZE + 128]; 56 63 static int buffsize = 0; 57 static struct mem_file cmdfile = { NULL, 0 };64 static struct mem_file cmdfile = { NULL, 0, NULL }; 58 65 static double btime ; 59 66 static double ticks ; 60 67 61 68 #define log1(X) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks) 62 #define log2(X,Y) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,Y) 63 #define log3(X,Y,Z) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,Y,Z) 69 #define log2(X,Y) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y)) 70 #define log3(X,Y,Z) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y),(Z)) 71 #define log4(W,X,Y,Z) fprintf(stderr, "%9.3f: "W,((double)times(NULL)-btime)/ticks,(X),(Y),(Z)) 64 72 65 73 #if __BYTE_ORDER == __LITTLE_ENDIAN … … 71 79 #endif 72 80 73 static inline unsigned do_div(unsigned v, unsigned d)81 static inline unsigned roundup (unsigned v, unsigned d) 74 82 { 75 83 v+= --d; … … 92 100 { 93 101 int res, len = 5 ; 94 char buffer[64];95 102 96 103 buffer[0]= 'T'; … … 101 108 if (src!=NULL) 102 109 len += stringcopy (&buffer[4], src, 60); 110 else 111 len = 4 ; 103 112 buffer[63]= '\0' ; // truncate anyway 104 113 … … 106 115 if (res < len) 107 116 { 108 fprintf (stderr,"Error in usb_bulk_write during send_char: %d/4\n", res);117 log2("Error in usb_bulk_write during send_char: %d/4\n", res); 109 118 return 0; 110 119 } … … 113 122 } 114 123 115 static int send_binsize (usb_dev_handle *handle, int s z)124 static int send_binsize (usb_dev_handle *handle, int size) 116 125 { 117 126 int res; 118 char buffer[8];119 127 buffer[0]= 'T'; 120 128 buffer[1]= 'I'; 121 129 buffer[2]= 'S'; 122 130 buffer[3]= 's'; 123 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( (sz>4096)?4096:sz);131 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( size < CHUNK_SIZE ? size : CHUNK_SIZE ); 124 132 125 133 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 126 134 if (res < 8) 127 135 { 128 fprintf (stderr,"Error in usb_bulk_write during send_binsize: %d/8\n", res);136 log2("Error in usb_bulk_write during send_binsize: %d/8\n", res); 129 137 return 0; 130 138 } … … 133 141 } 134 142 135 static int send_ address (usb_dev_handle *handle, int addr)143 static int send_word (usb_dev_handle *handle, const char req, int word) 136 144 { 137 145 int res; 138 char buffer[8];139 146 buffer[0]= 'T'; 140 147 buffer[1]= 'I'; 141 148 buffer[2]= 'S'; 142 buffer[3]= 'a';143 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( addr);149 buffer[3]= req; 150 *(u_int32_t *) &buffer[4]= cpu_to_le32 (word); 144 151 145 152 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 146 153 if (res < 8) 147 154 { 148 fprintf (stderr,"Error in usb_bulk_write: %d/8\n", res);155 log2("Error in usb_bulk_write: %d/8\n", res); 149 156 return 0; 150 157 } … … 153 160 } 154 161 155 static struct mem_file readfile( const char *filename)162 static int send_poke (usb_dev_handle *handle, int poke) 156 163 { 157 struct mem_file toread = { NULL, 0 }; 164 int res; 165 buffer[0]= 'T'; 166 buffer[1]= 'I'; 167 buffer[2]= 'S'; 168 buffer[3]= 'p'; 169 *(u_int32_t *) &buffer[4]= cpu_to_le32 (poke); 170 171 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 172 if (res < 8) 173 { 174 log2("Error in usb_bulk_write: %d/8\n", res); 175 return 0; 176 } 177 178 return 1; 179 } 180 181 static struct mem_file readfile( char *filename ) 182 { 183 struct mem_file toread = { NULL, 0, NULL }; 158 184 int fd= open (filename, O_RDONLY); 159 185 160 186 if (fd < 0) 161 187 { 162 fprintf (stderr, "Error opening %s file\n", filename);188 log3("Error opening %s file (err=%d)\n", filename, errno); 163 189 return toread; 164 190 } … … 167 193 if (toread.size < 0 || lseek (fd, 0, SEEK_SET) < 0) 168 194 { 169 fprintf (stderr, "Error with lseek other %s file\n", filename);195 log3("Error with lseek other %s file (err=%d)\n", filename, errno); 170 196 close (fd); 171 197 return toread; 172 198 } 173 199 174 toread.content= malloc ( do_div(toread.size, 4));200 toread.content= malloc (roundup (toread.size, 4)); 175 201 if (toread.content == NULL) 176 202 { 177 fprintf (stderr,"Out of memory requesting %d bytes\n", toread.size);203 log2("Out of memory requesting %d bytes\n", toread.size); 178 204 close (fd); 179 205 return toread; … … 182 208 if ((toread.size= read (fd, toread.content, toread.size)) < 0) 183 209 { 184 fprintf (stderr, "Error reading %s file\n", filename);210 log3("Error reading %s file (err=%d)\n", filename, errno); 185 211 close (fd); 186 212 return toread; … … 190 216 191 217 return toread ; 218 } 219 220 static int savefile( char *filename, struct mem_file buffer ) 221 { 222 int fd= creat (filename, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH ); 223 224 if (fd < 0) 225 { 226 log3("Error opening %s file for writing (err=%d)\n", filename, errno); 227 return 1; 228 } 229 230 if (buffer.size != write (fd, buffer.content, buffer.size)) 231 { 232 log3("Error writing %s file (err=%d)\n", filename, errno); 233 close (fd); 234 return 1; 235 } 236 237 close (fd); 238 239 return 0 ; 192 240 } 193 241 … … 218 266 else 219 267 { 220 char inbuff[256]; 221 int insize= usb_bulk_read (handle, IN_EP, 222 inbuff, sizeof (inbuff), 5000); 268 char inbuff[MAX_SIZE + 128]; 269 int insize= usb_bulk_read (handle, IN_EP, inbuff, sizeof (inbuff), 1000); 223 270 224 271 if (insize < 48) … … 235 282 while (size > 0) 236 283 { 237 int outsize= usb_bulk_write (handle, OUT_EP, p, 64, 5000); 238 if (outsize < 64) 284 int chunksize = size < CHUNK_SIZE ? size : CHUNK_SIZE ; 285 int outsize = usb_bulk_write (handle, OUT_EP, p, chunksize, 1000); 286 if (outsize < chunksize) 239 287 { 240 log 2("Error in usb_bulk_write: %d/64\n", outsize);288 log3("Error in usb_bulk_write: %d/%d\n", outsize,chunksize); 241 289 break; 242 290 } 243 291 244 p+= 64;245 size-= 64;292 p+= chunksize; 293 size-= chunksize; 246 294 } 247 295 … … 249 297 { 250 298 log2("Sent %d bytes to OMAP\n",buffsize); 251 usb_bulk_write (handle, OUT_EP, buffer, 0, 1000);252 299 253 300 p= NULL; 254 301 size= 0; 255 302 256 int res=1, sz= 0, loop= 1, cmd=0 ;303 int res=1, sz= 0, loop= 1, cmd=0, ftag=0, finfo=0, fline=0 ; 257 304 int vendor, device, info ; 258 305 char *cmdp = cmdfile.content ; 259 struct mem_file current = { NULL, 0 };306 struct mem_file current = { NULL, 0, NULL }; 260 307 261 308 err = 1 ; // Set error by default … … 265 312 if (loop<0) loop++ ; // Avoid infinite loop 266 313 267 if (res>0 )314 if (res>0 || ftag) 268 315 res= usb_bulk_read (handle, IN_EP, 269 316 inbuff, sizeof (inbuff), 5000); … … 275 322 } 276 323 324 if (ftag) 325 { 326 switch (ftag) 327 { 328 case 0xaaaa0001: 329 // A string should be in the buffer with length still set in finfo 330 if ( res != finfo) 331 { 332 log3("Error waiting string from flasher program: length = %d vs %d expected\n", res, finfo); 333 break ; 334 } 335 // Fix the string just in case 336 inbuff[res] = '\0' ; 337 if (fline) 338 fprintf(stderr, "%s",inbuff); 339 else 340 log2("Flasher: %s", inbuff); 341 if ( inbuff[res-1] == '\n' ) 342 fline = 0 ; 343 else 344 fline ++ ; 345 break ; 346 case 0xaaaa0002: 347 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 348 break ; 349 case 0xaaaa0003: 350 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 351 log2("Flasher: NAND read = 0x%08X\n", finfo); 352 break ; 353 case 0xaaaa0004: 354 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 355 log2("Flasher: NAND size = 0x%08X\n", finfo); 356 break ; 357 case 0xaaaa0005: 358 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 359 log2("Flasher: Error code = %d\n", finfo); 360 err = - finfo ; // Will quit on error 361 break ; 362 case 0xaaaa0006: 363 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 364 log2("Flasher: NAND remain = 0x%08X\n", finfo); 365 break ; 366 } 367 ftag = 0 ; 368 continue ; 369 } 370 371 if (err<0) 372 { 373 err = -err ; // Keep err as positive number 374 if (send_cmd (handle,'e',NULL)) 375 log1("Asking stop\n"); 376 else 377 log1("Can't ask to stop\n"); 378 break ; // Leave loop 379 } 380 277 381 if (res >= 4) 278 382 { … … 305 409 sz= le32_to_cpu (*(u_int32_t *) &inbuff[4]); 306 410 //log2("OMAP read %d\n", sz); // DEBUG 307 res= usb_bulk_write (handle, OUT_EP, p, sz, 5000);411 res= usb_bulk_write (handle, OUT_EP, p, sz, 1000); 308 412 if (res < sz) 309 413 { … … 318 422 break; 319 423 424 case 'x': 425 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 426 u_int32_t len = le32_to_cpu (*(u_int32_t *) &inbuff[8]); 427 u_int32_t crc = le32_to_cpu (*(u_int32_t *) &inbuff[12]); 428 log4("OMAP crc32 computing: pos 0x%08x/0x%08x, current crc32 0x%08X\n",info,len,crc); 429 break; 430 320 431 case 'A': 321 432 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 322 433 log2("OMAP address info: 0x%08X\n", info); 434 break; 435 436 case 'C': 437 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 438 log2("OMAP crc32 found: 0x%08X\n", info); 323 439 break; 324 440 … … 343 459 break; 344 460 461 case 'D': 462 if (!current.content) 463 { 464 log1("Can't dump memory without buffer\n"); 465 loop = 0 ; 466 break ; 467 } 468 res -= 4 ; 469 if (res < 1) 470 { 471 log2("Received empty memory dump (res=%d)\n",res); 472 // reset buffer size anyway 473 current.size = 0 ; 474 res = 0 ; // Target is waiting a new command 475 476 } else { 477 if (res > size) 478 { 479 log2("Can't dump %d bytes as buffer is full\n",res); 480 loop = 0 ; 481 break ; 482 } 483 memcpy(p,&inbuff[4],res); 484 p += res ; 485 size -= res ; 486 } 487 if ( size == 0 ) 488 { 489 log2("%d bytes dumped to buffer\n",current.size); 490 res = 0 ; // Target is waiting a new command 491 } 492 break; 493 345 494 case 'M': 346 loop=3 ; 347 log2("0x%08X | ",info); 348 while (++loop<36) 349 fprintf (stderr,"%02hhX", inbuff[loop]); 350 loop=3 ; 351 fprintf (stderr, " |"); 352 while (++loop<36) 353 if ((int)inbuff[loop]>=0x20 && (int)inbuff[loop]<0x7f) 354 fprintf (stderr,"%c", inbuff[loop]); 355 else 356 fprintf (stderr,"."); 357 fprintf (stderr,"|\n"); 495 sz = 0 ; 496 res -= 4 ; 497 while (sz<res) 498 { 499 log2("0x%08X | ",info); 500 501 loop=0 ; 502 while (++loop<=DUMP_LINE_SIZE) 503 fprintf (stderr,"%02hhX", inbuff[3+sz+loop]); 504 fprintf (stderr, " |"); 505 506 loop=0 ; 507 while (++loop<=DUMP_LINE_SIZE) 508 if ((int)inbuff[3+sz+loop]>=0x20 && (int)inbuff[3+sz+loop]<0x7f) 509 fprintf (stderr,"%c", inbuff[3+sz+loop]); 510 else 511 fprintf (stderr,"."); 512 513 fprintf (stderr,"|\n"); 514 515 info += DUMP_LINE_SIZE; 516 sz += DUMP_LINE_SIZE; 517 } 358 518 res = 0 ; // Target is waiting a new command 359 info += 32 ;360 519 break; 361 520 … … 369 528 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 370 529 log2("OMAP is booting at address: 0x%08X\n", info); 371 res = 0 ; // Target is waiting a new command530 loop = err = res = 0 ; // Quit now 372 531 break; 373 532 … … 376 535 break; 377 536 } 378 } else { 379 // Fix the string just in case 380 inbuff[res] = '\0' ; 381 log2("Got: %s\n", inbuff); 537 } else 538 { 539 info = le32_to_cpu (*(u_int32_t *) inbuff); 540 switch (info) 541 { 542 case 0xaaaa0001: 543 case 0xaaaa0002: 544 case 0xaaaa0003: 545 case 0xaaaa0004: 546 case 0xaaaa0005: 547 case 0xaaaa0006: 548 ftag = info ; 549 break ; 550 case 0xff555580: 551 log1("Flasher: Command finished\n"); 552 break ; 553 default: 554 // Fix the string just in case 555 inbuff[res] = '\0' ; 556 // Strip final EOL in the string 557 if ( inbuff[res-1] == '\n' ) 558 inbuff[res-1] = '\0' ; 559 if (res==4) 560 log3("Got: %s (0x%08X)\n", inbuff, info); 561 else 562 log2("Got: %s\n", inbuff); 563 } 382 564 } 383 565 } … … 397 579 switch (cmdp[cmd]) 398 580 { 581 case 'D': // Save downloaded memory to a file still specified 582 if (current.filename == NULL) 583 { 584 log1("Can't save without a file specified with 'F' command\n"); 585 loop = 0 ; // Just quit on error 586 break ; 587 } 588 if (current.content == NULL) 589 { 590 log2("Can't save without download buffer to file '%s'\n",current.filename); 591 loop = 0 ; // Just quit on error 592 break ; 593 } 594 if (current.size==0) 595 log2("Nothing to save, file %s is still up to date\n",current.filename); 596 else if (savefile(current.filename, current)==0) 597 { 598 info = crc32(0,current.content,current.size); 599 log3("Downloaded memory saved to file %s with CRC32=0x%08X\n",current.filename,info); 600 } else 601 { 602 log2("Can't save downloaded memory saved to file %s\n",current.filename); 603 // Just quit on error 604 loop = 0 ; 605 } 606 // Release memory 607 free((void *)current.content); 608 free((void *)current.filename); 609 current.content = NULL ; 610 current.filename = NULL ; 611 res -- ; 612 break; 613 case 'd': // Save downloaded memory to a file 614 cmd += 2 ; 615 if (cmd >= cmdfile.size || cmdp[cmd] == '\0') 616 { 617 log1("Bad 'd' format in command download\n"); 618 break ; 619 } 620 if (current.content == NULL) 621 { 622 log2("Can't save without download buffer to file '%s'\n",&cmdp[cmd]); 623 loop = 0 ; // Just quit on error 624 break ; 625 } 626 if (current.size==0) 627 log2("Nothing to save, file %s is still up to date\n",&cmdp[cmd]); 628 else if (savefile(&cmdp[cmd], current)==0) 629 { 630 info = crc32(0,current.content,current.size); 631 log3("Downloaded memory saved to file %s with CRC32=0x%08X\n",&cmdp[cmd],info); 632 } else 633 { 634 log2("Can't save downloaded memory saved to file %s\n",&cmdp[cmd]); 635 // Just quit on error 636 loop = 0 ; 637 } 638 // Release memory 639 free((void *)current.content); 640 current.content = NULL ; 641 res -- ; 642 break; 399 643 case 'f': // Put a file to be uploaded in a memory buffer 400 644 cmd += 2 ; … … 407 651 if (current.content != NULL) 408 652 free((void *)current.content); 409 current = readfile( (const char *)&cmdp[cmd]);653 current = readfile(&cmdp[cmd]); 410 654 if (current.content == NULL) 411 655 { 412 656 log2("Can't read file '%s'\n",&cmdp[cmd]); 413 657 loop = 0 ; // Just quit on error 658 break ; 414 659 } 415 660 p = current.content ; … … 425 670 } 426 671 break; 672 case 'F': // Set a filename that would be loaded to check crc and saved 673 cmd += 2 ; 674 if (cmd >= cmdfile.size || cmdp[cmd] == '\0') 675 { 676 log1("Bad 'F' format in command file\n"); 677 break ; 678 } 679 // Free previously used memory buffer 680 if (current.filename != NULL) 681 free((void *)current.filename); 682 info = strlen(&cmdp[cmd]); 683 if (info == 0) 684 { 685 log2("Can't read filename '%s' length\n",&cmdp[cmd]); 686 loop = 0 ; // Just quit on error 687 break ; 688 } 689 current.filename = malloc (++info); 690 if (current.filename == NULL) 691 { 692 log2("Out of memory requesting %d bytes\n", info); 693 loop = 0 ; // Just quit on error 694 break ; 695 } 696 if (info!=stringcopy(current.filename,&cmdp[cmd],info)) 697 { 698 log2("Can't read filename '%s'\n",&cmdp[cmd]); 699 loop = 0 ; // Just quit on error 700 break ; 701 } 702 // still read next command 703 res -- ; 704 break; 705 case 'C': // Get a CRC32 and send it to target 706 cmd += 2 ; 707 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 708 { 709 log2("Can't read crc32 '%s'\n",&cmdp[cmd]); 710 loop = 0 ; // Just quit on error 711 break ; 712 } 713 // compute the current CRC32 if a file is referenced and exists 714 if (!info && current.filename != NULL) 715 { 716 struct mem_file loader = readfile(current.filename); 717 if (loader.content == NULL) 718 { 719 log2("Can't read file '%s', will be initialized with target\n",current.filename); 720 } else 721 { 722 log3("Checking CRC32 of %d bytes from %s file\n",loader.size,current.filename); 723 info = crc32(0,loader.content,loader.size); 724 free(loader.content); 725 } 726 } 727 if (send_word (handle, 'C', info)) 728 log2("Sending crc32 0x%02X\n", info); 729 else 730 { 731 log2("Can't send crc32 0x%02X\n", info); 732 loop = 0 ; // Just quit on error 733 } 734 break; 427 735 case 'a': // Get an address and send it to target 428 736 cmd += 2 ; … … 431 739 log2("Can't read address '%s'\n",&cmdp[cmd]); 432 740 loop = 0 ; // Just quit on error 433 } 434 if (send_address (handle, info)) 741 break ; 742 } 743 if (send_word (handle, 'a', info)) 435 744 log2("Sending address 0x%02X\n", info); 436 745 else … … 440 749 } 441 750 break; 751 case 'm': // Get a size in kB and ask a memory download 752 cmd += 2 ; 753 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 754 { 755 log2("Can't read size '%s'\n",&cmdp[cmd]); 756 loop = 0 ; // Just quit on error 757 break ; 758 } 759 // size unit is kbytes 760 size = info * 1024 ; 761 // Free previously used memory buffer 762 if (current.content != NULL) 763 free((void *)current.content); 764 current.size = size ; 765 p = malloc (roundup (size, 4)); 766 if ( p == NULL) 767 { 768 log2("Out of memory requesting %d bytes\n", roundup (size, 4)); 769 loop=0 ; 770 break ; 771 } 772 current.content = p ; 773 if (!(send_word (handle,'m',size))) 774 { 775 log2("Can't ask to download %d bytes from memory\n",size); 776 loop = 0 ; // Just quit on error 777 } else 778 log2("Allocated %d kBytes to download memory\n",info); 779 break; 442 780 case 'M': // Ask memory dump 443 781 if (!(send_cmd (handle,'M',NULL))) 444 782 { 445 783 log1("Can't ask to read memory\n"); 784 loop = 0 ; // Just quit on error 785 } 786 break; 787 case 'P': // Ask a peek onto the address 788 if (!(send_cmd (handle,'P',NULL))) 789 { 790 log1("Can't ask to peek memory\n"); 791 loop = 0 ; // Just quit on error 792 } 793 break; 794 case 'S': // Ask to change stack to the last given address 795 if (send_cmd (handle,'S',NULL)) 796 log1("Asking stack relocate\n"); 797 else 798 { 799 log1("Can't ask to relocate stack\n"); 446 800 loop = 0 ; // Just quit on error 447 801 } … … 457 811 break; 458 812 case 'b': // Boot the target by just branching to the last given address 459 if (send_cmd (handle,'b',NULL)) 813 if (send_cmd (handle,'b',NULL)) { 460 814 log1("Asking boot\n"); 461 else 815 // Quit now witout error set 816 loop = err = -10 ; 817 cmd = cmdfile.size ; 818 res = 1 ; 819 } else 462 820 { 463 821 log1("Can't ask to boot\n"); … … 467 825 case 'e': // End of commands 468 826 log1("Commands read and sent\n"); 827 if (send_cmd (handle,'e',NULL)) 828 log1("Asking stop\n"); 829 else 830 log1("Can't ask to stop\n"); 469 831 // Quit now witout error set 470 832 loop = err = 0 ; … … 472 834 res = 1 ; 473 835 break ; 836 case 'k': // Boot a linux kernel to the last given address 837 cmd += 2 ; 838 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 839 { 840 log2("Can't read mach id '%s'\n",&cmdp[cmd]); 841 loop = 0 ; // Just quit on error 842 break ; 843 } 844 if (send_word (handle,'k', info)) { 845 log1("Asking kernel to boot\n"); 846 // Quit now witout error set 847 loop = err = -10 ; 848 cmd = cmdfile.size ; 849 res = 1 ; 850 } else 851 { 852 log1("Can't ask to boot a kernel\n"); 853 loop = 0 ; // Just quit on error 854 } 855 break; 856 case 'p': // poke 857 cmd += 2 ; 858 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 859 { 860 log2("Can't read value to poke '%s'\n",&cmdp[cmd]); 861 loop = 0 ; // Just quit on error 862 break ; 863 } 864 if (send_poke (handle, info)) 865 log2("Sending poke 0x%08X\n", info); 866 else 867 { 868 log2("Can't send poke 0x%08X\n", info); 869 loop = 0 ; // Just quit on error 870 } 871 break; 474 872 case '#': 873 cmd += 2 ; 874 log2("%s\n", &cmdp[cmd]); 475 875 case '/': 476 876 // skip comments … … 490 890 } 491 891 } 892 // Free used memory buffer 893 if (current.content != NULL) 894 free((void *)current.content); 895 if (current.filename != NULL) 896 free((void *)current.filename); 492 897 } 493 898 } … … 495 900 496 901 if (err>=0) { 902 log1("Releasing usb interface\n"); 497 903 err = usb_release_interface (handle, 0); 498 904 if (err < 0) 499 905 log2("Error in usb_release_interface (%d)\n",err); 906 log1("Released usb interface\n"); 500 907 } 501 908 … … 551 958 } 552 959 553 size= do_div(size, 4);960 size= roundup (size, 4); 554 961 555 962 p[0x21]= cpu_to_le32 (size - 0x40); … … 562 969 p[0x12]= cpu_to_le32 (size); 563 970 564 buffsize= 128 + do_div(size, 4);971 buffsize= 128 + roundup (size, 4); 565 972 566 973 cmdfile = readfile(argv[ARG_CMDFILE]); … … 575 982 if (cmdbuffer[i] == '\n' || cmdbuffer[i] == '\r' || cmdbuffer[i] == ';') 576 983 cmdbuffer[i] = '\0' ; 984 // Skip comment line 985 if (cmdbuffer[i] == '/') { 986 while ( i++ < cmdfile.size ) { 987 if (cmdbuffer[i] == '\n' || cmdbuffer[i] == '\r') { 988 i-- ; 989 break ; 990 } 991 } 992 } 577 993 } while ( i++ < cmdfile.size ); 578 994 }
Note: See TracChangeset
for help on using the changeset viewer.