spl_fat.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * (C) Copyright 2014
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Dan Murphy <dmurphy@ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. * FAT Image Functions copied from spl_mmc.c
  10. */
  11. #include <common.h>
  12. #include <spl.h>
  13. #include <asm/u-boot.h>
  14. #include <fat.h>
  15. #include <errno.h>
  16. #include <image.h>
  17. static int fat_registered;
  18. #ifdef CONFIG_SPL_FAT_SUPPORT
  19. static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
  20. {
  21. int err = 0;
  22. if (fat_registered)
  23. return err;
  24. err = fat_register_device(block_dev, partition);
  25. if (err) {
  26. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  27. printf("%s: fat register err - %d\n", __func__, err);
  28. #endif
  29. return err;
  30. }
  31. fat_registered = 1;
  32. return err;
  33. }
  34. int spl_load_image_fat(block_dev_desc_t *block_dev,
  35. int partition,
  36. const char *filename)
  37. {
  38. int err;
  39. struct image_header *header;
  40. err = spl_register_fat_device(block_dev, partition);
  41. if (err)
  42. goto end;
  43. header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
  44. sizeof(struct image_header));
  45. err = file_fat_read(filename, header, sizeof(struct image_header));
  46. if (err <= 0)
  47. goto end;
  48. spl_parse_image_header(header);
  49. err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
  50. end:
  51. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  52. if (err <= 0)
  53. printf("%s: error reading image %s, err - %d\n",
  54. __func__, filename, err);
  55. #endif
  56. return (err <= 0);
  57. }
  58. #ifdef CONFIG_SPL_OS_BOOT
  59. int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
  60. {
  61. int err;
  62. __maybe_unused char *file;
  63. err = spl_register_fat_device(block_dev, partition);
  64. if (err)
  65. return err;
  66. #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
  67. file = getenv("falcon_args_file");
  68. if (file) {
  69. err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
  70. if (err <= 0) {
  71. printf("spl: error reading image %s, err - %d, falling back to default\n",
  72. file, err);
  73. goto defaults;
  74. }
  75. file = getenv("falcon_image_file");
  76. if (file) {
  77. err = spl_load_image_fat(block_dev, partition, file);
  78. if (err != 0) {
  79. puts("spl: falling back to default\n");
  80. goto defaults;
  81. }
  82. return 0;
  83. } else
  84. puts("spl: falcon_image_file not set in environment, falling back to default\n");
  85. } else
  86. puts("spl: falcon_args_file not set in environment, falling back to default\n");
  87. defaults:
  88. #endif
  89. err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME,
  90. (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
  91. if (err <= 0) {
  92. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  93. printf("%s: error reading image %s, err - %d\n",
  94. __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
  95. #endif
  96. return -1;
  97. }
  98. return spl_load_image_fat(block_dev, partition,
  99. CONFIG_SPL_FS_LOAD_KERNEL_NAME);
  100. }
  101. #else
  102. int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
  103. {
  104. return -ENOSYS;
  105. }
  106. #endif
  107. #endif