Mercurial > ecos
comparison packages/redboot/current/src/flash.c @ 143:6b5f480c6929 ecos-sw-2000-12-08
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
| author | jlarmour |
|---|---|
| date | Fri, 08 Dec 2000 03:30:06 +0000 |
| parents | 289bf90c6a9b |
| children | 2e9a636d9de9 |
comparison
equal
deleted
inserted
replaced
| 142:12eccf9656f3 | 143:6b5f480c6929 |
|---|---|
| 112 fis_load, | 112 fis_load, |
| 113 FIS_cmds | 113 FIS_cmds |
| 114 ); | 114 ); |
| 115 local_cmd_entry("create", | 115 local_cmd_entry("create", |
| 116 "Create an image", | 116 "Create an image", |
| 117 "-b <mem_base> -l <image_length> [-s <data_length>] [-f <flash_addr>] [-e <entry_point>] [-r <ram_addr>] <name>", | 117 "-b <mem_base> -l <image_length> [-s <data_length>] |
| 118 [-f <flash_addr>] [-e <entry_point>] [-r <ram_addr>] [-n] <name>", | |
| 118 fis_create, | 119 fis_create, |
| 119 FIS_cmds | 120 FIS_cmds |
| 120 ); | 121 ); |
| 121 | 122 |
| 122 // Define table boundaries | 123 // Define table boundaries |
| 195 } | 196 } |
| 196 printf("*** Initialize FLASH Image System\n"); | 197 printf("*** Initialize FLASH Image System\n"); |
| 197 if (full_init) { | 198 if (full_init) { |
| 198 if ((stat = flash_erase((void *)((unsigned long)flash_start+(2*block_size)), | 199 if ((stat = flash_erase((void *)((unsigned long)flash_start+(2*block_size)), |
| 199 (blocks-4)*block_size, (void **)&err_addr)) != 0) { | 200 (blocks-4)*block_size, (void **)&err_addr)) != 0) { |
| 200 printf(" initialization failed %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 201 printf(" initialization failed %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 201 } | 202 } |
| 202 } else { | 203 } else { |
| 203 printf(" Warning: device contents not erased, some blocks may not be usable\n"); | 204 printf(" Warning: device contents not erased, some blocks may not be usable\n"); |
| 204 } | 205 } |
| 205 // Create a pseudo image for RedBoot | 206 // Create a pseudo image for RedBoot |
| 240 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 241 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 241 // Insure [quietly] that the directory is unlocked before trying to update | 242 // Insure [quietly] that the directory is unlocked before trying to update |
| 242 flash_unlock((void *)fis_base, block_size, (void **)&err_addr); | 243 flash_unlock((void *)fis_base, block_size, (void **)&err_addr); |
| 243 #endif | 244 #endif |
| 244 if ((stat = flash_erase(fis_base, block_size, (void **)&err_addr)) != 0) { | 245 if ((stat = flash_erase(fis_base, block_size, (void **)&err_addr)) != 0) { |
| 245 printf(" initialization failed %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 246 printf(" initialization failed %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 246 } else { | 247 } else { |
| 247 if ((stat = flash_program(fis_base, fis_work_block, | 248 if ((stat = flash_program(fis_base, fis_work_block, |
| 248 img_count*sizeof(*img), (void **)&err_addr)) != 0) { | 249 img_count*sizeof(*img), (void **)&err_addr)) != 0) { |
| 249 printf("Error writing image descriptors at %p: %x(%s)\n", | 250 printf("Error writing image descriptors at %p: 0x%x(%s)\n", |
| 250 err_addr, stat, flash_errmsg(stat)); | 251 err_addr, stat, flash_errmsg(stat)); |
| 251 } | 252 } |
| 252 } | 253 } |
| 253 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 254 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 254 // Insure [quietly] that the directory is locked after the update | 255 // Insure [quietly] that the directory is locked after the update |
| 371 bool exec_addr_set = false; | 372 bool exec_addr_set = false; |
| 372 bool entry_addr_set = false; | 373 bool entry_addr_set = false; |
| 373 bool flash_addr_set = false; | 374 bool flash_addr_set = false; |
| 374 bool length_set = false; | 375 bool length_set = false; |
| 375 bool img_size_set = false; | 376 bool img_size_set = false; |
| 377 bool no_copy = false; | |
| 376 void *fis_addr, *err_addr; | 378 void *fis_addr, *err_addr; |
| 377 struct fis_image_desc *img; | 379 struct fis_image_desc *img; |
| 378 bool slot_found; | 380 bool slot_found; |
| 379 struct option_info opts[6]; | 381 struct option_info opts[7]; |
| 380 bool prog_ok; | 382 bool prog_ok; |
| 381 | 383 |
| 382 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, | 384 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, |
| 383 (void **)&mem_addr, (bool *)&mem_addr_set, "memory base address"); | 385 (void **)&mem_addr, (bool *)&mem_addr_set, "memory base address"); |
| 384 init_opts(&opts[1], 'r', true, OPTION_ARG_TYPE_NUM, | 386 init_opts(&opts[1], 'r', true, OPTION_ARG_TYPE_NUM, |
| 389 (void **)&flash_addr, (bool *)&flash_addr_set, "FLASH memory base address"); | 391 (void **)&flash_addr, (bool *)&flash_addr_set, "FLASH memory base address"); |
| 390 init_opts(&opts[4], 'l', true, OPTION_ARG_TYPE_NUM, | 392 init_opts(&opts[4], 'l', true, OPTION_ARG_TYPE_NUM, |
| 391 (void **)&length, (bool *)&length_set, "image length [in FLASH]"); | 393 (void **)&length, (bool *)&length_set, "image length [in FLASH]"); |
| 392 init_opts(&opts[5], 's', true, OPTION_ARG_TYPE_NUM, | 394 init_opts(&opts[5], 's', true, OPTION_ARG_TYPE_NUM, |
| 393 (void **)&img_size, (bool *)&img_size_set, "image size [actual data]"); | 395 (void **)&img_size, (bool *)&img_size_set, "image size [actual data]"); |
| 394 if (!scan_opts(argc, argv, 2, opts, 6, (void *)&name, OPTION_ARG_TYPE_STR, "file name")) | 396 init_opts(&opts[6], 'n', false, OPTION_ARG_TYPE_FLG, |
| 397 (void **)&no_copy, (bool *)0, "don't copy from RAM to FLASH, just update directory"); | |
| 398 if (!scan_opts(argc, argv, 2, opts, 7, (void *)&name, OPTION_ARG_TYPE_STR, "file name")) | |
| 395 { | 399 { |
| 396 fis_usage("invalid arguments"); | 400 fis_usage("invalid arguments"); |
| 397 return; | 401 return; |
| 398 } | 402 } |
| 399 | 403 |
| 400 if (!mem_addr_set || !length_set || !name) { | 404 if ((!no_copy && !mem_addr_set) || (no_copy && !flash_addr_set) || |
| 405 !length_set || !name) { | |
| 401 fis_usage("required parameter missing"); | 406 fis_usage("required parameter missing"); |
| 402 return; | 407 return; |
| 403 } | 408 } |
| 404 if (!img_size_set) { | 409 if (!img_size_set) { |
| 405 img_size = length; | 410 img_size = length; |
| 406 } | 411 } |
| 407 // 'length' is size of FLASH image, 'img_size' is actual data size | 412 // 'length' is size of FLASH image, 'img_size' is actual data size |
| 408 // Round up length to FLASH block size | 413 // Round up length to FLASH block size |
| 414 #ifndef CYGPKG_HAL_MIPS // FIXME: compiler is b0rken | |
| 409 length = ((length + block_size - 1) / block_size) * block_size; | 415 length = ((length + block_size - 1) / block_size) * block_size; |
| 410 if (length < img_size) { | 416 if (length < img_size) { |
| 411 printf("Invalid FLASH image size/length combination"); | 417 printf("Invalid FLASH image size/length combination\n"); |
| 412 return; | 418 return; |
| 413 } | 419 } |
| 420 #endif | |
| 414 if (flash_addr_set && | 421 if (flash_addr_set && |
| 415 ((stat = flash_verify_addr((void *)flash_addr)) || | 422 ((stat = flash_verify_addr((void *)flash_addr)) || |
| 416 (stat = flash_verify_addr((void *)(flash_addr+img_size-1))))) { | 423 (stat = flash_verify_addr((void *)(flash_addr+img_size-1))))) { |
| 417 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); | 424 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); |
| 418 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); | 425 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); |
| 419 return; | 426 return; |
| 420 } | 427 } |
| 421 if ((mem_addr < (unsigned long)ram_start) || | |
| 422 ((mem_addr+img_size) >= (unsigned long)ram_end)) { | |
| 423 printf("** WARNING: RAM address: %p may be invalid\n", (void *)mem_addr); | |
| 424 printf(" valid range is %p-%p\n", (void *)ram_start, (void *)ram_end); | |
| 425 } | |
| 426 if (strlen(name) >= sizeof(img->name)) { | 428 if (strlen(name) >= sizeof(img->name)) { |
| 427 printf("Name is too long, must be less than %d chars\n", (int)sizeof(img->name)); | 429 printf("Name is too long, must be less than %d chars\n", (int)sizeof(img->name)); |
| 428 return; | 430 return; |
| 429 } | 431 } |
| 430 if (!flash_addr_set && !fis_find_free(&flash_addr, length)) { | 432 if (!no_copy) { |
| 431 printf("Can't locate %ld bytes free in FLASH\n", length); | 433 if ((mem_addr < (unsigned long)ram_start) || |
| 432 return; | 434 ((mem_addr+img_size) >= (unsigned long)ram_end)) { |
| 435 printf("** WARNING: RAM address: %p may be invalid\n", (void *)mem_addr); | |
| 436 printf(" valid range is %p-%p\n", (void *)ram_start, (void *)ram_end); | |
| 437 } | |
| 438 if (!flash_addr_set && !fis_find_free(&flash_addr, length)) { | |
| 439 printf("Can't locate %ld bytes free in FLASH\n", length); | |
| 440 return; | |
| 441 } | |
| 433 } | 442 } |
| 434 // Find a slot in the directory for this entry | 443 // Find a slot in the directory for this entry |
| 435 // First, see if an image by this name is already present | 444 // First, see if an image by this name is already present |
| 436 slot_found = false; | 445 slot_found = false; |
| 437 fis_addr = (void *)((unsigned long)flash_end - block_size); | 446 fis_addr = (void *)((unsigned long)flash_end - block_size); |
| 442 if (flash_addr_set && (img->flash_base != flash_addr)) { | 451 if (flash_addr_set && (img->flash_base != flash_addr)) { |
| 443 printf("Image found, but FLASH address incorrect\n"); | 452 printf("Image found, but FLASH address incorrect\n"); |
| 444 return; | 453 return; |
| 445 } | 454 } |
| 446 if (img->size != length) { | 455 if (img->size != length) { |
| 447 printf("Image found, but LENGTH is incorrect (0x%x != 0x%x)\n", img->size, length); | 456 printf("Image found, but LENGTH is incorrect (0x%lx != 0x%lx)\n", img->size, length); |
| 448 return; | 457 return; |
| 449 } | 458 } |
| 450 if (!verify_action("An image named '%s' exists", name)) { | 459 if (!verify_action("An image named '%s' exists", name)) { |
| 451 return; | 460 return; |
| 452 } else { | 461 } else { |
| 463 slot_found = true; | 472 slot_found = true; |
| 464 break; | 473 break; |
| 465 } | 474 } |
| 466 } | 475 } |
| 467 } | 476 } |
| 468 // Safety check - make sure the address range is not within the code we're running | 477 if (!no_copy) { |
| 469 if (flash_code_overlaps((void *)flash_addr, (void *)(flash_addr+img_size-1))) { | 478 // Safety check - make sure the address range is not within the code we're running |
| 470 printf("Can't program this region - contains code in use!\n"); | 479 if (flash_code_overlaps((void *)flash_addr, (void *)(flash_addr+img_size-1))) { |
| 471 return; | 480 printf("Can't program this region - contains code in use!\n"); |
| 472 } | 481 return; |
| 473 prog_ok = true; | 482 } |
| 474 if (prog_ok) { | 483 prog_ok = true; |
| 475 // Erase area to be programmed | 484 if (prog_ok) { |
| 476 if ((stat = flash_erase((void *)flash_addr, length, (void **)&err_addr)) != 0) { | 485 // Erase area to be programmed |
| 477 printf("Can't erase region at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 486 if ((stat = flash_erase((void *)flash_addr, length, (void **)&err_addr)) != 0) { |
| 478 prog_ok = false; | 487 printf("Can't erase region at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 479 } | 488 prog_ok = false; |
| 480 } | 489 } |
| 481 if (prog_ok) { | 490 } |
| 482 // Now program it | 491 if (prog_ok) { |
| 483 if ((stat = flash_program((void *)flash_addr, (void *)mem_addr, img_size, (void **)&err_addr)) != 0) { | 492 // Now program it |
| 484 printf("Can't program region at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 493 if ((stat = flash_program((void *)flash_addr, (void *)mem_addr, img_size, (void **)&err_addr)) != 0) { |
| 485 prog_ok = false; | 494 printf("Can't program region at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 495 prog_ok = false; | |
| 496 } | |
| 486 } | 497 } |
| 487 } | 498 } |
| 488 // Update directory | 499 // Update directory |
| 489 memset(img, 0, sizeof(*img)); | 500 memset(img, 0, sizeof(*img)); |
| 490 strcpy(img->name, name); | 501 strcpy(img->name, name); |
| 491 img->flash_base = flash_addr; | 502 img->flash_base = flash_addr; |
| 492 img->mem_base = exec_addr_set ? exec_addr : (flash_addr_set ? flash_addr : mem_addr); | 503 img->mem_base = exec_addr_set ? exec_addr : (flash_addr_set ? flash_addr : mem_addr); |
| 493 img->entry_point = entry_addr_set ? entry_addr : (unsigned long)entry_address; // Hope it's been set | 504 img->entry_point = entry_addr_set ? entry_addr : (unsigned long)entry_address; // Hope it's been set |
| 494 img->size = length; | 505 img->size = length; |
| 495 img->data_length = img_size; | 506 img->data_length = img_size; |
| 496 img->file_cksum = _cksum((unsigned long *)mem_addr, img_size); | 507 img->file_cksum = _cksum((unsigned long *)flash_addr, img_size); |
| 497 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 508 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 498 // Insure [quietly] that the directory is unlocked before trying to update | 509 // Insure [quietly] that the directory is unlocked before trying to update |
| 499 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr); | 510 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr); |
| 500 #endif | 511 #endif |
| 501 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) { | 512 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) { |
| 502 printf("Error erasing at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 513 printf("Error erasing at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 503 // Don't try to program if the erase failed | 514 // Don't try to program if the erase failed |
| 504 } else { | 515 } else { |
| 505 // Now program it | 516 // Now program it |
| 506 if ((stat = flash_program((void *)fis_addr, (void *)fis_work_block, block_size, (void **)&err_addr)) != 0) { | 517 if ((stat = flash_program((void *)fis_addr, (void *)fis_work_block, block_size, (void **)&err_addr)) != 0) { |
| 507 printf("Error programming at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 518 printf("Error programming at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 508 } | 519 } |
| 509 } | 520 } |
| 510 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 521 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 511 // Insure [quietly] that the directory is locked after the update | 522 // Insure [quietly] that the directory is locked after the update |
| 512 flash_lock((void *)fis_addr, block_size, (void **)&err_addr); | 523 flash_lock((void *)fis_addr, block_size, (void **)&err_addr); |
| 548 if (flash_code_overlaps((void *)flash_addr, (void *)(flash_addr+length-1))) { | 559 if (flash_code_overlaps((void *)flash_addr, (void *)(flash_addr+length-1))) { |
| 549 printf("Can't program this region - contains code in use!\n"); | 560 printf("Can't program this region - contains code in use!\n"); |
| 550 return; | 561 return; |
| 551 } | 562 } |
| 552 if ((stat = flash_erase((void *)flash_addr, length, (void **)&err_addr)) != 0) { | 563 if ((stat = flash_erase((void *)flash_addr, length, (void **)&err_addr)) != 0) { |
| 553 printf("Error erasing at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 564 printf("Error erasing at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 554 } | 565 } |
| 555 } | 566 } |
| 556 | 567 |
| 557 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface* | 568 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface* |
| 558 | 569 |
| 586 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); | 597 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); |
| 587 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); | 598 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); |
| 588 return; | 599 return; |
| 589 } | 600 } |
| 590 if ((stat = flash_lock((void *)flash_addr, length, (void **)&err_addr)) != 0) { | 601 if ((stat = flash_lock((void *)flash_addr, length, (void **)&err_addr)) != 0) { |
| 591 printf("Error locking at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 602 printf("Error locking at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 592 } | 603 } |
| 593 } | 604 } |
| 594 | 605 |
| 595 static void | 606 static void |
| 596 fis_unlock(int argc, char *argv[]) | 607 fis_unlock(int argc, char *argv[]) |
| 622 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); | 633 printf("Invalid FLASH address: %p (%s)\n", (void *)flash_addr, flash_errmsg(stat)); |
| 623 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); | 634 printf(" valid range is %p-%p\n", (void *)flash_start, (void *)flash_end); |
| 624 return; | 635 return; |
| 625 } | 636 } |
| 626 if ((stat = flash_unlock((void *)flash_addr, length, (void **)&err_addr)) != 0) { | 637 if ((stat = flash_unlock((void *)flash_addr, length, (void **)&err_addr)) != 0) { |
| 627 printf("Error unlocking at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 638 printf("Error unlocking at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 628 } | 639 } |
| 629 } | 640 } |
| 630 #endif | 641 #endif |
| 631 | 642 |
| 632 static void | 643 static void |
| 663 printf("No image '%s' found\n", name); | 674 printf("No image '%s' found\n", name); |
| 664 return; | 675 return; |
| 665 } | 676 } |
| 666 // Erase Data blocks (free space) | 677 // Erase Data blocks (free space) |
| 667 if ((stat = flash_erase((void *)img->flash_base, img->size, (void **)&err_addr)) != 0) { | 678 if ((stat = flash_erase((void *)img->flash_base, img->size, (void **)&err_addr)) != 0) { |
| 668 printf("Error erasing at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 679 printf("Error erasing at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 669 } | 680 } |
| 670 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 681 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 671 // Insure [quietly] that the directory is unlocked before trying to update | 682 // Insure [quietly] that the directory is unlocked before trying to update |
| 672 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr); | 683 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr); |
| 673 #endif | 684 #endif |
| 674 // Update directory | 685 // Update directory |
| 675 memset(img, 0xFF, sizeof(*img)); | 686 memset(img, 0xFF, sizeof(*img)); |
| 676 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) { | 687 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) { |
| 677 printf("Error erasing at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 688 printf("Error erasing at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 678 // Don't try to program if the erase failed | 689 // Don't try to program if the erase failed |
| 679 } else { | 690 } else { |
| 680 // Now program it | 691 // Now program it |
| 681 if ((stat = flash_program((void *)fis_addr, (void *)fis_work_block, block_size, (void **)&err_addr)) != 0) { | 692 if ((stat = flash_program((void *)fis_addr, (void *)fis_work_block, block_size, (void **)&err_addr)) != 0) { |
| 682 printf("Error programming at %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 693 printf("Error programming at %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 683 } | 694 } |
| 684 } | 695 } |
| 685 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 696 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 686 // Insure [quietly] that the directory is locked after the update | 697 // Insure [quietly] that the directory is locked after the update |
| 687 flash_lock((void *)fis_addr, block_size, (void **)&err_addr); | 698 flash_lock((void *)fis_addr, block_size, (void **)&err_addr); |
| 695 struct fis_image_desc *img; | 706 struct fis_image_desc *img; |
| 696 unsigned long mem_addr; | 707 unsigned long mem_addr; |
| 697 bool mem_addr_set = false; | 708 bool mem_addr_set = false; |
| 698 bool show_cksum = false; | 709 bool show_cksum = false; |
| 699 struct option_info opts[2]; | 710 struct option_info opts[2]; |
| 711 unsigned long cksum; | |
| 700 | 712 |
| 701 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, | 713 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, |
| 702 (void **)&mem_addr, (bool *)&mem_addr_set, "memory [load] base address"); | 714 (void **)&mem_addr, (bool *)&mem_addr_set, "memory [load] base address"); |
| 703 init_opts(&opts[1], 'c', false, OPTION_ARG_TYPE_FLG, | 715 init_opts(&opts[1], 'c', false, OPTION_ARG_TYPE_FLG, |
| 704 (void **)&show_cksum, (bool *)0, "display checksum"); | 716 (void **)&show_cksum, (bool *)0, "display checksum"); |
| 720 printf("Not a loadable image\n"); | 732 printf("Not a loadable image\n"); |
| 721 return; | 733 return; |
| 722 } | 734 } |
| 723 memcpy((void *)mem_addr, (void *)img->flash_base, img->size); | 735 memcpy((void *)mem_addr, (void *)img->flash_base, img->size); |
| 724 entry_address = (unsigned long *)img->entry_point; | 736 entry_address = (unsigned long *)img->entry_point; |
| 737 cksum = _cksum((unsigned long *)mem_addr, img->data_length); | |
| 738 if (show_cksum) { | |
| 739 printf("Checksum: 0x%08lx\n", cksum); | |
| 740 } | |
| 725 if (img->file_cksum) { | 741 if (img->file_cksum) { |
| 726 unsigned long cksum = _cksum((unsigned long *)mem_addr, img->data_length); | |
| 727 if (cksum != img->file_cksum) { | 742 if (cksum != img->file_cksum) { |
| 728 printf("** Warning - checksum failure. stored: %08lx, computed: %08lx\n", | 743 printf("** Warning - checksum failure. stored: 0x%08lx, computed: 0x%08lx\n", |
| 729 img->file_cksum, cksum); | 744 img->file_cksum, cksum); |
| 730 } | |
| 731 if (show_cksum) { | |
| 732 printf("Checksum: %08lx\n", cksum); | |
| 733 } | 745 } |
| 734 } | 746 } |
| 735 } | 747 } |
| 736 | 748 |
| 737 static bool | 749 static bool |
| 742 | 754 |
| 743 if (!init) { | 755 if (!init) { |
| 744 init = 1; | 756 init = 1; |
| 745 if ((stat = flash_init((void *)(ram_end-FLASH_MIN_WORKSPACE), | 757 if ((stat = flash_init((void *)(ram_end-FLASH_MIN_WORKSPACE), |
| 746 FLASH_MIN_WORKSPACE)) != 0) { | 758 FLASH_MIN_WORKSPACE)) != 0) { |
| 747 printf("FLASH: driver init failed!, status: %x\n", stat); | 759 printf("FLASH: driver init failed!, status: 0x%x\n", stat); |
| 748 return false; | 760 return false; |
| 749 } | 761 } |
| 750 flash_get_limits((void *)0, (void **)&flash_start, (void **)&flash_end); | 762 flash_get_limits((void *)0, (void **)&flash_start, (void **)&flash_end); |
| 751 flash_get_block_info(&block_size, &blocks); | 763 flash_get_block_info(&block_size, &blocks); |
| 752 printf("FLASH: %p - %p, %d blocks of %p bytes each.\n", | 764 printf("FLASH: %p - %p, %d blocks of %p bytes each.\n", |
| 1076 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 1088 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 1077 // Insure [quietly] that the config page is unlocked before trying to update | 1089 // Insure [quietly] that the config page is unlocked before trying to update |
| 1078 flash_unlock((void *)cfg_base, block_size, (void **)&err_addr); | 1090 flash_unlock((void *)cfg_base, block_size, (void **)&err_addr); |
| 1079 #endif | 1091 #endif |
| 1080 if ((stat = flash_erase(cfg_base, block_size, (void **)&err_addr)) != 0) { | 1092 if ((stat = flash_erase(cfg_base, block_size, (void **)&err_addr)) != 0) { |
| 1081 printf(" initialization failed %p: %x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 1093 printf(" initialization failed %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 1082 } else { | 1094 } else { |
| 1083 if ((stat = flash_program(cfg_base, (void *)&config, | 1095 if ((stat = flash_program(cfg_base, (void *)&config, |
| 1084 sizeof(config), (void **)&err_addr)) != 0) { | 1096 sizeof(config), (void **)&err_addr)) != 0) { |
| 1085 printf("Error writing config data at %p: %x(%s)\n", | 1097 printf("Error writing config data at %p: 0x%x(%s)\n", |
| 1086 err_addr, stat, flash_errmsg(stat)); | 1098 err_addr, stat, flash_errmsg(stat)); |
| 1087 } | 1099 } |
| 1088 } | 1100 } |
| 1089 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 1101 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 1090 // Insure [quietly] that the config data is locked after the update | 1102 // Insure [quietly] that the config data is locked after the update |
