2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-10-15 15:53:12 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:52 +00:00
|
|
|
#include <env.h>
|
2014-10-15 15:53:12 +00:00
|
|
|
#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>
|
|
|
|
|
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 = {};
|
|
|
|
|
2018-08-14 09:27:02 +00:00
|
|
|
header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
|
2014-10-15 15:53:12 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2016-11-06 17:33:57 +00:00
|
|
|
err = ext4fs_read((char *)header, 0, 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-11-06 17:33:57 +00:00
|
|
|
err = ext4fs_read((char *)spl_image->load_addr, 0, 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)
|
2017-08-03 18:22:12 +00:00
|
|
|
file = env_get("falcon_args_file");
|
2014-10-15 15:53:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-11-06 17:33:57 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, 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;
|
|
|
|
}
|
2017-08-03 18:22:12 +00:00
|
|
|
file = env_get("falcon_image_file");
|
2014-10-15 15:53:12 +00:00
|
|
|
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");
|
|
|
|
|
2016-11-06 17:33:57 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, 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
|