From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/7] bootm: retire bootm_has_initrd
Date: Fri, 14 Feb 2025 11:48:16 +0100 [thread overview]
Message-ID: <20250214104817.2975052-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250214104817.2975052-1-a.fatoum@pengutronix.de>
All what's done by bootm_has_initrd can be folded into bootm_load_initrd
by having it return a special value (NULL) to indicate that no initrd
is available.
The advantage of doing it in one function is that it simplifies
overriding the initrd in a follow-up commit
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/lib32/bootm.c | 18 ++++++++----------
arch/kvx/lib/bootm.c | 23 +++++++++++------------
common/booti.c | 10 +++++-----
common/bootm.c | 35 ++++++++++++++---------------------
include/bootm.h | 4 ++--
5 files changed, 40 insertions(+), 50 deletions(-)
diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index aeb873a3a723..d3a4d99a5828 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -241,6 +241,7 @@ static int __do_bootm_linux(struct image_data *data, unsigned long free_mem,
{
unsigned long kernel;
unsigned long initrd_start = 0, initrd_size = 0, initrd_end = 0;
+ const struct resource *initrd_res;
void *tee;
enum arm_security_state state = bootm_arm_security_state();
void *fdt_load_address = NULL;
@@ -259,16 +260,13 @@ static int __do_bootm_linux(struct image_data *data, unsigned long free_mem,
}
}
- if (bootm_has_initrd(data)) {
- ret = bootm_load_initrd(data, initrd_start);
- if (ret)
- return ret;
- }
-
- if (data->initrd_res) {
- initrd_start = data->initrd_res->start;
- initrd_end = data->initrd_res->end;
- initrd_size = resource_size(data->initrd_res);
+ initrd_res = bootm_load_initrd(data, initrd_start);
+ if (IS_ERR(initrd_res)) {
+ return PTR_ERR(initrd_res);
+ } else if (initrd_res) {
+ initrd_start = initrd_res->start;
+ initrd_end = initrd_res->end;
+ initrd_size = resource_size(initrd_res);
free_mem = PAGE_ALIGN(initrd_end + 1);
}
diff --git a/arch/kvx/lib/bootm.c b/arch/kvx/lib/bootm.c
index 4c77f676ec0b..6c35b68f3d5d 100644
--- a/arch/kvx/lib/bootm.c
+++ b/arch/kvx/lib/bootm.c
@@ -54,6 +54,7 @@ static int do_boot_entry(struct image_data *data, boot_func_entry entry,
static int do_boot_elf(struct image_data *data, struct elf_image *elf)
{
+ const struct resource *initrd_res;
int ret;
void *fdt;
boot_func_entry entry;
@@ -61,21 +62,19 @@ static int do_boot_elf(struct image_data *data, struct elf_image *elf)
/* load initrd after the elf */
load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
- if (bootm_has_initrd(data)) {
- if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
- initrd_address = data->initrd_address;
- else
- initrd_address = load_addr;
+ if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
+ initrd_address = data->initrd_address;
+ else
+ initrd_address = load_addr;
+ initrd_res = bootm_load_initrd(data, initrd_address);
+ if (IS_ERR(initrd_res)) {
+ printf("Failed to load initrd\n");
+ return ret;
+ } else if (initrd_res) {
printf("Loading initrd at 0x%lx\n", initrd_address);
- ret = bootm_load_initrd(data, initrd_address);
- if (ret) {
- printf("Failed to load initrd\n");
- return ret;
- }
-
if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
- load_addr += resource_size(data->initrd_res);
+ load_addr += resource_size(initrd_res);
load_addr = PAGE_ALIGN(load_addr);
}
}
diff --git a/common/booti.c b/common/booti.c
index e745ff696376..5efd4f97bbc2 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -58,12 +58,12 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
if (oftree) {
unsigned long devicetree;
+ const struct resource *initrd_res;
- if (bootm_has_initrd(data)) {
- ret = bootm_load_initrd(data, image_end);
- if (ret)
- return ERR_PTR(ret);
-
+ initrd_res = bootm_load_initrd(data, image_end);
+ if (IS_ERR(initrd_res)) {
+ return ERR_CAST(initrd_res);
+ } else if (initrd_res) {
image_end += resource_size(data->initrd_res);
image_end = PAGE_ALIGN(image_end);
}
diff --git a/common/bootm.c b/common/bootm.c
index d24b18b41cb2..d2373f321c19 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -213,14 +213,6 @@ static bool fitconfig_has_ramdisk(struct image_data *data)
return fit_has_image(data->os_fit, data->fit_config, "ramdisk");
}
-bool bootm_has_initrd(struct image_data *data)
-{
- if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
- return false;
-
- return fitconfig_has_ramdisk(data) || data->initrd_file;
-}
-
static int bootm_open_initrd_uimage(struct image_data *data)
{
int ret;
@@ -262,19 +254,17 @@ static int bootm_open_initrd_uimage(struct image_data *data)
*
* Return: 0 on success, negative error code otherwise
*/
-int bootm_load_initrd(struct image_data *data, unsigned long load_address)
+const struct resource *
+bootm_load_initrd(struct image_data *data, unsigned long load_address)
{
enum filetype type;
int ret;
if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
- return -ENOSYS;
-
- if (!bootm_has_initrd(data))
- return -EINVAL;
+ return NULL;
if (data->initrd_res)
- return 0;
+ return data->initrd_res;
if (fitconfig_has_ramdisk(data)) {
const void *initrd;
@@ -285,7 +275,7 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
if (ret) {
pr_err("Cannot open ramdisk image in FIT image: %s\n",
strerror(-ret));
- return ret;
+ return ERR_PTR(ret);
}
data->initrd_res = request_sdram_region("initrd",
load_address,
@@ -295,17 +285,20 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
" 0x%08llx-0x%08llx\n",
(unsigned long long)load_address,
(unsigned long long)load_address + initrd_size - 1);
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
}
memcpy((void *)load_address, initrd, initrd_size);
pr_info("Loaded initrd from FIT image\n");
goto done1;
}
+ if (!data->initrd_file)
+ return NULL;
+
ret = file_name_detect_type(data->initrd_file, &type);
if (ret) {
pr_err("could not open initrd \"%s\": %s\n", data->initrd_file, strerror(-ret));
- return ret;
+ return ERR_PTR(ret);
}
if (type == filetype_uimage) {
@@ -314,7 +307,7 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
if (ret) {
pr_err("loading initrd failed with %s\n",
strerror(-ret));
- return ret;
+ return ERR_PTR(ret);
}
num = uimage_part_num(data->initrd_part);
@@ -322,14 +315,14 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
data->initrd_res = uimage_load_to_sdram(data->initrd,
num, load_address);
if (!data->initrd_res)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
goto done;
}
data->initrd_res = file_to_sdram(data->initrd_file, load_address);
if (!data->initrd_res)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
done:
@@ -343,7 +336,7 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
&data->initrd_res->start,
&data->initrd_res->end);
- return 0;
+ return data->initrd_res;
}
static int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
diff --git a/include/bootm.h b/include/bootm.h
index fdec137771f0..b86d06b0f55d 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -142,8 +142,8 @@ void bootm_data_restore_defaults(const struct bootm_data *data);
int bootm_load_os(struct image_data *data, unsigned long load_address);
-bool bootm_has_initrd(struct image_data *data);
-int bootm_load_initrd(struct image_data *data, unsigned long load_address);
+const struct resource *
+bootm_load_initrd(struct image_data *data, unsigned long load_address);
void *bootm_get_devicetree(struct image_data *data);
int bootm_load_devicetree(struct image_data *data, void *fdt,
--
2.39.5
next prev parent reply other threads:[~2025-02-14 10:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 10:48 [PATCH 0/7] commands: boot: add support for overriding boot artifacts Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 1/7] bootm: add helper functions for checking if FIT image is used Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 2/7] boot: move global.linux.bootargs.dyn. to common code Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 3/7] blspec: don't clobber bootm.image on boot attempt Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 4/7] fastboot: drop useless bootm.image clobber Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 5/7] bootm: don't clobber global.bootm. variables after script boot fails Ahmad Fatoum
2025-02-14 10:48 ` Ahmad Fatoum [this message]
2025-02-14 20:02 ` [PATCH] fixup! bootm: retire bootm_has_initrd Ahmad Fatoum
2025-02-14 10:48 ` [PATCH 7/7] commands: boot: add support for overriding boot artifacts Ahmad Fatoum
2025-02-15 12:29 ` [PATCH] fixup! " Ahmad Fatoum
2025-02-17 9:27 ` [PATCH 0/7] " 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=20250214104817.2975052-7-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