
XiaomiRouter自学之路(09-更改串口波特率及Enter键触发)
在前面几个章节我们有提到串口波特率不是平常奇怪用的115200,还有U-boot启动后不是通过按Enter键使之进入命令行模式,这边将这两个问题修改下,符合使用情况
1.修改串口波特率
在上一章节的启动过程分析中,我们看到了有个console初始化的语句,在board_init_f()函数里面,所以我们先定位到该函数,看到有三个函数与console有关
init_baudrate(); /* initialze baudrate settings */
serial_init(); /* serial communications setup */
console_init_f();
先看第一个函数init_baudrate()初始化波特率,应该就是了
static int init_baudrate (void)
{
gd->baudrate = CONFIG_BAUDRATE;
return (0);
}
把include/configs/rt2880.h第80行的57600改成115200
#define CONFIG_BAUDRATE 115200
重新编译,烧录后,发现真的可以了,波特率变成115200,不过还是接着看下后面两个函数是干嘛用的。
定位到serial_init()函数位于board/rt2880/serial.c中,后面会调用到serial_setbrg()函数,主要就是就行串口时钟的初始化等。
接着console_init_f()函数位于common/console.c中,也不知道干了啥,如下:
int console_init_f (void)
{
DECLARE_GLOBAL_DATA_PTR;
gd->have_console = 1;
#ifdef CONFIG_SILENT_CONSOLE
if (getenv("silent") != NULL)
gd->flags |= GD_FLG_SILENT;
#endif
return (0);
}
所以串口的波特率只要修改第一个地方即可。
2.使用Enter键触发命令行
对于Enter键触发命令行的修改应该比较明确,在[08-U-boot启动数值具体说明]中已经有很详细的分析了,我们只需要将原本的默认BootType = 3,设置成4即可,因为4执行的是命令行模式,
所以修改如下:
OperationSelect();
while ( timer1 > 0 ) {
--timer1;
/* delay 100 * 10ms */
for ( i=0; i<100; ++i ) {
if ( ( my_tmp = tstc() ) != 0 ) { /* we got a key press */
timer1 = 0; /* no more delay */
BootType = getc();
if ( ( BootType < '0' || BootType > '5' ) && ( BootType != '7' ) && ( BootType != '8' ) && ( BootType != '9' ) )
BootType = '4';
printf( "\n\rYou choosed %c\n\n", BootType );
break;
}
udelay(10000);
}
printf ("\b\b\b%2d ", timer1);
}
顺便将OperationSelect()里面的提示修改,原本的default位3改成4,方便用户查看。
printf( " %d: Boot system code via Flash.\n", SEL_BOOT_FLASH );
printf( " %d: Entr boot command line interface.(default)\n", SEL_ENTER_CLI );
提交到Github即可,如下:
linye@ubuntu:~/XiaomiRouter/U-boot$ git add include/configs/rt2880.h lib_mips/board.c
linye@ubuntu:~/XiaomiRouter/U-boot$ git add .gitignore
linye@ubuntu:~/XiaomiRouter/U-boot$ git commit -s
[master 5931df7] 1.Change baudrate to 115200. 2.Modify default boottype
3 files changed, 5 insertions(+), 4 deletions(-)
linye@ubuntu:~/XiaomiRouter/U-boot$ tig
linye@ubuntu:~/XiaomiRouter/U-boot$ git push origin master
Username for 'https://github.com': creator_ly@163.com
Password for 'https://creator_ly@163.com@github.com':
To https://github.com/XiaomiRouter/U-boot.git
0c81c2f..5931df7 master -> master
更改串口波特率及Enter键触发的分析就到这边,有感悟时会持续会更新。
注:以上内容都是本人在学习过程积累的一些心得,难免会有参考到其他文章的一些知识,如有侵权,请及时通知我,我将及时删除或标注内容出处,如有错误之处也请指出,进行探讨学习。文章只是起一个引导作用,详细的数据解析内容还请查看XiaomiRouter相关教程,感谢您的查阅。
网友评论