⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot_usb.lst

📁 OMAP1510的USB驱动程序
💻 LST
字号:
C51 COMPILER V8.09   BOOT_USB                                                              05/05/2008 19:21:52 PAGE 1   


C51 COMPILER V8.09, COMPILATION OF MODULE BOOT_USB
OBJECT MODULE PLACED IN boot_usb.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE boot_usb.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /* qt2410_boot_usb - Ram Loader for Armzone QT2410 Devel Boards
   2           * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
   3           *
   4           *  This program is free software; you can redistribute it and/or modify
   5           *  it under the terms of the GNU General Public License version 2 
   6           *  as published by the Free Software Foundation
   7           *
   8           *  This program is distributed in the hope that it will be useful,
   9           *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10           *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11           *  GNU General Public License for more details.
  12           *
  13           *  You should have received a copy of the GNU General Public License
  14           *  along with this program; if not, write to the Free Software
  15           *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16           */
  17          
  18          /*
  19           * This program allows you to download executable code from the PC to the target
  20           * RAM.  After downloading it, the code can be executed.
  21           *
  22           * In order to make this work, the board must be running from the usb ram
  23           * loader in NOR flash rather than the regular OS in NAND.  To achieve this,
  24           * push move the small switch on the KERNEL board from NAND to NOR before powering
  25           * up the device.
  26           */
  27          
  28          #include <stdio.h>
  29          #include <stdlib.h>
  30          #include <unistd.h>
*** WARNING C318 IN LINE 30 OF boot_usb.c: can't open file 'unistd.h'
  31          #include <string.h>
  32          #include <errno.h>
  33          
  34          #include <sys/types.h>
*** WARNING C318 IN LINE 34 OF boot_usb.c: can't open file 'sys/types.h'
  35          #include <sys/stat.h>
*** WARNING C318 IN LINE 35 OF boot_usb.c: can't open file 'sys/stat.h'
  36          #include <sys/mman.h>
*** WARNING C318 IN LINE 36 OF boot_usb.c: can't open file 'sys/mman.h'
  37          #include <fcntl.h>
*** WARNING C318 IN LINE 37 OF boot_usb.c: can't open file 'fcntl.h'
  38          
  39          #include <usb.h>
*** WARNING C318 IN LINE 39 OF boot_usb.c: can't open file 'usb.h'
  40          
  41          const char *
  42          hexdump(const void *data, unsigned int len)
*** ERROR C141 IN LINE 42 OF BOOT_USB.C: syntax error near ','
  43          {
  44   1              static char string[65535];
  45   1              unsigned char *d = (unsigned char *) data;
*** ERROR C141 IN LINE 45 OF BOOT_USB.C: syntax error near 'data'
  46   1              unsigned int i, left;
*** ERROR C202 IN LINE 46 OF BOOT_USB.C: 'i': undefined identifier
C51 COMPILER V8.09   BOOT_USB                                                              05/05/2008 19:21:52 PAGE 2   

  47   1      
  48   1              string[0] = '\0';
  49   1              left = sizeof(string);
  50   1              for (i = 0; len--; i += 3) {
*** ERROR C202 IN LINE 50 OF BOOT_USB.C: 'i': undefined identifier
  51   2                      if (i >= sizeof(string) -4)
*** ERROR C202 IN LINE 51 OF BOOT_USB.C: 'i': undefined identifier
  52   2                              break;
  53   2                      snprintf(string+i, 4, " %02x", *d++);
*** ERROR C202 IN LINE 53 OF BOOT_USB.C: 'i': undefined identifier
  54   2              }
  55   1              return string;
  56   1      }
  57          
  58          #define QT2410_VENDOR_ID        0x5345
  59          #define QT2410_PRODUCT_ID       0x1234
  60          #define QT2410_OUT_EP   0x03
  61          #define QT2410_IN_EP    0x81
  62          
  63          static struct usb_dev_handle *hdl;
  64          static struct usb_device *find_qt2410_device(void)
  65          {
  66   1              struct usb_bus *bus;
  67   1      
  68   1              for (bus = usb_busses; bus; bus = bus->next) {
*** ERROR C202 IN LINE 68 OF BOOT_USB.C: 'usb_busses': undefined identifier
  69   2                      struct usb_device *dev;
  70   2                      for (dev = bus->devices; dev; dev = dev->next) {
*** ERROR C230 IN LINE 70 OF BOOT_USB.C: 'usb_bus': unknown struct/union/enum tag
*** ERROR C204 IN LINE 70 OF BOOT_USB.C: 'devices': undefined member
  71   3                              if (dev->descriptor.idVendor == QT2410_VENDOR_ID
*** ERROR C230 IN LINE 71 OF BOOT_USB.C: 'usb_device': unknown struct/union/enum tag
*** ERROR C204 IN LINE 71 OF BOOT_USB.C: 'descriptor': undefined member
  72   3                                  && dev->descriptor.idProduct == QT2410_PRODUCT_ID
  73   3                                  && dev->descriptor.iManufacturer == 1
  74   3                                  && dev->descriptor.iProduct == 2
  75   3                                  && dev->descriptor.bNumConfigurations == 1
  76   3                                  && dev->config->bNumInterfaces == 1
  77   3                                  && dev->config->iConfiguration == 0)
  78   3                                      return dev;
  79   3                      }
  80   2              }
  81   1              return NULL;
  82   1      }
  83          
  84          
  85          static u_int16_t qt2410_csum(const unsigned char *data, u_int32_t len)
