Linux2.6 kernel usb gadget drive porting __linux

Source: Internet
Author: User
Tags gdb debugger
Linux2.6 kernel USB Gadget drive porting

Before writing a little bit of the knowledge of USB slave end
In the kernel 2.4 version, the embedded USB drive is in the Kernel/arch/arm directory ep0.c ep**.c, when debugging USB driver is difficult, mainly if the addition of too much PRINTK, will affect the timing of USB, Causes the enumeration to fail or keep USB reset.
In the kernel 2.6 version, the USB driver was changed to the gadget interface, and in the/kernel/drivers/usb/gadget directory there was a series of files that were USB driven, where SERIAL.C was bulk-driven or CDC ACM-driven , run make Menuconfig configure all USB features, make modules, then there are some G_serial.ko, G_enther.ko, G_rnds.ko, G_file_storage.ko, g_ in the gadget directory. Gadget.ko. Where the G_serial.ko run when there is a parameter is USE_ACM, if 0 is the normal USB bulk drive, it is best to modify the Serial.c file, instead of the TTY associated, this time windows with USB bulk driver, Under the DDK has the source code, compiles is OK. If you do not want to write the Windows side of the drive, you can put the USE_ACM to 1, the host end with Windows Usbser.sys Drive, that is, USB to the serial port driver, sometimes in the C:/windows/driver/dllcach directory,  can use expand to solve it, concrete reference/kernel/document. In the Windows side need to write an INF file, in the INF file can turn USB into a modem, so that Windows can use it to dial the Internet, of course, in the small machine to communicate with the GPRS module, module initialization at command can be written in the INF file. In the Windows Resource management is not see the serial port, can only see the modem (COMX), in the HyperTerminal can not open this serial port, but in the SECURECRT is able to access the serial port. If you want to virtual a real serial port, you can modify the INF file, it virtual out of the real serial port, want to add modem when you can choose to add a standard modem, module initialization at command can be written in the modem properties--> initialization commands, such as atd*99***1#
G_file_storage.ko is a U disk drive, such as the SD card when u disk, Insmod G_file_storage.ko file=/mnt/mmc Luns=1, if there are 3 partitions can be a U disk, then luns=3. Note that there is no MKDOSFS in BusyBox to format the FAT file system, and you need to compile the source code that modifies the MKDOSFS.
G_enter.ko is the USB virtual out of a network card, in the Windows end with Usblan.sys can constitute a direct docking of networks.
G_rnds.ko only Windows driver under XP, Windows 2000 under the development of handwriting, you can go to Microsoft's website to check rnds. which can be rnds to debug the program
Whether using USB to the serial port or USB card to match the GDB debugger, more than TTY serial debugging faster

1. Configuration options
Configuration options Related explanations


Option Configuration Module G_file_storage.ko
file-backed Storage Gadget
configuration options, generating module S3c2410_udc.ko files
USB peripheral Controller (s3c2410 USB Device Controller)--->
(X) s3c2410 USB Device Controller
Generate the corresponding driver after compiling
[Root@vm-dev linux-2.6.24.4]# ls Drivers/usb/gadget/*.ko
Drivers/usb/gadget/g_file_storage.ko Drivers/usb/gadget/s3c2410_udc.ko
[Root@vm-dev linux-2.6.24.4]#
2. Compile error
In the compilation of the error on the Debugfs, then comment out the corresponding code can be, unrelated to the driver, as for this debugfs, I also do not know what is a thing, and did not study him in detail, there are friends who know to share.
Drivers/usb/gadget/s3c2410_udc.c
static int __init udc_init (void)
{
int retval;
........
#if 0
No idea about Debugfs
Delete by Lyj
S3c2410_udc_debugfs_root = Debugfs_create_dir (Gadget_name, NULL);
if (Is_err (S3c2410_udc_debugfs_root)) {
PRINTK (kern_err "%s:debugfs dir creation failed%ld\n",
Gadget_name, Ptr_err (s3c2410_udc_debugfs_root));
S3c2410_udc_debugfs_root = NULL;
}
#endif
.........
}
3, the probe function does not carry out the question correctly. Online also have a lot of people complain s3c2410_udc_probe function did not perform, it seems that linux2.6 is not so popular, haha. This is because it is not very familiar with the linux2.6 platform device call process, just add s3c_device_usbgadget structure to the/arch/arm/mach-s3c2410.c.
Add End
static struct Platform_device *smdk2410_devices[] __initdata = {
&S3C_DEVICE_USB,
.......
&s3c_device_usbgadget,
&s3c_device_ts,
&s3c_device_ds,
&s3c_device_gpio,
&s3c_device_ad7655,
};
Add by Lyj
Most of these platform_device definitions are in the ARCH/ARM/PLAT-S3C24XX/DEVS.C file, and a small subset is defined in the/arch/arm/mach-s3c2410.c file, adding a new platform_ Device, it is recommended to add to the mach-s3c2410.c file because most of the DEVS.C files are self-contained and can be used directly by the device.
Arch/arm/plat-s3c24xx/devs.c
#if 1
/* USB Device (Gadget) * *

static struct resource s3c_usbgadget_resource[] = {
[0] = {
. Start = S3c24xx_pa_usbdev,
. end = S3c24xx_pa_usbdev + S3c24xx_sz_usbdev-1,
. Flags = Ioresource_mem,
},
[1] = {
. Start = IRQ_USBD,
. end = IRQ_USBD,
. Flags = IORESOURCE_IRQ,
}

};
#endif
struct Platform_device s3c_device_usbgadget = {
. Name = "S3c2410-usbgadget",
. id =-1,
. num_resources = Array_size (S3c_usbgadget_resource),
. resource = S3c_usbgadget_resource,
};

Export_symbol (S3c_device_usbgadget);
4. Timing problem
Even after the driver loaded, there is no problem, at the computer can also see the corresponding USB device display as a U disk device, but the content is empty. This is a very painful one.
Later, under the guidance of high man, using grasping bag tool (originally only know debugging network to use grab Bag tool, the original debugging USB device also want to use this thing). It is found that the header is complete at the time of the opening, but the subsequent content is no longer transmitted. When the normal USB device is mounted, the first is to pass the entire USB disk information, and then there will be a continuous one-stop interaction information, which is not in the 2410 connection, that is, after the connection shows the U disc, there will be no interaction information.
In High man's inspiration, in the drivers/usb/gadget/file_storage.c file to add countless debugging information, and finally positioning is the USB transmission timing problem. Only one line of code was changed in the entire gadget modification:
/* Use this to bulk or interrupt transfers, not EP0 * *
static void Start_transfer (struct Fsg_dev *fsg, struct usb_ep, *ep,
struct usb_request *req, int *pbusy,
Enum Fsg_buffer_state *state)
{
int RC;
PRINTK ("start_transfer\n");
Udelay (1000);
if (ep = fsg->bulk_in)

This is a patch I made: Usb_gadget.patch
---linux-2.6.24.4/drivers/usb/gadget/file_storage.c 2008-03-25 02:49:18.000000000 +0800
+++ drivers/usb/gadget/file_storage.c 2016-11-25 15:35:23.000000000 +0800
@@ -1090,7 +1090,7 @@
static int ep0_queue (struct Fsg_dev *FSG)
{
int RC;
-
+//printk ("Ep0_queue \ n");
rc = Usb_ep_queue (fsg->ep0, Fsg->ep0req, gfp_atomic);
if (RC!= 0 && RC!=-eshutdown) {

@@ -1098,6 +1098,7 @@
WARN (FSG, "error in submission:%s-->%d\n",
&nb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.