spl_net.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0+
  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>
  8. */
  9. #include <common.h>
  10. #include <env.h>
  11. #include <errno.h>
  12. #include <spl.h>
  13. #include <net.h>
  14. #include <linux/libfdt.h>
  15. #if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)
  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. static int spl_net_load_image(struct spl_image_info *spl_image,
  25. struct spl_boot_device *bootdev)
  26. {
  27. struct image_header *header = (struct image_header *)load_addr;
  28. int rv;
  29. env_init();
  30. env_relocate();
  31. env_set("autoload", "yes");
  32. rv = eth_initialize();
  33. if (rv == 0) {
  34. printf("No Ethernet devices found\n");
  35. return -ENODEV;
  36. }
  37. if (bootdev->boot_device_name)
  38. env_set("ethact", bootdev->boot_device_name);
  39. rv = net_loop(BOOTP);
  40. if (rv < 0) {
  41. printf("Problem booting with BOOTP\n");
  42. return rv;
  43. }
  44. if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
  45. image_get_magic(header) == FDT_MAGIC) {
  46. struct spl_load_info load;
  47. debug("Found FIT\n");
  48. load.bl_len = 1;
  49. load.read = spl_net_load_read;
  50. rv = spl_load_simple_fit(spl_image, &load, 0, header);
  51. } else {
  52. debug("Legacy image\n");
  53. rv = spl_parse_image_header(spl_image, header);
  54. if (rv)
  55. return rv;
  56. memcpy((void *)spl_image->load_addr, header, spl_image->size);
  57. }
  58. return rv;
  59. }
  60. #endif
  61. #ifdef CONFIG_SPL_ETH_SUPPORT
  62. int spl_net_load_image_cpgmac(struct spl_image_info *spl_image,
  63. struct spl_boot_device *bootdev)
  64. {
  65. #ifdef CONFIG_SPL_ETH_DEVICE
  66. bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE;
  67. #endif
  68. return spl_net_load_image(spl_image, bootdev);
  69. }
  70. SPL_LOAD_IMAGE_METHOD("eth device", 0, BOOT_DEVICE_CPGMAC,
  71. spl_net_load_image_cpgmac);
  72. #endif
  73. #ifdef CONFIG_SPL_USB_ETHER
  74. int spl_net_load_image_usb(struct spl_image_info *spl_image,
  75. struct spl_boot_device *bootdev)
  76. {
  77. bootdev->boot_device_name = "usb_ether";
  78. #if CONFIG_IS_ENABLED(DM_USB_GADGET)
  79. usb_ether_init();
  80. #endif
  81. return spl_net_load_image(spl_image, bootdev);
  82. }
  83. SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb);
  84. #endif