需求:3368的老主板更换为3568的新主板,为了app兼容两款主板,要求串口号一致。有个ttyS0的口,需要对应改为ttySWK0
跟踪驱动代码:
dw8250_probe(drivers\tty\serial\8250\8250_dw.c) -->serial8250_register_8250_port(drivers\tty\serial\8250\8250_core.c) -->uart_add_one_port(drivers\tty\serial\serial_core.c) -->tty_port_register_device_attr_serdev(drivers\tty\tty_port.c) -->tty_register_device_attr -->tty_line_name(drivers\tty\tty_io.c)
tty_line_name函数:
1 static ssize_t tty_line_name(struct tty_driver *driver, int index, char *p) 2 { 3 if (driver->flags & TTY_DRIVER_UNNUMBERED_NODE) 4 return sprintf(p, "%s", driver->name); 5 else 6 return sprintf(p, "%s%d", driver->name, 7 index + driver->name_base); 8 9 }
可知ttySx串口节点设备名称是由驱动名称 driver->name和串口序号index 组成的。
这里做一个判断,index是0,串口节点设备名称则为ttySWK0即可满足需求:
1 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c 2 index b6f42d0ee626..fb6750ad356d 100644 3 --- a/drivers/tty/tty_io.c 4 +++ b/drivers/tty/tty_io.c 5 @@ -1135,9 +1135,14 @@ static ssize_t tty_line_name(struct tty_driver *driver, int index, char *p) 6 { 7 if (driver->flags & TTY_DRIVER_UNNUMBERED_NODE) 8 return sprintf(p, "%s", driver->name); 9 - else 10 + else{ 11 + if(index == 0){ 12 + return sprintf(p, "ttySWK%d",index); 13 + }else 14 return sprintf(p, "%s%d", driver->name, 15 index + driver->name_base); 16 + } 17 + 18 }
编译好重新烧录,ttyS改为ttySWK0:
设置串口权限:
/device/rockchip/common diff --git a/ueventd.rockchip.rc b/ueventd.rockchip.rc index f16524a..9408538 100755 --- a/ueventd.rockchip.rc +++ b/ueventd.rockchip.rc @@ -75,6 +75,7 @@ /dev/ttyS7 0666 root root /dev/ttyS8 0666 root root /dev/ttyS9 0666 root root +/dev/ttySWK0 0666 root root
参考:
https://www.jianshu.com/p/c345576b94a1?ivk_sa=1024320u
https://www.ngui.cc/article/show-884649.html?action=onClick