blob: 0fba0172ea4d78c9a70e829c1e89e50bef4312f3 [file] [log] [blame]
Ilya Yanok7ac2fe22012-09-18 00:22:50 +00001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Ilya Yanok7ac2fe22012-09-18 00:22:50 +00009 */
10#include <common.h>
Nikita Kiryanov36afd452015-11-08 17:11:49 +020011#include <errno.h>
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000012#include <spl.h>
13#include <net.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
Simon Glass7ec03892016-09-24 18:20:11 -060017#if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)
Simon Glass2a2ee2a2016-09-24 18:20:13 -060018static int spl_net_load_image(struct spl_image_info *spl_image,
19 struct spl_boot_device *bootdev)
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000020{
21 int rv;
22
23 env_init();
24 env_relocate();
25 setenv("autoload", "yes");
26 load_addr = CONFIG_SYS_TEXT_BASE - sizeof(struct image_header);
Joe Hershbergerd2eaec62015-03-22 17:09:06 -050027 rv = eth_initialize();
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000028 if (rv == 0) {
29 printf("No Ethernet devices found\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020030 return -ENODEV;
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000031 }
Simon Glassecdfd692016-09-24 18:19:57 -060032 if (bootdev->boot_device_name)
33 setenv("ethact", bootdev->boot_device_name);
Joe Hershbergerbc0571f2015-04-08 01:41:21 -050034 rv = net_loop(BOOTP);
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000035 if (rv < 0) {
36 printf("Problem booting with BOOTP\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020037 return rv;
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000038 }
Simon Glass2a2ee2a2016-09-24 18:20:13 -060039 return spl_parse_image_header(spl_image,
Simon Glass71316c12016-09-24 18:19:53 -060040 (struct image_header *)load_addr);
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000041}
Simon Glass7ec03892016-09-24 18:20:11 -060042#endif
43
44#ifdef CONFIG_SPL_ETH_SUPPORT
Simon Glass2a2ee2a2016-09-24 18:20:13 -060045int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
46 struct spl_boot_device *bootdev)
Simon Glass7ec03892016-09-24 18:20:11 -060047{
48#ifdef CONFIG_SPL_ETH_DEVICE
49 bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
50#endif
51
Simon Glass2a2ee2a2016-09-24 18:20:13 -060052 return spl_net_load_image(spl_image, bootdev);
Simon Glass7ec03892016-09-24 18:20:11 -060053}
Simon Glassebc4ef62016-11-30 15:30:50 -070054SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC,
55 spl_net_load_image_cpgmac);
Simon Glass7ec03892016-09-24 18:20:11 -060056#endif
57
58#ifdef CONFIG_SPL_USBETH_SUPPORT
Simon Glass2a2ee2a2016-09-24 18:20:13 -060059int spl_net_load_image_usb(struct spl_image_info *spl_image,
60 struct spl_boot_device *bootdev)
Simon Glass7ec03892016-09-24 18:20:11 -060061{
62 bootdev->boot_device_name = "usb_ether";
63
Simon Glass2a2ee2a2016-09-24 18:20:13 -060064 return spl_net_load_image(spl_image, bootdev);
Simon Glass7ec03892016-09-24 18:20:11 -060065}
Simon Glassebc4ef62016-11-30 15:30:50 -070066SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
Simon Glass7ec03892016-09-24 18:20:11 -060067#endif