History log of /u-boot/net/net.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 798962ce 07-Oct-2023 Sean Anderson <seanga2@gmail.com>

net: Add option for tracing packets

Add an option to trace all packets send/received. This can be helpful when
debugging protocol issues, as the packets can then be imported into
wireshark [1] and analyzed further.

[1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7d04986a 14-Oct-2023 Sean Anderson <seanga2@gmail.com>

net: Fix compiling SPL when fastboot is enabled

When fastboot is enabled in U-Boot proper and SPL_NET is enabled, we will
try to (unsuccessfully) reference it in SPL. Fix these linker errors by
conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 8f911a7b 13-Aug-2023 Siddharth Vadapalli <s-vadapalli@ti.com>

net: Fix the displayed value of bytes transferred

In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable
"net_boot_file_size" is printed using "%d", resulting in negative values
being reported for large file sizes. Fix this by using "%u" to print the
decimal value corresponding to the bytes transferred.

Fixes: 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 7d04986a 14-Oct-2023 Sean Anderson <seanga2@gmail.com>

net: Fix compiling SPL when fastboot is enabled

When fastboot is enabled in U-Boot proper and SPL_NET is enabled, we will
try to (unsuccessfully) reference it in SPL. Fix these linker errors by
conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 8f911a7b 13-Aug-2023 Siddharth Vadapalli <s-vadapalli@ti.com>

net: Fix the displayed value of bytes transferred

In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable
"net_boot_file_size" is printed using "%d", resulting in negative values
being reported for large file sizes. Fix this by using "%u" to print the
decimal value corresponding to the bytes transferred.

Fixes: 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 8f911a7b 13-Aug-2023 Siddharth Vadapalli <s-vadapalli@ti.com>

net: Fix the displayed value of bytes transferred

In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable
"net_boot_file_size" is printed using "%d", resulting in negative values
being reported for large file sizes. Fix this by using "%u" to print the
decimal value corresponding to the bytes transferred.

Fixes: 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 0d6d5a4a 06-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Add missing break into IPv6 protocol handler

IPv6 protocol handler is not terminated with a break statment.
It can lead to running unexpected code.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7fbf230d 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: tftp: Add IPv6 support for tftpboot

The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
instead. If an address in the command is an IPv6 address it will use IPv6
to boot or if there is a suffix -ipv6 in the end of the command it also
force using IPv6. All other tftpboot features and parameters are left
the same.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ffdbf3ba 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 06869686 17-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: deal with fragment-overlapping-two-holes case

With a suitable sequence of malicious packets, it's currently possible
to get a hole descriptor to contain arbitrary attacker-controlled
contents, and then with one more packet to use that as an arbitrary
write vector.

While one could possibly change the algorithm so we instead loop over
all holes, and in each hole puts as much of the current fragment as
belongs there (taking care to carefully update the hole list as
appropriate), it's not worth the complexity: In real, non-malicious
scenarios, one never gets overlapping fragments, and certainly not
fragments that would be supersets of one another.

So instead opt for this simple protection: Simply don't allow the
eventual memcpy() to write beyond the last_byte of the current hole.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 06653c70 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: fix ip_len in reassembled IP datagram

For some reason, the ip_len field in a reassembled IP datagram is set
to just the size of the payload, but it should be set to the value it
would have had if the datagram had never been fragmented in the first
place, i.e. size of payload plus size of IP header.

That latter value is currently returned correctly via the "len"
variable. And before entering net_defragment(), len does have the
value ntohs(ip->ip_len), so if we're not dealing with a
fragment (so net_defragment leaves *len alone), that relationship of
course also holds after the net_defragment() call.

The only use I can find of ip->ip_len after the net_defragment call is
the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the
functions that are passed the "ip" pointer themselves inspect ->ip_len
but instead use the passed len.

But that sanity check is a bit odd, since the RHS really should be
"ntohs(ip->ip_len) - 20", i.e. the IP payload size.

Now that we've fixed things so that len == ntohs(ip->ip_len) in all
cases, change that sanity check to use len-20 as the RHS.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# 1817c382 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: (actually/better) deal with CVE-2022-{30790,30552}

I hit a strange problem with v2022.10: Sometimes my tftp transfer
would seemingly just hang. It only happened for some files. Moreover,
changing tftpblocksize from 65464 to 65460 or 65000 made it work again
for all the files I tried. So I started suspecting it had something to
do with the file sizes and in particular the way the tftp blocks get
fragmented and reassembled.

v2022.01 showed no problems with any of the files or any value of
tftpblocksize.

Looking at what had changed in net.c or tftp.c since January showed
only one remotely interesting thing, b85d130ea0ca.

So I fired up wireshark on my host to see if somehow one of the
packets would be too small. But no, with both v2022.01 and v2022.10,
the exact same sequence of packets were sent, all but the last of size
1500, and the last being 1280 bytes.

But then it struck me that 1280 is 5*256, so one of the two bytes
on-the-wire is 0 and the other is 5, and when then looking at the code
again the lack of endianness conversion becomes obvious. [ntohs is
both applied to ip->ip_off just above, as well as to ip->ip_len just a
little further down when the "len" is actually computed].

IOWs the current code would falsely reject any packet which happens to
be a multiple of 256 bytes in size, breaking tftp transfers somewhat
randomly, and if it did get one of those "malicious" packets with
ip_len set to, say, 27, it would be seen by this check as being 6912
and hence not rejected.

====

Now, just adding the missing ntohs() would make my initial problem go
away, in that I can now download the file where the last fragment ends
up being 1280 bytes. But there's another bug in the code and/or
analysis: The right-hand side is too strict, in that it is ok for the
last fragment not to have a multiple of 8 bytes as payload - it really
must be ok, because nothing in the IP spec says that IP datagrams must
have a multiple of 8 bytes as payload. And comments in the code also
mention this.

To fix that, replace the comparison with <= IP_HDR_SIZE and add
another check that len is actually a multiple of 8 when the "more
fragments" bit is set - which it necessarily is for the case where
offset8 ends up being 0, since we're only called when

(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)).

