Linux 下USB-CDROM 的实现:

注:红色的为新增代码

1          增加一个USB cdrom function:

1.1         修改board_xxproject.c

1.1.1    static char *usb_functions_default[] ={

                "diag",

                "modem",

                "nmea",

                "rmnet",

                "usb_mass_storage",

                "usb_cdrom",

};

1.1.2    static char *usb_functions_default_adb[] = {

                     "diag",

                    "adb",

                "modem",

                "nmea",

                "rmnet",

                "usb_mass_storage",

                "usb_cdrom",

};

1.1.3    static char *usb_functions_all[] = {

#ifdef CONFIG_USB_ANDROID_RNDIS

               "rndis",

#endif

#ifdefCONFIG_USB_ANDROID_DIAG

               "diag",

#endif

           "adb",

#ifdef CONFIG_USB_F_SERIAL

               "modem",

               "nmea",

#endif

#ifdefCONFIG_USB_ANDROID_RMNET

               "rmnet",

#endif

                "usb_mass_storage",

#ifdefCONFIG_USB_CDROM

               "usb_cdrom",

#endif

#ifdefCONFIG_USB_ANDROID_ACM

               "acm",

#endif

};

1.1.4    定义 platform device结构体:

#ifdefCONFIG_USB_CDROM

staticstruct usb_mass_storage_platform_data cdrom_pdata = {

                .nluns          =1,

                .vendor        ="Qualcomm Incorporated",

                .product   = "Usb cdrom",

                .release =0x0100,

                .can_stall     =1,

};

 

staticstruct platform_device usb_cdrom_device = {

                .name                 ="usb_cdrom",

                .id                      =-1,

                .dev                    ={

                   .platform_data                  =&cdrom_pdata,

                 },

};

#endif

1.1.5    加到platform devices 里面

     static structplatform_device *devices[] __initdata = {

     ………..

     ………..

     #ifdef CONFIG_USB_ANDROID_DIAG

       &usb_diag_device,

#endif

     #ifdef CONFIG_USB_CDROM

       &usb_cdrom_device, 

#endif

&android_usb_device,

…………

…………

}

 

1.2         增加usb cdrom function的驱动文件,这个文件可以copy 内核里面已有的F_mass_storage.c,改名F_usb_cdrom.c然后做必要的修改就可以了,具体修改如下:

1.2.1    static int fsg_probe(structplatform_device *pdev)

{

           struct usb_mass_storage_platform_data*pdata = pdev->dev.platform_data;

           int i, nluns;

 

           dev_dbg(&pdev->dev, "%s:pdata: %p\n", __func__, pdata);

           if (!pdata)

                 return -1;

 

            nluns = pdata->nluns;

            if (nluns > FSG_MAX_LUNS)

                  nluns = FSG_MAX_LUNS;

            fsg_cfg.nluns = nluns;

            for (i = 0; i < nluns; i++) {

                   fsg_cfg.luns[i].removable= 1;

                   fsg_cfg.luns[i].cdrom = 1;

                   fsg_cfg.luns[i].ro = 1;

                   fsg_cfg.luns[i].nofua = fsg_nofua;

           }

           fsg_cfg.vendor_name = pdata->vendor;

         fsg_cfg.product_name= pdata->product;

           fsg_cfg.release = pdata->release;

           fsg_cfg.can_stall = pdata->can_stall;

           fsg_cfg.pdev = pdev;

 

           return 0;

}

1.2.2     //#define FUNCTION_NAME         "usb_mass_storage"

     #defineFUNCTION_NAME     " usb_cdrom "

1.2.3    修改kernel/drivers/usb/gadget/makefile和kconfig

         Makefile中增加:obj-$(CONFIG_USB_CDROM)      += f_usb_cdrom.o

         Kconfig中增加:

config USB_CDROM

           boolean"usb cdrom function"

         depends on USB_ANDROID

              default y

              help 

Provides USB cdrom function for android gadgetdriver

1.2.4    修改kernel\arch\arm\configs\xxproject_defconfig:

                        CONFIG_USB_CDROM=y

2          将pc端cdrom要显示的文件加载到android文件系统,使内核cdrom的驱动能关联的这些文件,假设要显示的文件时cdrom.iso(光盘标准文件格式),先将cdrom.iso放到vendor\qcom\proprietary\wlan-bin\cd_rom_img下,然后修改vendor\qcom         \ proprietary \wlan-bin\msm7630\android.mk:

在最后增加:

PRODUCT_COPY_FILES+= $(LOCAL_PATH)/../cd_rom_img/cd_rom_last.iso:data/cd_rom_img/cdrom.iso

编译之后cdrom.iso 会被加载到userdata.img里面。

修改system\core\rootdir\etc\init.qcom.sh 在文件开头增加:

echo /data/cd_rom_img/cdrom.iso >/sys/devices/platform/usb_cdrom/lun0/file

最后全部编译下载,开机连usb,cdrom.iso里面的文件在pc端就可以访问了。

Logo

更多推荐