Linux??????????Printk
???????????? ???????[ 2016/12/26 16:36:59 ] ?????????????? Linux
????1????饗????s3c2440 linux??
?????????????????У???????printk?????????????÷???C??????ó????е?printf????????????ó?????????????stdio.h?е??????linux???????????????????linux????У???????printk????????????????????
????printf??printk??????:printk????????????"<N>"??????????N???Χ??0~7????????????????
??????printk("<n>"......);?е?n < console_loglevel ???????????????????????
??????????????Printk.c (kernel) ?г???????console_loglevel ??????7.
/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */
/* We show everything that is MORE important than this.. */
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */int console_printk[4] = {
DEFAULT_CONSOLE_LOGLEVEL?? /* console_loglevel */
DEFAULT_MESSAGE_LOGLEVEL?? /* default_message_loglevel */
MINIMUM_CONSOLE_LOGLEVEL?? /* minimum_console_loglevel */
DEFAULT_CONSOLE_LOGLEVEL?? /* default_console_loglevel */
};
????2?????????cat /proc/sys/kernel/printk??????????
????# cat /proc/sys/kernel/printk
????7 4 1 7
???????е? 7 4 1 7?????????console_loglevel??default_message_loglevel??minimum_console_loglevel??default_console_loglevel
????3????????????
????#echo "1 4 1 7">/proc/sys/kernel/printk ???????????????console_loglevel?????1????????е????????????????????
????4??printk?????????????????
??????????????Kernel.h (includelinux) ??????0~7??8???????????
#define ????KERN_EMERG ?? "<0>" /* system is unusable */
#define KERN_ALERT "<1>" /* action must be taken immediately */
#define KERN_CRIT "<2>" /* critical conditions */
#define KERN_ERR "<3>" /* error conditions */
#define KERN_WARNING "<4>" /* warning conditions */
#define KERN_NOTICE "<5>" /* normal but significant condition*/
#define KERN_INFO "<6>" /* informational*/
#define KERN_DEBUG "<7>" /* debug-level messages */
#define console_loglevel ???????? (console_printk[0])
#define default_message_loglevel (console_printk[1])
#define minimum_console_loglevel (console_printk[2])
#define default_console_loglevel (console_printk[3])
???????printk??
?????? printk(KERN_WARNING"there is a warning here!
");//????м???ж??????
?????? printk(KERN_DEBUG"%s %s %d
"?? __FILE__?? __FUNCTION__?? __LINE__);
??????????У????????????????log_buf?е????????????????????????????????????? #dmesg
#
# dmesg
Linux version 2.6.22.6 (book@book-desktop) (gcc version 3.4.5) #19 Thu Dec 8 14:06:03 CST 2016
CPU: ARM920T [41129200] revision 0 (ARMv4T)?? cr=c0007177
Machine: SMDK2440
Memory policy: ECC disabled?? Data cache writeback
On node 0 totalpages: 16384
DMA zone: 128 pages used for memmap
DMA zone: 0 pages reserved
DMA zone: 16256 pages?? LIFO batch:3
Normal zone: 0 pages used for memmap
CPU S3C2440A (id 0x32440001)
................................
????????????? cat /proc/kmsg& ??????У?????????????????????У?__FILE__?? __FUNCTION__?? __LINE__??????????????????????????????С??????á?
# cat /proc/kmsg&
# ./firstdrvtest on
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 23
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 25
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 27
# ./firstdrvtest off
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 23
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 25
<7>/work/LinuxDrives/20.printk_debug/first_drv.c first_drv_open 27
????5????????printk??????????
printk
vprintk
vscnprintf //????????????????BUFFER
// Copy the output into log_buf.
// ?????BUFFER??????????????????д??log_buf
// ????printk("abc")????"<4>abc"?? ??д??log_buf
// ??????dmesg?????log_buf???????????????????????????
// ?????????write???????
release_console_sem
call_console_drivers
//??log_buf??????????????????
_call_console_drivers
if ((msg_log_level < console_loglevel??//?????????????
__call_console_drivers
con->write //con??console_drivers?????е??????t??????????? ??drives/serial/s3c2410.c?в?
??????ú???????????console????
????static void s3c24xx_serial_console_write(struct console *co?? const char *s??
????unsigned int count)
????{
????uart_console_write(cons_uart?? s?? count?? s3c24xx_serial_console_putchar);
????}
??????????????????????s3c24xx_serial_console_putchar????
static int s3c24xx_serial_initconsole(void)
{
...........................
register_console(&s3c24xx_serial_console);
return 0;
}
static struct console s3c24xx_serial_console =
{
.name= S3C24XX_SERIAL_NAME??//????????????TTYSAC
.device= uart_console_device?? //init?????????????/dev/console?????????
.flags= CON_PRINTBUFFER??//???????г??????console???????log_buf?????????
.index= -1??//?????????????uboot?е????????
.write= s3c24xx_serial_console_write??//????????????
.setup= s3c24xx_serial_console_setup //???????ú???
};
??????????????????????????????????????????????????????????????????д????????s3c2440??????????????????????????
static void s3c24xx_serial_console_putchar(struct uart_port *port?? int ch)
{
unsigned int ufcon = rd_regl(cons_uart?? S3C2410_UFCON);
while (!s3c24xx_serial_console_txrdy(port?? ufcon))
barrier();
wr_regb(cons_uart?? S3C2410_UTXH?? ch);
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11