spl: Convert spl_net_load_image() to use linker list
[platform/kernel/u-boot.git] / common / spl / spl_net.c
1 /*
2  * (C) Copyright 2000-2004
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2012
6  * Ilya Yanok <ilya.yanok@gmail.com>
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10 #include <common.h>
11 #include <errno.h>
12 #include <spl.h>
13 #include <net.h>
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 #if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)
18 static int spl_net_load_image(struct spl_boot_device *bootdev)
19 {
20         int rv;
21
22         env_init();
23         env_relocate();
24         setenv("autoload", "yes");
25         load_addr = CONFIG_SYS_TEXT_BASE - sizeof(struct image_header);
26         rv = eth_initialize();
27         if (rv == 0) {
28                 printf("No Ethernet devices found\n");
29                 return -ENODEV;
30         }
31         if (bootdev->boot_device_name)
32                 setenv("ethact", bootdev->boot_device_name);
33         rv = net_loop(BOOTP);
34         if (rv < 0) {
35                 printf("Problem booting with BOOTP\n");
36                 return rv;
37         }
38         return spl_parse_image_header(&spl_image,
39                                       (struct image_header *)load_addr);
40 }
41 #endif
42
43 #ifdef CONFIG_SPL_ETH_SUPPORT
44 int spl_net_load_image_cpgmac(struct spl_boot_device *bootdev)
45 {
46 #ifdef CONFIG_SPL_ETH_DEVICE
47         bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
48 #endif
49
50         return spl_net_load_image(bootdev);
51 }
52 SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_CPGMAC, spl_net_load_image_cpgmac);
53 #endif
54
55 #ifdef CONFIG_SPL_USBETH_SUPPORT
56 int spl_net_load_image_usb(struct spl_boot_device *bootdev)
57 {
58         bootdev->boot_device_name = "usb_ether";
59
60         return spl_net_load_image(bootdev);
61 }
62 SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
63 #endif