在U-Boot中添加命令

命令的结构体表示(include/command.h)

struct cmd_tbl_s {
   char		*name;		/* Command Name*/
   int		maxargs;	/* maximum number of arguments	*/
   int		repeatable;	/* autorepeat allowed?		*/
				/* Implementation function	*/
   int		(*cmd)(struct cmd_tbl_s *, int, int, char *[]);
   char		*usage;		/* Usage message	(short)	*/
#ifdef	CFG_LONGHELP
    char		*help;		/* Help  message	(long)	*/
#endif
#ifdef CONFIG_AUTO_COMPLETE
   /* do auto completion on the arguments */
   int  (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};

使用U_BOOT_CMD()这个宏来声明一个命令。
示例:

U_BOOT_CMD(
	flinfo,    2,    1,    do_flinfo,
	"flinfo  - print FLASH memory information\n",
	"\n    - print information for all FLASH memory banks\n"
	"flinfo N\n    - print information for FLASH memory bank # N\n"
);


U_BOOT_CMD宏的定义

#define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))

#ifdef  CFG_LONGHELP

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}

#else	/* no long help info */

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

#endif	/* CFG_LONGHELP */


选择一个会编译进uboot的cmd_XXX.c文件
比如: cmd_console.c文件

………………………………………………….
void do_test_addcmd()
{
	printf("only test adding command\n");
}
/***************************************************/
U_BOOT_CMD(
	coninfo,	3,	1,	do_coninfo,
	"coninfo - print console devices and information\n",
	""
);

U_BOOT_CMD(
	test_addcmd,	1,	1,	do_test_addcmd,
	"test_addcmd - only test adding command \n",
	""
);


实例:

       在U-Boot中添加一个打开或关闭蜂鸣器的命令:当输入buzzer  open时打开蜂鸣器使它响,输入buzzer  close时关闭蜂鸣器。

cmd_buzzer.c(添加在common目录下,并在Makefile添加“COBJS-y  +=cmd_buzze.o”语句):


#include <common.h>
#include <command.h>

#define GPD0CON ( *((volatile unsigned long *)0xE02000A0) ) 
#define GPD0DAT ( *((volatile unsigned long *)0xE02000A4) )

void do_buzzer_addcmd(cmd_tbl_t *cmdtp, int flag, int argc,char *argv[])
{
	GPD0CON &= 0xfffffff0;
	GPD0CON |= 0x00000001;	//设置为输出
	GPD0DAT &= 0xfe;	    //关闭蜂鸣器
	
	if(0 == strcmp(argv[1],"open"))
	{
		GPD0DAT |= 0x01;
		printf("Open the buzzer\n");
	}

	else if(0 == strcmp(argv[1],"close"))
	{
		GPD0DAT &= 0xfe;
		printf("Close the buzzer\n");	
	}

	else if(0 == strcmp(argv[1],"--help"))
		printf ("Help:\n%s\n", cmdtp->help);	

	else
		printf ("Usage:\n%s\n", cmdtp->usage);	
}

U_BOOT_CMD(
        buzzer,       2,      1,      do_buzzer_addcmd,
        "\tbuzzer	   --Close or open the buzzer \n",//命令说明
	"\tbuzzer  open    --Open  the buzzer\n"	  //帮助信息
	"\tbuzzer  close   --Close the buzzer\n"
);

在顶层make,把生成的u-boot.bin下载到开发板上,在u-boot下运行命令。



附录(下载、烧写U-Boot步骤,s5pv210为例):

          1. 使用USB线通过DNW下载sq210_usb.bin到0xd0020010(初始化板子,使板子有一个下载环境)

          2. 使用USB线通过DNW下载u-boot.bin到0x23e00000(下载到内存(RAM))

          3. 烧录uboot(烧写到flash)
                                 nand erase 0x0 0x60000
                                 tftp 0x20008000 u-boot.bin
                                 nand write 0x20008000 0x0 0x60000


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值