====

So, does this fix CVE-2022-30790 for real? It certainly correctly
rejects the POC code which relies on sending a packet of size 27 with
the MFRAG flag set. Can the attack be carried out with a size 27
packet that doesn't set MFRAG (hence must set a non-zero fragment
offset)? I dunno. If we get a packet without MFRAG, we update
h->last_byte in the hole we've found to be start+len, hence we'd enter
one of

if ((h >= thisfrag) && (h->last_byte <= start + len)) {

or

} else if (h->last_byte <= start + len) {

and thus won't reach any of the

/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);

/* fragment sits in the middle: split the hole */
newh = thisfrag + (len / 8);

IOW these division are now guaranteed to be exact, and thus I think
the scenario in CVE-2022-30790 cannot happen anymore.

====

However, there's a big elephant in the room, which has always been
spelled out in the comments, and which makes me believe that one can
still cause mayhem even with packets whose payloads are all 8-byte
aligned:

This code doesn't deal with a fragment that overlaps with two
different holes (thus being a superset of a previously-received
fragment).

Suppose each character below represents 8 bytes, with D being already
received data, H being a hole descriptor (struct hole), h being
non-populated chunks, and P representing where the payload of a just
received packet should go:

DDDHhhhhDDDDHhhhDDDD
PPPPPPPPP

