/* $Id: Exp $ * * omap3_usbload, an USB download application for OMAP3 processors * Copyright (C) 2008 Martin Mueller * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with paparazzi; see the file COPYING. If not, write to * the Free Software Foundation, 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ /* needs libusb-dev gcc -o omap3dl omap3dl.c -lusb vcvarsall.bat x86 cl omap3dl.c libusb.lib */ #include #include #include #include #define VERSION "0.1" //#define DEBUG #if defined(_WIN32) && !defined(__CYGWIN__) #define COMPILE_FOR_WINDOWS #elif defined(__CYGWIN__) #define COMPILE_FOR_CYGWIN #else #define COMPILE_FOR_LINUX #endif #if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN #include #include #endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN #if defined COMPILE_FOR_WINDOWS #include #define open _open #define close _close #define read _read #define write _write #define lseek _lseek #define usleep(x) Sleep(x/1000) #endif // defined COMPILE_FOR_WINDOWS #define VENDOR_ID_TI 0x0451 #define DEVICE_ID_3430 0xD009 #define OMAP3_BOOT_CMD 0xF0030002 #define EP_BULK_IN 0x81 #define EP_BULK_OUT 0x01 #define BUF_LEN 4096 int main(int argc, char **argv) { struct usb_bus *bus; usb_dev_handle *udev; int file_fd; int file_cnt; int file_len; int usb_cnt; char dat_buf[BUF_LEN]; unsigned int command; printf("\nTI OMAP3 USB boot ROM tool, version " VERSION "\n"); printf("(c) 2008 Martin Mueller \n\n"); if (argc != 2) { printf("usage: omap3dl \n\n"); return(-1); } usb_init(); usb_find_busses(); while (1) { printf("."); fflush(stdout); if (usb_find_devices()) { for (bus = usb_get_busses(); bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == VENDOR_ID_TI) && (dev->descriptor.idProduct == DEVICE_ID_3430)) { udev = usb_open(dev); if (udev) { printf("\n\nfound device!\n"); file_fd = open(argv[1], O_RDONLY); if (file_fd < 0) { perror("open bin file"); goto err; } file_len = lseek(file_fd, 0, SEEK_END); lseek(file_fd, 0, SEEK_SET); if (usb_set_configuration(udev, 1) < 0) { printf("could not set configuration\n"); goto err; } file_cnt = usb_bulk_read(udev, EP_BULK_IN, dat_buf, BUF_LEN, 1000); if (file_cnt <= 0) { printf("could not get ASIC ID\n"); goto err; } #ifdef DEBUG for (command=0; command 0) { usb_cnt = usb_bulk_write(udev, EP_BULK_OUT, dat_buf, file_cnt, 1000); if (usb_cnt != file_cnt) { printf("could not write to usb"); goto err; } } } while (file_cnt > 0); printf("download ok\n"); close(file_fd); usb_close(udev); return(0); } } } } } usleep(100*1000); } return(0); err: close(file_fd); usb_close(udev); return(-1); }