1 // SPDX-License-Identifier: GPL-2.0+
3 * Bootdev for ethernet (uses PXE)
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
9 #define LOG_CATEGORY UCLASS_BOOTSTD
21 #include <test/test.h>
23 static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
24 struct bootflow *bflow)
29 /* Must be an Ethernet device */
30 ret = bootflow_iter_check_net(iter);
32 return log_msg_ret("net", ret);
34 ret = bootmeth_check(bflow->method, iter);
36 return log_msg_ret("check", ret);
39 * Like extlinux boot, this assumes there is only one Ethernet device.
40 * In this case, that means that @eth is ignored
43 snprintf(name, sizeof(name), "%s.%d", dev->name, iter->part);
44 bflow->name = strdup(name);
46 return log_msg_ret("name", -ENOMEM);
48 /* See distro_pxe_read_bootflow() for the standard impl of this */
49 log_debug("dhcp complete - reading bootflow with method '%s'\n",
51 ret = bootmeth_read_bootflow(bflow->method, bflow);
52 log_debug("reading bootflow returned %d\n", ret);
54 return log_msg_ret("method", ret);
59 static int eth_bootdev_bind(struct udevice *dev)
61 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
63 ucp->prio = BOOTDEVP_6_NET_BASE;
68 static int eth_bootdev_hunt(struct bootdev_hunter *info, bool show)
72 if (!test_eth_enabled())
75 /* init PCI first since this is often used to provide Ehternet */
76 if (IS_ENABLED(CONFIG_PCI)) {
79 log_warning("Failed to init PCI (%dE)\n", ret);
83 * Ethernet devices can also come from USB, but that is a higher
84 * priority (BOOTDEVP_5_SCAN_SLOW) than ethernet, so it should have been
85 * enumerated already. If something like 'bootflow scan dhcp' is used
86 * then the user will need to run 'usb start' first.
88 if (IS_ENABLED(CONFIG_CMD_DHCP)) {
89 ret = dhcp_run(0, NULL, false);
97 struct bootdev_ops eth_bootdev_ops = {
98 .get_bootflow = eth_get_bootflow,
101 static const struct udevice_id eth_bootdev_ids[] = {
102 { .compatible = "u-boot,bootdev-eth" },
106 U_BOOT_DRIVER(eth_bootdev) = {
107 .name = "eth_bootdev",
108 .id = UCLASS_BOOTDEV,
109 .ops = ð_bootdev_ops,
110 .bind = eth_bootdev_bind,
111 .of_match = eth_bootdev_ids,
114 BOOTDEV_HUNTER(eth_bootdev_hunt) = {
115 .prio = BOOTDEVP_6_NET_BASE,
116 .uclass = UCLASS_ETH,
117 .hunt = eth_bootdev_hunt,
118 .drv = DM_DRIVER_REF(eth_bootdev),