Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 2 | /* |
| 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 Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 8 | */ |
Simon Glass | 79fd214 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 9 | #include <env.h> |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 13 | #include <spl.h> |
Sean Anderson | 810e16e | 2023-11-08 11:48:52 -0500 | [diff] [blame] | 14 | #include <spl_load.h> |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 15 | #include <net.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 17 | |
Simon Glass | e5cd9a4 | 2021-07-10 21:14:26 -0600 | [diff] [blame] | 18 | #if defined(CONFIG_SPL_ETH) || defined(CONFIG_SPL_USB_ETHER) |
Andrew F. Davis | 0a88c80 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 19 | static 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 Anderson | 5ff7772 | 2023-10-14 16:47:55 -0400 | [diff] [blame] | 24 | memcpy(buf, map_sysmem(image_load_addr + sector, count), count); |
Andrew F. Davis | 0a88c80 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 25 | return count; |
| 26 | } |
| 27 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 28 | static int spl_net_load_image(struct spl_image_info *spl_image, |
| 29 | struct spl_boot_device *bootdev) |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 30 | { |
Sean Anderson | 810e16e | 2023-11-08 11:48:52 -0500 | [diff] [blame] | 31 | struct spl_load_info load; |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 32 | int rv; |
| 33 | |
| 34 | env_init(); |
| 35 | env_relocate(); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 36 | env_set("autoload", "yes"); |
Joe Hershberger | 3dbe17e | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 37 | rv = eth_initialize(); |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 38 | if (rv == 0) { |
| 39 | printf("No Ethernet devices found\n"); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 40 | return -ENODEV; |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 41 | } |
Simon Glass | c0b6c9b | 2016-09-24 18:19:57 -0600 | [diff] [blame] | 42 | if (bootdev->boot_device_name) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 43 | env_set("ethact", bootdev->boot_device_name); |
Joe Hershberger | c80b41b0 | 2015-04-08 01:41:21 -0500 | [diff] [blame] | 44 | rv = net_loop(BOOTP); |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 45 | if (rv < 0) { |
| 46 | printf("Problem booting with BOOTP\n"); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 47 | return rv; |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 48 | } |
Andrew F. Davis | 0a88c80 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 49 | |
Sean Anderson | 810e16e | 2023-11-08 11:48:52 -0500 | [diff] [blame] | 50 | spl_set_bl_len(&load, 1); |
| 51 | load.read = spl_net_load_read; |
| 52 | return spl_load(spl_image, bootdev, &load, 0, 0); |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 53 | } |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 54 | #endif |
| 55 | |
Simon Glass | e5cd9a4 | 2021-07-10 21:14:26 -0600 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_ETH |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 57 | int spl_net_load_image_cpgmac(struct spl_image_info *spl_image, |
| 58 | struct spl_boot_device *bootdev) |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 59 | { |
| 60 | #ifdef CONFIG_SPL_ETH_DEVICE |
| 61 | bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE; |
| 62 | #endif |
| 63 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 64 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 65 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 66 | SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC, |
| 67 | spl_net_load_image_cpgmac); |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 68 | #endif |
| 69 | |
Faiz Abbas | c01553b | 2018-02-16 21:17:44 +0530 | [diff] [blame] | 70 | #ifdef CONFIG_SPL_USB_ETHER |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 71 | int spl_net_load_image_usb(struct spl_image_info *spl_image, |
| 72 | struct spl_boot_device *bootdev) |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 73 | { |
| 74 | bootdev->boot_device_name = "usb_ether"; |
Jean-Jacques Hiblot | 2c75314 | 2018-12-04 11:30:48 +0100 | [diff] [blame] | 75 | #if CONFIG_IS_ENABLED(DM_USB_GADGET) |
| 76 | usb_ether_init(); |
| 77 | #endif |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 78 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 79 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 80 | SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); |
Simon Glass | d9aefcb | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 81 | #endif |