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 static int spl_register_fat_device(struct blk_desc
*block_dev
, int partition
)
29 err
= fat_register_device(block_dev
, partition
);
31 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
32 printf("%s: fat register err - %d\n", __func__
, err
);
42 static ulong
spl_fit_read(struct spl_load_info
*load
, ulong file_offset
,
43 ulong size
, void *buf
)
47 char *filename
= (char *)load
->filename
;
49 ret
= fat_read_file(filename
, buf
, file_offset
, size
, &actread
);
56 int spl_load_image_fat(struct spl_image_info
*spl_image
,
57 struct blk_desc
*block_dev
, int partition
,
61 struct image_header
*header
;
63 err
= spl_register_fat_device(block_dev
, partition
);
67 header
= (struct image_header
*)(CONFIG_SYS_TEXT_BASE
-
68 sizeof(struct image_header
));
70 err
= file_fat_read(filename
, header
, sizeof(struct image_header
));
74 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT
) &&
75 image_get_magic(header
) == FDT_MAGIC
) {
76 struct spl_load_info load
;
79 load
.read
= spl_fit_read
;
81 load
.filename
= (void *)filename
;
84 return spl_load_simple_fit(spl_image
, &load
, 0, header
);
86 err
= spl_parse_image_header(spl_image
, header
);
90 err
= file_fat_read(filename
,
91 (u8
*)(uintptr_t)spl_image
->load_addr
, 0);
95 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
97 printf("%s: error reading image %s, err - %d\n",
98 __func__
, filename
, err
);
104 #ifdef CONFIG_SPL_OS_BOOT
105 int spl_load_image_fat_os(struct spl_image_info
*spl_image
,
106 struct blk_desc
*block_dev
, int partition
)
109 __maybe_unused
char *file
;
111 err
= spl_register_fat_device(block_dev
, partition
);
115 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
116 file
= getenv("falcon_args_file");
118 err
= file_fat_read(file
, (void *)CONFIG_SYS_SPL_ARGS_ADDR
, 0);
120 printf("spl: error reading image %s, err - %d, falling back to default\n",
124 file
= getenv("falcon_image_file");
126 err
= spl_load_image_fat(spl_image
, block_dev
,
129 puts("spl: falling back to default\n");
135 puts("spl: falcon_image_file not set in environment, falling back to default\n");
137 puts("spl: falcon_args_file not set in environment, falling back to default\n");
142 err
= file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME
,
143 (void *)CONFIG_SYS_SPL_ARGS_ADDR
, 0);
145 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
146 printf("%s: error reading image %s, err - %d\n",
147 __func__
, CONFIG_SPL_FS_LOAD_ARGS_NAME
, err
);
152 return spl_load_image_fat(spl_image
, block_dev
, partition
,
153 CONFIG_SPL_FS_LOAD_KERNEL_NAME
);
156 int spl_load_image_fat_os(struct spl_image_info
*spl_image
,
157 struct blk_desc
*block_dev
, int partition
)