Android 串口开发

原文链接:https://blog.csdn.net/u010872301/article/details/94735221 

1. 主板型号:AIO-3399J

2. 芯片型号:RK3399

3. 操作系统版本:Android 7.1

4. Linux版本:v4.4.103

产品链接:http://www.t-firefly.com/solution/info/index/id/71.html

RPLIDAR A3M1 激光雷达通讯接口采用 3.3V 电平的串口。UART ttyS配置文件适配的波特率:256000bps。本文根据驱动来修改非标准波特率,然后通过APP读写雷达设备串口数据,修改串口读写、串口安全权限的问题。

5. RK3399采用的是8250通用驱动8250_dw.c:
 

static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,struct ktermios *old)
{
    。。。
    diff = rate * 20 / 1000;
    if ((rate_temp < rate) && ((rate - rate_temp) > diff)) 
    。。。
}

串口设置的是3M的波特率,从log可以看出,串口走的是clk_uart4_pmu 整数分频,由676M PLL分出来接近48M的的clk(48M根据上面的公式,是分出 3M波特率的最小时钟)。这虽然有误差,但在允许范围内,这个误差的大小驱动里设定为正负2%。

串口以256000波特率发送的数据,根据波特率大小来设置时钟,一般1.5M以下的波特率都可以分出来。1.5M以上的波特率,可能会经 过小数分频或整数分频。如果以上都分不出来,则需要修改PLL。但修改PLL有风险,会影响其他模块。

6. APP对串口设备读写操作时,无法打开某个设备文件,提示权限失败:unable to open /dev/ttyS3, error:Permission denied。

6.1 、确认设备节点是否存在;

6.2、 确认设备节点权限;尝试向所有组添加权限(chmod 666 /dev/ttyS3);

./device/rockchip/common/ueventd.rockchip.rc
 
/dev/ttyS3                0666   system     system

6.3、在device/rockchip/rk3399/rk3399_firefly_edp_box/sepolicy/目录下,添加untrusted_app.te;

allow  untrusted_app  serial_device:chr_file  {read open ioctl getattr create write};

6.4、在device.mk和system_server.te添加并编译权限;

+BOARD_SEPOLICY_DIRS += \
+  device/rockchip/rk3399/rk3399_firefly_edp_box/sepolicy
+
+BOARD_SEPOLICY_UNION += \
+  untrusted_app.te

rw_dir_perms包含read write;

+#untrusted_app
+allow system_server serial_device:chr_file rw_file_perms;


6.5、selinux security level引起的denied u:r:untrusted_app:s0:c512,c768问题,由于security level为MLS访问机制所添加的安全上下文的扩展部分mlstrustedsubject,这一attribute包含了所有能越过MLS检查的客体type。所以在device.te加入type serial_device, dev_type, mlstrustedobject;

2019-06-04 11:40:17.518 1696-1696/? W/ample.hello_ros: type=1400 audit(0.0:74): avc: denied { write } for name="ttyS3" dev="tmpfs" ino=2524 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_f


此时APP的接口获得对串口的内核节点的访问权限。
--------------------- 
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章