Chinaunix首页 | 论坛 | 博客
  • 博客访问: 353396
  • 博文数量: 49
  • 博客积分: 3229
  • 博客等级: 中校
  • 技术积分: 616
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-26 21:46
文章分类

全部博文(49)

文章存档

2011年(8)

2010年(2)

2009年(3)

2008年(36)

我的朋友

分类:

2008-09-01 22:37:46

首先给vivi增加网络下载的命令。
在vivi源码中, ./drivers/net/net_device.c中有关于网络命令的代码。

/*
 * Network Interface
 * based on ARMBOOT
 * Author : SW.LEE
 *
 */


#include <config.h>
#include <printk.h>
#include <heap.h>
#include <time.h>
#include <command.h>
#include <types.h>
#include <io.h>
#include <sizes.h>
#include <vivi_string.h>
#include <errno.h>
#include <string.h>

#undef NETDEV_DEBUG
#ifdef NETDEV_DEBUG
#define DPRINTK(args...) printk(##args)
#else
#define DPRINTK(args...)
#endif



void command_tftpboot(int argc, const char**argv);
static user_subcommand_t net_cmds[] = {
{
        "tftpboot",
        netboot_common,
        "net tftpboot \t\t-- tftp file transfer"
}
};


void command_net(int argc, const char **argv)
{
    switch (argc) {
    case 1:
            invalid_cmd("net", net_cmds);
            break;
    case 2:
            if (strncmp("help", argv[1], 4) == 0) {
                print_usage("", net_cmds);
                break;
}
    default:
            execsubcmd(net_cmds, argc-1, argv+1);
}
}

user_command_t net_cmd = {
    "net",
    command_net,
    NULL,
    "net [{cmds}]\t\t\t-- Manage Network functions"
};


当我们使用net这个命令的时候,vivi就会调用command_net这个函数。
默认情况下,vivi并没有添加这个命令。于是,我们将这个命令加入到vivi中:
将net_device.c移到lib目录下。然后修改command.c文件。在你认为合适的地方加入
extern user_command_t net_cmd;
然后在int init_builtin_cmds(void)添加
add_command(&net_cmd);
在Makefile的相应部分加入obj-y += net_device.o

想测试以下,增加命令是否成功。为了编译成功,先改一下netboot_common为NULL。编译,下载,启动,输入net或net help,可发现以成功添加了net命令。
阅读(1939) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~