mortree

坚持多写一些东西

LK 打印log控制

  我们知道,LK里面的log只能通过uart打印出来,看一下除了UART的初始化以及相关操作,这边主要来看一下log的打印是如何控制打印级别的:

首先看该文件:

1. project/msm8610.mk

# top level project rules for the msm8610 project
#
LOCAL_DIR := $(GET_LOCAL_DIR)

TARGET := msm8610

MODULES += app/aboot

ifeq ($(TARGET_BUILD_VARIANT),user) //打印log级别 DEBUG为1
DEBUG := 0
else
DEBUG := 1
endif

EMMC_BOOT := 1
ENABLE_SDHCI_SUPPORT := 1

#enable power on vibrator feature
ENABLE_PON_VIB_SUPPORT := true
ENABLE_PWM_SUPPORT := true

#DEFINES += WITH_DEBUG_DCC=1
DEFINES += WITH_DEBUG_UART=1            //定义该变量,串口才会进行初始化相关操作,log才能通过串口输出
DEFINES += WITH_DEBUG_LOG_BUF=1
#DEFINES += WITH_DEBUG_FBCON=1
DEFINES += DEVICE_TREE=1
#DEFINES += MMC_BOOT_BAM=1
#DEFINES += CRYPTO_BAM=1
DEFINES += ABOOT_IGNORE_BOOT_HEADER_ADDRS=1

DEFINES += ABOOT_FORCE_KERNEL_ADDR=0x00008000
DEFINES += ABOOT_FORCE_RAMDISK_ADDR=0x02000000
DEFINES += ABOOT_FORCE_TAGS_ADDR=0x01e00000
DEFINES += ABOOT_FORCE_KERNEL64_ADDR=0x00080000

#Disable thumb mode
#TODO: The gold linker has issues generating correct
#thumb interworking code for LK. Confirm that the issue
#is with the linker and file a bug report.
ENABLE_THUMB := false

ifeq ($(ENABLE_PON_VIB_SUPPORT),true)
DEFINES += PON_VIB_SUPPORT=1
endif

ifeq ($(ENABLE_SDHCI_SUPPORT),1)
DEFINES += MMC_SDHCI_SUPPORT=1
endif
2.  lk\include\Debug.h

#if defined(DEBUG)              //mk里面定义为1
#define DEBUGLEVEL DEBUG         //此时打印级别为1
#else
#define DEBUGLEVEL 2
#endif

/* debug levels */
#define CRITICAL 0
#define ALWAYS 0
#define INFO 1
#define SPEW 2

/* output */
void _dputc(char c); // XXX for now, platform implements
int _dputs(const char *str);
int _dprintf(const char *fmt, ...) __PRINTFLIKE(1, 2);
int _dvprintf(const char *fmt, va_list ap);

#define dputc(level, str) do { if ((level) <= DEBUGLEVEL) { _dputc(str); } } while (0)          //串口打印
#define dputs(level, str) do { if ((level) <= DEBUGLEVEL) { _dputs(str); } } while (0)          //串口打印
#define dprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dprintf(x); } } while (0)    //只打印 0 1 级别的log
#define dvprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dvprintf(x); } } while (0)
3.  lk\lib\debug\Debug.c
int _dprintf(const char *fmt, ...)
{
	char buf[256];
	char ts_buf[13];
	int err;

	snprintf(ts_buf, sizeof(ts_buf), "[%u] ", current_time());  
	dputs(ALWAYS, ts_buf);

	dputs(ALWAYS, ts_buf);
	va_list ap;
	va_start(ap, fmt);
	err = vsnprintf(buf, sizeof(buf), fmt, ap);   //字符转换
	va_end(ap);

	dputs(ALWAYS, buf);           //串口输出
	return err;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yanleizhouqing/article/details/52116120
文章标签: LK LOG
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