2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-01-16 17:23:29 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Dan Murphy <dmurphy@ti.com>
|
|
|
|
*
|
|
|
|
* FAT Image Functions copied from spl_mmc.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:52 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-01-16 17:23:29 +00:00
|
|
|
#include <spl.h>
|
|
|
|
#include <asm/u-boot.h>
|
|
|
|
#include <fat.h>
|
2015-11-08 15:11:45 +00:00
|
|
|
#include <errno.h>
|
2014-01-16 17:23:29 +00:00
|
|
|
#include <image.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2014-01-16 17:23:29 +00:00
|
|
|
|
|
|
|
static int fat_registered;
|
|
|
|
|
2016-02-29 22:25:34 +00:00
|
|
|
static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
|
2014-01-16 17:23:29 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (fat_registered)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = fat_register_device(block_dev, partition);
|
|
|
|
if (err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2014-01-16 17:23:30 +00:00
|
|
|
printf("%s: fat register err - %d\n", __func__, err);
|
2014-01-16 17:23:29 +00:00
|
|
|
#endif
|
2014-10-15 15:53:14 +00:00
|
|
|
return err;
|
2014-01-16 17:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fat_registered = 1;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-05-24 05:04:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:15 +00:00
|
|
|
int spl_load_image_fat(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:15 +00:00
|
|
|
struct blk_desc *block_dev, int partition,
|
|
|
|
const char *filename)
|
2014-01-16 17:23:29 +00:00
|
|
|
{
|
|
|
|
int err;
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *header;
|
2014-01-16 17:23:29 +00:00
|
|
|
|
|
|
|
err = spl_register_fat_device(block_dev, partition);
|
2014-01-16 17:23:30 +00:00
|
|
|
if (err)
|
2014-01-16 17:23:29 +00:00
|
|
|
goto end;
|
|
|
|
|
2018-08-14 09:27:02 +00:00
|
|
|
header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
|
2014-01-16 17:23:29 +00:00
|
|
|
|
2022-09-07 02:26:52 +00:00
|
|
|
err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
|
2014-01-16 17:23:29 +00:00
|
|
|
if (err <= 0)
|
|
|
|
goto end;
|
|
|
|
|
2018-05-31 15:59:19 +00:00
|
|
|
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;
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_parse_image_header(spl_image, bootdev,
|
2022-09-07 02:26:52 +00:00
|
|
|
(struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
|
2018-05-31 15:59:19 +00:00
|
|
|
if (err == -EAGAIN)
|
|
|
|
return err;
|
|
|
|
if (err == 0)
|
|
|
|
err = 1;
|
|
|
|
} else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
|
2016-05-24 05:04:39 +00:00
|
|
|
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;
|
2014-01-16 17:23:29 +00:00
|
|
|
|
2016-09-25 00:20:16 +00:00
|
|
|
return spl_load_simple_fit(spl_image, &load, 0, header);
|
2016-05-24 05:04:39 +00:00
|
|
|
} else {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_parse_image_header(spl_image, bootdev, header);
|
2016-05-24 05:04:39 +00:00
|
|
|
if (err)
|
|
|
|
goto end;
|
|
|
|
|
2016-04-27 14:07:20 +00:00
|
|
|
err = file_fat_read(filename,
|
2016-09-25 00:20:15 +00:00
|
|
|
(u8 *)(uintptr_t)spl_image->load_addr, 0);
|
2016-05-24 05:04:39 +00:00
|
|
|
}
|
2014-01-16 17:23:29 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
if (err <= 0)
|
2014-01-16 17:23:30 +00:00
|
|
|
printf("%s: error reading image %s, err - %d\n",
|
|
|
|
__func__, filename, err);
|
2014-01-16 17:23:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return (err <= 0);
|
|
|
|
}
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2016-09-25 00:20:15 +00:00
|
|
|
int spl_load_image_fat_os(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:15 +00:00
|
|
|
struct blk_desc *block_dev, int partition)
|
2014-01-16 17:23:29 +00:00
|
|
|
{
|
|
|
|
int err;
|
2014-03-28 16:03:42 +00:00
|
|
|
__maybe_unused char *file;
|
2014-01-16 17:23:29 +00:00
|
|
|
|
|
|
|
err = spl_register_fat_device(block_dev, partition);
|
2014-01-16 17:23:30 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-01-16 17:23:29 +00:00
|
|
|
|
2014-03-28 16:03:42 +00:00
|
|
|
#if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
|
2017-08-03 18:22:12 +00:00
|
|
|
file = env_get("falcon_args_file");
|
2014-03-28 16:03:42 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-08-03 18:22:12 +00:00
|
|
|
file = env_get("falcon_image_file");
|
2014-03-28 16:03:42 +00:00
|
|
|
if (file) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_fat(spl_image, bootdev, block_dev,
|
2016-09-25 00:20:15 +00:00
|
|
|
partition, file);
|
2014-03-28 16:03:42 +00:00
|
|
|
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
|
|
|
|
|
2014-10-15 15:53:11 +00:00
|
|
|
err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME,
|
2014-01-16 17:23:29 +00:00
|
|
|
(void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
|
|
|
|
if (err <= 0) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2014-01-16 17:23:30 +00:00
|
|
|
printf("%s: error reading image %s, err - %d\n",
|
2014-10-15 15:53:11 +00:00
|
|
|
__func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
|
2014-01-16 17:23:29 +00:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
return spl_load_image_fat(spl_image, bootdev, block_dev, partition,
|
2014-10-15 15:53:11 +00:00
|
|
|
CONFIG_SPL_FS_LOAD_KERNEL_NAME);
|
2014-01-16 17:23:29 +00:00
|
|
|
}
|
2015-11-08 15:11:45 +00:00
|
|
|
#else
|
2016-09-25 00:20:15 +00:00
|
|
|
int spl_load_image_fat_os(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:15 +00:00
|
|
|
struct blk_desc *block_dev, int partition)
|
2015-11-08 15:11:45 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2014-01-16 17:23:29 +00:00
|
|
|
#endif
|