1*4882a593Smuzhiyun/* 2*4882a593Smuzhiyun * (C) Copyright 2001 3*4882a593Smuzhiyun * Denis Peter, MPL AG Switzerland 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun */ 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunUSB Support 9*4882a593Smuzhiyun=========== 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunThe USB support is implemented on the base of the UHCI Host 12*4882a593Smuzhiyuncontroller. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunCurrently supported are USB Hubs, USB Keyboards, USB Floppys, USB 15*4882a593Smuzhiyunflash sticks and USB network adaptors. 16*4882a593SmuzhiyunTested with a TEAC Floppy TEAC FD-05PUB and Chicony KU-8933 Keyboard. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunHow it works: 19*4882a593Smuzhiyun------------- 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunThe USB (at least the USB UHCI) needs a frame list (4k), transfer 22*4882a593Smuzhiyundescripor and queue headers which are all located in the main memory. 23*4882a593SmuzhiyunThe UHCI allocates every milisecond the PCI bus and reads the current 24*4882a593Smuzhiyunframe pointer. This may cause to crash the OS during boot. So the USB 25*4882a593Smuzhiyun_MUST_ be stopped during OS boot. This is the reason, why the USB is 26*4882a593SmuzhiyunNOT automatically started during start-up. If someone needs the USB 27*4882a593Smuzhiyunhe has to start it and should therefore be aware that he had to stop 28*4882a593Smuzhiyunit before booting the OS. 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunFor USB keyboards this can be done by a script which is automatically 31*4882a593Smuzhiyunstarted after the U-Boot is up and running. To boot an OS with a an 32*4882a593SmuzhiyunUSB keyboard another script is necessary, which first disables the 33*4882a593SmuzhiyunUSB and then executes the boot command. If the boot command fails, 34*4882a593Smuzhiyunthe script can reenable the USB kbd. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunCommon USB Commands: 37*4882a593Smuzhiyun- usb start: 38*4882a593Smuzhiyun- usb reset: (re)starts the USB. All USB devices will be 39*4882a593Smuzhiyun initialized and a device tree is build for them. 40*4882a593Smuzhiyun- usb tree: shows all USB devices in a tree like display 41*4882a593Smuzhiyun- usb info [dev]: shows all USB infos of the device dev, or of all 42*4882a593Smuzhiyun the devices 43*4882a593Smuzhiyun- usb stop [f]: stops the USB. If f==1 the USB will also stop if 44*4882a593Smuzhiyun an USB keyboard is assigned as stdin. The stdin 45*4882a593Smuzhiyun is then switched to serial input. 46*4882a593SmuzhiyunStorage USB Commands: 47*4882a593Smuzhiyun- usb scan: scans the USB for storage devices.The USB must be 48*4882a593Smuzhiyun running for this command (usb start) 49*4882a593Smuzhiyun- usb device [dev]: show or set current USB storage device 50*4882a593Smuzhiyun- usb part [dev]: print partition table of one or all USB storage 51*4882a593Smuzhiyun devices 52*4882a593Smuzhiyun- usb read addr blk# cnt: 53*4882a593Smuzhiyun read `cnt' blocks starting at block `blk#'to 54*4882a593Smuzhiyun memory address `addr' 55*4882a593Smuzhiyun- usbboot addr dev:part: 56*4882a593Smuzhiyun boot from USB device 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunConfig Switches: 59*4882a593Smuzhiyun---------------- 60*4882a593SmuzhiyunCONFIG_CMD_USB enables basic USB support and the usb command 61*4882a593SmuzhiyunCONFIG_USB_UHCI defines the lowlevel part.A lowlevel part must be defined 62*4882a593Smuzhiyun if using CONFIG_CMD_USB 63*4882a593SmuzhiyunCONFIG_USB_KEYBOARD enables the USB Keyboard 64*4882a593SmuzhiyunCONFIG_USB_STORAGE enables the USB storage devices 65*4882a593SmuzhiyunCONFIG_USB_HOST_ETHER enables USB ethernet adapter support 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunUSB Host Networking 69*4882a593Smuzhiyun=================== 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunIf you have a supported USB Ethernet adapter you can use it in U-Boot 72*4882a593Smuzhiyunto obtain an IP address and load a kernel from a network server. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunNote: USB Host Networking is not the same as making your board act as a USB 75*4882a593Smuzhiyunclient. In that case your board is pretending to be an Ethernet adapter 76*4882a593Smuzhiyunand will appear as a network interface to an attached computer. In that 77*4882a593Smuzhiyuncase the connection is via a USB cable with the computer acting as the host. 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunWith USB Host Networking, your board is the USB host. It controls the 80*4882a593SmuzhiyunEthernet adapter to which it is directly connected and the connection to 81*4882a593Smuzhiyunthe outside world is your adapter's Ethernet cable. Your board becomes an 82*4882a593Smuzhiyunindependent network device, able to connect and perform network operations 83*4882a593Smuzhiyunindependently of your computer. 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunDevice support 87*4882a593Smuzhiyun-------------- 88*4882a593Smuzhiyun 89*4882a593SmuzhiyunCurrently supported devices are listed in the drivers according to 90*4882a593Smuzhiyuntheir vendor and product IDs. You can check your device by connecting it 91*4882a593Smuzhiyunto a Linux machine and typing 'lsusb'. The drivers are in 92*4882a593Smuzhiyundrivers/usb/eth. 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunFor example this lsusb output line shows a device with Vendor ID 0x0x95 95*4882a593Smuzhiyunand product ID 0x7720: 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunBus 002 Device 010: ID 0b95:7720 ASIX Electronics Corp. AX88772 98*4882a593Smuzhiyun 99*4882a593SmuzhiyunIf you look at drivers/usb/eth/asix.c you will see this line within the 100*4882a593Smuzhiyunsupported device list, so we know this adapter is supported. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun { 0x0b95, 0x7720 }, /* Trendnet TU2-ET100 V3.0R */ 103*4882a593Smuzhiyun 104*4882a593SmuzhiyunIf your adapter is not listed there is a still a chance that it will 105*4882a593Smuzhiyunwork. Try looking up the manufacturer of the chip inside your adapter. 106*4882a593Smuzhiyunor take the adapter apart and look for chip markings. Then add a line 107*4882a593Smuzhiyunfor your vendor/product ID into the table of the appropriate driver, 108*4882a593Smuzhiyunbuild U-Boot and see if it works. If not then there might be differences 109*4882a593Smuzhiyunbetween the chip in your adapter and the driver. You could try to get a 110*4882a593Smuzhiyundatasheet for your device and add support for it to U-Boot. This is not 111*4882a593Smuzhiyunparticularly difficult - you only need to provide support for four basic 112*4882a593Smuzhiyunfunctions: init, halt, send and recv. 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunEnabling USB Host Networking 116*4882a593Smuzhiyun---------------------------- 117*4882a593Smuzhiyun 118*4882a593SmuzhiyunThe normal U-Boot commands are used with USB networking, but you must 119*4882a593Smuzhiyunstart USB first. For example: 120*4882a593Smuzhiyun 121*4882a593Smuzhiyunusb start 122*4882a593Smuzhiyunsetenv bootfile /tftpboot/uImage 123*4882a593Smuzhiyunbootp 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun 126*4882a593SmuzhiyunTo enable USB Host Ethernet in U-Boot, your platform must of course 127*4882a593Smuzhiyunsupport USB with CONFIG_CMD_USB enabled and working. You will need to 128*4882a593Smuzhiyunadd some config settings to your board config: 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunCONFIG_CMD_USB=y /* the 'usb' interactive command */ 131*4882a593SmuzhiyunCONFIG_USB_HOST_ETHER=y /* Enable USB Ethernet adapters */ 132*4882a593Smuzhiyun 133*4882a593Smuzhiyunand one or more of the following for individual adapter hardware: 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunCONFIG_USB_ETHER_ASIX=y 136*4882a593SmuzhiyunCONFIG_USB_ETHER_ASIX88179=y 137*4882a593SmuzhiyunCONFIG_USB_ETHER_LAN75XX=y 138*4882a593SmuzhiyunCONFIG_USB_ETHER_LAN78XX=y 139*4882a593SmuzhiyunCONFIG_USB_ETHER_MCS7830=y 140*4882a593SmuzhiyunCONFIG_USB_ETHER_RTL8152=y 141*4882a593SmuzhiyunCONFIG_USB_ETHER_SMSC95XX=y 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunAs with built-in networking, you will also want to enable some network 144*4882a593Smuzhiyuncommands, for example: 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunCONFIG_CMD_NET=y 147*4882a593SmuzhiyunCONFIG_CMD_PING=y 148*4882a593SmuzhiyunCONFIG_CMD_DHCP=y 149*4882a593Smuzhiyun 150*4882a593Smuzhiyunand some bootp options, which tell your board to obtain its subnet, 151*4882a593Smuzhiyungateway IP, host name and boot path from the bootp/dhcp server. These 152*4882a593Smuzhiyunsettings should start you off: 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun#define CONFIG_BOOTP_SUBNETMASK 155*4882a593Smuzhiyun#define CONFIG_BOOTP_GATEWAY 156*4882a593Smuzhiyun#define CONFIG_BOOTP_HOSTNAME 157*4882a593Smuzhiyun#define CONFIG_BOOTP_BOOTPATH 158*4882a593Smuzhiyun 159*4882a593SmuzhiyunYou can also set the default IP address of your board and the server 160*4882a593Smuzhiyunas well as the default file to load when a 'bootp' command is issued. 161*4882a593SmuzhiyunHowever note that encoding these individual network settings into a 162*4882a593Smuzhiyuncommon exectuable is discouraged, as it leads to potential conflicts, 163*4882a593Smuzhiyunand all the parameters can either get stored in the board's external 164*4882a593Smuzhiyunenvironment, or get obtained from the bootp server if not set. 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun#define CONFIG_IPADDR 10.0.0.2 (replace with your value) 167*4882a593Smuzhiyun#define CONFIG_SERVERIP 10.0.0.1 (replace with your value) 168*4882a593Smuzhiyun#define CONFIG_BOOTFILE "uImage" 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun 171*4882a593SmuzhiyunThe 'usb start' command should identify the adapter something like this: 172*4882a593Smuzhiyun 173*4882a593SmuzhiyunCrOS> usb start 174*4882a593Smuzhiyun(Re)start USB... 175*4882a593SmuzhiyunUSB EHCI 1.00 176*4882a593Smuzhiyunscanning bus for devices... 3 USB Device(s) found 177*4882a593Smuzhiyun scanning bus for storage devices... 0 Storage Device(s) found 178*4882a593Smuzhiyun scanning bus for ethernet devices... 1 Ethernet Device(s) found 179*4882a593SmuzhiyunCrOS> print ethact 180*4882a593Smuzhiyunethact=asx0 181*4882a593Smuzhiyun 182*4882a593SmuzhiyunYou can see that it found an ethernet device and we can print out the 183*4882a593Smuzhiyundevice name (asx0 in this case). 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunThen 'bootp' or 'dhcp' should use it to obtain an IP address from DHCP, 186*4882a593Smuzhiyunperhaps something like this: 187*4882a593Smuzhiyun 188*4882a593SmuzhiyunCrOS> bootp 189*4882a593SmuzhiyunWaiting for Ethernet connection... done. 190*4882a593SmuzhiyunBOOTP broadcast 1 191*4882a593SmuzhiyunBOOTP broadcast 2 192*4882a593SmuzhiyunDHCP client bound to address 172.22.73.81 193*4882a593SmuzhiyunUsing asx0 device 194*4882a593SmuzhiyunTFTP from server 172.22.72.144; our IP address is 172.22.73.81 195*4882a593SmuzhiyunFilename '/tftpboot/uImage-sjg-seaboard-261347'. 196*4882a593SmuzhiyunLoad address: 0x40c000 197*4882a593SmuzhiyunLoading: ################################################################# 198*4882a593Smuzhiyun ################################################################# 199*4882a593Smuzhiyun ################################################################# 200*4882a593Smuzhiyun ################################################ 201*4882a593Smuzhiyundone 202*4882a593SmuzhiyunBytes transferred = 3557464 (364858 hex) 203*4882a593SmuzhiyunCrOS> 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun 206*4882a593SmuzhiyunAnother way of doing this is to issue a tftp command, which will cause the 207*4882a593Smuzhiyunbootp to happen automatically. 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun 210*4882a593SmuzhiyunMAC Addresses 211*4882a593Smuzhiyun------------- 212*4882a593Smuzhiyun 213*4882a593SmuzhiyunMost Ethernet dongles have a built-in MAC address which is unique in the 214*4882a593Smuzhiyunworld. This is important so that devices on the network can be 215*4882a593Smuzhiyundistinguised from each other. MAC address conflicts are evil and 216*4882a593Smuzhiyungenerally result in strange and eratic behaviour. 217*4882a593Smuzhiyun 218*4882a593SmuzhiyunSome boards have USB Ethernet chips on-board, and these sometimes do not 219*4882a593Smuzhiyunhave an assigned MAC address. In this case it is up to you to assign 220*4882a593Smuzhiyunone which is unique. You should obtain a valid MAC address from a range 221*4882a593Smuzhiyunassigned to you before you ship the product. 222*4882a593Smuzhiyun 223*4882a593SmuzhiyunBuilt-in Ethernet adapters support setting the MAC address by means of 224*4882a593Smuzhiyunan ethaddr environment variable for each interface (ethaddr, eth1addr, 225*4882a593Smuzhiyuneth2addr). There is similar support on the USB network side, using the 226*4882a593Smuzhiyunnames usbethaddr, usbeth1addr, etc. They are kept separate since we 227*4882a593Smuzhiyundon't want a USB device taking the MAC address of a built-in device or 228*4882a593Smuzhiyunvice versa. 229*4882a593Smuzhiyun 230*4882a593SmuzhiyunSo if your USB Ethernet chip doesn't have a MAC address available then 231*4882a593Smuzhiyunyou must set usbethaddr to a suitable MAC address. At the time of 232*4882a593Smuzhiyunwriting this functionality is only supported by the SMSC driver. 233