📄 cmdnet.c
字号:
/* netcmd.c*/
#include "config.h"#include "machine.h"#include "command.h"#include <priv_data.h>
#include "mtd/mtd.h"#include "heap.h"#include "vivi_string.h"#include "vivi_lib.h"#include "printk.h"#include <string.h>#include <types.h>#include <io.h>
#include <net.h>//#include "asm/global_data.h"
extern bd_t *global_bd;
static user_subcommand_t net_cmds[];
extern ulong downfilesize;
#ifdef CONFIG_NET_PING
static void command_net_ping(int argc, const char * argv[])
{
bd_t * bd = global_bd;
if (argc == 2) {
NetPingIP = string_to_ip(argv[1]);
NetLoop(PING);
}
}
#endif
ulong string_to_num(const char* s){ char *e; return simple_strtoul(s, &e, 10);}
static void command_net_tftp(int argc, const char * argv[])
{
bd_t * bd = global_bd;
if (argc == 4) {
bd->serverip = string_to_ip(argv[1]);
load_addr = string_to_num(argv[2]);
sprintf(BootFile,"%s",argv[3]);
NetLoop(TFTP);
} else {
printk("param is invalid\n");
}
}
static void command_write_flash(int argc, const char **argv)
{
int ret; loff_t to; size_t size; mtd_partition_t *dst_part; int flag;
if (downfilesize==0) {
printk("Please download the code to write firset.\n");
return;
}
if (argc == 2) {
if (strncmp("flash",argv[0],5)==0) {
dst_part = get_mtd_partition(argv[1]); if (dst_part == NULL) { printk("Could not found \"%s\" partition\n", argv[1]); return; }
to = dst_part->offset; size = dst_part->size; flag = dst_part->flag;
if (downfilesize>size) {
printk("An image size is too large to write flash. \n");
return;
}
ret = write_to_flash(to, downfilesize, (char *)load_addr, flag);
}
}
}
static void command_net_set(int argc, const char **argv){
bd_t * bd = global_bd; int i;
char *e,*s=argv[2];
if (strncmp("mac", argv[1], 3)==0) {
for(i=0;i<6;i++) {
bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
if (s) { s = (*e) ? e+1 : e;
} }
} else if (strncmp("ipaddr", argv[1], 6)==0) {
bd->ipaddr = string_to_ip(argv[2]);
} else if (strncmp("serverip", argv[1], 8)==0) {
bd->serverip = string_to_ip(argv[2]);
} else if (strncmp("netmask", argv[1], 7)==0) {
bd->netmask = string_to_ip(argv[2]);
} else if (strncmp("gateway", argv[1], 7)==0) {
bd->gateway = string_to_ip(argv[2]);
} else {
printk("Parameter Invalid\n");
}
}
/*static void command_net_mac(int argc, const char **argv)
{
}*/
static void command_net_save(int argc, const char **argv){ if (argc != 1) { invalid_cmd("net save", net_cmds); return; } save_priv_data_blk();}
static void command_net_show(int argc, const char **argv)
{
bd_t * bd = global_bd;
int i;
printk("Current Network Configuration\n");
printk("Ethernet Address: ");
for (i=0;i<5;i++) printk("%02X:",bd->bi_enetaddr[i]);
printk("%02X\n",bd->bi_enetaddr[i]);
//print_usage("net", net_cmds);
printk("IP Address: ");
print_IPaddr(bd->ipaddr);
printk("\n");
printk("Net Mask: ");
print_IPaddr(bd->netmask);
printk("\n");
printk("Gateway: ");
print_IPaddr(bd->gateway);
printk("\n");
printk("Server IP: ");
print_IPaddr(bd->serverip);
printk("\n");
}
static void command_net_help(int argc, const char **argv)
{
print_usage("net", net_cmds);
}
static user_subcommand_t net_cmds[] = {
#ifdef CONFIG_NET_PING
{ "ping", command_net_ping, "ping ipaddr -- Ping function"},
#endif
{
"tftp", command_net_tftp, "tftp <serverip> <filename> -- Download code From TFTP Server"}, { "flash", command_write_flash, "flash <partname> -- Flash downloaded code to part"}, { "set", command_net_set, "set <ipaddr> <mask> <gateway> -- Set IP Configuration"},/* { "mac", command_net_mac, "mac <mac address> -- Set MAC Address"},*/ { "show", command_net_show, "show -- Show Current network Configuration"}, { "save", command_net_save, "save \t\t\t-- Save parameter table to flash memeory"}, { "help", command_net_help, "help"}, { NULL, NULL, NULL}
};
static void command_net(int argc, const char **argv){ if (argc == 1) { command_net_show(argc-1, argv+1); command_net_help(1,NULL); } else { execsubcmd(net_cmds, argc-1, argv+1);
}}
user_command_t net_cmd = { "net", command_net, NULL, "net ["
#ifdef CONFIG_NET_PING
"ping|"
#endif
"tftp|set|mac| show| save |help] \t\t-- Network Manage"};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -