blob: 898f9df705a29996da45c7575695dc49be137284 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanok7ac2fe22012-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 Yanok7ac2fe22012-09-18 00:22:50 +00008 */
9#include <common.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060010#include <env.h>
Nikita Kiryanov36afd452015-11-08 17:11:49 +020011#include <errno.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060012#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000014#include <spl.h>
Sean Anderson2e5476b2023-11-08 11:48:52 -050015#include <spl_load.h>
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000016#include <net.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000018
Simon Glassf2d7a362021-07-10 21:14:26 -060019#if defined(CONFIG_SPL_ETH) || defined(CONFIG_SPL_USB_ETHER)
Andrew F. Davis6dca5e82017-04-07 14:29:36 -050020static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
21 ulong count, void *buf)
22{
23 debug("%s: sector %lx, count %lx, buf %lx\n",
24 __func__, sector, count, (ulong)buf);
Sean Andersonb02c4e92023-10-14 16:47:55 -040025 memcpy(buf, map_sysmem(image_load_addr + sector, count), count);
Andrew F. Davis6dca5e82017-04-07 14:29:36 -050026 return count;
27}
28
Simon Glass2a2ee2a2016-09-24 18:20:13 -060029static int spl_net_load_image(struct spl_image_info *spl_image,
30 struct spl_boot_device *bootdev)
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000031{
Sean Anderson2e5476b2023-11-08 11:48:52 -050032 struct spl_load_info load;
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000033 int rv;
34
35 env_init();
36 env_relocate();
Simon Glass382bee52017-08-03 12:22:09 -060037 env_set("autoload", "yes");
Joe Hershbergerd2eaec62015-03-22 17:09:06 -050038 rv = eth_initialize();
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000039 if (rv == 0) {
40 printf("No Ethernet devices found\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020041 return -ENODEV;
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000042 }
Simon Glassecdfd692016-09-24 18:19:57 -060043 if (bootdev->boot_device_name)
Simon Glass382bee52017-08-03 12:22:09 -060044 env_set("ethact", bootdev->boot_device_name);
Joe Hershbergerbc0571f2015-04-08 01:41:21 -050045 rv = net_loop(BOOTP);
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000046 if (rv < 0) {
47 printf("Problem booting with BOOTP\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020048 return rv;
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000049 }
Andrew F. Davis6dca5e82017-04-07 14:29:36 -050050
Sean Anderson2e5476b2023-11-08 11:48:52 -050051 spl_set_bl_len(&load, 1);
52 load.read = spl_net_load_read;
53 return spl_load(spl_image, bootdev, &load, 0, 0);
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000054}
Simon Glass7ec03892016-09-24 18:20:11 -060055#endif
56
Simon Glassf2d7a362021-07-10 21:14:26 -060057#ifdef CONFIG_SPL_ETH
Simon Glass2a2ee2a2016-09-24 18:20:13 -060058int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
59 struct spl_boot_device *bootdev)
Simon Glass7ec03892016-09-24 18:20:11 -060060{
61#ifdef CONFIG_SPL_ETH_DEVICE
62 bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
63#endif
64
Simon Glass2a2ee2a2016-09-24 18:20:13 -060065 return spl_net_load_image(spl_image, bootdev);
Simon Glass7ec03892016-09-24 18:20:11 -060066}
Simon Glassebc4ef62016-11-30 15:30:50 -070067SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC,
68 spl_net_load_image_cpgmac);
Simon Glass7ec03892016-09-24 18:20:11 -060069#endif
70
Faiz Abbasb432b1e2018-02-16 21:17:44 +053071#ifdef CONFIG_SPL_USB_ETHER
Simon Glass2a2ee2a2016-09-24 18:20:13 -060072int spl_net_load_image_usb(struct spl_image_info *spl_image,
73 struct spl_boot_device *bootdev)
Simon Glass7ec03892016-09-24 18:20:11 -060074{
75 bootdev->boot_device_name = "usb_ether";
Jean-Jacques Hiblot0f46fb52018-12-04 11:30:48 +010076#if CONFIG_IS_ENABLED(DM_USB_GADGET)
77 usb_ether_init();
78#endif
Simon Glass2a2ee2a2016-09-24 18:20:13 -060079 return spl_net_load_image(spl_image, bootdev);
Simon Glass7ec03892016-09-24 18:20:11 -060080}
Simon Glassebc4ef62016-11-30 15:30:50 -070081SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
Simon Glass7ec03892016-09-24 18:20:11 -060082#endif