]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/redboot/v2_0/src/mxc_usb.c
Initial revision
[karo-tx-redboot.git] / packages / redboot / v2_0 / src / mxc_usb.c
1 //==========================================================================
2 //
3 //      mxc_usb.c
4 //
5 //      usb download support for RedBoot
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002, 2003 Gary Thomas
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 //
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
43 //
44 // Author(s):    Kevin Zhang
45 // Contributors: Kevin Zhang
46 // Date:         2006-09-06
47 // Purpose:      
48 // Description:  this code is based on tftp_client.c
49 //              
50 // This code is part of RedBoot (tm).
51 //
52 //####DESCRIPTIONEND####
53 //
54 //==========================================================================
55
56 #include <redboot.h>
57
58 static struct {
59     bool open;
60     int  total_timeouts, packets_received;
61     unsigned long last_good_block;
62     int  avail, actual_len;
63 //    char data[SEGSIZE+sizeof(struct mxcusbhdr)];
64 //    char *bufp;
65 } mxcusb_stream;
66
67 extern void mxc_pcd_open(void);
68 extern void mxc_pcd_exit(void);
69 extern int mxc_pcd_int_hndlr(long buffer, long length);
70
71 int
72 mxcusb_stream_open(connection_info_t *info,
73                  int *err)
74 {
75 //    diag_printf("%s()\n", __FUNCTION__);
76     
77     mxc_pcd_open();
78     return 0;
79 }
80
81 void
82 mxcusb_stream_close(int *err)
83 {
84 //    diag_printf("%s()\n", __FUNCTION__);
85
86     mxc_pcd_exit();
87 }
88
89 void
90 mxcusb_stream_terminate(bool abort,
91                       int (*getc)(void))
92 {
93     int err;
94
95 //    diag_printf("%s()\n", __FUNCTION__);
96 }
97
98 int
99 mxcusb_stream_read(char *buf,
100                  int len,
101                  int *err)
102 {
103 //    diag_printf("%s(len=%d buf=%x)\n", __FUNCTION__, len, buf);
104
105         return mxc_pcd_int_hndlr(buf, len);
106 }
107
108 char *
109 mxcusb_error(int err)
110 {
111     char *errmsg = "Unknown error";
112
113     diag_printf("%s()\n", __FUNCTION__);
114 #if 0
115     switch (err) {
116     case MXCUSB_ENOTFOUND:
117         return "file not found";
118     case MXCUSB_EACCESS:
119         return "access violation";
120     case MXCUSB_ENOSPACE:
121         return "disk full or allocation exceeded";
122     case MXCUSB_EBADOP:
123         return "illegal MXCUSB operation";
124     case MXCUSB_EBADID:
125         return "unknown transfer ID";
126     case MXCUSB_EEXISTS:
127         return "file already exists";
128     case MXCUSB_ENOUSER:
129         return "no such user";
130     case MXCUSB_TIMEOUT:
131         return "operation timed out";
132     case MXCUSB_INVALID:
133         return "invalid parameter";
134     case MXCUSB_TOOLARGE:
135         return "file is larger than buffer";
136     }
137 #endif
138     return errmsg;
139 }
140
141 //
142 // RedBoot interface
143 //
144 GETC_IO_FUNCS(mxcusb_io, mxcusb_stream_open, mxcusb_stream_close,
145               mxcusb_stream_terminate, mxcusb_stream_read, mxcusb_error);
146 RedBoot_load(usb, mxcusb_io, true, false, 0);
147