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