以Firefly的RK系列为例,适配方法如下步骤。

本方法已验证适配以下Firefly产品,在3.1release和3.2release验证功能正常。

  • AIO-3399J,芯片为RK3399

1. 准备基础环境

从Firefly官网下载对应AIO-3399J buildroot的驱动代码

驱动下载链接:https://wiki.t-firefly.com/zh_CN/AIO-3399J/buildroot_compile.html

2. 修改内核配置文件

由于在firefly-rk3399-buildroot.mk中配置RK_KERNEL_DEFCONFIG=firefly_linux_defconfig,所以在kernel\arch\arm64\configs\firefly_linux_defconfig中增加内核配置。

CONFIG_USB_CHIPIDEA=y
CONFIG_USB_CHIPIDEA_OF=y
CONFIG_USB_CHIPIDEA_UDC=y
CONFIG_USB_CHIPIDEA_HOST=y

3. 修改dr_mode模式

在kernel\arch\arm64\boot\dts\rockchip\rk3399-firefly-aio.dts中把dr_mode = "host"修改为dr_mode = "peripheral",如下

usbdrd_dwc3_0 {
	dr_mode = "peripheral";
};

步骤2,3完成后重新用./build.sh kernel编译kernel

4. 修改init.rk3568.usb.cfg文件

device\board\hihope\rk3568\init.rk3568.usb.cfg文件如下

 1 "jobs" : [{
 2            "name" : "boot",
 3            "cmds" : [
 4                "mkdir /dev/usb-ffs 0770 shell shell",
 5                "mkdir /dev/usb-ffs/hdc 0770 shell shell",
 6                "mount configfs none /config",
 7                "mkdir /config/usb_gadget/g1 0770 shell shell",
 8                "write /config/usb_gadget/g1/idVendor 0x2207",
 9                "write /config/usb_gadget/g1/idProduct 0x0018",
 10               "write /config/usb_gadget/g1/os_desc/use 1",
 11               "write /config/usb_gadget/g1/bcdDevice 0x0223",
 12               "write /config/usb_gadget/g1/bcdUSB 0x0200",
 13               "mkdir /config/usb_gadget/g1/strings/0x409 0770",
 14               "copy /sys/block/mmcblk0/device/cid /config/usb_gadget/g1/strings/0x409/serialnumber",
 15               "write /config/usb_gadget/g1/strings/0x409/manufacturer Rockchip",
 16               "write /config/usb_gadget/g1/strings/0x409/product \"HDC Device\"",
 17               "mkdir /config/usb_gadget/g1/functions/ffs.hdc",
 18               "mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell",
 19               "mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell",
 20               "write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1",
 21               "write /config/usb_gadget/g1/os_desc/qw_sign MSFT100",
 22               "write /config/usb_gadget/g1/configs/b.1/MaxPower 500",
 23               "symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1",
 24               "mount functionfs hdc /dev/usb-ffs/hdc uid=2000,gid=2000",
 25               "setparam sys.usb.configfs 1",
 26               "setparam sys.usb.controller fcc00000.dwc3"
 27           ]
  • 修改第8、9行中的idVendor、idProduct值,这两个值是在厂家驱动写入的,可以在Ubuntu环境下输入lsusb读取这2个值;

插入AIO-3399J单板,读取如下

hengyi@hengyi-virtual-machine:~$ lsusb
Bus 001 Device 003: ID 2207:5000                                 // 此处2个分别为idVendor和idProduct
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 0e0f:0008 VMware, Inc. 
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

可以看出idVendor=0x2207、idProduct=0x5000,根据这两个值进行修改第8、9行值。

备注:lsusb命令的解读可以参考https://ipcmen.com/lsusb

  • 14行要将/sys/block/mmcblk0/device/cid修改为/sys/block/mmcblk2/device/cid,原因如下:

在串口中查询到cd sys/block中,可以看到block下只有mmcblk2

# ls -l
total 0
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 mmcblk2 -> ../devices/platform/fe330000.sdhci/mmc_host/mmc2/mmc2:0001/block/mmcblk2
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 mmcblk2boot0 -> ../devices/platform/fe330000.sdhci/mmc_host/mmc2/mmc2:0001/block/mmcblk2/mmcblk2boot0
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 mmcblk0boot1 -> ../devices/platform/fe330000.sdhci/mmc_host/mmc2/mmc2:0001/block/mmcblk2/mmcblk2boot1
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 ram0 -> ../devices/virtual/block/ram0
lrwxrwxrwx 1 root root 0 2017-08-05 17:00 zram0 -> ../devices/virtual/block/zram0
#
  • 15行根据芯片厂家型号填制造商RK3568/RK3399就填Rockchip,Hi3516就填HISILICON

  • 26行控制器修改为fe800000.dwc3,原因如:

    在驱动代码中,kernel\linux\linux-5.10\arch\arm64\boot\dts\rockchip\rk3399.dtsi中可以看到如下代码

    usbdrd3_0: usb@fe800000 {
    		compatible = "rockchip,rk3399-dwc3";
    		#address-cells = <2>;
    		#size-cells = <2>;
    		ranges;
    		clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>,
    			 <&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_RKSOC_AXI_PERF>,
    			 <&cru ACLK_USB3>, <&cru ACLK_USB3_GRF>;
    		clock-names = "ref_clk", "suspend_clk",
    			      "bus_clk", "aclk_usb3_rksoc_axi_perf",
    			      "aclk_usb3", "grf_clk";
    		resets = <&cru SRST_A_USB3_OTG0>;
    		reset-names = "usb3-otg";
    		status = "disabled";
    
    		usbdrd_dwc3_0: usb@fe800000 {
    			compatible = "snps,dwc3";
    			reg = <0x0 0xfe800000 0x0 0x100000>;
    			interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH 0>;
    			clocks = <&cru SCLK_USB3OTG0_REF>, <&cru ACLK_USB3OTG0>,
    				 <&cru SCLK_USB3OTG0_SUSPEND>;
    			clock-names = "ref", "bus_early", "suspend";
    			dr_mode = "otg";
    			phys = <&u2phy0_otg>, <&tcphy0_usb3>;
    			phy-names = "usb2-phy", "usb3-phy";
    			phy_type = "utmi_wide";
    			snps,dis_enblslpm_quirk;
    			snps,dis-u2-freeclk-exists-quirk;
    			snps,dis_u2_susphy_quirk;
    			snps,dis-del-phy-power-chg-quirk;
    			snps,dis-tx-ipgap-linecheck-quirk;
    			power-domains = <&power RK3399_PD_USB3>;
    			status = "disabled";
    		};
    	};

     

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