u-boot添加命令

在u-boot中添加命令hello
1.  在common目录下添加文件cmd_hello.c

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

     intdo_hello(cmd_tbl_t*cmdtp,intflag, intargc,char*argv[])
     {
         printf(“HelloWorld\n”);

     }

     U_BOOT_CMD(
            hello,CONFIG_SYS_MAXARGS,1,do_hello,

            “hello        -  myhellocommand\n”,
            “helloworld\n”
     );

2.  修改common/Makefile,添加如下内容
     COBJS-y+=cmd_hello.o

 

 

TFTP下载更新u-boot,kernel,文件系统命令(ces2440开发板)

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

void show_help_meg()
{
printf("\r\n######## system update describe ########\r\n");
printf("\r\n");
printf("[1] update bootloader(u-boot.bin)\r\n");
printf("[2] update Linux(uImage)\r\n");
printf("[3] update yaffs2(rootfs.yaffs) \r\n");
printf("[4] update u-boot,kernel and yaffs2\r\n");
printf("[q] exit\r\n");
printf("\r\n");
printf("please input the option: ");

}

char get_cmd_key()
{
while(1)
{
  if(tstc())
  {
   return getc();
  }
}
}
int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
char c_key;
        char cmd_buf[200];
printf("set ip");
strcpy(cmd_buf,"setenv ipaddr 192.168.0.240;setenv serverip     192.168.0.160; setenv gatewayip 192.168.0.1");
run_command(cmd_buf, 0);
while(1)
{
  show_help_meg();
  c_key = get_cmd_key();
  printf("%c\n",c_key);
  switch(c_key)
  {
   case '1':
   {
    strcpy(cmd_buf,"tftp 30008000 u-boot.bin;nand erase 0 30000; nand write 0x30008000 0 30000");
    break;//run_command(cmd_buf,0);
   }
   case '2':
   {
    strcpy(cmd_buf,"tftp 30008000 uImage; nand erase 40000 200000; nand write 0x30008000 40000 200000");
                                break;
   }
   case '3':
                        {
                                strcpy(cmd_buf,"tftp 30008000 rootfs.yaffs; nand erase 240000; nand write.yaffs2 30008000 240000 5a5af0");
                                break;
                        }
   case '4':
   {
    strcpy(cmd_buf,"tftp 30008000 u-boot.bin;na    nd erase 0 30000; nand write 0x30008000 0 30000");
    run_command(cmd_buf, 0);
    strcpy(cmd_buf,"tftp 30008000 uImage; nand     erase 40000 200000; nand write 0x30008000 40000 200000");
    run_command(cmd_buf, 0);
    strcpy(cmd_buf,"tftp 30008000 rootfs.yaffs;     nand erase 240000; nand write.yaffs2 30008000 240000 5a5af0");
    break;
   }
   case 'q':
                        {
    return 0;
                                break;
                        }
  }
  run_command(cmd_buf, 0);
}

return 0;
}

U_BOOT_CMD(
  update, 1, 0, do_update,
  "system update",
  "update u-boot,kernel,rootfs by tftp\n"
);

 如果需要把当前环境变量写入nandflash 可以执行saveenv指令。加在升级之后

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值