mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
From: Michael Olbrich <m.olbrich@pengutronix.de>
To: oss-tools@pengutronix.de
Cc: Michael Olbrich <m.olbrich@pengutronix.de>
Subject: [OSS-Tools] [PATCH 3/4] state: support backend-diskuuid / backend-offset
Date: Mon, 24 Jan 2022 12:21:42 +0100	[thread overview]
Message-ID: <20220124112143.3016473-4-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <20220124112143.3016473-1-m.olbrich@pengutronix.de>

On some platforms (e.g. EFI on x86_64) the state backend can only be
selected by a partiton UUID. On existing devices with a DOS partition
table, there may be no spare partition available for state.

This makes it possible to select the disk via UUID. The exact position is
defined by an explicitly specified offset.

The same patch was submittet to barebox:
https://lore.barebox.org/barebox/20220124100458.2924679-4-m.olbrich@pengutronix.de/

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 src/barebox-state/state.c | 55 ++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index 363ac8a5d485..f825ee6f1303 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -593,6 +593,7 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
 	const char *backend_type;
 	const char *storage_type = NULL;
 	const char *alias;
+	const char *diskuuid;
 	uint32_t stridesize;
 	struct device_node *partition_node;
 	off_t offset = 0;
@@ -608,30 +609,48 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
 	if (IS_ERR(state))
 		return state;
 
-	partition_node = of_parse_phandle(node, "backend", 0);
-	if (!partition_node) {
-		dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n");
-		ret = -EINVAL;
-		goto out_release_state;
-	}
+	ret = of_property_read_string(node, "backend-diskuuid", &diskuuid);
+	if (ret == 0) {
+		u64 off;
+
+		ret = devpath_from_diskuuid(diskuuid, &state->backend_path);
+		if (ret) {
+			dev_err(&state->dev, "state failed find backend device for diskuuid='%s'\n",
+				diskuuid);
+			goto out_release_state;
+		}
+		ret = of_property_read_u64(node, "backend-offset", &off);
+		if (ret) {
+			dev_err(&state->dev, "'backend-offset' property undefined\n");
+			goto out_release_state;
+		}
+		offset = off;
+	} else {
+		partition_node = of_parse_phandle(node, "backend", 0);
+		if (!partition_node) {
+			dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n");
+			ret = -EINVAL;
+			goto out_release_state;
+		}
 
 #ifdef __BAREBOX__
-	ret = of_partition_ensure_probed(partition_node);
-	if (ret)
-		goto out_release_state;
+		ret = of_partition_ensure_probed(partition_node);
+		if (ret)
+			goto out_release_state;
 
-	ret = of_find_path_by_node(partition_node, &state->backend_path, 0);
+		ret = of_find_path_by_node(partition_node, &state->backend_path, 0);
 #else
-	ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size);
+		ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size);
 #endif
-	if (ret) {
-		if (ret != -EPROBE_DEFER)
-			dev_err(&state->dev, "state failed to parse path to backend: %s\n",
-			       strerror(-ret));
-		goto out_release_state;
-	}
+		if (ret) {
+			if (ret != -EPROBE_DEFER)
+				dev_err(&state->dev, "state failed to parse path to backend: %s\n",
+				       strerror(-ret));
+			goto out_release_state;
+		}
 
-	state->backend_reproducible_name = of_get_reproducible_name(partition_node);
+		state->backend_reproducible_name = of_get_reproducible_name(partition_node);
+	}
 
 	ret = of_property_read_string(node, "backend-type", &backend_type);
 	if (ret) {
-- 
2.30.2


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de


  parent reply	other threads:[~2022-01-24 11:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 11:21 [OSS-Tools] [PATCH 0/4] improve barebox-state support on EFI system Michael Olbrich
2022-01-24 11:21 ` [OSS-Tools] [PATCH 1/4] state: support deep probe Michael Olbrich
2022-01-24 11:21 ` [OSS-Tools] [PATCH 2/4] state: implement helper to find device path from diskuuid Michael Olbrich
2022-01-24 11:21 ` Michael Olbrich [this message]
2022-01-24 11:21 ` [OSS-Tools] [PATCH 4/4] state: automatically find state.dtb in the ESP Michael Olbrich
2022-02-05 23:37 ` [OSS-Tools] [PATCH 0/4] improve barebox-state support on EFI system Roland Hieber
2022-02-06  7:22   ` Michael Olbrich

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=20220124112143.3016473-4-m.olbrich@pengutronix.de \
    --to=m.olbrich@pengutronix.de \
    --cc=oss-tools@pengutronix.de \
    /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