����Linux�Ż�
Linux����

linux-3.0-Gadget������ֲʵ��ģ��U��

����ʱ��:2017-06-08 11:04:56��Դ:linux��վ����:zouleideboke
cpu: s3c2440(arm9)
Linux�ںˣ�linux-3.0
�����壺fl2440
����ģ�飺USB-DEVICE(gadget)
 
ǰ�ԣ����������Ǿ����Ὣ�����ֻ��������߲���pc,Ȼ��PC�������ֻ�ʶ��Ϊ�洢�豸���������ǿ��Խ��ж�д�ļ�����ô���Ľ��ܵļ���������ν�fl2440������ģ��������������ֻ�����pc�Ĵ洢�豸��Ҳ����ģ��U�̡�
 
1.�޸��ں�Դ��
[zoulei@CentOS linux-3.0]$ vim drivers/usb/gadget/file_storage.c
1067 /* Use this for bulk or interrupt transfers, not ep0 */  
1068 static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,  
1069                 struct usb_request *req, int *pbusy,  
1070                 enum fsg_buffer_state *state)  
1071 {  
1072         int     rc;  
1073         udelay(800);  /*������ʱ*/  
......  
}  
329 } mod_data = {                // Default values  
......  
/*�޸�mod_data��ʼֵ*/  
332         .removable              = 1,  
333         .can_stall              = 0,  
......  
}
˵�����ҵ��ں�Դ��Ĭ�Ͼ��������ֵ��������Ҫ�Ķ�������DZ�İ汾�ں˾���Ҫ�Ķ��ˣ�
��arch/arm/mach-s3c2440/mach-smdk2440.c������gadget�豸�ṹ���ʼ���� USB device����������ƣ���fl2440ԭ��ͼ���Կ���GPG9���ſ�����������
linux-3.0-Gadget������ֲʵ��ģ��U��
[zoulei@CentOS linux-3.0]$ vim arch/arm/mach-s3c2440/mach-smdk2440.c
#include <plat/udc.h>   /*Added by zoulei  for usbgadget 2017.05.07*/  
165 /*usbgadget info was added by zoulei 2017.05.07*/   
167 static struct s3c2410_udc_mach_info s3c_udc_cfg __initdata = {  
168     .pullup_pin = S3C2410_GPG(9),  
169   
170 };  
274 static struct platform_device *smdk2440_devices[] __initdata = {  
......  
285         &s3c_device_usbgadget, /*added by zoulei 2017.05.7*/  
286 };  
311 static void __init smdk2440_machine_init(void)  
312 {  
......  
316         s3c24xx_udc_set_platdata(&s3c_udc_cfg);/*Added pull-up resistor by zoulei 2017 05.07*/  
......  
321 }
ע�⣺����<plat/udc.h>ͷ�ļ�ʱ����÷����ļ�ͷ����Ͷˣ����������ܻ������
 
2.����make menuconfig
[zoulei@CentOS linux-3.0]$ make menuconfig
Device drivers -->
[*] USB support -->
<*>   USB Gadget Support  --->
[*]       S3C2410 udc debug messages
<M>   USB Gadget Drivers 
<M>   Gadget zero(DEVELOPMENT)
<M>     File-backed Storage Gadget
˵��:<M>USB Gadget Supportѡ����Ҫ�DZ����s3c2410_udc.ko,������������ѡ�����ʱֻ�����g_file_storage.ko
��Ϊ����file-backed������ʱ��Ҫ���Ӿ����ļ���������������Ҫѡ��ģ����룬Ҳ����ѡ��ǰ��ѡ��M
 
3.�������
��������޸�֮�����±����ںˣ�����driver/usb/gadgetĿ¼������g_file_storage.koģ���ļ������ں�Դ��Ŀ¼������
udisk32M.img�ļ������������ļ����ص��������Ͻ��в��ԣ��ұ������ں�һ��Ҫ��¼�������������У�
��1������FAT32�ļ�ϵͳӳ���ڿ�����������ִ����������
dd if=/dev/zero of=udisk32M.img bs=1k count = 32768 
mkfs.vfat udisk32M.img 
linux-3.0-Gadget������ֲʵ��ģ��U��
��2������g_file_storage.ko�������뾵���ļ���������������loop�豸 
���ǽ�����ص�mediaĿ¼�£����û�и�Ŀ¼���½�һ��mediaĿ¼
insmod g_file_storage.ko file=udisk32M.img stall=0 removable=1 
mount -o loop /udisk32M.img /media/
linux-3.0-Gadget������ֲʵ��ģ��U��
ע��:��������IJ���֮�󣬵����ǽ�usb�����߲���pc��ʱ���������ϻ��ӡg_file_storage gadget: full speed config #1��Ϣ����PC�ϳ�����һ����ΪH,��СΪ32M�Ĵ��̣�����û���κ��ļ�����ͼ��ʾ
linux-3.0-Gadget������ֲʵ��ģ��U��
���ǿ��Կ���/media/Ŀ¼��������System Volume Information��������������д�ļ�����һ��
linux-3.0-Gadget������ֲʵ��ģ��U��
�ڿ�������д�ļ�֮���ٿ���Windows�Ϸ������滹��û���κ����ݣ����°β�usb��֮�󣬷������������һ��test.txt�ļ���ͼ��
����Windows��дһ��test1.txt�ļ����鿴�������Ϸ��ֲ�û�г���test1.txt�ļ������¹����ļ�ϵͳӳ�� /mediaĿ¼������˸��ļ���ͼ��
linux-3.0-Gadget������ֲʵ��ģ��U��
linux-3.0-Gadget������ֲʵ��ģ��U��
�����Է���ģ��U�̿���������������fl2440������ģ���U�̵Ĺ��ܳɹ�ʵ�֣�
 
4.�����ĵ����⼰�������
��������fl2440������ģ���U��ʱ���ҽ�/media Ŀ¼��Ϊ���ص㣬���Ǻ���ж�ؾͳ������´���
���⣺>: umount /media
umount: can't umount /media: Device or resource busy
�����
>: fuser -km /media
Copyright (C) 2011 fulinux<fulinux@gmail.com>
root login: root
>: df -lh
df: invalid option -- l
BusyBox v1.20.2 (2017-03-01 01:32:52 PST) multi-call binary.
Usage: df [-Pkmhai] [-B SIZE] [FILESYSTEM]...
Print filesystem usage statistics
-P      POSIX output format
-k      1024-byte blocks (default)
-m      1M-byte blocks
-h      Human readable (e.g. 1K 243M 2G)
-a      Show all filesystems
-i      Inodes
-B SIZE Blocksize
>: umount /media
ע�⣺ -k(  kill processes accessing the named fileɱ������ָ���ļ��Ľ���) -m( show all processes using the named filesystems)
fuser��������ʾ����ij���ļ��Ľ��̵�PID
 
�������ø��µ�ַ��//m.ajphoenix.com/linux/31336.html