blob: f4b4bc483397fc6104922f56de014c5408e2435c [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}
54SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_CPGMAC, spl_net_load_image_cpgmac);
55#endif
56
57#ifdef CONFIG_SPL_USBETH_SUPPORT
Simon Glass2a2ee2a2016-09-24 18:20:13 -060058int spl_net_load_image_usb(struct spl_image_info *spl_image,
59 struct spl_boot_device *bootdev)
Simon Glass7ec03892016-09-24 18:20:11 -060060{
61 bootdev->boot_device_name = "usb_ether";
62
Simon Glass2a2ee2a2016-09-24 18:20:13 -060063 return spl_net_load_image(spl_image, bootdev);
Simon Glass7ec03892016-09-24 18:20:11 -060064}
65SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
66#endif