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
13 #include <asm/u-boot.h>
17 #include <linux/libfdt.h>
19 static int fat_registered
;
21 static int spl_register_fat_device(struct blk_desc
*block_dev
, int partition
)
28 err
= fat_register_device(block_dev
, partition
);
30 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
31 printf("%s: fat register err - %d\n", __func__
, err
);
41 static ulong
spl_fit_read(struct spl_load_info
*load
, ulong file_offset
,
42 ulong size
, void *buf
)
46 char *filename
= (char *)load
->filename
;
48 ret
= fat_read_file(filename
, buf
, file_offset
, size
, &actread
);
55 int spl_load_image_fat(struct spl_image_info
*spl_image
,
56 struct blk_desc
*block_dev
, int partition
,
60 struct image_header
*header
;
62 err
= spl_register_fat_device(block_dev
, partition
);
66 header
= (struct image_header
*)(CONFIG_SYS_TEXT_BASE
-
67 sizeof(struct image_header
));
69 err
= file_fat_read(filename
, header
, sizeof(struct image_header
));
73 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL
) &&
74 image_get_magic(header
) == FDT_MAGIC
) {
75 err
= file_fat_read(filename
, (void *)CONFIG_SYS_LOAD_ADDR
, 0);
78 err
= spl_parse_image_header(spl_image
,
79 (struct image_header
*)CONFIG_SYS_LOAD_ADDR
);
84 } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT
) &&
85 image_get_magic(header
) == FDT_MAGIC
) {
86 struct spl_load_info load
;
89 load
.read
= spl_fit_read
;
91 load
.filename
= (void *)filename
;
94 return spl_load_simple_fit(spl_image
, &load
, 0, header
);
96 err
= spl_parse_image_header(spl_image
, header
);
100 err
= file_fat_read(filename
,
101 (u8
*)(uintptr_t)spl_image
->load_addr
, 0);
105 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
107 printf("%s: error reading image %s, err - %d\n",
108 __func__
, filename
, err
);
114 #ifdef CONFIG_SPL_OS_BOOT
115 int spl_load_image_fat_os(struct spl_image_info
*spl_image
,
116 struct blk_desc
*block_dev
, int partition
)
119 __maybe_unused
char *file
;
121 err
= spl_register_fat_device(block_dev
, partition
);
125 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
126 file
= env_get("falcon_args_file");
128 err
= file_fat_read(file
, (void *)CONFIG_SYS_SPL_ARGS_ADDR
, 0);
130 printf("spl: error reading image %s, err - %d, falling back to default\n",
134 file
= env_get("falcon_image_file");
136 err
= spl_load_image_fat(spl_image
, block_dev
,
139 puts("spl: falling back to default\n");
145 puts("spl: falcon_image_file not set in environment, falling back to default\n");
147 puts("spl: falcon_args_file not set in environment, falling back to default\n");
152 err
= file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME
,
153 (void *)CONFIG_SYS_SPL_ARGS_ADDR
, 0);
155 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
156 printf("%s: error reading image %s, err - %d\n",
157 __func__
, CONFIG_SPL_FS_LOAD_ARGS_NAME
, err
);
162 return spl_load_image_fat(spl_image
, block_dev
, partition
,
163 CONFIG_SPL_FS_LOAD_KERNEL_NAME
);
166 int spl_load_image_fat_os(struct spl_image_info
*spl_image
,
167 struct blk_desc
*block_dev
, int partition
)