blob: be7278bb93344d756135fdf6f38919bb557fa9ae [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 */
Simon Glass79fd2142019-08-01 09:46:43 -06009#include <env.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020010#include <errno.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Ilya Yanokf7a2c552012-09-18 00:22:50 +000013#include <spl.h>
Sean Anderson810e16e2023-11-08 11:48:52 -050014#include <spl_load.h>
Ilya Yanokf7a2c552012-09-18 00:22:50 +000015#include <net.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Ilya Yanokf7a2c552012-09-18 00:22:50 +000017
Simon Glasse5cd9a42021-07-10 21:14:26 -060018#if defined(CONFIG_SPL_ETH) || defined(CONFIG_SPL_USB_ETHER)
Andrew F. Davis0a88c802017-04-07 14:29:36 -050019static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
20 ulong count, void *buf)
21{
22 debug("%s: sector %lx, count %lx, buf %lx\n",
23 __func__, sector, count, (ulong)buf);
Sean Anderson5ff77722023-10-14 16:47:55 -040024 memcpy(buf, map_sysmem(image_load_addr + sector, count), count);
Andrew F. Davis0a88c802017-04-07 14:29:36 -050025 return count;
26}
27
Simon Glassee306792016-09-24 18:20:13 -060028static int spl_net_load_image(struct spl_image_info *spl_image,
29 struct spl_boot_device *bootdev)
Ilya Yanokf7a2c552012-09-18 00:22:50 +000030{
Sean Anderson810e16e2023-11-08 11:48:52 -050031 struct spl_load_info load;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000032 int rv;
33
34 env_init();
35 env_relocate();
Simon Glass6a38e412017-08-03 12:22:09 -060036 env_set("autoload", "yes");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -050037 rv = eth_initialize();
Ilya Yanokf7a2c552012-09-18 00:22:50 +000038 if (rv == 0) {
39 printf("No Ethernet devices found\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020040 return -ENODEV;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000041 }
Simon Glassc0b6c9b2016-09-24 18:19:57 -060042 if (bootdev->boot_device_name)
Simon Glass6a38e412017-08-03 12:22:09 -060043 env_set("ethact", bootdev->boot_device_name);
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050044 rv = net_loop(BOOTP);
Ilya Yanokf7a2c552012-09-18 00:22:50 +000045 if (rv < 0) {
46 printf("Problem booting with BOOTP\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020047 return rv;
Ilya Yanokf7a2c552012-09-18 00:22:50 +000048 }
Andrew F. Davis0a88c802017-04-07 14:29:36 -050049
Sean Anderson810e16e2023-11-08 11:48:52 -050050 spl_set_bl_len(&load, 1);
51 load.read = spl_net_load_read;
52 return spl_load(spl_image, bootdev, &load, 0, 0);
Ilya Yanokf7a2c552012-09-18 00:22:50 +000053}
Simon Glassd9aefcb2016-09-24 18:20:11 -060054#endif
55
Simon Glasse5cd9a42021-07-10 21:14:26 -060056#ifdef CONFIG_SPL_ETH
Simon Glassee306792016-09-24 18:20:13 -060057int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
58 struct spl_boot_device *bootdev)
Simon Glassd9aefcb2016-09-24 18:20:11 -060059{
60#ifdef CONFIG_SPL_ETH_DEVICE
61 bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
62#endif
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("eth device", 0, BOOT_DEVICE_CPGMAC,
67 spl_net_load_image_cpgmac);
Simon Glassd9aefcb2016-09-24 18:20:11 -060068#endif
69
Faiz Abbasc01553b2018-02-16 21:17:44 +053070#ifdef CONFIG_SPL_USB_ETHER
Simon Glassee306792016-09-24 18:20:13 -060071int spl_net_load_image_usb(struct spl_image_info *spl_image,
72 struct spl_boot_device *bootdev)
Simon Glassd9aefcb2016-09-24 18:20:11 -060073{
74 bootdev->boot_device_name = "usb_ether";
Jean-Jacques Hiblot2c753142018-12-04 11:30:48 +010075#if CONFIG_IS_ENABLED(DM_USB_GADGET)
76 usb_ether_init();
77#endif
Simon Glassee306792016-09-24 18:20:13 -060078 return spl_net_load_image(spl_image, bootdev);
Simon Glassd9aefcb2016-09-24 18:20:11 -060079}
Simon Glass4fc1f252016-11-30 15:30:50 -070080SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
Simon Glassd9aefcb2016-09-24 18:20:11 -060081#endif