+// SPDX-License-Identifier: GPL-2.0
/*
* Copied from Linux Monitor (LiMon) - Networking.
*
* Copyright 2000 Roland Borde
* Copyright 2000 Paolo Scaffardi
* Copyright 2000-2002 Wolfgang Denk, wd@denx.de
- * SPDX-License-Identifier: GPL-2.0
*/
/*
#include <common.h>
#include <command.h>
+#include <console.h>
#include <environment.h>
#include <errno.h>
#include <net.h>
-#if defined(CONFIG_STATUS_LED)
+#include <net/fastboot.h>
+#include <net/tftp.h>
+#if defined(CONFIG_LED_STATUS)
#include <miiphy.h>
#include <status_led.h>
#endif
#if defined(CONFIG_CMD_SNTP)
#include "sntp.h"
#endif
-#include "tftp.h"
-
-DECLARE_GLOBAL_DATA_PTR;
/** BOOTP EXTENTIONS **/
/* Ethernet bcast address */
const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
const u8 net_null_ethaddr[6];
-#ifdef CONFIG_API
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
void (*push_packet)(void *, int len) = 0;
#endif
/* Network loop state */
ushort net_native_vlan = 0xFFFF;
/* Boot File name */
-char net_boot_file_name[128];
+char net_boot_file_name[1024];
/* The actual transferred size of the bootfile (in bytes) */
u32 net_boot_file_size;
/* Boot file size in blocks as reported by the DHCP server */
static int on_bootfile(const char *name, const char *value, enum env_op op,
int flags)
{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
switch (op) {
case env_op_create:
case env_op_overwrite:
}
U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_ip = string_to_ip(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr);
+
+static int on_gatewayip(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_gateway = string_to_ip(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip);
+
+static int on_netmask(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_netmask = string_to_ip(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(netmask, on_netmask);
+
+static int on_serverip(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_server_ip = string_to_ip(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(serverip, on_serverip);
+
+static int on_nvlan(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_native_vlan = string_to_vlan(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(nvlan, on_nvlan);
+
+static int on_vlan(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_our_vlan = string_to_vlan(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(vlan, on_vlan);
+
+#if defined(CONFIG_CMD_DNS)
+static int on_dnsip(const char *name, const char *value, enum env_op op,
+ int flags)
+{
+ if (flags & H_PROGRAMMATIC)
+ return 0;
+
+ net_dns_server = string_to_ip(value);
+
+ return 0;
+}
+U_BOOT_ENV_CALLBACK(dnsip, on_dnsip);
+#endif
+
/*
* Check if autoload is enabled. If so, use either NFS or TFTP to download
* the boot file.
void net_auto_load(void)
{
#if defined(CONFIG_CMD_NFS)
- const char *s = getenv("autoload");
+ const char *s = env_get("autoload");
if (s != NULL && strcmp(s, "NFS") == 0) {
/*
return;
}
#endif
- if (getenv_yesno("autoload") == 0) {
+ if (env_get_yesno("autoload") == 0) {
/*
* Just use BOOTP/RARP to configure system;
* Do not use TFTP to load the bootfile.
static void net_init_loop(void)
{
- static int env_changed_id;
- int env_id = get_env_id();
-
- /* update only when the environment has changed */
- if (env_changed_id != env_id) {
- net_ip = getenv_ip("ipaddr");
- net_gateway = getenv_ip("gatewayip");
- net_netmask = getenv_ip("netmask");
- net_server_ip = getenv_ip("serverip");
- net_native_vlan = getenv_vlan("nvlan");
- net_our_vlan = getenv_vlan("vlan");
-#if defined(CONFIG_CMD_DNS)
- net_dns_server = getenv_ip("dnsip");
-#endif
- env_changed_id = env_id;
- }
if (eth_get_dev())
memcpy(net_ethaddr, eth_get_ethaddr(), 6);
tftp_start_server();
break;
#endif
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+ case FASTBOOT:
+ fastboot_start_server();
+ break;
+#endif
#if defined(CONFIG_CMD_DHCP)
case DHCP:
bootp_reset();
cdp_start();
break;
#endif
-#if defined(CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
+#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD)
case NETCONS:
nc_start();
break;
#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
#if defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN) && \
- defined(CONFIG_STATUS_LED) && \
- defined(STATUS_LED_RED)
+ defined(CONFIG_LED_STATUS) && \
+ defined(CONFIG_LED_STATUS_RED)
/*
* Echo the inverted link state to the fault LED.
*/
if (miiphy_link(eth_get_dev()->name, CONFIG_SYS_FAULT_MII_ADDR))
- status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
+ status_led_set(CONFIG_LED_STATUS_RED, CONFIG_LED_STATUS_OFF);
else
- status_led_set(STATUS_LED_RED, STATUS_LED_ON);
+ status_led_set(CONFIG_LED_STATUS_RED, CONFIG_LED_STATUS_ON);
#endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */
#endif /* CONFIG_MII, ... */
#ifdef CONFIG_USB_KEYBOARD
#ifdef CONFIG_SHOW_ACTIVITY
show_activity(1);
#endif
+ if (arp_timeout_check() > 0)
+ time_start = get_timer(0);
+
/*
* Check the ethernet for a new packet. The ethernet
* receive routine will process it.
/* include a debug print as well incase the debug
messages are directed to stderr */
debug_cond(DEBUG_INT_STATE, "--- net_loop Abort!\n");
+ ret = -EINTR;
goto done;
}
- arp_timeout_check();
-
/*
* Check for a timeout, and run the timeout handler
* if we have one.
#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
#if defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN) && \
- defined(CONFIG_STATUS_LED) && \
- defined(STATUS_LED_RED)
+ defined(CONFIG_LED_STATUS) && \
+ defined(CONFIG_LED_STATUS_RED)
/*
* Echo the inverted link state to the fault LED.
*/
if (miiphy_link(eth_get_dev()->name,
CONFIG_SYS_FAULT_MII_ADDR))
- status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
+ status_led_set(CONFIG_LED_STATUS_RED,
+ CONFIG_LED_STATUS_OFF);
else
- status_led_set(STATUS_LED_RED, STATUS_LED_ON);
+ status_led_set(CONFIG_LED_STATUS_RED,
+ CONFIG_LED_STATUS_ON);
#endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */
#endif /* CONFIG_MII, ... */
debug_cond(DEBUG_INT_STATE, "--- net_loop timeout\n");
if (net_boot_file_size > 0) {
printf("Bytes transferred = %d (%x hex)\n",
net_boot_file_size, net_boot_file_size);
- setenv_hex("filesize", net_boot_file_size);
- setenv_hex("fileaddr", load_addr);
+ env_set_hex("filesize", net_boot_file_size);
+ env_set_hex("fileaddr", load_addr);
}
if (protocol != NETCONS)
eth_halt();
unsigned long retrycnt = 0;
int ret;
- nretry = getenv("netretry");
+ nretry = env_get("netretry");
if (nretry) {
if (!strcmp(nretry, "yes"))
retry_forever = 1;
retry_forever = 0;
}
- if ((!retry_forever) && (net_try_count >= retrycnt)) {
+ if ((!retry_forever) && (net_try_count > retrycnt)) {
eth_halt();
net_set_state(NETLOOP_FAIL);
/*
#ifndef CONFIG_NET_MAXDEFRAG
#define CONFIG_NET_MAXDEFRAG 16384
#endif
-/*
- * MAXDEFRAG, above, is chosen in the config file and is real data
- * so we need to add the NFS overhead, which is more than TFTP.
- * To use sizeof in the internal unnamed structures, we need a real
- * instance (can't do "sizeof(struct rpc_t.u.reply))", unfortunately).
- * The compiler doesn't complain nor allocates the actual structure
- */
-static struct rpc_t rpc_specimen;
-#define IP_PKTSIZE (CONFIG_NET_MAXDEFRAG + sizeof(rpc_specimen.u.reply))
+#define IP_PKTSIZE (CONFIG_NET_MAXDEFRAG)
#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE)
if (len < ETHER_HDR_SIZE)
return;
-#ifdef CONFIG_API
+#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
if (push_packet) {
(*push_packet)(in_packet, len);
return;
}
#endif
-#if defined(CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
+#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD)
nc_input_packet((uchar *)ip + IP_UDP_HDR_SIZE,
src_ip,
ntohs(ip->udp_dst),
/* Fall through */
case NETCONS:
+ case FASTBOOT:
case TFTPSRV:
if (net_ip.s_addr == 0) {
puts("*** ERROR: `ipaddr' not set\n");
return htons(id);
}
-ushort getenv_vlan(char *var)
+ushort env_get_vlan(char *var)
{
- return string_to_vlan(getenv(var));
+ return string_to_vlan(env_get(var));
}