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