1 //==========================================================================
5 // usb download support for RedBoot
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
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.
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
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.
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.
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.
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####
44 // Author(s): Fisher ZHU
45 // Contributors: Fisher ZHU
48 // Description: this code architecture is based on mxc_usb.c
50 // This code is part of RedBoot (tm).
53 // Date Author Comments
54 // 2008-10-27 Fisher ZHU Initial Creation, support for i.mx37
55 //####DESCRIPTIONEND####
57 //==========================================================================
60 #include <pkgconf/devs_usb_imx_otg.h>
63 int total_timeouts, packets_received;
64 unsigned long last_good_block;
65 int avail, actual_len;
66 // char data[SEGSIZE+sizeof(struct imxotghdr)];
70 EXTERN unsigned long entry_address;
71 EXTERN unsigned long load_address;
72 EXTERN unsigned long load_address_end;
74 extern cyg_uint32 usb_download_address;
75 extern cyg_uint32 usb_download_length;
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);
84 imxotg_stream_open(connection_info_t *info,
87 //diag_printf("%s()\n", __FUNCTION__);
88 usbs_imx_otg_device_init();
93 imxotg_stream_close(int *err)
95 //diag_printf("%s()\n", __FUNCTION__);
96 usbs_imx_otg_device_deinit();
100 imxotg_stream_terminate(bool abort,
104 //diag_printf("%s()\n", __FUNCTION__);
105 load_address_end = load_address + usb_download_length;
106 entry_address = load_address;
110 imxotg_stream_read(char *buf,
115 //diag_printf("%s(transfer length=%d,buffer address=0x%08x)\n", __FUNCTION__, len, buf);
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);
128 imxotg_error(int err)
130 char *errmsg = "Unknown error";
132 //diag_printf("%s()\n", __FUNCTION__);
135 case MXCUSB_ENOTFOUND:
136 return "file not found";
138 return "access violation";
139 case MXCUSB_ENOSPACE:
140 return "disk full or allocation exceeded";
142 return "illegal MXCUSB operation";
144 return "unknown transfer ID";
146 return "file already exists";
148 return "no such user";
150 return "operation timed out";
152 return "invalid parameter";
153 case MXCUSB_TOOLARGE:
154 return "file is larger than buffer";
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);