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> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 17 | #if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT) |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 18 | static int spl_net_load_image(struct spl_image_info *spl_image, |
| 19 | struct spl_boot_device *bootdev) |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 20 | { |
| 21 | int rv; |
| 22 | |
| 23 | env_init(); |
| 24 | env_relocate(); |
| 25 | setenv("autoload", "yes"); |
| 26 | load_addr = CONFIG_SYS_TEXT_BASE - sizeof(struct image_header); |
Joe Hershberger | d2eaec6 | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 27 | rv = eth_initialize(); |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 28 | if (rv == 0) { |
| 29 | printf("No Ethernet devices found\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 30 | return -ENODEV; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 31 | } |
Simon Glass | ecdfd69 | 2016-09-24 18:19:57 -0600 | [diff] [blame] | 32 | if (bootdev->boot_device_name) |
| 33 | setenv("ethact", bootdev->boot_device_name); |
Joe Hershberger | bc0571f | 2015-04-08 01:41:21 -0500 | [diff] [blame] | 34 | rv = net_loop(BOOTP); |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 35 | if (rv < 0) { |
| 36 | printf("Problem booting with BOOTP\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 37 | return rv; |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 38 | } |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 39 | return spl_parse_image_header(spl_image, |
Simon Glass | 71316c1 | 2016-09-24 18:19:53 -0600 | [diff] [blame] | 40 | (struct image_header *)load_addr); |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 41 | } |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | #ifdef CONFIG_SPL_ETH_SUPPORT |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 45 | int spl_net_load_image_cpgmac(struct spl_image_info *spl_image, |
| 46 | struct spl_boot_device *bootdev) |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 47 | { |
| 48 | #ifdef CONFIG_SPL_ETH_DEVICE |
| 49 | bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE; |
| 50 | #endif |
| 51 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 52 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 53 | } |
| 54 | SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_CPGMAC, spl_net_load_image_cpgmac); |
| 55 | #endif |
| 56 | |
| 57 | #ifdef CONFIG_SPL_USBETH_SUPPORT |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 58 | int spl_net_load_image_usb(struct spl_image_info *spl_image, |
| 59 | struct spl_boot_device *bootdev) |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 60 | { |
| 61 | bootdev->boot_device_name = "usb_ether"; |
| 62 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 63 | return spl_net_load_image(spl_image, bootdev); |
Simon Glass | 7ec0389 | 2016-09-24 18:20:11 -0600 | [diff] [blame] | 64 | } |
| 65 | SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); |
| 66 | #endif |