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