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>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <part.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,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:14 +00:00
|
|
|
struct blk_desc *block_dev, int partition,
|
|
|
|
const char *filename)
|
2014-10-15 15:53:12 +00:00
|
|
|
{
|
|
|
|
s32 err;
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *header;
|
2014-11-17 22:39:36 +00:00
|
|
|
loff_t filelen, actlen;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition part_info = {};
|
2014-10-15 15:53:12 +00:00
|
|
|
|
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);
|
|
|
|
|
2023-05-02 16:10:20 +00:00
|
|
|
err = ext4fs_mount(part_info.size);
|
2014-10-15 15:53:12 +00:00
|
|
|
if (!err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: ext4fs mount err - %d\n", __func__, err);
|
|
|
|
#endif
|
2020-06-16 20:03:52 +00:00
|
|
|
return -1;
|
2014-10-15 15:53:12 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2022-09-07 02:26:52 +00:00
|
|
|
err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), &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;
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_parse_image_header(spl_image, bootdev, 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
|
|
|
}
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2016-09-25 00:20:14 +00:00
|
|
|
int spl_load_image_ext_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:14 +00:00
|
|
|
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;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition part_info = {};
|
2014-10-15 15:53:12 +00:00
|
|
|
__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);
|
|
|
|
|
2023-05-02 16:10:20 +00:00
|
|
|
err = ext4fs_mount(part_info.size);
|
2014-10-15 15:53:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-09-26 14:14:17 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_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) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_ext(spl_image, bootdev, block_dev,
|
2016-09-25 00:20:14 +00:00
|
|
|
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");
|
|
|
|
|
2023-09-26 14:14:17 +00:00
|
|
|
err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_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;
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
return spl_load_image_ext(spl_image, bootdev, 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,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:14 +00:00
|
|
|
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
|