mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-11 07:24:46 +00:00

Currently when booting dhcp_run() may be executed multiple times: once in eth_bootdev_hunt() and once in the network booting bootmeth. We need to call eth_bootdev_hunt() when setting up the EFI sub-system to supply the simple network protocol. We don't need an IP address set up. We can reduce the bootime by not executing dhcp_run() in eth_bootdev_hunt(). Furthermore eth_bootdev_hunt() with autostart=yes leads on the legacy network stack leads to downloading a file via TFTP and to booting the downloaded file. Instead of running dchp_run() just check that there is a network device in eth_bootdev_hunt(). Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
124 lines
2.8 KiB
C
124 lines
2.8 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Bootdev for ethernet (uses PXE)
|
|
*
|
|
* Copyright 2021 Google LLC
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
*/
|
|
|
|
#define LOG_CATEGORY UCLASS_BOOTSTD
|
|
|
|
#include <bootdev.h>
|
|
#include <bootflow.h>
|
|
#include <command.h>
|
|
#include <bootmeth.h>
|
|
#include <dm.h>
|
|
#include <extlinux.h>
|
|
#include <init.h>
|
|
#include <log.h>
|
|
#include <net.h>
|
|
#include <test/test.h>
|
|
|
|
static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
|
|
struct bootflow *bflow)
|
|
{
|
|
char name[60];
|
|
int ret;
|
|
|
|
/* Must be an Ethernet device */
|
|
ret = bootflow_iter_check_net(iter);
|
|
if (ret)
|
|
return log_msg_ret("net", ret);
|
|
|
|
ret = bootmeth_check(bflow->method, iter);
|
|
if (ret)
|
|
return log_msg_ret("check", ret);
|
|
|
|
/*
|
|
* Like extlinux boot, this assumes there is only one Ethernet device.
|
|
* In this case, that means that @eth is ignored
|
|
*/
|
|
|
|
snprintf(name, sizeof(name), "%s.%d", dev->name, iter->part);
|
|
bflow->name = strdup(name);
|
|
if (!bflow->name)
|
|
return log_msg_ret("name", -ENOMEM);
|
|
|
|
/* See distro_pxe_read_bootflow() for the standard impl of this */
|
|
log_debug("dhcp complete - reading bootflow with method '%s'\n",
|
|
bflow->method->name);
|
|
ret = bootmeth_read_bootflow(bflow->method, bflow);
|
|
log_debug("reading bootflow returned %d\n", ret);
|
|
if (ret)
|
|
return log_msg_ret("method", ret);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int eth_bootdev_bind(struct udevice *dev)
|
|
{
|
|
struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
|
|
|
|
ucp->prio = BOOTDEVP_6_NET_BASE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* eth_bootdev_hunt() - probe all network devices
|
|
*
|
|
* Network devices can also come from USB, but that is a higher
|
|
* priority (BOOTDEVP_5_SCAN_SLOW) than network, so it should have been
|
|
* enumerated already. If something like 'bootflow scan dhcp' is used,
|
|
* then the user will need to run 'usb start' first.
|
|
*
|
|
* @info: info structure describing this hunter
|
|
* @show: true to show information from the hunter
|
|
*
|
|
* Return: 0 if device found, -EINVAL otherwise
|
|
*/
|
|
static int eth_bootdev_hunt(struct bootdev_hunter *info, bool show)
|
|
{
|
|
int ret;
|
|
struct udevice *dev = NULL;
|
|
|
|
if (!test_eth_enabled())
|
|
return 0;
|
|
|
|
/* init PCI first since this is often used to provide Ehternet */
|
|
if (IS_ENABLED(CONFIG_PCI)) {
|
|
ret = pci_init();
|
|
if (ret)
|
|
log_warning("Failed to init PCI (%dE)\n", ret);
|
|
}
|
|
|
|
ret = -EINVAL;
|
|
uclass_foreach_dev_probe(UCLASS_ETH, dev)
|
|
ret = 0;
|
|
|
|
return ret;
|
|
}
|
|
|
|
struct bootdev_ops eth_bootdev_ops = {
|
|
.get_bootflow = eth_get_bootflow,
|
|
};
|
|
|
|
static const struct udevice_id eth_bootdev_ids[] = {
|
|
{ .compatible = "u-boot,bootdev-eth" },
|
|
{ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(eth_bootdev) = {
|
|
.name = "eth_bootdev",
|
|
.id = UCLASS_BOOTDEV,
|
|
.ops = ð_bootdev_ops,
|
|
.bind = eth_bootdev_bind,
|
|
.of_match = eth_bootdev_ids,
|
|
};
|
|
|
|
BOOTDEV_HUNTER(eth_bootdev_hunt) = {
|
|
.prio = BOOTDEVP_6_NET_BASE,
|
|
.uclass = UCLASS_ETH,
|
|
.hunt = eth_bootdev_hunt,
|
|
.drv = DM_DRIVER_REF(eth_bootdev),
|
|
};
|