]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/redboot/v2_0/src/imx_usb.c
Initial revision
[karo-tx-redboot.git] / packages / redboot / v2_0 / src / imx_usb.c
1 //==========================================================================
2 //
3 //      imx_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):    Fisher ZHU
45 // Contributors: Fisher ZHU
46 // Date:         2008-10-27
47 // Purpose:      
48 // Description:  this code architecture is based on mxc_usb.c
49 //              
50 // This code is part of RedBoot (tm).
51 // 
52 // Revision History:
53 // Date                 Author                  Comments
54 // 2008-10-27   Fisher ZHU              Initial Creation, support for i.mx37
55 //####DESCRIPTIONEND####
56 //
57 //==========================================================================
58
59 #include <redboot.h>
60 #include <pkgconf/devs_usb_imx_otg.h>
61 static struct {
62     bool open;
63     int  total_timeouts, packets_received;
64     unsigned long last_good_block;
65     int  avail, actual_len;
66 //    char data[SEGSIZE+sizeof(struct imxotghdr)];
67 //    char *bufp;
68 } imxotg_stream;
69
70 EXTERN unsigned long entry_address;
71 EXTERN unsigned long load_address;
72 EXTERN unsigned long load_address_end;
73
74 extern cyg_uint32 usb_download_address;
75 extern cyg_uint32 usb_download_length;
76
77 extern void usbs_imx_otg_device_init(void);
78 extern void usbs_imx_otg_device_deinit(void);
79 #if defined(CYGBLD_IMX_USB_DOWNLOAD_SUPPORT)
80 extern void usbs_imx_otg_download(unsigned char * buffer, unsigned int length);
81 #endif
82
83 int
84 imxotg_stream_open(connection_info_t *info,
85                  int *err)
86 {
87     //diag_printf("%s()\n", __FUNCTION__);
88     usbs_imx_otg_device_init();
89     return 0;
90 }
91
92 void
93 imxotg_stream_close(int *err)
94 {
95     //diag_printf("%s()\n", __FUNCTION__);
96     usbs_imx_otg_device_deinit();
97 }
98
99 void
100 imxotg_stream_terminate(bool abort,
101                       int (*getc)(void))
102 {
103     int err;
104     //diag_printf("%s()\n", __FUNCTION__);
105     load_address_end = load_address + usb_download_length;
106         entry_address = load_address;
107 }
108
109 int
110 imxotg_stream_read(char *buf,
111                  int len,
112                  int *err)
113 {
114         
115         //diag_printf("%s(transfer length=%d,buffer address=0x%08x)\n", __FUNCTION__, len, buf);
116
117         /*buf and len are not used by usb download. 
118         buf is a buffer pointer created by redboot, but USB download will download the binary file directly to
119         the memory pointed by load_address.
120         len is the buffer length, while USB download will download all the binary file once. 
121         The two variables are actually dummy.*/
122         usb_download_address = load_address;
123         usbs_imx_otg_download(buf,len);                                                                                 
124         return 0;
125 }
126
127 char *
128 imxotg_error(int err)
129 {
130     char *errmsg = "Unknown error";
131
132     //diag_printf("%s()\n", __FUNCTION__);
133 #if 0
134     switch (err) {
135     case MXCUSB_ENOTFOUND:
136         return "file not found";
137     case MXCUSB_EACCESS:
138         return "access violation";
139     case MXCUSB_ENOSPACE:
140         return "disk full or allocation exceeded";
141     case MXCUSB_EBADOP:
142         return "illegal MXCUSB operation";
143     case MXCUSB_EBADID:
144         return "unknown transfer ID";
145     case MXCUSB_EEXISTS:
146         return "file already exists";
147     case MXCUSB_ENOUSER:
148         return "no such user";
149     case MXCUSB_TIMEOUT:
150         return "operation timed out";
151     case MXCUSB_INVALID:
152         return "invalid parameter";
153     case MXCUSB_TOOLARGE:
154         return "file is larger than buffer";
155     }
156 #endif
157     return errmsg;
158 }
159
160 //
161 // RedBoot interface
162 //
163 GETC_IO_FUNCS(imxotg_io, imxotg_stream_open, imxotg_stream_close,
164               imxotg_stream_terminate, imxotg_stream_read, imxotg_error);
165 RedBoot_load(usb, imxotg_io, true, false, 0);
166
167