关于命令的几个文件:
include /command.h
common/command.c
include/cmd_confdefs.h
common/cmd_*.c
先看一下添加命令的宏:
U_BOOT_CMD
定义在include/command.h中
#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}
可以看到每一个命令定义一个cmd_tbl_t结构体,该结构体也定义在同个头文件中。
CFG_CMD_* 等的命令的配置定义在:
Include/cmd_confdefs.h中
只有定义了相关的配置,在common/cmd_*.c命令函数才会有效
我们现在不创建一个新的cmd_*.c,而是在原来的基础上添加一个命令
例如:添加flash的强制写命令
添加在common/cmd_bootc文件中
添加在u-boot的common/cmd_boot.c中
typedef unsigned short FLASH_PORT_WIDTH;
typedef volatile unsigned short FLASH_PORT_WIDTHV;
#define FLASH_ID_MASK 0xFF
#define FPW FLASH_PORT_WIDTH
#define FPWV FLASH_PORT_WIDTHV
#define AMDNORADDRBASE 0x2000000
#define AMDNORSIZE 0x10000
extern int flash_sect_protect (int p, ulong addr_first, ulong addr_last);
int do_writeuboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int rcode = 0;
ulong addr, dest, count;
ulong noradd,endaddr,seccount;
flash_info_t *info;
int rc;
printf("Add by jk for test the writeboot\n");
if (argc < 4) {
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
//将输入的命令中的参数转化
//./writeboot 80000000 2000000 186bc
//./writeboot 源拷贝 目的NORflash 大小
addr = simple_strtoul(argv[1], NULL, 16);
dest = simple_strtoul(argv[2], NULL, 16);
count = simple_strtoul(argv[3], NULL, 16);
if (count == 0) {
puts ("Zero length ???\n");
return 1;
}
noradd=AMDNORADDRBASE;
seccount=count/AMDNORSIZE;
if((count%AMDNORSIZE)!=0)
seccount++;
endaddr=noradd+0x1FFFF;
这两个地址很重要,一定要是sector的边界,否则就出错,这里硬性定义了从2000000 ----201FFFF
printf("writeboot the noradd=%8lx, endaddr=%8lx\n",noradd,endaddr);
//原先这里设置了sector保护,因此要去掉
flash_sect_protect(0,noradd,endaddr);
//info=flash_info;
info=flash_get_info(noradd);
//大小是8M, sector_count是135
printf("the flash_info.size=%x,flash_sector=%d\n",info.size, info.sector_count);
if(noradd==info->start[0])
printf("find the u-boot address\n");
puts("Erasing Flash...");
//这里擦除的变量是sector,不是地址
flash_erase(info,0,9);
//这里的函数是将addr源,拷贝到dest地址, 大小是coun
puts ("Copy to Flash... ");
rc = flash_write ((uchar *)addr, dest, count);
if (rc != 0) {
flash_perror (rc);
return (1);
}
puts ("done\n");
flash_sect_protect(1,noradd,endaddr);
return 0;
}
//这里最大的参数为 CFG_MAXARGS=16
U_BOOT_CMD(
writeboot, CFG_MAXARGS, 1, do_writeuboot,
"writeuboot - update the davinci u-boot.bin in NOR flash\n"
"argv[1] --start the Memory Address'\n"
"argv[2] --start the NOR Flash Address'\n"
"argv[3] --the u-boot.bin hex size'\n",
);