LV09-03-linux-03-USB驱动移植

本文主要是linux——USB驱动移植的相关笔记,若笔记中有错误或者不合适的地方,欢迎批评指正😃。

点击查看使用工具及版本
Windows windows11
Ubuntu Ubuntu16.04的64位版本
VMware® Workstation 16 Pro 16.2.3 build-19376536
SecureCRT Version 8.7.2 (x64 build 2214) - 正式版-2020年5月14日
Linux开发板 华清远见 底板: FS4412_DEV_V5 核心板: FS4412 V2
u-boot 2013.01
点击查看本文参考资料
参考方向参考原文
系统实验手册USB驱动移植
点击查看相关文件下载
文件下载链接
------

一、修改设备树文件

我们打开设备树文件:

1
vim /home/hk/5linux/linux-3.14/arch/arm/boot/dts/exynos4412-fs4412.dts

然后在设备树文件最后一个};前边添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
usbphy: usbphy@125B0000 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "samsung,exynos4x12-usb2phy";
reg = <0x125B0000 0x100>;
ranges;
clocks = <&clock 2>, <&clock 305>;
clock-names = "xusbxti", "otg";
usbphy-sys {
reg = <0x10020704 0x8 0x1001021c 0x4>;
};
};
ehci@12580000 {
status = "okay";
usbphy = <&usbphy>;
};
usb3503@08 {
compatible = "smsc,usb3503";
reg = <0x08 0x4>;
connect-gpios = <&gpm3 3 1>;
intn-gpios = <&gpx2 3 1>;
reset-gpios = <&gpm2 4 1>;
initial-mode = <1>;
};

二、配置内核

我们到linux内核源码顶层目录下,执行以下命令:

1
2
cd vim /home/hk/5linux/linux-3.14/
make menuconfig # 打开图形配置界面

1. USB support

我们首先进入USB support配置选项中:

image-20220908192104278

然后开始进行自选项的配置:

1
2
3
4
5
6
7
8
Device Drivers  --->
[*] USB support --->
<*> EHCI HCD (USB 2.0) support
<*> EHCI support for Samsung S5P/EXYNOS SoC Series
<*> USB Mass Storage support
<*> USB3503 HSIC to USB20 Driver
USB Physical Layer drivers --->
<*> Samsung USB 2.0 PHY controller Driver

2. SCSI device support

我们首先进入SCSI device support配置选项中:

image-20220908193026254

然后开始进行自选项的配置:

1
2
3
4
5
Device Drivers  --->
SCSI device support --->
<*> SCSI device support
<*> SCSI disk support
<*> SCSI generic support

3. USB转串口支持

我们后边还可能用到USB转串口支持,所以这里配置一下USB转串口的驱动支持(常见的三种USB串口芯片为CH341PL2303 CP210X),这些芯片驱动的配置选项中在这里:

image-20220909061857213

然后我们来修改一下其中所需要的一些选项:

1
2
3
4
5
6
Device Drivers  --->
[*] USB support --->
<*> USB Serial Converter support --->
<*> USB Winchiphead CH341 Single Port Serial Driver
<*> USB CP210x family of UART Bridge Controllers
<*> USB Prolific 2303 Single Port Serial Driver

需要注意的是,除了这些选项外,还有呢很多的依赖需要进行配置,这个时候我们可以使用图形界面为我们提供的搜索功能,来看一下配置这些芯片驱动的以来是否也都打开了,没打开的可以搜索一下打开。

  • USB_SERIAL_CH341
1
2
3
4
5
6
7
8
9
10
┌──────────────────────────── Search Results ─────────────────────────────┐
│ Symbol: USB_SERIAL_CH341 [=y] │
│ Type : tristate │
│ Prompt: USB Winchiphead CH341 Single Port Serial Driver │
│ Location: │
│ -> Device Drivers │
│ -> USB support (USB_SUPPORT [=y]) │
│ (1) -> USB Serial Converter support (USB_SERIAL [=y]) │
│ Defined at drivers/usb/serial/Kconfig:99 │
│ Depends on: USB_SUPPORT [=y] && USB [=y] && USB_SERIAL [=y] │
  • USB_SERIAL_PL2303
1
2
3
4
5
6
7
8
9
10
┌──────────────────────────── Search Results ─────────────────────────────┐
│ Symbol: USB_SERIAL_PL2303 [=y] │
│ Type : tristate │
│ Prompt: USB Prolific 2303 Single Port Serial Driver │
│ Location: │
│ -> Device Drivers │
│ -> USB support (USB_SUPPORT [=y]) │
│ (1) -> USB Serial Converter support (USB_SERIAL [=y]) │
│ Defined at drivers/usb/serial/Kconfig:510
│ Depends on: USB_SUPPORT [=y] && USB [=y] && USB_SERIAL [=y] │
  • USB_SERIAL_CP210X
1
2
3
4
5
6
7
8
9
10
┌──────────────────────────── Search Results ─────────────────────────────┐
│ Symbol: USB_SERIAL_CP210X [=y] │
│ Type : tristate │
│ Prompt: USB CP210x family of UART Bridge Controllers │
│ Location: │
│ -> Device Drivers │
│ -> USB support (USB_SUPPORT [=y]) │
│ (1) -> USB Serial Converter support (USB_SERIAL [=y]) │
│ Defined at drivers/usb/serial/Kconfig:132 │
│ Depends on: USB_SUPPORT [=y] && USB [=y] && USB_SERIAL [=y] │

三、编译内核和设备树

接下来我们在linux源码顶层目录中执行:

1
2
make uImage    # 编译内核
make dtbs # 编译设备树

四、重启测试

  • 拷贝相关文件
1
2
cp ~/5linux/linux-3.14/arch/arm/boot/uImage ~/3tftp/fs4412/
cp ~/5linux/linux-3.14/arch/arm/boot/dts/exynos4412-fs4412.dtb ~/3tftp/fs4412/
  • 重启开发板
  • 插入U盘到任一USB接口

若有以下提示,则说明USB移植完成:

1
2
3
4
5
6
7
8
9
10
[root@farsight]#[   10.255000] usb 1-3.3: new high-speed USB device number 3 using exynos-ehci
[ 10.370000] usb-storage 1-3.3:1.0: USB Mass Storage device detected
[ 10.375000] scsi0 : usb-storage 1-3.3:1.0
[ 11.380000] scsi 0:0:0:0: Direct-Access SanDisk Ultra USB 3.0 1.00 PQ: 0 ANSI: 6
[ 11.395000] sd 0:0:0:0: [sda] 120127488 512-byte logical blocks: (61.5 GB/57.2 GiB)
[ 11.405000] sd 0:0:0:0: [sda] Write Protect is off
[ 11.405000] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 11.410000] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 11.445000] sda: sda1 sda2
[ 11.455000] sd 0:0:0:0: [sda] Attached SCSI removable disk

我们可以再看一下/dev/下的设备:

1
2
[root@farsight]#ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2

回会发现有sda开头的节点出现,这也说明了我们的USB驱动移植成功。

  • USB转串口测试

我们插上老师给我们的一个协调器模块,可能会看到如下信息:

1
2
3
[root@farsight]#[  138.540000] usb 1-3.2: new full-speed USB device number 5 using exynos-ehci
[ 138.655000] ch341 1-3.2:1.0: ch341-uart converter detected
[ 138.665000] usb 1-3.2: ch341-uart converter now attached to ttyUSB0

然后我们看一下设备节点:

1
2
[root@farsight]#ls /dev/ttyUSB0
/dev/ttyUSB0