一. console disable
1. 问题描述
在用串口输出内核的log时,到了下面一句话就没有了
[ 44.352822].(1)[1027:sh]<< printk console disable >>
串口打印被disable了,如何破?
2.分析
在./mediatek/kernel/drivers/mtprof/bootprof.c中
2.1 创建了/proc/bootprof文件
-
static int __init init_boot_prof(void)
-
{
-
struct proc_dir_entry *pe;
-
pe = proc_create("bootprof", 0664, NULL, &mt_bootprof_fops); //创建了/proc/bootprof文件
-
return 0;
-
}
mt_bootprof_fops
中规定了/proc/bootprof的写操作是mt_bootprof_write
2.2 /proc/bootprof的写操作
-
static ssize_t mt_bootprof_write(struct file *filp, const char *ubuf,
-
size_t cnt, loff_t *data)
-
{
-
copy_from_user(&buf, ubuf, copy_size); cnt);
-
if(cnt==1){
-
if(buf[0] == '0')
-
mt_bootprof_switch(0);
-
else if(buf[0] == '1')
-
mt_bootprof_switch(1);
-
}
-
return cnt;
-
}
如果写入0,就关闭console打印,如果写入1就打开console打印
2.3 mt_bootprof_switch
-
static void mt_bootprof_switch(int on)
-
{
-
dbmsg("on=%d", on);
-
mutex_lock(&mt_bootprof_lock);
-
if (mt_bootprof_enabled ^ on)
-
{
-
if (on)
-
{
-
mt_bootprof_enabled = 1;
-
mt_enable_uart(); //这个是我添加的
-
}
-
else
-
{ // boot up complete
-
mt_bootprof_enabled = 0;
-
bootup_finish(); -->就是调用mt_disable_uart()
-
}
-
}
-
mutex_unlock(&mt_bootprof_lock);
-
-
}
mt_bootprof_switch
中若是打开则会调用mt_enable_uart
若是关闭则会调用mt_disable_uart
3.
mt_disable_uart与mt_enable_uart实际上只是将标志printk_disable_uart置1或置0
那么这个标志printk_disable_uart是如何影响串口打印的呢?
答案是控制printk中的输出
在/kernel/kernel/printk.c中
-
printk
-
--> 对每个args调用vprintk
-
--> 添加时间打印后调用 console_unlock
-
--> call_console_drivers
-
-->_call_console_drivers
-
-->在调用con->write之前先判断printk_disable_uart标志是不是等于1
-
如果等于1,则不打印
二.实验
1.代码修改
a. ./mediatek/kernel/drivers/mtprof/bootprof.c中
-
+extern void mt_enable_uart(void);
-
static void mt_bootprof_switch(int on)
-
{
-
mutex_lock(&mt_bootprof_lock);
-
if (mt_bootprof_enabled ^ on)
-
{
-
if (on)
-
{
-
mt_bootprof_enabled = 1;
-
+ mt_enable_uart(); //当on=1时需要将enable_uart
-
}
-
}
-
-
static ssize_t mt_bootprof_write(struct file *filp, const char *ubuf,
-
- if(cnt==1){ //将文件打开数的判断去掉,可能上层一直有占用这个
-
+ //if(cnt==1){
-
if(buf[0] == '0')
-
mt_bootprof_switch(0);
-
else if(buf[0] == '1')
-
mt_bootprof_switch(1);
-
- }
-
+ //}
-
-
}
b. kernel/kernel/printk中
-
inline void mt_enable_uart(void)
-
{
-
+ printk_disable_uart = 0;
-
+ printk("<< printk console enabled >>\n");
-
+
-
+#if 0
-
if(mt_need_uart_console == 1){ //这个标志会影响printk_disable_uart
-
if(printk_disable_uart == 0)
-
return;
-
@@ -97,6 +103,7 @@ inline void mt_enable_uart(void)
-
}else{
-
printk("<< printk console can't be enabled >>\n");
-
}
-
+#endif
-
}
2.实验
root@hqunited72_we_72_kk:/ # echo 1 > /proc/bootprof //串口会从disable中继续打印
root@hqunited72_we_72_kk:/ # echo 0 > /proc/bootprof //串口不打印了
阅读(7321) | 评论(3) | 转发(0) |