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指令。加在升级之后

 

你可能感兴趣的:(linux,u-boot,bootloader)