Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 9 | */ |
| 10 | #include <common.h> |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 11 | #include <errno.h> |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 12 | #include <spl.h> |
| 13 | #include <net.h> |
Andrew F. Davis | 6dca5e8 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 14 | #include <libfdt.h> |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 18 | #if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT) |
Andrew F. Davis | 6dca5e8 | 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); |
| 24 | memcpy(buf, (void *)(load_addr + sector), count); |
| 25 | return count; |
| 26 | } |
| 27 | |
Simon Glass | 2a2ee2a | 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 | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 30 | { |
Andrew F. Davis | 6dca5e8 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 31 | struct image_header *header = (struct image_header *)load_addr; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 32 | int rv; |
| 33 | |
| 34 | env_init(); |
| 35 | env_relocate(); |
| 36 | setenv("autoload", "yes"); |
Joe Hershberger | d2eaec6 | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 37 | rv = eth_initialize(); |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 38 | if (rv == 0) { |
| 39 | printf("No Ethernet devices found\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 40 | return -ENODEV; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 41 | } |
Simon Glass | ecdfd69 | 2016-09-24 18:19:57 -0600 | [diff] [blame] | 42 | if (bootdev->boot_device_name) |
| 43 | setenv("ethact", bootdev->boot_device_name); |
Joe Hershberger | bc0571f | 2015-04-08 01:41:21 -0500 | [diff] [blame] | 44 | rv = net_loop(BOOTP); |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 45 | if (rv < 0) { |
| 46 | printf("Problem booting with BOOTP\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 47 | return rv; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 48 | } |
Andrew F. Davis | 6dca5e8 | 2017-04-07 14:29:36 -0500 | [diff] [blame] | 49 | |
| 50 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && |
| 51 | image_get_magic(header) == FDT_MAGIC) { |
| 52 | struct spl_load_info load; |
| 53 | |
| 54 | debug("Found FIT\n"); |
| 55 | load.bl_len = 1; |
| 56 | load.read = spl_net_load_read; |
| 57 | rv = spl_load_simple_fit(spl_image, &load, 0, header); |
| 58 | } else { |
| 59 | debug("Legacy image\n"); |
| 60 | |
| 61 | rv = spl_parse_image_header(spl_image, header); |
| 62 | if (rv) |
| 63 | return rv; |
| 64 | |
| 65 | memcpy((void *)spl_image->load_addr, header, spl_image->size); |
| 66 | } |
| 67 | |
| 68 | return rv; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 69 | } |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #ifdef CONFIG_SPL_ETH_SUPPORT |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 73 | int spl_net_load_image_cpgmac(struct spl_image_info *spl_image, |
| 74 | struct spl_boot_device *bootdev) |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 75 | { |
| 76 | #ifdef CONFIG_SPL_ETH_DEVICE |
| 77 | bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE; |
| 78 | #endif |
| 79 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 80 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 81 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 82 | SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC, |
| 83 | spl_net_load_image_cpgmac); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | #ifdef CONFIG_SPL_USBETH_SUPPORT |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 87 | int spl_net_load_image_usb(struct spl_image_info *spl_image, |
| 88 | struct spl_boot_device *bootdev) |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 89 | { |
| 90 | bootdev->boot_device_name = "usb_ether"; |
| 91 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 92 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 93 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 94 | SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 95 | #endif |