uboot试验记录-添加自己的命令

大家肯定都用过linux下的clear命令,清屏-清除所有的屏幕输出。当然清屏完全没必要,不过像我一样的强迫症患者,还是要看着uboot没有clear很不爽,今天动手为uboot加个clear命令, 我们知道uboot的common目录中存放着通用的一些东东,包括大多数命令,同时我们的命令具有通用性,就放在common目录好了,扩展性需要,我们采用添加源文件的形式,而不是只添加命令和命令执行函数,其实众多开发板附带代码完全可以抛弃裸机测试代码,只需要在uboot中添加命令即可,arm没有必要写裸机程序,废话少说,下面是试验步骤:

1. 在common目录下,新建文件:com_utils.c,内容如下:

01 /*
02 * (C) Copyright 2000-2003
03 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
04 *
05 * See file CREDITS for list of people who contributed to this
06 * project.
07 *
08 * This program is free software; you can redistribute it and/or
09 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 /*
25 * Misc boot support
26 */
27 #include
28 #include
29
30 void do_clear( cmd_tbl_t * cmdtp , int flag , int argc , char * argv [])
31 {
32     printf( "Clean the screen /n ");
33     printf( "%c" , '/f');
34 }
35
36 /* -------------------------------------------------------------------- */
37
38 U_BOOT_CMD(
39     clear , 1 , 1 , do_clear ,
40     "clear the uart com screen" ,
41     ""
42 );

其中,U_BOOT_CMD是声明命令的宏,clear是命令,do_clear是执行命令的函数,其他参数读者自行研究即可

2. 修改common目录下的Makefile,添加如下:

01 # command
02 # we add our command file here, always –y
03 COBJS-y += cmd_utils.o
04 COBJS - $( CONFIG_CMD_AMBAPP) += cmd_ambapp . o
05 COBJS - $( CONFIG_SOURCE) += cmd_source . o
06 COBJS - $( CONFIG_CMD_SOURCE) += cmd_source . o
07 COBJS - $( CONFIG_CMD_BDI) += cmd_bdinfo . o
08 COBJS - $( CONFIG_CMD_BEDBUG) += bedbug . o cmd_bedbug . o
09 COBJS - $( CONFIG_CMD_BMP) += cmd_bmp . o
10 COBJS - $( CONFIG_CMD_BOOTLDR) += cmd_bootldr . o
11 COBJS - $( CONFIG_CMD_CACHE) += cmd_cache . o

其中,COBJS-y += cmd_utils.o  是我们添加,这样编译器就会编译到我们的命令文件

3. 这时候,我们的命令已经添加完毕了,编译测试即可

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值