*** ERROR C129 IN LINE 85 OF BOOT_USB.C: missing ';' before 'qt2410_csum'
  86          {
  87                  u_int16_t csum = 0;
  88                  int j;
  89          
  90                  for (j = 0; j < len; j ++) {
  91                          csum += data[j];
  92                  }
  93          
  94                  return csum;
  95          }
  96          
  97          #define CHUNK_SIZE 100
  98          static int qt2410_send_file(u_int32_t addr, void *data, u_int32_t len)
  99          {
C51 COMPILER V8.09   BOOT_USB                                                              05/05/2008 19:21:52 PAGE 3   

 100                  int ret = 0;
 101                  unsigned char *buf, *cur;
 102                  u_int16_t csum = qt2410_csum(data, len);
 103                  u_int32_t len_total = len + 10;
 104          
 105                  printf("csum = 0x%4x\n", csum);
 106          
 107                  /* 4 bytes address, 4 bytes length, data, 2 bytes csum */
 108          
 109                  buf = malloc(len_total);
 110                  if (!buf)
 111                          return -ENOMEM;
 112          
 113                  /* FIXME: endian safeness !!! */
 114                  buf[0] = addr & 0xff;
 115                  buf[1] = (addr >> 8) & 0xff;
 116                  buf[2] = (addr >> 16) & 0xff;
 117                  buf[3] = (addr >> 24) & 0xff;
 118          
 119                  buf[4] = len_total & 0xff;
 120                  buf[5] = (len_total >> 8) & 0xff;
 121                  buf[6] = (len_total >> 16) & 0xff;
 122                  buf[7] = (len_total >> 24) & 0xff;
 123          
 124                  memcpy(buf+8, data, len);
 125          
 126                  buf[len+8] = csum & 0xff;
 127                  buf[len+9] = (csum >> 8) & 0xff;
 128          
 129                  printf("send_file: addr = 0x%08x, len = 0x%08x\n", addr, len);
 130          
 131                  for (cur = buf; cur < buf+len_total; cur += CHUNK_SIZE) {
 132                          int remain = (buf + len_total) - cur;
 133                          if (remain > CHUNK_SIZE)
 134                                  remain = CHUNK_SIZE;
 135          
 136          #if 0
                              printf("sending urb(0x%08x): %s\n", 
                                      addr + (cur - buf), hexdump(cur, remain));
              #endif
 140          
 141                          ret = usb_bulk_write(hdl, QT2410_OUT_EP, cur, remain, 0);
 142                          if (ret < 0)
 143                                  break;
 144                  }
 145          
 146                  free(buf);
 147          
 148                  return ret;
 149          }
 150          
 151          #if 0
              static int qt2410_send_file(u_int32_t addr, void *data, u_int32_t len)
              {
                      int i, ret;
                      u_int32_t cur_addr;
                      void *cur_data;
              
                      for (cur_addr = addr, cur_data = data; 
                           cur_addr < addr + len;
                           cur_addr += CHUNK_SIZE, cur_data += CHUNK_SIZE) {
                              int remain = (data + len) - cur_data;
C51 COMPILER V8.09   BOOT_USB                                                              05/05/2008 19:21:52 PAGE 4   

                              if (remain > CHUNK_SIZE)
                                      remain = CHUNK_SIZE;
                      
                              ret = qt2410_send_chunk(cur_addr, cur_data, remain);
                              if (ret < 0)
                                      return ret;
                      }
              
                      return 0;
              }
              #endif
 173          
 174          //#define KERNEL_RAM_BASE       0x30008000
 175          #define KERNEL_RAM_BASE 0x33F80000
 176          
 177          int main(int argc, char **argv)
 178          {
 179                  struct usb_device *dev;
 180                  char *filename, *prog;
 181                  struct stat st;
 182                  int fd;
 183                  u_int32_t word = 0x7c7c7c7c;
 184          
 185                  usb_init();
 186                  if (!usb_find_busses())
 187                          exit(1);
 188                  if (!usb_find_devices())
 189                          exit(1);
 190          
 191                  dev = find_qt2410_device();
 192                  if (!dev) {
 193                          printf("Cannot find QT2410 device in bootloader mode\n");
 194                          exit(1);
 195                  }
 196          
 197                  hdl = usb_open(dev);
 198                  if (!hdl) {
 199                          printf("Unable to open usb device: %s\n", usb_strerror());
 200                          exit(1);
 201                  }
 202          
 203                  if (usb_claim_interface(hdl, 0) < 0) {
 204                          printf("Unable to claim usb interface 1 of device: %s\n", usb_strerror());
 205                          exit(1);
 206                  }
 207          
 208                  filename = argv[1];
 209                  if (!filename) {
 210                          printf("You have to specify the file you want to flash\n");
 211                          exit(2);
 212                  }
 213          
 214                  fd = open(filename, O_RDONLY);
 215                  if (fd < 0)
 216                          exit(2);
 217          
 218                  if (fstat(fd, &st) < 0) {
 219                          printf("Error to access file `%s': %s\n", filename, strerror(errno));
 220                          exit(2);
 221                  }
 222          
 223                  /* mmap kernel image passed as parameter */
C51 COMPILER V8.09   BOOT_USB                                                              05/05/2008 19:21:52 PAGE 5   

 224                  prog = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
 225                  if (!prog)
 226                          exit(1);
 227          
 228                  if (qt2410_send_file(KERNEL_RAM_BASE, prog, st.st_size)) {
 229                          printf("Error downloading program\n");
 230                          exit(1);
 231                  }
 232                  exit(0);
 233          }

C51 COMPILATION COMPLETE.  6 WARNING(S),  12 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -