X-008-UBOOT-支持命令行(Bubblegum-96平台)

作者:wowo 发布于:2016-7-27 21:41 分类:X Project

1. 前言

经过前面文章的铺垫,u-boot command line的支持已经成了一个顺理成章的事情了。因此,本文没有太多技术细节,仅仅记录支持命令行的实现过程,权当“X Project” “【任务2】启动到u-boot command line”的一个完结。

2. 支持命令行的过程

由“X-007-UBOOT-DDR的初始化(Bubblegum-96平台)”的描述可知,我们已经成功初始化DDR,并将u-boot放到DDR中执行,基于该成果,我们进一步调试命令行功能。

2.1 修改版型的配置头文件,将u-boot的DEBUG功能打开,以便得到更多的打印信息

pengo@ubuntu:~/work/xprj/u-boot$ git diff
diff --git a/include/configs/bubblegum.h b/include/configs/bubblegum.h
index 6ee4227..5f22528 100644
--- a/include/configs/bubblegum.h
+++ b/include/configs/bubblegum.h
@@ -10,7 +10,7 @@
#ifndef __BUBBLEGUM_H
#define __BUBBLEGUM_H
 
-#define DEBUGX
+#define DEBUG

2.2 根据“X-007-UBOOT-DDR的初始化(Bubblegum-96平台)”所提示的步骤,运行u-boot,得到如下的错误信息。

initcall: 0000000011003180
U-Boot code: 11000000 -> 11014E30  BSS: -> 11014F38
initcall: 0000000011002fc8
initcall: 000000001100321c
DRAM:  initcall: 0000000011002834
dram_init
dram_init OK
initcall: 0000000011003484
Monitor len: 00014F38
Ram size: FFFFFFFF80000000
Ram top: FFFFFFFF80000000
initcall: 0000000011002ff8
initcall: 00000000110031b4
TLB table from ffffffff7fff0000 to ffffffff7fff6000
initcall: 000000001100300c
initcall: 0000000011003130
Reserving 83k for U-Boot at: ffffffff7ffdb000
initcall: 00000000110030fc
Reserving 24k for malloc() at: ffffffff7ffd5000
initcall: 0000000011003354
"Synchronous Abort" handler, esr 0x96000040
ELR:     1100b684
LR:      11003384
x0 : ffffffff7ffd4f68 x1 : 0000000000000000
x2 : 0000000000000098 x3 : 0000000000000000
x4 : 0000000000000000 x5 : 0000000000000098
x6 : 0000000000000000 x7 : 0000000000000004
x8 : 0000000000000031 x9 : 0000000000000000
x10: 000000000000000f x11: 000000000007f468
x12: 000000001100d0d8 x13: 000000000000003c
x14: 0000000000000001 x15: 0000000000000008
x16: 0000000000000008 x17: 0000000000000000
x18: 000000000007f990 x19: 0000000011011c70
x20: 0000000011011ba0 x21: 0000000000000000
x22: 0000000011011286 x23: 000000001101185b
x24: 0000000011011293 x25: 0000000080000000
x26: 0000000000000010 x27: 0000002000000000
x28: 000000000000000c x29: 000000000007f930
Resetting CPU ...
resetting ...

2.3 分析错误信息

上面黄色位置的信息可以推测,应该是reserve_malloc后面的那个init call出问题了,查一下代码:

#ifndef CONFIG_SPL_BUILD
        reserve_malloc,
        reserve_board,
#endif

reserve_malloc后面的函数是reserve_board:

/* (permanently) allocate a Board Info struct */
static int reserve_board(void)
{
        if (!gd->bd) {
                gd->start_addr_sp -= sizeof(bd_t);
                gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
                memset(gd->bd, '\0', sizeof(bd_t));
                debug("Reserving %zu Bytes for Board Info at: %08lx\n",
                      sizeof(bd_t), gd->start_addr_sp);
        }
        return 0;
}

start_addr_sp不对?再看一下上面的日志输出:

Ram size: FFFFFFFF80000000
Ram top: FFFFFFFF80000000

RAM size不对?回忆一下编译过程,有个编译错误:

/home/pengo/work/xprj/u-boot/board/actions/bubblegum/board.c:136:33: warning: integer overflow in expression [-Woverflow]

代码136行对ram_size的赋值如下:

gd->ram_size = 2 * 1024 * 1024 * 1024; /* 2GB, TODO */

溢出?先不纠结,先把这个问题修复再说。

2.4 修改ram_size的赋值,避免溢出

diff --git a/board/actions/bubblegum/board.c b/board/actions/bubblegum/board.c
index 81472a4..ea6fddc 100755
--- a/board/actions/bubblegum/board.c
+++ b/board/actions/bubblegum/board.c
@@ -133,7 +133,7 @@ int dram_init(void)
 
        /* no need do dram init in here, we have done it in SPL */
 
-       gd->ram_size = 2 * 1024 * 1024 * 1024;  /* 2GB, TODO */
+       gd->ram_size = CONFIG_SYS_SDRAM_SIZE;

 
        printf("dram_init OK\n");
        return 0;


diff --git a/include/configs/bubblegum.h b/include/configs/bubblegum.h
 
/*
  * u-boot SPL definitions, which is resided in SRAM
@@ -33,6 +33,8 @@
#define CONFIG_SYS_SDRAM_BASE          0x0
#define CONFIG_NR_DRAM_BANKS           1
 
+#define CONFIG_SYS_SDRAM_SIZE          0x3FFFFFFF
+

暂时使用一个安全的值,后面再完善。编译重新运行后,出现如下的输出:


Initial value for argc=3
Final value for argc=3
initcall: 00000000110024c4 (relocated to 000000003ffdd4c4)
initcall: 00000000110035d0 (relocated to 000000003ffde5d0)
initcall: 00000000110035c0 (relocated to 000000003ffde5c0)
fdtdec_get_config_string: bootcmd
fdtdec_get_config_int: bootsecure
## U-Boot command line is disabled. Please enable CONFIG_CMDLINE
No CLI available
resetting ...

OK,一切正常了,只不过由于没有定义CONFIG_CMDLINE,无法进入命令行。打开相应的配置即可。

2.5 配置命令行功能

配置u-boot,开启命令行有关的配置项包括:

    Command line interface  --->
            [*] Support U-Boot commands
            ([xprj]# ) Shell prompt
            Info commands  ---> 
                      [*] bdinfo
                      [*] coninfo

修改后的配置文件为:

pengo@ubuntu:~/work/xprj/u-boot$ git diff configs/bubblegum_defconfig
diff --git a/configs/bubblegum_defconfig b/configs/bubblegum_defconfig
index 85a488d..bc0c5f7 100644
--- a/configs/bubblegum_defconfig
+++ b/configs/bubblegum_defconfig
@@ -198,8 +198,9 @@ CONFIG_BOOTSTAGE_STASH_SIZE=4096
#
# Command line interface
#
-# CONFIG_CMDLINE is not set
-CONFIG_SYS_PROMPT="=> "
+CONFIG_CMDLINE=y

+# CONFIG_HUSH_PARSER is not set
+CONFIG_SYS_PROMPT="[xprj]# "
 
#
# Autoboot options
@@ -213,8 +214,8 @@ CONFIG_SYS_PROMPT="=> "
#
# Info commands
#
-# CONFIG_CMD_BDI is not set
-# CONFIG_CMD_CONSOLE is not set
+CONFIG_CMD_BDI=y
+CONFIG_CMD_CONSOLE=y

# CONFIG_CMD_CPU is not set
# CONFIG_CMD_LICENSE is not set

再次编译并运行u-boot,OK了,如下:

[xprj]# help
?       - alias for 'help'
bdinfo  - print Board Info structure
coninfo - print console devices and information
dm      - Driver model low level access
env     - environment handling commands
help    - print command description/usage
printenv- print environment variables
reset   - Perform RESET of the CPU
setenv  - set environment variables
version - print monitor, compiler and linker version


[xprj]# bdinfo 
arch_number = 0x00000000
boot_params = 0x00000000
DRAM bank   = 0x00000000
-> start    = 0x00000000
-> size     = 0x3FFFFFFF
baudrate    = 115200 bps
TLB addr    = 0x3FFF0000
relocaddr   = 0x3FFD8000
reloc off   = 0x2EFD8000
irq_sp      = 0x3FFD0BD0
sp start    = 0x3FFD0BD0

以上改动,可参考如下patch:

https://github.com/wowotechX/u-boot/commit/7cc2bd4716bb095925eb6e2c3e43cef157cf40d4

原创文章,转发请注明出处。蜗窝科技,www.wowotech.net

标签: u-boot cmdline

评论:

HZero
2018-09-16 19:14
后来又看了下bubblegum的硬件手册,UART5的TX和RX都是1.8V驱动,所有使用的串口子板也应当是1.8V的电平,之前用的CH340芯片的串口子板,逻辑高电平最低为2.0V,难怪不能正常工作了,新淘的串口子板1.8v电平,连上后输入输出都OK了
wowo
2018-09-17 11:49
@HZero:很不错哦,自己捣鼓明白了,应该收获不小吧?呵呵~~
HZero
2018-09-13 22:11
我又重新到官网上下载了uboot-dtb.img,通过它提供的ADFU工具烧写进去,发现串口也是无法输入,只能输出。串口子板是我从淘宝上买的,不是原装的,难道是串口子板的问题?郁闷了
HZero
2018-09-13 13:49
博主,请教下我用bubblegum按照所述方法烧录你提供的uboot镜像,用串口子板连接uart5,可以看到输出并启动到命令行,但是却无法输入,这个是不是应该是我的硬件除了问题啊?
wowo
2018-09-13 21:51
@HZero:这个版本的串口驱动很简单,可能会有些问题,你可以多试几次,或者跟进去debug一下。
schedule
2016-08-01 12:21
另外, 之前有个“文章分类” 菜单,现在没了, 用起来不方便了
wowo
2016-08-01 17:14
@schedule:分类在右侧还有,导航栏的确实去掉了。主要是做网页的技术不高,抱歉哈~~
schedule
2016-07-31 10:35
linuxer 去哪里了?最近老不更新了。 wowo 风向变了?
wowo
2016-07-31 12:16
@schedule:linuxer最近有点忙,工作事情还是优先的。
放心吧,蜗窝的风格不会变。x project的目的是把kernel的分析文章串起来,因此马上就回来了:-)
linuxer
2016-08-01 09:39
@schedule:除了工作忙之外,更主要的是暑假了,孩子没有人带,很大的一部分精力被孩子耗掉了。估计等到9月份就回归了。
schedule
2016-08-01 12:20
@linuxer:期待您的回归

发表评论:

Copyright @ 2013-2015 蜗窝科技 All rights reserved. Powered by emlog