uboot usb网卡分析

前言:最近折腾下uboot,分析了下uboot的usb接口的网卡,就usb底层操作(寄存器操作)而言却是很难,我也不太懂。我们在uboot添加自己的usb接口网卡,前提uboot里已经是做好了usb底层设置的(例如arch/arm/cpu/arm920t/s3c24x0/usb_ohci.c文件提供了usb寄存器的操作函数,发送数据包,初始化等。。。。)。

一,怎样在uboot可以使用usb start ,usb scan命令

uboot里有个doc目录,里面有个文件README.usb提供了方法:

How it works:
-------------

The USB (at least the USB UHCI) needs a frame list (4k), transfer
descripor and queue headers which are all located in the main memory.
The UHCI allocates every milisecond the PCI bus and reads the current
frame pointer. This may cause to crash the OS during boot. So the USB
_MUST_ be stopped during OS boot. This is the reason, why the USB is
NOT automatically started during start-up. If someone needs the USB
he has to start it and should therefore be aware that he had to stop
it before booting the OS.

For USB keyboards this can be done by a script which is automatically
started after the U-Boot is up and running. To boot an OS with a an
USB keyboard another script is necessary, which first disables the
USB and then executes the boot command. If the boot command fails,
the script can reenable the USB kbd.

Common USB Commands:
- usb start:
- usb reset:        (re)starts the USB. All USB devices will be
            initialized and a device tree is build for them.
- usb tree:        shows all USB devices in a tree like display
- usb info [dev]:   shows all USB infos of the device dev, or of all
            the devices
- usb stop [f]:        stops the USB. If f==1 the USB will also stop if
            an USB keyboard is assigned as stdin. The stdin
            is then switched to serial input.
Storage USB Commands:
- usb scan:        scans the USB for storage devices.The USB must be
            running for this command (usb start)
- usb device [dev]: show or set current USB staorage device
- usb part [dev]:   print partition table of one or all USB storage
            devices
- usb read addr blk# cnt:
            read `cnt' blocks starting at block `blk#'to
            memory address `addr'
- usbboot addr dev:part:
            boot from USB device

Config Switches:    我们去配置文件   \include\configs\ xxx.h 添加这几个宏就可以了
----------------
CONFIG_CMD_USB        enables basic vmUSB support and the usb command
CONFIG_USB_UHCI        defines the lowlevel part.A lowlevel part must be defined
            if using CONFIG_CMD_USB
CONFIG_USB_KEYBOARD enables the USB Keyboard
CONFIG_USB_STORAGE  enables the USB storage devices
CONFIG_USB_HOST_ETHER    enables USB ethernet adapter support

重新编译uboot,烧录,重启uboot 输入   usb start      就发现 usb开始工作了

二。怎样添加usb 接口的 网卡

我们先跟踪代码去一步一步分析,我们在用nfs时,会大概经过这么几个过程

   static voidNfsSend (void) {  /*nfs  发送函数*/

         nfs_read_req         

                rpc_req

                     NetSendUDPPacket   /*把数据打包成udp*/

                              eth_send         /×发送以太网数据包×/

                                     eth_current->send(eth_current, packet, length);  /×用 我们注册 的eth_device提供的send函数去发送×/

在net/eth.c提供了一个eth_register(struct eth_device *dev)这个函数,我们只要写一个驱动,在这个驱动里去分配 ,设置,注册这个eth_device结构体就可以了。这个结构体提供  发送数据包,接收数据包,初始化函数等。思想就是这样的

三。利用uboot已经提供好的usb接口网络设备框架

其实uboot里已经写好了一个usb接口网络设备的框架,我们只要去看懂,然后写硬件相关部分就可以了

在uboot  的cmd_usb.c文件里定了一个

U_BOOT_CMD(
    usb,    5,    1,    do_usb,
    "USB sub-system",
    "start - start (scan) USB controller\n"
    "usb reset - reset (rescan) USB controller\n"
    "usb stop [f] - stop USB [f]=force stop\n"
    "usb tree - show USB device tree\n"
    "usb info [dev] - show available USB devices\n"
    "usb storage - show details of USB storage devices\n"
    "usb dev [dev] - show or set current USB storage device\n"
    "usb part [dev] - print partition table of one or all USB storage"
    " devices\n"
    "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
    "    to memory address `addr'\n"
    "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n"
    "    from memory address `addr'"
);结构体。

当我们在uboot下输入usb 相关命令时会调用do_usb

do_usb  --       cmd_usb.c

       usb_host_eth_scan(1) {            --usb_ether.c                      

            probe_valid_drivers(dev);        --usb_ether.c     

                  eth_register(eth);                --usb_ether.c     

我们分析这个 usb_ether.c     c文件,我们发现一个数组:usb_eth_prob_dev prob_dev[]

static const struct usb_eth_prob_dev prob_dev[] = {
     #ifdef CONFIG_USB_ETHER_ASIX
    {
        .before_probe = asix_eth_before_probe,
        .probe = asix_eth_probe,
        .get_info = asix_eth_get_info,
    },
#endif
#ifdef CONFIG_USB_ETHER_SMSC95XX
    {
        .before_probe = smsc95xx_eth_before_probe,
        .probe = smsc95xx_eth_probe,
        .get_info = smsc95xx_eth_get_info,
    },
#endif

 

。。。。。。。添加我们的网卡芯片,仿照

 

 


    { },        /* END */
};

四。怎样写usb接口网卡驱动,  其实readme.usb文件里有详细的介绍

USB Host Networking
===================

If you have a supported USB Ethernet adapter you can use it in U-Boot
to obtain an IP address and load a kernel from a network server.

Note: USB Host Networking is not the same as making your board act as a USB
client. In that case your board is pretending to be an Ethernet adapter
and will appear as a network interface to an attached computer. In that
case the connection is via a USB cable with the computer acting as the host.

With USB Host Networking, your board is the USB host. It controls the
Ethernet adapter to which it is directly connected and the connection to
the outside world is your adapter's Ethernet cable. Your board becomes an
independent network device, able to connect and perform network operations
independently of your computer.


Device support
--------------

Currently supported devices are listed in the drivers according to
their vendor and product IDs. You can check your device by connecting it
to a Linux machine and typing 'lsusb'. The drivers are in
drivers/usb/eth.

For example this lsusb output line shows a device with Vendor ID 0x0x95
and product ID 0x7720:

Bus 002 Device 010: ID 0b95:7720 ASIX Electronics Corp. AX88772

If you look at drivers/usb/eth/asix.c you will see this line within the
supported device list, so we know this adapter is supported.

    { 0x0b95, 0x7720 },    /* Trendnet TU2-ET100 V3.0R */

If your adapter is not listed there is a still a chance that it will
work. Try looking up the manufacturer of the chip inside your adapter.
or take the adapter apart and look for chip markings. Then add a line
for your vendor/product ID into the table of the appropriate driver,
build U-Boot and see if it works. If not then there might be differences
between the chip in your adapter and the driver. You could try to get a
datasheet for your device and add support for it to U-Boot. This is not
particularly difficult - you only need to provide support for four basic
functions: init, halt, send and recv.(我们添加自己网卡的发送,接收函数。。。。)

 

 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值