Chinaunix首页 | 论坛 | 博客
  • 博客访问: 112991
  • 博文数量: 49
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-23 17:29
文章分类
文章存档

2014年(39)

2013年(10)

我的朋友

分类: 嵌入式

2014-02-07 14:07:07

lib_arm/board.c

开启调试信息要在include/common.h中定义DEBUG 即可

#ifdef    DEBUG
#define debug(fmt,args...)    printf (fmt ,##args)
#define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
#else
#define debug(fmt,args...)
#define debugX(level,fmt,args...)
#endif    /* DEBUG */

static int display_banner (void)
{
    printf ("\n\n%s\n\n", version_string);
    debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
           _armboot_start, _bss_start, _bss_end);
#ifdef CONFIG_MODEM_SUPPORT 未定义
    debug ("Modem Support enabled\n");
#endif
#ifdef CONFIG_USE_IRQ 未定义
    debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
    debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
#endif

    return (0);
}



这个函数只执行了两句话

printf ("\n\n%s\n\n", version_string);
debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", _armboot_start, _bss_start, _bss_end);



version_string很显然是关于uboot版本的一个字符串。需要注意的就是其中C语言中多字符串相连的用法。
如"string1""string2" ,编译时会自动将两个连成一个字符串"string1string2".

const char version_string[] = U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;




printf 见common/console.c


void printf(const char *fmt, ...)
{
    va_list args;
    uint i;
    char printbuffer[CONFIG_SYS_PBSIZE];

    va_start(args, fmt);

    /* For this to work, printbuffer must be larger than
     * anything we ever want to print.
     */

    i = vsprintf(printbuffer, fmt, args);
    va_end(args);

    /* Print the string */
    puts(printbuffer);
}

其中可以看到vsprintf这个函数是对字符串处理的关键,而最终的打印是能过 puts(printbuffer);来完成的。那么下面就重点分析字符串的打印,即puts


void puts(const char *s)
{
    if (gd->flags & GD_FLG_DEVINIT) {
        /* Send to the standard output */
        fputs(stdout, s);
    } else {
        /* Send directly to the handler */
        serial_puts(s);
    }
}

在这里看到了对gd->flags的使用


#define    GD_FLG_RELOC    0x00001        /* Code was relocated to RAM        */
#define    GD_FLG_DEVINIT    0x00002        /* Devices have been initialized    */
#define    GD_FLG_SILENT    0x00004        /* Silent mode                */
#define    GD_FLG_POSTFAIL    0x00008        /* Critical POST test failed        */
#define    GD_FLG_POSTSTOP    0x00010        /* POST seqeunce aborted        */
#define    GD_FLG_LOGINIT    0x00020        /* Log Buffer has been initialized    */
#define    GD_FLG_DISABLE_CONSOLE    0x00040 /* Disable console (in & out)     */

这些标识都是gd->flags的不同位。GD_FLG_DEVINIT位就决定了输出是向自己的标准输出还是向串口输出。

阅读(1172) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~