spl_fat.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <image.h>
  16. static int fat_registered;
  17. #ifdef CONFIG_SPL_FAT_SUPPORT
  18. static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
  19. {
  20. int err = 0;
  21. if (fat_registered)
  22. return err;
  23. err = fat_register_device(block_dev, partition);
  24. if (err) {
  25. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  26. printf("%s: fat register err - %d\n", __func__, err);
  27. #endif
  28. hang();
  29. }
  30. fat_registered = 1;
  31. return err;
  32. }
  33. int spl_load_image_fat(block_dev_desc_t *block_dev,
  34. int partition,
  35. const char *filename)
  36. {
  37. int err;
  38. struct image_header *header;
  39. err = spl_register_fat_device(block_dev, partition);
  40. if (err)
  41. goto end;
  42. header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
  43. sizeof(struct image_header));
  44. err = file_fat_read(filename, header, sizeof(struct image_header));
  45. if (err <= 0)
  46. goto end;
  47. spl_parse_image_header(header);
  48. err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
  49. end:
  50. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  51. if (err <= 0)
  52. printf("%s: error reading image %s, err - %d\n",
  53. __func__, filename, err);
  54. #endif
  55. return (err <= 0);
  56. }
  57. #ifdef CONFIG_SPL_OS_BOOT
  58. int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
  59. {
  60. int err;
  61. __maybe_unused char *file;
  62. err = spl_register_fat_device(block_dev, partition);
  63. if (err)
  64. return err;
  65. #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
  66. file = getenv("falcon_args_file");
  67. if (file) {
  68. err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
  69. if (err <= 0) {
  70. printf("spl: error reading image %s, err - %d, falling back to default\n",
  71. file, err);
  72. goto defaults;
  73. }
  74. file = getenv("falcon_image_file");
  75. if (file) {
  76. err = spl_load_image_fat(block_dev, partition, file);
  77. if (err != 0) {
  78. puts("spl: falling back to default\n");
  79. goto defaults;
  80. }
  81. return 0;
  82. } else
  83. puts("spl: falcon_image_file not set in environment, falling back to default\n");
  84. } else
  85. puts("spl: falcon_args_file not set in environment, falling back to default\n");
  86. defaults:
  87. #endif
  88. err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME,
  89. (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
  90. if (err <= 0) {
  91. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  92. printf("%s: error reading image %s, err - %d\n",
  93. __func__, CONFIG_SPL_FAT_LOAD_ARGS_NAME, err);
  94. #endif
  95. return -1;
  96. }
  97. return spl_load_image_fat(block_dev, partition,
  98. CONFIG_SPL_FAT_LOAD_KERNEL_NAME);
  99. }
  100. #endif
  101. #endif