3 * Texas Instruments, <www.ti.com>
5 * Dan Murphy <dmurphy@ti.com>
7 * SPDX-License-Identifier: GPL-2.0+
9 * FAT Image Functions copied from spl_mmc.c
14 #include <asm/u-boot.h>
20 static int fat_registered;
22 #ifdef CONFIG_SPL_FAT_SUPPORT
23 static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
30 err = fat_register_device(block_dev, partition);
32 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
33 printf("%s: fat register err - %d\n", __func__, err);
43 static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
44 ulong size, void *buf)
48 char *filename = (char *)load->filename;
50 ret = fat_read_file(filename, buf, file_offset, size, &actread);
57 int spl_load_image_fat(struct spl_image_info *spl_image,
58 struct blk_desc *block_dev, int partition,
62 struct image_header *header;
64 err = spl_register_fat_device(block_dev, partition);
68 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
69 sizeof(struct image_header));
71 err = file_fat_read(filename, header, sizeof(struct image_header));
75 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
76 image_get_magic(header) == FDT_MAGIC) {
77 struct spl_load_info load;
80 load.read = spl_fit_read;
82 load.filename = (void *)filename;
85 return spl_load_simple_fit(spl_image, &load, 0, header);
87 err = spl_parse_image_header(spl_image, header);
91 err = file_fat_read(filename,
92 (u8 *)(uintptr_t)spl_image->load_addr, 0);
96 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
98 printf("%s: error reading image %s, err - %d\n",
99 __func__, filename, err);
105 #ifdef CONFIG_SPL_OS_BOOT
106 int spl_load_image_fat_os(struct spl_image_info *spl_image,
107 struct blk_desc *block_dev, int partition)
110 __maybe_unused char *file;
112 err = spl_register_fat_device(block_dev, partition);
116 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
117 file = getenv("falcon_args_file");
119 err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
121 printf("spl: error reading image %s, err - %d, falling back to default\n",
125 file = getenv("falcon_image_file");
127 err = spl_load_image_fat(spl_image, block_dev,
130 puts("spl: falling back to default\n");
136 puts("spl: falcon_image_file not set in environment, falling back to default\n");
138 puts("spl: falcon_args_file not set in environment, falling back to default\n");
143 err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME,
144 (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
146 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
147 printf("%s: error reading image %s, err - %d\n",
148 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
153 return spl_load_image_fat(spl_image, block_dev, partition,
154 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
157 int spl_load_image_fat_os(struct spl_image_info *spl_image,
158 struct blk_desc *block_dev, int partition)