1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
6 * Dan Murphy <dmurphy@ti.com>
8 * FAT Image Functions copied from spl_mmc.c
15 #include <asm/u-boot.h>
19 #include <linux/libfdt.h>
21 static int fat_registered;
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 spl_boot_device *bootdev,
59 struct blk_desc *block_dev, int partition,
63 struct image_header *header;
65 err = spl_register_fat_device(block_dev, partition);
69 header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
71 err = file_fat_read(filename, header, sizeof(struct image_header));
75 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
76 image_get_magic(header) == FDT_MAGIC) {
77 err = file_fat_read(filename, (void *)CONFIG_SYS_LOAD_ADDR, 0);
80 err = spl_parse_image_header(spl_image, bootdev,
81 (struct image_header *)CONFIG_SYS_LOAD_ADDR);
86 } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
87 image_get_magic(header) == FDT_MAGIC) {
88 struct spl_load_info load;
91 load.read = spl_fit_read;
93 load.filename = (void *)filename;
96 return spl_load_simple_fit(spl_image, &load, 0, header);
98 err = spl_parse_image_header(spl_image, bootdev, header);
102 err = file_fat_read(filename,
103 (u8 *)(uintptr_t)spl_image->load_addr, 0);
107 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
109 printf("%s: error reading image %s, err - %d\n",
110 __func__, filename, err);
116 #if CONFIG_IS_ENABLED(OS_BOOT)
117 int spl_load_image_fat_os(struct spl_image_info *spl_image,
118 struct spl_boot_device *bootdev,
119 struct blk_desc *block_dev, int partition)
122 __maybe_unused char *file;
124 err = spl_register_fat_device(block_dev, partition);
128 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
129 file = env_get("falcon_args_file");
131 err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
133 printf("spl: error reading image %s, err - %d, falling back to default\n",
137 file = env_get("falcon_image_file");
139 err = spl_load_image_fat(spl_image, bootdev, block_dev,
142 puts("spl: falling back to default\n");
148 puts("spl: falcon_image_file not set in environment, falling back to default\n");
150 puts("spl: falcon_args_file not set in environment, falling back to default\n");
155 err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME,
156 (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
158 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
159 printf("%s: error reading image %s, err - %d\n",
160 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
165 return spl_load_image_fat(spl_image, bootdev, block_dev, partition,
166 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
169 int spl_load_image_fat_os(struct spl_image_info *spl_image,
170 struct spl_boot_device *bootdev,
171 struct blk_desc *block_dev, int partition)