1 // SPDX-License-Identifier: GPL-2.0+
3 * Bootdevice for ethernet (uses PXE)
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
19 static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
20 struct bootflow *bflow)
25 /* Must be an Ethernet device */
26 ret = bootflow_iter_uses_network(iter);
28 return log_msg_ret("net", ret);
30 ret = bootmeth_check(bflow->method, iter);
32 return log_msg_ret("check", ret);
35 * Like distro boot, this assumes there is only one Ethernet device.
36 * In this case, that means that @eth is ignored
39 snprintf(name, sizeof(name), "%s.%d", dev->name, iter->part);
40 bflow->name = strdup(name);
42 return log_msg_ret("name", -ENOMEM);
45 * There is not a direct interface to the network stack so run
46 * everything through the command-line interpreter for now.
48 * Don't bother checking the result of dhcp. It can fail with:
50 * DHCP client bound to address 192.168.4.50 (4 ms)
51 * *** Warning: no boot file name; using 'C0A80432.img'
52 * Using smsc95xx_eth device
53 * TFTP from server 192.168.4.1; our IP address is 192.168.4.50
54 * Filename 'C0A80432.img'.
55 * Load address: 0x200000
57 * TFTP error: 'File not found' (1)
59 * This is not a real failure, since we don't actually care if the
62 log_debug("running dhcp\n");
63 run_command("dhcp", 0);
64 bflow->state = BOOTFLOWST_MEDIA;
66 /* See distro_pxe_read_bootflow() for the standard impl of this */
67 log_debug("dhcp complete - reading bootflow with method %s\n",
69 ret = bootmeth_read_bootflow(bflow->method, bflow);
70 log_debug("reading bootflow returned %d\n", ret);
72 return log_msg_ret("method", ret);
77 static int eth_bootdev_bind(struct udevice *dev)
79 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
81 ucp->prio = BOOTDEVP_4_NET_BASE;
86 struct bootdev_ops eth_bootdev_ops = {
87 .get_bootflow = eth_get_bootflow,
90 static const struct udevice_id eth_bootdev_ids[] = {
91 { .compatible = "u-boot,bootdev-eth" },
95 U_BOOT_DRIVER(eth_bootdev) = {
96 .name = "eth_bootdev",
98 .ops = ð_bootdev_ops,
99 .bind = eth_bootdev_bind,
100 .of_match = eth_bootdev_ids,