1、硬件电路
typeC USB口ID引脚是连接CPU的KEYIN2/EXTINT4/GPIO126引脚,需配置该引脚的pinmap
2、配置ID引脚Pinmap
bsp/bootloader/u-boot15/board/spreadtrum/sl8541e_3h10_32b/pinmap-sp9832e_32b.c
注: BITS_PIN_AF(1)}为中断模式
{REG_PIN_KEYIN2, BITS_PIN_AF(1)},
{REG_MISC_PIN_KEYIN2,BITS_PIN_DS(1)|BIT_PIN_NULL|BIT_PIN_WPU|BIT_PIN_SLP_AP|BIT_PIN_SLP_WPU|BIT_PIN_SLP_IE},//USBID
3、配置dts(bsp/kernel/kernel5.4/arch/arm/boot/dts/sl8541e-3h10_32b-overlay.dts)
extcon_gpio: extcon-gpio {
compatible = "linux,extcon-usb-gpio";
vbus-gpio = <&pmic_eic 0 GPIO_ACTIVE_HIGH>;
id-gpio = <&eic_debounce 4 GPIO_ACTIVE_HIGH>;//配置ID脚为中断4,默认高电平
};
4、OTG功能正常情况下,插入u盘,可以进入usb_irq_handler函数(extcon-usb-gpio.c),然后进入usb_extcon_detect_cable函数(extcon-usb-gpio.c),设置主机模式为host模式,流程正常
5、添加pl2303、ch343驱动代码,defconfig配置CONFIG_USB_SERIAL_PL2303=y、CONFIG_USB_SERIAL_CH343=y
6、USB插入外部串口小板,logcat log中用串口APP通讯报AVC错误:
09-19 16:04:03.459 3739 3739 W .ftsafe.caishui: type=1400 audit(0.0:553): avc: denied { read write } for name="ttyUSB0" dev="tmpfs" ino=76676 scontext=u:r:untrusted_app_27:s0:c102,c256,c512,c768 tcontext=u:object_r:usb_serial_device:s0 tclass=chr_file permissive=0 app=com.ftsafe.caishui
09-19 16:39:50.209 3366 3366 W safe.serialport: type=1400 audit(0.0:402): avc: denied { read write } for name="ttyACM0" dev="tmpfs" ino=17103 scontext=u:r:untrusted_app_27:s0:c103,c256,c512,c768 tcontext=u:object_r:usb_serial_device:s0 tclass=chr_file permissive=0 app=com.ftsafe.serialport
7、ttyUSB、ttyACM节点权限与SElinux权限,串口APP才可以访问,串口通讯成功(在控制台可以看节点权限是否添加上,ls -LZ /dev/ttyUSB*)
1)device/sprd/mpool/module/app/msepolicy/vendor/untrusted_app_27.te
allow untrusted_app_27 xx_serial_device:chr_file { read write open ioctl getattr };
2)device/sprd/mpool/module/ueventd/msoc/sharkle/sharkle.ueventd.rc
/dev/ttyUSB* 0666 system system
/dev/ttyACM* 0666 system system
3) device/sprd/mpool/sepolicy/system/public/file.te
type xx_serial_device, dev_type, mlstrustedobject;//mlstrustedobject必须声明
4)device/sprd/mpool/sepolicy/vendor/file_contexts
/dev/ttyUSB[0-9]* u:object_r:ft_serial_device:s0
/dev/ttyACM[0-9]* u:object_r:ft_serial_device:s0