blob: b6967ff69ee73037b29a818fca79f64b429b5cc1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanokf7a2c552012-09-18 00:22:50 +00002/*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * (C) Copyright 2012
7 * Ilya Yanok <ilya.yanok@gmail.com>
Ilya Yanokf7a2c552012-09-18 00:22:50 +00008 */
9#include <common.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020010#include <errno.h>
Ilya Yanokf7a2c552012-09-18 00:22:50 +000011#include <spl.h>
12#include <net.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Ilya Yanokf7a2c552012-09-18 00:22:50 +000014
Faiz Abbasc01553b2018-02-16 21:17:44 +053015#if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)
Andrew F. Davis0a88c802017-04-07 14:29:36 -050016static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
17 ulong count, void *buf)
18{
19 debug("%s: sector %lx, count %lx, buf %lx\n",
20 __func__, sector, count, (ulong)buf);
21 memcpy(buf, (void *)(load_addr + sector), count);
22 return count;
23}
24
Simon Glassee306792016-09-24 18:20:13 -060025static int spl_net_load_image(struct spl_image_info *spl_image,
26 struct spl_boot_device *bootdev)
Ilya Yanokf7a2c552012-09-18 00:22:50 +000027{
Andrew F. Davis0a88c802017-04-07 14:29:36 -050028 struct image_header *header = (struct image_header *)load_addr;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000029 int rv;
30
31 env_init();
32 env_relocate();
Simon Glass6a38e412017-08-03 12:22:09 -060033 env_set("autoload", "yes");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -050034 rv = eth_initialize();
Ilya Yanokf7a2c552012-09-18 00:22:50 +000035 if (rv == 0) {
36 printf("No Ethernet devices found\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020037 return -ENODEV;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000038 }
Simon Glassc0b6c9b2016-09-24 18:19:57 -060039 if (bootdev->boot_device_name)
Simon Glass6a38e412017-08-03 12:22:09 -060040 env_set("ethact", bootdev->boot_device_name);
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050041 rv = net_loop(BOOTP);
Ilya Yanokf7a2c552012-09-18 00:22:50 +000042 if (rv < 0) {
43 printf("Problem booting with BOOTP\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020044 return rv;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000045 }
Andrew F. Davis0a88c802017-04-07 14:29:36 -050046
47 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
48 image_get_magic(header) == FDT_MAGIC) {
49 struct spl_load_info load;
50
51 debug("Found FIT\n");
52 load.bl_len = 1;
53 load.read = spl_net_load_read;
54 rv = spl_load_simple_fit(spl_image, &load, 0, header);
55 } else {
56 debug("Legacy image\n");
57
58 rv = spl_parse_image_header(spl_image, header);
59 if (rv)
60 return rv;
61
62 memcpy((void *)spl_image->load_addr, header, spl_image->size);
63 }
64
65 return rv;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000066}
Simon Glassd9aefcb2016-09-24 18:20:11 -060067#endif
68
69#ifdef CONFIG_SPL_ETH_SUPPORT
Simon Glassee306792016-09-24 18:20:13 -060070int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
71 struct spl_boot_device *bootdev)
Simon Glassd9aefcb2016-09-24 18:20:11 -060072{
73#ifdef CONFIG_SPL_ETH_DEVICE
74 bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
75#endif
76
Simon Glassee306792016-09-24 18:20:13 -060077 return spl_net_load_image(spl_image, bootdev);
Simon Glassd9aefcb2016-09-24 18:20:11 -060078}
Simon Glass4fc1f252016-11-30 15:30:50 -070079SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC,
80 spl_net_load_image_cpgmac);
Simon Glassd9aefcb2016-09-24 18:20:11 -060081#endif
82
Faiz Abbasc01553b2018-02-16 21:17:44 +053083#ifdef CONFIG_SPL_USB_ETHER
Simon Glassee306792016-09-24 18:20:13 -060084int spl_net_load_image_usb(struct spl_image_info *spl_image,
85 struct spl_boot_device *bootdev)
Simon Glassd9aefcb2016-09-24 18:20:11 -060086{
87 bootdev->boot_device_name = "usb_ether";
88
Simon Glassee306792016-09-24 18:20:13 -060089 return spl_net_load_image(spl_image, bootdev);
Simon Glassd9aefcb2016-09-24 18:20:11 -060090}
Simon Glass4fc1f252016-11-30 15:30:50 -070091SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
Simon Glassd9aefcb2016-09-24 18:20:11 -060092#endif