I'm pretty sure in this case we'd end up with h being the first hole,
enter the simple

} else if (h->last_byte <= start + len) {
/* overlaps with final part of the hole: shorten this hole */
h->last_byte = start;

case, and thus in the memcpy happily overwrite the second H with our
chosen payload. This is probably worth fixing...

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# ad359d89 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: compare received length to sizeof(ip_hdr), not sizeof(ip_udp_hdr)

While the code mostly/only handles UDP packets, it's possible for the
last fragment of a fragmented UDP packet to be smaller than 28 bytes;
it can be as small as 21 bytes (an IP header plus one byte of
payload). So until we've performed the defragmentation step and thus
know whether we're now holding a full packet, we should only check for
the existence of the fields in the ip header, i.e. that there are at
least 20 bytes present.

In practice, we always seem to be handed a "len" of minimum 60 from the
device layer, i.e. minimal ethernet frame length minus FCS, so this is
mostly theoretical.

After we've fetched the header's claimed length and used that to
update the len variable, check that the header itself claims to be the
minimal possible length.

This is probably how CVE-2022-30552 should have been dealt with in the
first place, because net_defragment() is not the only place that wants
to know the size of the IP datagram payload: If we receive a
non-fragmented ICMP packet, we pass "len" to receive_icmp() which in
turn may pass it to ping_receive() which does

compute_ip_checksum(icmph, len - IP_HDR_SIZE)

and due to the signature of compute_ip_checksum(), that would then
lead to accessing ~4G of address space, very likely leading to a
crash.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

# b0fcc48c 14-Oct-2022 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: improve check for no IP options

There's no reason we should accept an IP packet with a malformed IHL
field. So ensure that it is exactly 5, not just <= 5.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 4b290d4a 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

cmd: Add ncsi command

Adds an "ncsi" command to manually start NC-SI configuration.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 29caf930 02-Sep-2022 Stefan Roese <sr@denx.de>

cyclic: Use schedule() instead of WATCHDOG_RESET()

Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 85f8e03b 16-Apr-2022 Lyle Franklin <lylejfranklin@gmail.com>

Allow colon in PXE bootfile URLs

- U-boot's PXE flow supports prefixing your bootfile name with an
IP address to fetch from a server other than the DHCP server,
e.g. `hostIPaddr:bootfilename`:
https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
`f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
IP address before overriding the serverIP otherwise the whole
bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@amd.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@denx.de>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wd@denx.de>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wd@denx.de>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wd@denx.de>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wd@denx.de>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wd@denx.de>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wd@denx.de>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wd@denx.de>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wd@denx.de>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 43407539 18-Dec-2021 Simon Glass <sjg@chromium.org>

net: Drop #ifdefs with CONFIG_BOOTP_SERVERIP

Use IS_ENABLED() instead, to reduce the number of build paths.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 4b37fd14 18-Dec-2021 Simon Glass <sjg@chromium.org>

Convert CONFIG_UDP_CHECKSUM to Kconfig

This converts the following to Kconfig:
CONFIG_UDP_CHECKSUM

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# d9506cd4 20-Dec-2020 Yang Liu <yliu@cybertec.com.au>

net: fix ping in netconsole

Should not init eth device when doing ping in netconsole.

Signed-off-by: Yang Liu <yliu@cybertec.com.au>
Cc: Joe Hershberger <joe.hershberger@ni.com>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 912ece4c 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# def7a5c0 15-Jun-2020 Marek Szyprowski <m.szyprowski@samsung.com>

net: ping: reset stored IP address

Reset the stored ping IP address before entering a netloop with different
protocol to ensure that it won't be interrupted by the received
correct ICMP_ECHO_REPLY packet.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 808f13d8 09-Mar-2020 Krebs, Olaf <Olaf.Krebs@emh-metering.com>

net: Fix error if some network features are disabled

If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too!

Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com>
CC: Joe Hershberger <joe.hershberger@ni.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 215df01d 07-Feb-2020 Rasmus Villemoes <rasmus.villemoes@prevas.dk>

net: convert NET_MAXDEFRAG to Kconfig

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

These global variables are quite short and generic. In fact the same name
is more often used locally for struct members and function arguments.

Add a image_ prefix to make them easier to distinguish.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 Wolfgang Denk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 Wolfgang Denk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 Wolfgang Denk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 Wolfgang Denk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 Wolfgang Denk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 Wolfgang Denk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 Wolfgang Denk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 Wolfgang Denk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 Wolfgang Denk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 Wolfgang Denk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 8524423d 04-Nov-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: avoid address-of-packed-member error

sandbox_defconfig does not compile using GCC 9.2.1:

net/net.c: In function ‘net_process_received_packet’:
net/net.c:1288:23: error: taking address of packed member of ‘struct
ip_udp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1288 | sumptr = (ushort *)&(ip->udp_src);
| ^~~~~~~~~~~~~~

Avoid the error by using a u8 pointer instead of an u16 pointer and
in-lining ntohs().

Simplify the checksumming of the last message byte.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a6ab4b54 05-Dec-2019 Tom Rini <trini@konsulko.com>

net: nfs: Only link in NFS code outside of SPL builds

While we have networking use cases within SPL we do not support loading
files via NFS at this point in time. Disable calling nfs_start() so
that the NFS related code can be garbage collected at link time.

Signed-off-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 wdenk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 wdenk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 wdenk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 wdenk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 wdenk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 wdenk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 wdenk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 wdenk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 wdenk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 wdenk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 wdenk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 wdenk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# 9ce2aa17 14-Nov-2019 Simon Glass <sjg@chromium.org>

Drop CONFIG_SHOW_ACTIVITY

This feature is not enabled by any board. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 wdenk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 wdenk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 wdenk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 wdenk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 wdenk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 wdenk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 wdenk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 wdenk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 wdenk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 wdenk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 wdenk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 wdenk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# fe728806 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: net: fix unbounded memcpy of UDP packet

This patch adds a check to udp_len to fix unbounded memcpy for
CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3eaac630 18-Jul-2019 Ramon Fried <rfried.dev@gmail.com>

net: introduce packet capture support

Add support for capturing ethernet packets and storing
them in memory in PCAP(2.4) format, later to be analyzed by
any PCAP viewer software (IE. Wireshark)

This feature greatly assist debugging network issues such
as detecting dropped packets, packet corruption etc.

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Alex Marginean <alexm.osslist@gmail.com>
Tested-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f3998fdc 02-Aug-2019 Simon Glass <sjg@chromium.org>

env: Rename environment.h to env_internal.h

This file contains lots of internal details about the environment. Most
code can include env.h instead, calling the functions there as needed.

Rename this file and add a comment at the top to indicate its internal
nature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
[trini: Fixup apalis-tk1.c]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# c7694dd4 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set_hex() to env.h

Move env_set_hex() over to the new header file along with env_set_addr()
which uses it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a735e6e9 21-Nov-2018 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: explicitly assign errno to return code in case of network failure

When dealing with two ethernet ports and having "netretry" set
to "once", it could occur that the connection (e.g. an ARP
request) failed, hence the status of the netloop was
"NETLOOP_FAIL". Due to the setting of "netretry", the network
logic would then switch to the other network interface,
assigning "ret" with the return value of "net_start_again()".
If this call succeeded we would return 0 (i.e. success) to
the caller when in reality the network action failed.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>

# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>

# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>

# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>

# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>

# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>

# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>

# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# c645b181 08-Dec-2008 Wolfgang Denk <wd@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-net


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.

# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004

# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005

# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x

# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup

# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005

# 90dc6704 03-May-2005 wdenk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation

# 63153492 03-Apr-2005 wdenk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset

# b1bf6f2c 03-Apr-2005 wdenk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README

# 59acc296 03-Apr-2005 wdenk <wdenk>

Minor cleanup

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 289f932c 11-Jan-2005 wdenk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)

# d407bf52 11-Oct-2004 wdenk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# b9711de1 25-Apr-2004 wdenk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment

# 6e592385 18-Apr-2004 wdenk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# 3d3befa7 14-Mar-2004 wdenk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fc3e2165 08-Oct-2003 wdenk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# e0ac62d7 17-Aug-2003 wdenk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 0b97ab14 19-Jun-2003 wdenk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>


# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# f43308fa 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Read bootfile from env on netboot_common()

Instead of depending on a env callback for bootfile, read it explicitly.

We do this because the bootfile can be specified on the command line and
if it is, we will overwrite the internal variable. If a netboot_common()
is called again with no bootfile parameter, we want to use the one in
the environment.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 16cf145f 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Make copy_filename() accept NULL src

Rather than crashing, check the src ptr and set dst to empty string.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 3855cad6 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Re-check prerequisites when autoloading

With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>


# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 60177b26 08-May-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Protect net_state from reentrant net_loop()

Global variable "net_state" is used in net_loop() state-machine.
But it happens that some times the net_loop() can be called
multiple times in the same call stack. For example when the
netconsole is enabled and we print the message while some other
net protocol is in action. Netconsole will overwrite the "net_state"
and that will break the logic for earlier started protocol.

To protect the state save and restore "net_state" variable each
time when we enter and exit net_loop().

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>


# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>


# 17d413b2 09-Mar-2018 Leonid Iziumtsev <leonid.iziumtsev@gmail.com>

net: Fix netretry condition

The "net_try_count" counter starts from "1".
And the "retrycnt" contains requested amount of retries.

With current logic, that means that the actual retry amount
will be one time less then what we set in "netretry" env.
For example setting "netretry" to "once" will make "retrycnt"
equal "1", so no retries will be triggered at all.

Fix the logic by changing the statement of "if" condition.

Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>


# bfebc8c9 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()

We are now using an env_ prefix for environment functions. Rename these
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>


# 00caae6d 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>


# 018f5303 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename common functions related to setenv()

We are now using an env_ prefix for environment functions. Rename these
commonly used functions, for consistency. Also add function comments in
common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>


# 66c89ee3 20-Jul-2017 Holger Dengler <dengler@linutronix.de>

net: Fix compile failure in net.c

Add missing "defined" statement to fix the compile failures.

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 2d8d190c 19-Jan-2017 Uri Mashiach <uri.mashiach@compulab.co.il>

status_led: Kconfig migration

Move all of the status LED feature to drivers/led/Kconfig.
The LED status definitions were moved from the board configuration
files to the defconfig files.

TBD: Move all of the definitions in the include/status_led.h to the
relevant board's defconfig files.

Tested boards: CL-SOM-AM57x, CM-T335

Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>


# aa7a6487 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: Stop including NFS overhead in defragment max

At least on bfin, this "specimen" is actually allocated in the BSS and
wastes lots of memory in already tight memory conditions.

Also, with the introduction of NFSv3 support, this waste got
substantially larger.

Just remove it. If a board needs a specific different defragment size,
that board can override this setting.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>


# c5a75339 21-Dec-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Fix delay in net_retry test

Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout)

Check the arp timeout and adjust the timeout start time before the call
to eth_recv() so that the sandbox driver has the opportunity to adjust
the sandbox timer after the new start time has been recorded.

Also, change the adjustment amount by 11 seconds instead of exactly the
10 seconds that the ping timout is expecting since the timeout check is
looking for the time elapsed to be greater than but not equal to the
specified delay.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Simon Glass <sjg@chromium.org>


# 24b852a7 08-Nov-2015 Simon Glass <sjg@chromium.org>

Move console definitions into a new console.h file

The console includes a global variable and several functions that are only
used by a small subset of U-Boot files. Before adding more functions, move
the definitions into their own header file.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 45b47734 30-Aug-2015 Stefan Brüns <stefan.bruens@rwth-aachen.de>

net/arp: account for ARP delay, avoid duplicate packets on timeout

eth_rx() in the main reception loop may trigger sending a packet which
is already timed out (or will immediately) upon reception of an ARP reply.
As long as the ARP reply is pending, the timeout handler of a packet
should be postponed.
Happens on TFTP with bad network (e.g. WLAN).

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 34696958 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

net: tftp: Move tftp.h file from ./net to ./include/net

This change gives the ability to reuse the <tftp.h> header file by other
subsystems (like e.g. dfu).

Without this change compilation error emerges for the legacy update.c file.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 19a4fbaa 21-Aug-2015 Michal Simek <michal.simek@xilinx.com>

net: Return -EINTR when ctrl+c is pressed

Current behavior is that if CTRL+C is pressed command returns 0 that was
successful which is not correct behavior.
The easiest test case is "tftpboot 80000 uImage && echo yes"
and press CTRL+C. Then the second command is called which is incorrect.

Error log:
zynq-uboot> tftpb 80000 uImage && echo yes
Gem.e000b000:7 is connected to Gem.e000b000. Reconnecting to
Gem.e000b000
Gem.e000b000 Waiting for PHY auto negotiation to complete....... done
Using Gem.e000b000 device
TFTP from server 192.168.0.102; our IP address is 192.168.0.101
Filename 'uImage'.
Load address: 0x80000
Loading: ################
Abort
yes
zynq-uboot>

This patch adds -EINTR return value when CTRL+C is pressed.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# fd305633 20-May-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 38ba2558 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up SNTP variables and functions

Make a thorough pass through all variables and function names contained
within sntp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 698d78e5 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up RARP variables and functions

Make a thorough pass through all variables and function names contained
within rarp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 7044c6bb 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DHCP variables and functions

Make a thorough pass through all variables and function names contained
within bootp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 85d25e0e 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up ARP variables and functions

Make a thorough pass through all variables and function names contained
within arp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 8885c5fe 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up TFTP variables and functions

Make a thorough pass through all variables and function names contained
within tftp and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 5c421331 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Make netretry actually do something

netretry previously would only retry in one specific case (your MAC
address is not set) and no other. This is basically useless. In the DM
implementation for eth it turns this into a completely useless case
since an un-configured MAC address results in not even entering the
NetLoop. The behavior is now changed to retry any failed command
(rotating through the eth adapters if ethrotate != no).

It also defaulted to retry forever. It is now changed to default to not
retry

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)


# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# f59be6e8 25-Jul-2014 Stephen Warren <swarren@nvidia.com>

net: BOOTP retry timeout improvements

Currently, the BOOTP code sends out its initial request as soon as the
Ethernet driver indicates "link up". If this packet is lost or not
replied to for some reason, the code waits for a 1s timeout before
retrying. For some reason, such early packets are often lost on my
system, so this causes an annoying delay.

To optimize this, modify the BOOTP code to have very short timeouts for
the first packet transmitted, but gradually increase the timeout each
time a timeout occurs. This way, if the first packet is lost, the second
packet is transmitted quite quickly and hence the overall delay is low.
However, if there's still no response, we don't keep spewing out packets
at an insane speed.

It's arguably more correct to try and find out why the first packet is
lost. However, it seems to disappear inside my Ethenet chip; the TX chip
indicates no error during TX (not that it has much in the way of
reporting...), yet wireshark on the RX side doesn't see any packet.
FWIW, I'm using an ASIX USB Ethernet adapter. Perhaps "link up" is
reported too early or based on the wrong condition in HW, and we should
add some fixed extra delay into the driver. However, this would slow down
every link up event even if it ends up not being needed in some cases.
Having BOOTP retry quickly applies the fix/WAR to every possible
Ethernet device, and is quite simple to implement, so seems a better
solution.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 1f9ce306 12-Jun-2014 Hannes Petermaier <oe5hpm@oevsv.at>

fix: CONFIG_NETCONSOLE start/handle this stuff only outside SPL

SPL stage does not support various networking things, and therefore
CONFIG_NETCONSOLE cannot be built within SPL.

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>


# b63056d6 13-Aug-2013 Jim Lin <jilin@nvidia.com>

NET: Add net_busy_flag if CONFIG_USB_KEYBOARD is defined

This flag is to make console aware that NET transfer is running or not.

Signed-off-by: Jim Lin <jilin@nvidia.com>


# 7315cfd9 17-May-2013 Jim Lin <jilin@nvidia.com>

NET: Fix system hanging if NET device is not installed

If we try to boot from NET device, NetInitLoop in net.c will be invoked.
If NET device is not installed, eth_get_dev() function will return
eth_current value, which is NULL.
When NetInitLoop is called, "eth_get_dev->enetaddr" will access
restricted memory area and therefore cause hanging.
This issue is found on Tegra30 Cardhu platform after adding
CONFIG_CMD_NET and CONFIG_CMD_DHCP in config header file.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>


# 978226da 24-Feb-2013 Simon Glass <sjg@chromium.org>

net: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in net/

Signed-off-by: Simon Glass <sjg@chromium.org>


# a9f51c9b 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Add a bootfile env handler

Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# ec8a252c 11-Dec-2012 Joe Hershberger <joe.hershberger@ni.com>

env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>


# 8cab08e8 03-Oct-2012 Joe Hershberger <joe.hershberger@ni.com>

net: fix netconsole filtering

Adjustment of Michael Walle's fix patch

Commit 8a0eccb1056b313b45ab62e3aac400f339aa71b4 breaks netconsole. src_ip
must not be converted to host byte order, because nc_ip is already stored
in network byte order (see string_to_ip(), called by getenv_IPaddr()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>


# 1389f98f 24-Jun-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: bugfix: NetSetTimeout assumes CONFIG_SYS_HZ=1000

NetSetTimeout sets incorrect value to timeDelta when CONFIG_SYS_HZ != 1000.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>


# a03d6388 23-Jul-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Make sure the ethaddr is updated in net_init()

NetConsole may call NetSendUDPPacket before NetLoop is called. This
will cause the source MAC address (NetOurEther) to be wrong. Instead
of only changing it in NetLoop, move it to NetLoopInit so that it is
also updated when net_init() is called (especially by nc_start()).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>


# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# cb1c9911 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unused parameter from NetInitLoop()

Noone uses it.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 9214637a 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor NetSendUDPPacket to share more code

Share more of the code that is common between ARP vs not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 4545f4e6 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Alphabetize includes in net.c

Easier to find when alphabetized

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 0b4c5ff4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename CDPHandler to cdp_receive

This is not called as a handler, so don't name it that way

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 8d353eb8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename "x" to "eth_proto"

x is a poor variable name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 8b9c5322 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move RARP receive logic out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# a36b12f9 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move PING out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 50a47d05 04-Apr-2012 Mike Frysinger <vapier@gentoo.org>

net: punt bd->bi_ip_addr

This field gets read in one place (by "bdinfo"), and we can replace
that with getenv("ipaddr"). After all, the bi_ip_addr field is kept
up-to-date implicitly with the value of the ipaddr env var.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>


# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 573f14fe 10-Dec-2011 Simon Glass <sjg@chromium.org>

bootstage: Plumb in bootstage calls for basic operations

This inserts bootstage calls into tftp, usb start and bootm. We
could go further, but this is a reasonable start to illustrate
the concept.

Signed-off-by: Simon Glass <sjg@chromium.org>


# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 5c10419c 04-Nov-2011 Wolfgang Denk <wd@denx.de>

net/net.c: Fix GCC 4.6 build warning

Fix:
net.c: In function 'CDPHandler':
net.c:1083:8: warning: variable 'applid' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>


# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# ed1ada71 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Change for loop to memset()

This is intended purely as a code size reduction.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 39bccd21 26-Oct-2011 Simon Glass <sjg@chromium.org>

net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>


# 1fb7cd49 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: implement tftp logic

This adds logic to tftp.c to implement the tftp 'put' command, and
updates the README.

Signed-off-by: Simon Glass <sjg@chromium.org>


# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 8f79bb17 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Move ICMP code into its own function

NetReceive() is a very long function with a lot of indent. Before adding
code to the ICMP bit, split it out.

Signed-off-by: Simon Glass <sjg@chromium.org>


# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# 23a70bf9 31-May-2011 Enric Balletbo i Serra <eballetbo@iseebcn.com>

net/net.c: Update ipaddr if the environment has changed

At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

ipaddr=192.168.2.240
netmask=255.255.255.0
gatewayip=192.168.2.1
serverip=192.168.2.114

Then if you try boot from NFS results in:

Importing environment from mmc ...
Running uenvcmd ...
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC ac:de:48:00:00:00
*** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>


# ccb9ebef 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: do not use assignment in if condition

This removes the following checkpatch issue:
- ERROR: do not use assignment in if condition

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>


# c819abee 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix indentation

This removes the following checkpatch issues:
- ERROR: switch and case should be at the same indent
- WARNING: suspect code indent for conditional statements
- WARNING: labels should not be indented

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>


# 92895de9 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: parentheses not required for return

This removes the following checkpatch issue:
- ERROR: return is not a function, parentheses are not required

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>


# 6b147d11 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix pointer syntax issues

This removes the following checkpatch issues:
- ERROR: "foo * bar" should be "foo *bar"
- ERROR: "(foo*)" should be "(foo *)"

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>


# d3c65b01 03-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix brace issues

This removes the following checkpatch issues:
- WARNING: braces {} are not necessary for single statement blocks
- WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>


# 4f63acd0 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix whitespace issues

This removes the following checkpatch issues:
- ERROR: space prohibited after that open parenthesis '('
- ERROR: space prohibited before that close parenthesis ')'
- ERROR: space prohibited after that open square bracket '['
- ERROR: space prohibited after that '&' (ctx:WxW)
- ERROR: spaces required around that '=' (ctx:VxW)
- ERROR: space required before the open parenthesis '('
- ERROR: space required after that ',' (ctx:VxV)
- ERROR: need consistent spacing around '+' (ctx:WxV)
- WARNING: unnecessary whitespace before a quoted newline
- WARNING: please, no spaces at the start of a line
- WARNING: space prohibited between function name and open
parenthesis '('

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>


# c586ce6e 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: variable initializations

This removes the following checkpatch errors:
- ERROR: do not initialise globals to 0 or NULL
- ERROR: spaces required around that '=' (ctx:VxV)
- ERROR: that open brace { should be on the previous line

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>


# 3e38e429 10-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

net/net.c: cosmetic: fix lines over 80 characters

This removes the following checkpatch warning:
- WARNING: line over 80 characters

There are three such warnings left.

The first is hard to fix with cosmetic-only changes without compromising code
readability, so I'm leaving it as it is for now:
WARNING: line over 80 characters
#1537: FILE: net.c:1537:
+ [4 tabs] memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, ...

The other two cannot be fixed without splitting string literals, so it is
preferred to keep them longer than 80 characters.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Ben Warren <biggerbadderben@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>


# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>


# 8b6bbe10 01-May-2011 Simon Guinot <sguinot@lacie.com>

netconsole: remove `serverip' check

Netconsole use the environment variable `ncip' to configure the
destination IP. `serverip' don't need to be defined.

Signed-off-by: Simon Guinot <sguinot@lacie.com>


# 9030a55e 29-Mar-2011 Gray Remlin <gryrmln@gmail.com>

NET: Correct potential missing goto label in case statement.

If neither CONFIG_CMD_PING or CONFIG_CMD_SNTP are defined but
CONFIG_CMD_DNS is, a compile-time error will occur due to the
absence of a goto label.

Signed-off-by: Gray Remlin <gryrmln@gmail.com>


# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# bf6cb247 30-Sep-2010 Peter Tyser <ptyser@xes-inc.com>

rarp: Condtionally compile rarp support

Most people don't use the 'rarpboot' command, so only enable it when
CONFIG_CMD_RARP is defined.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# e397e59e 11-Jun-2010 Fillod Stephane <stephane.fillod@grassvalley.com>

ip/defrag: fix processing of last short fragment

TFTP'ing a file of size 1747851 bytes with CONFIG_IP_DEFRAG and
CONFIG_TFTP_BLOCKSIZE set to 4096 fails with a timeout, because
the last fragment is not taken into account. This patch fixes
IP fragments having less than 8 bytes of payload.

Signed-off-by: Stephane Fillod <stephane.fillod@grassvalley.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 9739946c 08-Mar-2010 Robin Getz <rgetz@blackfin.uclinux.org>

./net/net.c - make Microsoft dns servers happy with random_port() numbers

For some reason, (which I can't find any documentation on), if U-Boot
gives a port number higher than 17500 to a Microsoft DNS server, the
server will reply to port 17500, and U-Boot will ignore things (since
that isn't the port it asked the DNS server to reply to).

This fixes that by ensuring the random port number is less than 17500.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>


# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 67b96e87 28-Oct-2009 Remy Bohmer <linux@bohmer.net>

Repair the 'netretry=once' option.

'netretry = once' does the same as 'netretry = yes', because it is not stored
when it was tried once.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 5cfaa4e5 07-Aug-2009 Alessandro Rubini <rubini-list@gnudd.com>

net: defragment IP packets

The defragmenting code is enabled by CONFIG_IP_DEFRAG; the code is
useful for TFTP and NFS transfers. The user can specify the maximum
defragmented payload as CONFIG_NET_MAXDEFRAG (default 16k).
Since NFS has a bigger per-packet overhead than TFTP, the static
reassembly buffer can hold CONFIG_NET_MAXDEFRAG + the NFS overhead.

The packet buffer is used as an array of "hole" structures, acting as
a double-linked list. Each new fragment can split a hole in two,
reduce a hole or fill a hole. No support is there for a fragment
overlapping two diffrent holes (i.e., thre new fragment is across an
already-received fragment).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 97cfe861 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Save server's MAC address in environment

Linux's netconsole works much better when you can pass it the MAC address of
the server. (otherwise it just uses broadcast, which everyone else on my
network complains about :)

This sets the env var "serveraddr" (to match ethaddr), so that you can pass
it to linux with whatever bootargs you want to....

addnetconsole=set bootargs $(bootargs) netconsole=@$(ipaddr)/eth0,@$(serverip)/$(serveraddr)

Signed-of-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 09133f85 14-Jul-2009 Michael Zaidman <michael.zaidman@gmail.com>

DHCP regression on 2009-06

Fixed the DHCP/BOOTP/RARP regression introduced in u-boot-2009.06
by initializing our IP addr to 0 in order to accept any IP addr
assigned to us by the DHCP/BOOTP/RARP server.

Ack-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# da95427c 28-Apr-2009 Heiko Schocher <hs@denx.de>

netloop: updates for NetLoop

Fix some issues introduced from commit:
2f70c49e5b9813635ad73666aa30f304c7fdeda9
suggested by Mike Frysinger.

- added some comment for the env_id variable in common_cmd_nvedit.c
- moved some variables in fn scope instead of file scope
- NetInitLoop now static void

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Ben Warren <biggerbadderben@gmail.com>


# 3c172c4f 03-Apr-2009 Michael Zaidman <michael.zaidman@gmail.com>

NetLoop initialization bug

The patch fixes the bug of partial initialization of global network
parameters.

Upon u-boot's start up the first ping command causes a failure of the
consequent TFTP command. It happens in the recently added mechanism of
the NetLoop initialization where initialization of global network
parameters is separated in the NetInitLoop routine which is called per
env_id change. Thus, ping request will initialize the network parameters
necessary for ping operation only, afterwards the env_changed_id will be
set to the env_id that will prevent all following initialization requests
from other protocols.
The problem is that the initialized by ping subset of network parameters
is not sufficient for other protocols and particularly for TFTP which
requires the NetServerIp also.

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 95823ca0 11-Feb-2009 Mike Frysinger <vapier@gentoo.org>

net: get mac address from environment and use eth util funcs

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>


# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>


# 2f70c49e 10-Feb-2009 Heiko Schocher <hs@denx.de>

netloop: speed up NetLoop

NetLoop polls every cycle with getenv some environment variables.
This is horribly slow, especially when the environment is big.

This patch reads only the environment variables in NetLoop,
when they were changed.

Also moved the init part of the NetLoop function in a seperate
function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# af8626e0 22-Jan-2009 Olav Morken <olavmrk@gmail.com>

Fix IP alignment problem

This patch removes volatile from:
volatile IP_t *ip = (IP_t *)xip;

Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when
using volatile, which causes an exception since xip isn't aligned on a word
boundary.

Signed-off-by: Gunnar Rangoy <gunnar@rangoy.com>
Signed-off-by: Paul Driveklepp <pauldriveklepp@gmail.com>
Signed-off-by: Olav Morken <olavmrk@gmail.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 561858ee 03-Nov-2008 Peter Tyser <ptyser@xes-inc.com>

Update U-Boot's build timestamp on every compile

Use the GNU 'date' command to auto-generate a new U-Boot
timestamp on every compile.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>


# d32c5be5 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Add additional IP fragmentation check

Ignore IP packets which have the "more fragments" flag bit
set. This flag indicates the IP packet is fragmented and
must be ignored by U-Boot.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>


# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 25dbe98a 13-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more printf() format issues.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 0a5676be 12-Jul-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix some more printf() format issues.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>


# 9b55a253 10-Jul-2008 Wolfgang Denk <wd@denx.de>

Fix some more print() format errors.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 6b52cfe1 03-Jun-2008 Remy Bohmer <linux@bohmer.net>

Get rid of annoying/superfluous bad-checksum warning message

U-boot can complain a lot about 'checksum bad' when it is attached to the network.
It is annoying for ordinary users who start to doubt the network connection
in general when they see messages like this.

This is caused by the routine NetCksumOk() which cannot handle IP-headers longer
than 20 bytes. Those packages can be ignored anyway by U-boot, so we trash them
now before checking the checksum.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 40cb90ee 03-Apr-2008 Guennadi Liakhovetski <lg@denx.de>

net: make ARP timeout configurable

Currently the timeout waiting for an ARP reply is hard set to 5 seconds.
On i.MX31ADS due to a hardware "strangeness" up to four first IP packets
to the boards get lost, which typically are ARP replies. By configuring
the timeout to a lower value we significantly improve the first network
transfer time on this board. The timeout is specified in milliseconds,
later internally it is converted to deciseconds, because it has to be
converted to hardware ticks, and CFG_HZ ranges from 900 to 27000000 on
different boards.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 8b0c5c12 27-Dec-2007 Matthias Fuchs <matthias.fuchs@esd-electronics.com>

net: Add CONFIG_NET_DO_NOT_TRY_ANOTHER option

When CONFIG_NET_DO_NOT_TRY_ANOTHER is defined U-Boot's
networking stack does not automatically switch to
another interface. This patch does not touch the default
behavior.

Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c


# f34024d4 11-Sep-2007 Wolfgang Denk <wd@denx.de>

Fix memory corruption problem on STX GP3 SSA Board.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 85eb5caf 14-Aug-2007 Wolfgang Denk <wd@denx.de>

Coding style cleanup; rebuild CHANGELOG


# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>


# 610f2e9c 10-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove lingering references to CFG_CMD_* symbols.

Fixed some broken instances of "#ifdef CMD_CFG_IDE" too.
Those always evaluated TRUE, and thus were always compiled
even when IDE really wasn't defined/wanted.

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 83853178 06-Mar-2007 Ed Swarthout <Ed.Swarthout@freescale.com>

net - Support ping reply when processing net-loop

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp). This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>


# d87080b7 31-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

GCC-4.x fixes: clean up global data pointer initialization for all boards.


# d509b812 11-Mar-2006 Wolfgang Denk <wd@pollux.denx.de>

Fix behaviour if gatewayip is not set
Patch by Robin Gilks, 23 Dec 2004


# 3ada834e 10-Nov-2005 Wolfgang Denk <wd@pollux.(none)>

Add explanation for CDP checksum algorithm


# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.


# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x


# 6d51e505 02-Sep-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup compiler warnings.


# 9d2a873b 30-Aug-2005 Stefan Roese <sr@denx.de>

Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
Removed CFG_CMD_DISPLAY from default commands.
Fixed compiler warning in net.c.
Patch by Stefan Roese, 31 Aug 2005


# 7bc5ee07 25-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Prepare U-Boot for gcc-4.x


# b2f50807 12-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Minor code cleanup


# 8534bf9a 12-Aug-2005 Stefan Roese <sr@denx.de>

Add UPD-Checksum code, fix problem in net.c (return instead of break)
Patch by Reinhard Arlt, 12 Aug 2005


# 90dc6704 03-May-2005 wdenk <wdenk>

README: add explanation about patch policy
net/net.c: fix indentation


# 63153492 03-Apr-2005 wdenk <wdenk>

Patch by David Adair, 27 Oct 2004:
Add missing 440GX SDRAM Controller reset


# b1bf6f2c 03-Apr-2005 wdenk <wdenk>

* Patch by Richard Klingler, 03 Apr 2005:
Add call to eth_halt() in net/net.c when called functions fail
after eth_init() has been called.

* Patch by Sam Song, 3 April 2005:
- Update README.Netconsole
- Update README


# 59acc296 03-Apr-2005 wdenk <wdenk>

Minor cleanup


# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver


# 289f932c 11-Jan-2005 wdenk <wdenk>

* Some Cleanup.

* Patch by Richard Woodruff, 10 Jan 2005:
Update support for OMAP2420 (ARM11) and H4 board:
o clean up and add new types to H4 memory probe code.
o fix to work with internal boot.
o added PRCM config III operation.
o fix marginal flash timings.
o add revison ATAG usage.
o enable voltage scaling at power chip.
o fix compile error for i2c.

* Fix network problem (error when receiving multiple ARP packets)


# d407bf52 11-Oct-2004 wdenk <wdenk>

* Patch by Philippe Robin, 28 Sept 2004:
Fix Flash support for Versatile.

* Patch by Roger Blofeld, 16 Sep 2004:
Fix timeout for DHCP command retry


# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()


# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)


# b9711de1 25-Apr-2004 wdenk <wdenk>

* Patch by John Kerl, 19 Apr 2004:
Use U-boot's miiphy.h for PHY register names, rather than
introducing a new header file.

* Update pci_ids.h from linux-2.4.26

* Patch by Masami Komiya, 19 Apr 2004:
Fix problem cause by VLAN function on little endian architecture
without VLAN environment


# 6e592385 18-Apr-2004 wdenk <wdenk>

* Cleanup, minor fixes

* Patch by Rune Torgersen, 16 Apr 2004:
LBA48 fixes

* Patches by Pantelis Antoniou, 16 Apr 2004:
- Fix some compile problems;
add "once" functionality for the netretry variable


# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)


# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)


# 3d3befa7 14-Mar-2004 wdenk <wdenk>

* Patch by Philippe Robin, 09 Mar 2004:
Added ARM Integrator AP, CP and Versatile PB926EJ-S Reference
Platform support.

* Patch by Masami Komiya, 08 Mar 2004:
Don't overwrite server IP address or boot file name
when the boot server does not return values

* Patch by listmember@orkun.us, 5 Mar 2004:
Removed compile time restriction on CFG_I2C_SPEED for DS1338 RTC


# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup


# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup


# fc3e2165 08-Oct-2003 wdenk <wdenk>

* Patch by Sangmoon Kim, 23 Sep 2003:
fix pll_pci_to_mem_multiplier table for MPC8245

* Patch by Anders Larsen, 22 Sep 2003:
enable timed autoboot on PXA

* Patch by David M�ller, 22 Sep 2003:

- add $(CFLAGS) to "-print-libgcc-filename" so compiler driver
returns correct libgcc file path
- "latency" reduction of busy-loop waiting to improve "U-Boot" boot
time on s3c24x0 systems

* Patch by Jon Diekema, 19 Sep 2003:
- Add CFG_FAULT_ECHO_LINK_DOWN option to echo the inverted Ethernet
link state to the fault LED.
- In NetLoop, make the Fault LED reflect the link status. The link
status gets updated on entry, and on timeouts.


# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.


# e0ac62d7 17-Aug-2003 wdenk <wdenk>

* Make Ethernet autonegotiation on INCA-IP work for all clock rates;
allow selection of clock frequency as "make" target

* Implement memory autosizing code for IceCube boards

* Configure network port on INCA-IP for autonegotiation

* Fix overflow problem in network timeout code

* Patch by Richard Woodruff, 8 Aug 2003:
Allow crc32 to be used at address 0x000 (crc32_no_comp, too).


# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)


# 0b97ab14 19-Jun-2003 wdenk <wdenk>

* Patch by Richard Woodruff, 19 June 03:
- Fixed smc91c111 driver to sync with the u-boot environment (driver/smc91c111.c).
- Added eth_init error return check in NetLoop (net/net.c).


# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)


# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h


# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision