【问题标题】:How to define device label name, g_mass_storage module如何定义设备标签名称,g_mass_storage 模块
【发布时间】:2016-02-03 15:15:38
【问题描述】:

在内核配置中包含 g_mass_storage 模块的嵌入式系统上工作,我想定义设备的名称。后者对于在插入主机时识别设备很有用。

我正在使用以下功能:

int usb_gadget(void) 
{
    char cmd[512];
    int  fd = -1;
    int  len = -1;

    memset((void *)cmd, 0x00, sizeof(cmd));

    fd = open("proc/modules", O_RDONLY);
    if (fd > 0) 
    {
        len = read(fd, cmd, sizeof(cmd));
        if (len > 0) 
        {
            if (strstr(cmd, "g_mass_storage") > 0) 
            {
                fprintf(stderr, "Missing module \n");   
            } 
            else 
            {
                strcpy(cmd, "modprobe ");
                strcat(cmd, "g_mass_storage");
                strcat(cmd, " file=");
                strcat(cmd, "tmp/testfile");
                strcat(cmd," idVendor=2000 ");
                strcat(cmd," idProduct=2000 ");
                strcat(cmd," bcdDevice=2000 ");
                strcat(cmd," iManufacturer=TEST ");
                strcat(cmd," iProduct=BOARD1 ");
                strcat(cmd," iSerialNumber=1 ");                    
                system(cmd);
            }
            close(fd);
        }
    }
    return 0;
}

当设备连接到 Windows PC 时,设备定义为Local Disk(E:)

如何通过特定名称交换 Local Disk,就像我的 USB Key SnPKey 完成的那样?

编辑 1:

Mass Storage Gadget

根据上一个链接中给出的信息,我尝试通过iProduct 指定USB 产品字符串,但没有成功。

【问题讨论】:

  • 经过多次研究,这个写入似乎是在分区步骤中实现的。我很快就会在平台上实现测试。

标签: linux kernel usb usb-mass-storage removable-storage


【解决方案1】:

找到解决方案。

必须在扇区创建期间定义卷标。

在我的例子中,我通过写0x4E,0x4F,0x20,0x4E,0x41,0x4D,0x45,0x20,0x20,0x20,0x20 来验证这个过程,它等于NO NAME

【讨论】:

    猜你喜欢
    • 2015-06-01
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 2015-08-09
    相关资源
    最近更新 更多