From 6b8e03a95869f99cabeea0728e6f5469f3960bf7 Mon Sep 17 00:00:00 2001 From: Anshul Dalal Date: Tue, 23 Sep 2025 18:16:35 +0530 Subject: spl: fat: load kernel image before args in falcon Currently in falcon mode, the FS and raw mmc boot loads the args file first followed by the kernel image whereas others load in the opposite order. This inconsistency means falcon boot doesn't behave the same across various boot media. For example, in the case where the kernel file is a FIT with the kernel image present alongside the dtb and the args file is another DT, which DT should be picked? The one form the FIT or the one set by the args file? Currently this depends entirely on how the boot media handles falcon mode. Therefore, this patch enforces the load order of the kernel image first followed by the args file in FAT FS boot. So in the above example, the args file would take precedence. Reviewed-by: Tom Rini Signed-off-by: Anshul Dalal --- common/spl/spl_fat.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 8b7cafa7291..2c8eee01272 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -119,32 +119,40 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image, if (err) return err; -#if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) - file = env_get("falcon_args_file"); + if (!CONFIG_IS_ENABLED(ENV_SUPPORT)) + goto defaults; + + file = env_get("falcon_image_file"); if (file) { - err = file_fat_read(file, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0); - if (err <= 0) { - printf("spl: error reading image %s, err - %d, falling back to default\n", - file, err); + err = spl_load_image_fat(spl_image, bootdev, block_dev, + partition, file); + if (err != 0) { + puts("spl: falling back to default\n"); goto defaults; } - file = env_get("falcon_image_file"); + + file = env_get("falcon_args_file"); if (file) { - err = spl_load_image_fat(spl_image, bootdev, block_dev, - partition, file); - if (err != 0) { - puts("spl: falling back to default\n"); + err = file_fat_read( + file, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0); + if (err <= 0) { + printf("spl: error reading args %s, err - %d, falling back to default\n", + file, err); goto defaults; } - return 0; } else - puts("spl: falcon_image_file not set in environment, falling back to default\n"); + puts("spl: falcon_args_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"); + puts("spl: falcon_image_file not set in environment, falling back to default\n"); defaults: -#endif + + err = spl_load_image_fat(spl_image, bootdev, block_dev, partition, + CONFIG_SPL_FS_LOAD_KERNEL_NAME); + + if (err) + return err; err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0); @@ -156,8 +164,7 @@ defaults: return -1; } - return spl_load_image_fat(spl_image, bootdev, block_dev, partition, - CONFIG_SPL_FS_LOAD_KERNEL_NAME); + return 0; } #else int spl_load_image_fat_os(struct spl_image_info *spl_image, -- cgit v1.3.1 From 50953dd5cd8063e0902335c1588997e3ce12994c Mon Sep 17 00:00:00 2001 From: Anshul Dalal Date: Tue, 23 Sep 2025 18:16:36 +0530 Subject: spl: ext: load kernel image before args in falcon Load the kernel image before args in falcon mode to be consistent with the load order for other boot media. Reviewed-by: Tom Rini Signed-off-by: Anshul Dalal --- common/spl/spl_ext.c | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index 7e0274a3058..80bd084db4e 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -96,40 +96,53 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image, #endif return -1; } -#if defined(CONFIG_SPL_ENV_SUPPORT) - file = env_get("falcon_args_file"); + + if (!CONFIG_IS_ENABLED(ENV_SUPPORT)) + goto defaults; + + file = env_get("falcon_image_file"); if (file) { - err = ext4fs_open(file, &filelen); - if (err < 0) { - puts("spl: ext4fs_open failed\n"); - goto defaults; - } - err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen); - if (err < 0) { - printf("spl: error reading image %s, err - %d, falling back to default\n", - file, err); + err = spl_load_image_ext(spl_image, bootdev, block_dev, + partition, file); + if (err != 0) { + puts("spl: falling back to default\n"); goto defaults; } - file = env_get("falcon_image_file"); + + ext4fs_set_blk_dev(block_dev, &part_info); + ext4fs_mount(); + file = env_get("falcon_args_file"); if (file) { - err = spl_load_image_ext(spl_image, bootdev, block_dev, - partition, file); - if (err != 0) { - puts("spl: falling back to default\n"); + err = ext4fs_open(file, &filelen); + if (err < 0) { + puts("spl: ext4fs_open failed\n"); + goto defaults; + } + err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, + 0, filelen, &actlen); + if (err < 0) { + printf("spl: error reading args %s, err - %d, falling back to default\n", + file, err); goto defaults; } - return 0; } else { - puts("spl: falcon_image_file not set in environment, falling back to default\n"); + puts("spl: falcon_args_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"); + puts("spl: falcon_image_file not set in environment, falling back to default\n"); } defaults: -#endif + err = spl_load_image_ext(spl_image, bootdev, block_dev, partition, + CONFIG_SPL_FS_LOAD_KERNEL_NAME); + + if (err) + return err; + + ext4fs_set_blk_dev(block_dev, &part_info); + ext4fs_mount(); err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); if (err < 0) puts("spl: ext4fs_open failed\n"); @@ -143,8 +156,7 @@ defaults: return -1; } - return spl_load_image_ext(spl_image, bootdev, block_dev, partition, - CONFIG_SPL_FS_LOAD_KERNEL_NAME); + return 0; } #else int spl_load_image_ext_os(struct spl_image_info *spl_image, -- cgit v1.3.1 From 00edec55f388000b9161d2427e1ae2e55f53c8ea Mon Sep 17 00:00:00 2001 From: Anshul Dalal Date: Tue, 23 Sep 2025 18:16:37 +0530 Subject: spl: mmc: load kernel image before args in falcon Load the kernel image before args in falcon mode to be consistent with the load order for other boot media. Signed-off-by: Anshul Dalal --- common/spl/spl_mmc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index d06f9f0dee6..cd56cf71055 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -152,6 +152,16 @@ static int mmc_load_image_raw_os(struct spl_image_info *spl_image, { int ret; + ret = mmc_load_image_raw_sector(spl_image, bootdev, mmc, + CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); + if (ret) + return ret; + + if (spl_image->os != IH_OS_LINUX && spl_image->os != IH_OS_TEE) { + puts("Expected image is not found. Trying to start U-Boot\n"); + return -ENOENT; + } + #if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR) unsigned long count; @@ -165,16 +175,6 @@ static int mmc_load_image_raw_os(struct spl_image_info *spl_image, } #endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */ - ret = mmc_load_image_raw_sector(spl_image, bootdev, mmc, - CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); - if (ret) - return ret; - - if (spl_image->os != IH_OS_LINUX && spl_image->os != IH_OS_TEE) { - puts("Expected image is not found. Trying to start U-Boot\n"); - return -ENOENT; - } - return 0; } #else -- cgit v1.3.1 From d0b5b33c4fa7555d142a02edf07ba259691360b3 Mon Sep 17 00:00:00 2001 From: Anshul Dalal Date: Tue, 23 Sep 2025 18:16:38 +0530 Subject: spl: ext, fat: cleanup use of CONFIG_SPL_LIBCOMMON_SUPPORT Minor cleanup of spl_ext and spl_fat files, removing the outdated CONFIG_SPL_LIBCOMMON_SUPPORT symbols similar to the commit 1847129025e0 ("spl: mmc: Drop checks for CONFIG_SPL_LIBCOMMON_SUPPORT") and adding a few extra failure reports. Reviewed-by: Tom Rini Signed-off-by: Anshul Dalal --- common/spl/spl_ext.c | 8 -------- common/spl/spl_fat.c | 6 ------ 2 files changed, 14 deletions(-) diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index 80bd084db4e..c66ba03feb2 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -47,9 +47,7 @@ int spl_load_image_ext(struct spl_image_info *spl_image, err = ext4fs_mount(); if (!err) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: ext4fs mount err - %d\n", __func__, err); -#endif return -1; } @@ -63,11 +61,9 @@ int spl_load_image_ext(struct spl_image_info *spl_image, err = spl_load(spl_image, bootdev, &load, filelen, 0); end: -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT if (err < 0) printf("%s: error reading image %s, err - %d\n", __func__, filename, err); -#endif return err < 0; } @@ -91,9 +87,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image, err = ext4fs_mount(); if (!err) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: ext4fs mount err - %d\n", __func__, err); -#endif return -1; } @@ -149,10 +143,8 @@ defaults: err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen); if (err < 0) { -#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; } diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 2c8eee01272..dc52bd13cec 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -34,9 +34,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) err = fat_register_device(block_dev, partition); if (err) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: fat register err - %d\n", __func__, err); -#endif return err; } @@ -98,11 +96,9 @@ int spl_load_image_fat(struct spl_image_info *spl_image, err = spl_load(spl_image, bootdev, &load, size, 0); end: -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT if (err < 0) printf("%s: error reading image %s, err - %d\n", __func__, filename, err); -#endif return err; } @@ -157,10 +153,8 @@ defaults: err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0); if (err <= 0) { -#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; } -- cgit v1.3.1