From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master v2 2/2] bootm: remove ability for late override of bootm.image
Date: Mon, 7 Apr 2025 12:47:56 +0200 [thread overview]
Message-ID: <20250407104756.3379066-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250407104756.3379066-1-a.fatoum@pengutronix.de>
Overriding struct image_data::os_file at the location where we do it
now is not robust as the bootm handler is chosen by then and there
is no check if the override image is suitable for the original handler.
This can't be fixed in a straight-forward manner by moving the override
earlier as that would break appendroot for example.
To be able to do this robustly, some rework of the boot code may be in
order, so for now allow only overriding the oftree and the initrd.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- squash removal of unreferenced goto label and ensure it applies
cleanly
---
commands/boot.c | 4 ++--
common/bootm.c | 36 +++++++++---------------------------
include/bootm-overrides.h | 3 ---
3 files changed, 11 insertions(+), 32 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index aad01fdc6c95..07f4db4b8033 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -43,7 +43,7 @@ static int boot_add_override(struct bootm_overrides *overrides, char *var)
if (!strcmp(var, "bootm.image")) {
if (isempty(val))
return -EINVAL;
- overrides->os_file = val;
+ return -ENOSYS;
} else if (!strcmp(var, "bootm.oftree")) {
overrides->oftree_file = val;
} else if (!strcmp(var, "bootm.initrd")) {
@@ -191,7 +191,7 @@ BAREBOX_CMD_HELP_OPT ("-m","Show a menu with boot options")
BAREBOX_CMD_HELP_OPT ("-M INDEX","Show a menu with boot options with entry INDEX preselected")
BAREBOX_CMD_HELP_OPT ("-w SECS","Start watchdog with timeout SECS before booting")
#ifdef CONFIG_BOOT_OVERRIDE
-BAREBOX_CMD_HELP_OPT ("-o VAR[=VAL]","override VAR (bootm.{image,oftree,initrd}) with VAL")
+BAREBOX_CMD_HELP_OPT ("-o VAR[=VAL]","override VAR (bootm.{oftree,initrd}) with VAL")
BAREBOX_CMD_HELP_OPT (" ","if VAL is not specified, the value of VAR is taken")
#endif
BAREBOX_CMD_HELP_OPT ("-t SECS","specify timeout in SECS")
diff --git a/common/bootm.c b/common/bootm.c
index 6b63987f0900..a5065c3860b3 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -175,12 +175,6 @@ static bool bootm_get_override(char **oldpath, const char *newpath)
*/
int bootm_load_os(struct image_data *data, unsigned long load_address)
{
- if (bootm_get_override(&data->os_file, bootm_overrides.os_file)) {
- if (load_address == UIMAGE_INVALID_ADDRESS)
- return -EINVAL;
- goto os_file;
- }
-
if (data->os_res)
return 0;
@@ -220,7 +214,6 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
if (IS_ENABLED(CONFIG_ELF) && data->elf)
return elf_load(data->elf);
-os_file:
if (!data->os_file)
return -EINVAL;
@@ -569,19 +562,15 @@ int bootm_get_os_size(struct image_data *data)
struct stat s;
int ret;
- if (bootm_get_override(NULL, bootm_overrides.os_file)) {
- os_file = bootm_overrides.os_file;
- } else {
- if (data->elf)
- return elf_get_mem_size(data->elf);
- if (image_is_uimage(data))
- return uimage_get_size(data->os, uimage_part_num(data->os_part));
- if (data->os_fit)
- return data->fit_kernel_size;
- if (!data->os_file)
- return -EINVAL;
- os_file = data->os_file;
- }
+ if (data->elf)
+ return elf_get_mem_size(data->elf);
+ if (image_is_uimage(data))
+ return uimage_get_size(data->os, uimage_part_num(data->os_part));
+ if (data->os_fit)
+ return data->fit_kernel_size;
+ if (!data->os_file)
+ return -EINVAL;
+ os_file = data->os_file;
ret = stat(os_file, &s);
if (ret)
@@ -949,13 +938,6 @@ int bootm_boot(struct bootm_data *bootm_data)
printf("Passing control to %s handler\n", handler->name);
}
- if (bootm_get_override(&data->os_file, bootm_overrides.os_file)) {
- if (data->os_res) {
- release_sdram_region(data->os_res);
- data->os_res = NULL;
- }
- }
-
bootm_get_override(&data->oftree_file, bootm_overrides.oftree_file);
if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file)) {
diff --git a/include/bootm-overrides.h b/include/bootm-overrides.h
index 231c913709e2..19557f63acd9 100644
--- a/include/bootm-overrides.h
+++ b/include/bootm-overrides.h
@@ -3,7 +3,6 @@
#define __BOOTM_OVERRIDES_H
struct bootm_overrides {
- const char *os_file;
const char *oftree_file;
const char *initrd_file;
};
@@ -19,8 +18,6 @@ static inline void bootm_merge_overrides(struct bootm_overrides *dst,
{
if (!IS_ENABLED(CONFIG_BOOT_OVERRIDE))
return;
- if (src->os_file)
- dst->os_file = src->os_file;
if (src->oftree_file)
dst->oftree_file = src->oftree_file;
if (src->initrd_file)
--
2.39.5
next prev parent reply other threads:[~2025-04-07 10:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 10:47 [PATCH master v2 1/2] bootm: associate bootm overrides with struct bootentry Ahmad Fatoum
2025-04-07 10:47 ` Ahmad Fatoum [this message]
2025-04-07 13:01 ` Sascha Hauer
2025-04-07 13:16 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250407104756.3379066-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox