2014-10-15 15:53:12 +00:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <spl.h>
|
|
|
|
#include <asm/u-boot.h>
|
|
|
|
#include <ext4fs.h>
|
2015-11-08 15:11:45 +00:00
|
|
|
#include <errno.h>
|
2014-10-15 15:53:12 +00:00
|
|
|
#include <image.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_EXT_SUPPORT
|
2016-09-25 00:20:14 +00:00
|
|
|
int spl_load_image_ext(struct spl_image_info *spl_image,
|
|
|
|
struct blk_desc *block_dev, int partition,
|
|
|
|
const char *filename)
|
2014-10-15 15:53:12 +00:00
|
|
|
{
|
|
|
|
s32 err;
|
|
|
|
struct image_header *header;
|
2014-11-17 22:39:36 +00:00
|
|
|
loff_t filelen, actlen;
|
2014-10-15 15:53:12 +00:00
|
|
|
disk_partition_t part_info = {};
|
|
|
|
|
|
|
|
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
|
|
|
|
sizeof(struct image_header));
|
|
|
|
|
2016-02-29 22:25:48 +00:00
|
|
|
if (part_get_info(block_dev, partition, &part_info)) {
|
2014-10-15 15:53:12 +00:00
|
|
|
printf("spl: no partition table found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext4fs_set_blk_dev(block_dev, &part_info);
|
|
|
|
|
|
|
|
err = ext4fs_mount(0);
|
|
|
|
if (!err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: ext4fs mount err - %d\n", __func__, err);
|
|
|
|
#endif
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2014-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_open(filename, &filelen);
|
2014-10-15 15:53:12 +00:00
|
|
|
if (err < 0) {
|
|
|
|
puts("spl: ext4fs_open failed\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2014-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen);
|
2014-11-25 14:34:16 +00:00
|
|
|
if (err < 0) {
|
2014-10-15 15:53:12 +00:00
|
|
|
puts("spl: ext4fs_read failed\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:14 +00:00
|
|
|
err = spl_parse_image_header(spl_image, header);
|
2016-04-28 22:44:54 +00:00
|
|
|
if (err < 0) {
|
2016-06-18 10:21:17 +00:00
|
|
|
puts("spl: ext: failed to parse image header\n");
|
2016-04-28 22:44:54 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2014-10-15 15:53:12 +00:00
|
|
|
|
2016-09-25 00:20:14 +00:00
|
|
|
err = ext4fs_read((char *)spl_image->load_addr, filelen, &actlen);
|
2014-10-15 15:53:12 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2014-11-25 14:34:16 +00:00
|
|
|
if (err < 0)
|
2014-10-15 15:53:12 +00:00
|
|
|
printf("%s: error reading image %s, err - %d\n",
|
|
|
|
__func__, filename, err);
|
|
|
|
#endif
|
|
|
|
|
2014-11-25 14:34:16 +00:00
|
|
|
return err < 0;
|
2014-10-15 15:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_OS_BOOT
|
2016-09-25 00:20:14 +00:00
|
|
|
int spl_load_image_ext_os(struct spl_image_info *spl_image,
|
|
|
|
struct blk_desc *block_dev, int partition)
|
2014-10-15 15:53:12 +00:00
|
|
|
{
|
|
|
|
int err;
|
2014-11-17 22:39:36 +00:00
|
|
|
__maybe_unused loff_t filelen, actlen;
|
2014-10-15 15:53:12 +00:00
|
|
|
disk_partition_t part_info = {};
|
|
|
|
__maybe_unused char *file;
|
|
|
|
|
2016-02-29 22:25:48 +00:00
|
|
|
if (part_get_info(block_dev, partition, &part_info)) {
|
2014-10-15 15:53:12 +00:00
|
|
|
printf("spl: no partition table found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext4fs_set_blk_dev(block_dev, &part_info);
|
|
|
|
|
|
|
|
err = ext4fs_mount(0);
|
|
|
|
if (!err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: ext4fs mount err - %d\n", __func__, err);
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-14 10:06:36 +00:00
|
|
|
#if defined(CONFIG_SPL_ENV_SUPPORT)
|
2014-10-15 15:53:12 +00:00
|
|
|
file = getenv("falcon_args_file");
|
|
|
|
if (file) {
|
2014-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_open(file, &filelen);
|
2014-10-15 15:53:12 +00:00
|
|
|
if (err < 0) {
|
|
|
|
puts("spl: ext4fs_open failed\n");
|
|
|
|
goto defaults;
|
|
|
|
}
|
2014-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
|
2014-11-25 14:34:16 +00:00
|
|
|
if (err < 0) {
|
2014-10-15 15:53:12 +00:00
|
|
|
printf("spl: error reading image %s, err - %d, falling back to default\n",
|
|
|
|
file, err);
|
|
|
|
goto defaults;
|
|
|
|
}
|
|
|
|
file = getenv("falcon_image_file");
|
|
|
|
if (file) {
|
2016-09-25 00:20:14 +00:00
|
|
|
err = spl_load_image_ext(spl_image, block_dev,
|
|
|
|
partition, file);
|
2014-10-15 15:53:12 +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-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen);
|
2014-10-15 15:53:12 +00:00
|
|
|
if (err < 0)
|
|
|
|
puts("spl: ext4fs_open failed\n");
|
|
|
|
|
2014-11-17 22:39:36 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
|
2014-11-25 14:34:16 +00:00
|
|
|
if (err < 0) {
|
2014-10-15 15:53:12 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: error reading image %s, err - %d\n",
|
|
|
|
__func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:14 +00:00
|
|
|
return spl_load_image_ext(spl_image, block_dev, partition,
|
2014-10-15 15:53:12 +00:00
|
|
|
CONFIG_SPL_FS_LOAD_KERNEL_NAME);
|
|
|
|
}
|
2015-11-08 15:11:45 +00:00
|
|
|
#else
|
2016-09-25 00:20:14 +00:00
|
|
|
int spl_load_image_ext_os(struct spl_image_info *spl_image,
|
|
|
|
struct blk_desc *block_dev, int partition)
|
2015-11-08 15:11:45 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2014-10-15 15:53:12 +00:00
|
|
|
#endif
|
|
|
|
#endif
|