spl_net.c 2.3 KB

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