mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/3] bootsource: add function to get device_node we booted from
Date: Mon, 19 Feb 2024 15:51:58 +0100	[thread overview]
Message-ID: <20240219145159.1962618-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240219145159.1962618-1-s.hauer@pengutronix.de>

We have a relation between the bootsource and the corresponding
device_node. Add a function to get the device_node we booted from.
This is already open coded in of_fixup_bootargs_bootsource(),
use the newly created function for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootsource.c  | 14 ++++++++++++++
 common/oftree.c      |  7 +------
 include/bootsource.h |  1 +
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/common/bootsource.c b/common/bootsource.c
index da528a5b9b..5666d8d30d 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -108,6 +108,20 @@ char *bootsource_get_alias_name(void)
 	return basprintf("%s%d", stem, bootsource_instance);
 }
 
+struct device_node *bootsource_of_node_get(struct device_node *root)
+{
+	struct device_node *np;
+	char *alias_name;
+
+	alias_name = bootsource_get_alias_name();
+
+	np = of_find_node_by_alias(root, alias_name);
+
+	free(alias_name);
+
+	return np;
+}
+
 void bootsource_set_alias_name(const char *name)
 {
 	bootsource_alias_name = name;
diff --git a/common/oftree.c b/common/oftree.c
index 51eebd36bd..c12b3cfb16 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -124,14 +124,10 @@ void of_print_cmdline(struct device_node *root)
 static int of_fixup_bootargs_bootsource(struct device_node *root,
 					struct device_node *chosen)
 {
-	char *alias_name = bootsource_get_alias_name();
 	struct device_node *bootsource;
 	int ret = 0;
 
-	if (!alias_name)
-		return 0;
-
-	bootsource = of_find_node_by_alias(root, alias_name);
+	bootsource = bootsource_of_node_get(root);
 	/*
 	 * If kernel DTB doesn't have the appropriate alias set up,
 	 * give up and exit early. No error is reported.
@@ -140,7 +136,6 @@ static int of_fixup_bootargs_bootsource(struct device_node *root,
 		ret = of_set_property(chosen, "bootsource", bootsource->full_name,
 				      strlen(bootsource->full_name) + 1, true);
 
-	free(alias_name);
 	return ret;
 }
 
diff --git a/include/bootsource.h b/include/bootsource.h
index f2ab3a2ad4..33ad269460 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -33,6 +33,7 @@ char *bootsource_get_alias_name(void);
 const char *bootsource_to_string(enum bootsource src);
 const char *bootsource_get_alias_stem(enum bootsource bs);
 int bootsource_of_alias_xlate(enum bootsource bs, int instance);
+struct device_node *bootsource_of_node_get(struct device_node *root);
 
 /**
  * bootsource_set - set bootsource with optional DT mapping table
-- 
2.39.2




  parent reply	other threads:[~2024-02-19 14:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 14:51 [PATCH 0/3] use environment partitions in GPT Sascha Hauer
2024-02-19 14:51 ` [PATCH 1/3] partitions: efi: Allow to create barebox environment partition Sascha Hauer
2024-02-19 15:20   ` Ahmad Fatoum
2024-02-20 10:52     ` Sascha Hauer
2024-02-19 14:51 ` Sascha Hauer [this message]
2024-02-19 14:59   ` [PATCH 2/3] bootsource: add function to get device_node we booted from Marco Felsch
2024-02-19 15:21     ` Sascha Hauer
2024-02-20 10:56       ` Sascha Hauer
2024-02-19 14:51 ` [PATCH 3/3] environment: use barebox environment from GPT partitions Sascha Hauer
2024-02-19 15:06 ` [PATCH 0/3] use environment partitions in GPT Marco Felsch

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=20240219145159.1962618-3-s.hauer@pengutronix.de \
    --to=s.hauer@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