vivi中命令的实现
时间:2010-05-21 来源:charming2440
/* add user command */ |
static user_command_t flash_cmd = { |
void command_flash(int argc, const char **argv)
//mymtd已经在mtd_init()函数中已经初始化
|
static void command_help(int argc, const char **argv) |
上面的函数只是做了一个封装,下面才是真正实现功能的函数!
void print_usage(char *strhead, user_subcommand_t *cmds) |
void execsubcmd(user_subcommand_t *cmds, int argc, const char **argv) |
typedef struct user_subcommand { |
因为子命令比较多,应此定义了一个结构数组,数组中每一个元素表示一个子命令结构。需要的时候只需要遍历数组找到相应的子命令即可。
static user_subcommand_t flash_cmds[] = { |
{
struct mtd_info *mtd = mymtd;
loff_t ofs;
size_t blk_size, len;
if (argc != 3) {
putstr("invalid 'flash unlock' command: too few(many) arguments\r\n");
return;
}
ofs = (loff_t)strtoul(argv[1], NULL, 0, NULL);
len = (size_t)strtoul(argv[2], NULL, 0, NULL);
blk_size = find_erase_size(mtd, ofs, len);
printk("Unlocking blocks 0x%08lx-0x%08lx... ", ofs, ofs+blk_size);
if (mtd->unlock(mtd, ofs, blk_size) < 0)
putstr("failed\r\n");
else
putstr("done\r\n");
} 每个函数实现不同的功能。 在完成了前面的步骤之后,最重要的一步也是最简单的一步,将命令加到命令链表中,调用的是add_command()函数
/* add user command */ |