X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fspl%2Fspl_fat.c;h=0403016bb433c7bdb2299bdcc215204c6cb6bcec;hb=1612ff0dfba57b1002d8c7a54778eb553ace98f4;hp=1e532d5963e0e0ef84bbf3a90809c9b0aafc982d;hpb=e97f9d817e600cd6f43d1d0da76f5787e33a5c56;p=u-boot diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 1e532d5963..0403016bb4 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -1,11 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2014 * Texas Instruments, * * Dan Murphy * - * SPDX-License-Identifier: GPL-2.0+ - * * FAT Image Functions copied from spl_mmc.c */ @@ -13,12 +12,13 @@ #include #include #include +#include #include +#include static int fat_registered; -#ifdef CONFIG_SPL_FAT_SUPPORT -static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) +static int spl_register_fat_device(struct blk_desc *block_dev, int partition) { int err = 0; @@ -30,7 +30,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: fat register err - %d\n", __func__, err); #endif - hang(); + return err; } fat_registered = 1; @@ -38,9 +38,23 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) return err; } -int spl_load_image_fat(block_dev_desc_t *block_dev, - int partition, - const char *filename) +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, + ulong size, void *buf) +{ + loff_t actread; + int ret; + char *filename = (char *)load->filename; + + ret = fat_read_file(filename, buf, file_offset, size, &actread); + if (ret) + return ret; + + return actread; +} + +int spl_load_image_fat(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition, + const char *filename) { int err; struct image_header *header; @@ -56,9 +70,36 @@ int spl_load_image_fat(block_dev_desc_t *block_dev, if (err <= 0) goto end; - spl_parse_image_header(header); - - err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0); + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) && + image_get_magic(header) == FDT_MAGIC) { + err = file_fat_read(filename, (void *)CONFIG_SYS_LOAD_ADDR, 0); + if (err <= 0) + goto end; + err = spl_parse_image_header(spl_image, + (struct image_header *)CONFIG_SYS_LOAD_ADDR); + if (err == -EAGAIN) + return err; + if (err == 0) + err = 1; + } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) { + struct spl_load_info load; + + debug("Found FIT\n"); + load.read = spl_fit_read; + load.bl_len = 1; + load.filename = (void *)filename; + load.priv = NULL; + + return spl_load_simple_fit(spl_image, &load, 0, header); + } else { + err = spl_parse_image_header(spl_image, header); + if (err) + goto end; + + err = file_fat_read(filename, + (u8 *)(uintptr_t)spl_image->load_addr, 0); + } end: #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT @@ -71,26 +112,60 @@ end: } #ifdef CONFIG_SPL_OS_BOOT -int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) +int spl_load_image_fat_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) { int err; + __maybe_unused char *file; err = spl_register_fat_device(block_dev, partition); if (err) return err; - err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, +#if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) + file = env_get("falcon_args_file"); + if (file) { + err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); + if (err <= 0) { + printf("spl: error reading image %s, err - %d, falling back to default\n", + file, err); + goto defaults; + } + file = env_get("falcon_image_file"); + if (file) { + err = spl_load_image_fat(spl_image, block_dev, + partition, file); + if (err != 0) { + puts("spl: falling back to default\n"); + goto defaults; + } + + return 0; + } else + puts("spl: falcon_image_file not set in environment, falling back to default\n"); + } else + puts("spl: falcon_args_file not set in environment, falling back to default\n"); + +defaults: +#endif + + err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); if (err <= 0) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: error reading image %s, err - %d\n", - __func__, CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); + __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); #endif return -1; } - return spl_load_image_fat(block_dev, partition, - CONFIG_SPL_FAT_LOAD_KERNEL_NAME); + return spl_load_image_fat(spl_image, block_dev, partition, + CONFIG_SPL_FS_LOAD_KERNEL_NAME); +} +#else +int spl_load_image_fat_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) +{ + return -ENOSYS; } -#endif #endif