1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Ilya Yanok <ilya.yanok@gmail.com>
13 #include <linux/libfdt.h>
15 #if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)
16 static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
17 ulong count, void *buf)
19 debug("%s: sector %lx, count %lx, buf %lx\n",
20 __func__, sector, count, (ulong)buf);
21 memcpy(buf, (void *)(load_addr + sector), count);
25 static int spl_net_load_image(struct spl_image_info *spl_image,
26 struct spl_boot_device *bootdev)
28 struct image_header *header = (struct image_header *)load_addr;
33 env_set("autoload", "yes");
34 rv = eth_initialize();
36 printf("No Ethernet devices found\n");
39 if (bootdev->boot_device_name)
40 env_set("ethact", bootdev->boot_device_name);
43 printf("Problem booting with BOOTP\n");
47 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
48 image_get_magic(header) == FDT_MAGIC) {
49 struct spl_load_info load;
53 load.read = spl_net_load_read;
54 rv = spl_load_simple_fit(spl_image, &load, 0, header);
56 debug("Legacy image\n");
58 rv = spl_parse_image_header(spl_image, header);
62 memcpy((void *)spl_image->load_addr, header, spl_image->size);
69 #ifdef CONFIG_SPL_ETH_SUPPORT
70 int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
71 struct spl_boot_device *bootdev)
73 #ifdef CONFIG_SPL_ETH_DEVICE
74 bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
77 return spl_net_load_image(spl_image, bootdev);
79 SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC,
80 spl_net_load_image_cpgmac);
83 #ifdef CONFIG_SPL_USB_ETHER
84 int spl_net_load_image_usb(struct spl_image_info *spl_image,
85 struct spl_boot_device *bootdev)
87 bootdev->boot_device_name = "usb_ether";
88 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
91 return spl_net_load_image(spl_image, bootdev);
93 SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);