前言
uboot 中有个 ping 命令,用来检查网络是否通畅。
我们照着这个命令添加一个 ping2 命令。
step1
cmd/net.c
#if defined(CONFIG_CMD_PING2)
static int do_ping2(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
if (argc < 2)
return CMD_RET_USAGE;
net_ping_ip = string_to_ip(argv[1]);
if (net_ping_ip.s_addr == 0)
return CMD_RET_USAGE;
if (net_loop(PING) < 0) {
printf("ping failed; host %s is not alive\n", argv[1]);
return CMD_RET_FAILURE;
}
printf("host %s is alive\n", argv[1]);
return CMD_RET_SUCCESS;
}
U_BOOT_CMD(
ping2, 2, 1, do_ping2,
"send ICMP ECHO_REQUEST to network host",
"pingAddress"
);
#endif
step2
cmd/Kconfig
config CMD_PING2
bool "ping2"
help
Send ICMP ECHO_REQUEST to network host
step3
step4
重新编译 uboot
$ make O=OrangePiPC/ uboot-rebuild
step5
烧录,验证
=> help
? - alias for 'help'
base - print or set address offset
bdinfo - print Board Info structure
...
ping - send ICMP ECHO_REQUEST to network host
ping2 - send ICMP ECHO_REQUEST to network host
printenv - print environment variables
pxe - commands to get and boot from pxe files
random - fill memory with random pattern
reset - Perform RESET of the CPU
run - run commands in an environment variable
...
=> ping2 192.168.31.1
Using ethernet@1c30000 device
host 192.168.31.1 is alive