comparison packages/redboot/current/src/load.c @ 210:d2c90368aeef

Merge from eCos master repository on 2002-05-23-21:39:14-BST
author jlarmour
date Thu, 23 May 2002 22:59:51 +0000
parents e0c0827131d1
children 6eb55882e01c
comparison
equal deleted inserted replaced
209:19edcb2e78cc 210:d2c90368aeef
32 // 32 //
33 // This exception does not invalidate any other reasons why a work based on 33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License. 34 // this file might be covered by the GNU General Public License.
35 // 35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. 36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license 37 // at http://sources.redhat.com/ecos/ecos-license/
38 // ------------------------------------------- 38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND#### 39 //####ECOSGPLCOPYRIGHTEND####
40 //========================================================================== 40 //==========================================================================
41 //#####DESCRIPTIONBEGIN#### 41 //#####DESCRIPTIONBEGIN####
42 // 42 //
55 #include <redboot.h> 55 #include <redboot.h>
56 #include <xyzModem.h> 56 #include <xyzModem.h>
57 #include <elf.h> 57 #include <elf.h>
58 #ifdef CYGPKG_REDBOOT_DISK 58 #ifdef CYGPKG_REDBOOT_DISK
59 #include <fs/disk.h> 59 #include <fs/disk.h>
60 #endif
61 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
62 #include <net/http.h>
60 #endif 63 #endif
61 64
62 // Buffers, data used by redboot_getc 65 // Buffers, data used by redboot_getc
63 #define BUF_SIZE 256 66 #define BUF_SIZE 256
64 struct { 67 struct {
76 79
77 static char usage[] = "[-r] [-v] " 80 static char usage[] = "[-r] [-v] "
78 #ifdef CYGPKG_COMPRESS_ZLIB 81 #ifdef CYGPKG_COMPRESS_ZLIB
79 "[-d] " 82 "[-d] "
80 #endif 83 #endif
81 "[-h <host>] [-m {TFTP | xyzMODEM" 84 "[-h <host>] [-m {TFTP "
85 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
86 "| HTTP"
87 #endif
88 #ifdef xyzModem_zmodem
89 "| {x|y|z}MODEM"
90 #else
91 "| {x|y}MODEM"
92 #endif
82 #ifdef CYGPKG_REDBOOT_DISK 93 #ifdef CYGPKG_REDBOOT_DISK
83 " | disk" 94 " | disk"
84 #endif 95 #endif
85 #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1 96 #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1
86 " -c <channel_number>" 97 " -c <channel_number>"
506 } 517 }
507 518
508 #define MODE_TFTP 0 519 #define MODE_TFTP 0
509 #define MODE_XMODEM xyzModem_xmodem // 1 520 #define MODE_XMODEM xyzModem_xmodem // 1
510 #define MODE_YMODEM xyzModem_ymodem // 2 521 #define MODE_YMODEM xyzModem_ymodem // 2
522 #ifdef xyzModem_zmodem
511 #define MODE_ZMODEM xyzModem_zmodem // 3 523 #define MODE_ZMODEM xyzModem_zmodem // 3
524 #endif
512 #define MODE_DISK 4 525 #define MODE_DISK 4
526 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
527 #define MODE_HTTP 5
528 #endif
513 529
514 void 530 void
515 do_load(int argc, char *argv[]) 531 do_load(int argc, char *argv[])
516 { 532 {
517 int res, num_options; 533 int res, num_options;
600 mode = MODE_XMODEM; 616 mode = MODE_XMODEM;
601 break; 617 break;
602 case 'y': 618 case 'y':
603 mode = MODE_YMODEM; 619 mode = MODE_YMODEM;
604 break; 620 break;
621 #ifdef xyzModem_zmodem
605 case 'z': 622 case 'z':
606 mode = MODE_ZMODEM; 623 mode = MODE_ZMODEM;
607 break; 624 break;
625 #endif
608 default: 626 default:
609 diag_printf("Invalid 'mode': %s\n", mode_str); 627 diag_printf("Invalid 'mode': %s\n", mode_str);
610 return; 628 return;
611 } 629 }
612 // When using a serial download type, override verbose 630 // When using a serial download type, override verbose
614 verbose = false; 632 verbose = false;
615 #ifdef CYGPKG_REDBOOT_DISK 633 #ifdef CYGPKG_REDBOOT_DISK
616 } else if (strcasecmp(mode_str, "disk") == 0) { 634 } else if (strcasecmp(mode_str, "disk") == 0) {
617 mode = MODE_DISK; 635 mode = MODE_DISK;
618 #endif 636 #endif
637 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
638 } else if (strcasecmp(mode_str, "http") == 0) {
639 mode = MODE_HTTP;
640 #endif
619 #ifdef CYGPKG_REDBOOT_NETWORKING 641 #ifdef CYGPKG_REDBOOT_NETWORKING
620 } else if (strcasecmp(mode_str, "tftp") == 0) { 642 } else if (strcasecmp(mode_str, "tftp") == 0) {
621 mode = MODE_TFTP; 643 mode = MODE_TFTP;
622 if (!have_net) { 644 if (!have_net) {
623 diag_printf("TFTP mode requires a working network\n"); 645 diag_printf("TFTP mode requires a working network\n");
636 return; 658 return;
637 } 659 }
638 #endif 660 #endif
639 #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1 661 #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1
640 if (chan_set) { 662 if (chan_set) {
641 if ((mode != MODE_XMODEM) && (mode != MODE_YMODEM) && (mode != MODE_ZMODEM)) { 663 if ((mode != MODE_XMODEM) &&
664 #ifdef MODE_ZMODEM
665 (mode != MODE_ZMODEM) &&
666 #endif
667 (mode != MODE_YMODEM)) {
668 #ifdef xyzModem_zmodem
642 diag_printf("I/O channel can only be used with {xyz}Modem\n"); 669 diag_printf("I/O channel can only be used with {xyz}Modem\n");
670 #else
671 diag_printf("I/O channel can only be used with {xy}Modem\n");
672 #endif
643 return; 673 return;
644 } 674 }
645 if (chan >= CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) { 675 if (chan >= CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) {
646 diag_printf("Invalid I/O channel: %d\n", chan); 676 diag_printf("Invalid I/O channel: %d\n", chan);
647 return; 677 return;
679 709
680 diag_printf("Can't load '%s': %s\n", filename, disk_error(err)); 710 diag_printf("Can't load '%s': %s\n", filename, disk_error(err));
681 return; 711 return;
682 } 712 }
683 redboot_getc_init(disk_stream_read, verbose, decompress); 713 redboot_getc_init(disk_stream_read, verbose, decompress);
714 }
715 #endif
716 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
717 else if (mode == MODE_HTTP) {
718 res = http_stream_open(filename, &host, &err);
719 if (res < 0) {
720
721 diag_printf("Can't load '%s': %s\n", filename, http_error(err));
722 return;
723 }
724 redboot_getc_init(http_stream_read, verbose, decompress);
684 } 725 }
685 #endif 726 #endif
686 else { 727 else {
687 res = xyzModem_stream_open(filename, mode, chan, &err); 728 res = xyzModem_stream_open(filename, mode, chan, &err);
688 if (res < 0) { 729 if (res < 0) {
760 #ifdef CYGPKG_REDBOOT_DISK 801 #ifdef CYGPKG_REDBOOT_DISK
761 case MODE_DISK: 802 case MODE_DISK:
762 disk_stream_close(&err); 803 disk_stream_close(&err);
763 break; 804 break;
764 #endif 805 #endif
806 #ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
807 case MODE_HTTP:
808 http_stream_close(&err);
809 break;
810 #endif
765 #ifdef CYGPKG_REDBOOT_NETWORKING 811 #ifdef CYGPKG_REDBOOT_NETWORKING
766 case MODE_TFTP: 812 case MODE_TFTP:
767 tftp_stream_close(&err); 813 tftp_stream_close(&err);
768 break; 814 break;
769 #endif 815 #endif