mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Subject: [RFC Patch 1/3] blspec: create list of entries, iterate over list
Date: Fri,  4 Mar 2022 07:24:11 +0100	[thread overview]
Message-ID: <20220304062412.1248657-2-r.czerwinski@pengutronix.de> (raw)
In-Reply-To: <20220304062412.1248657-1-r.czerwinski@pengutronix.de>

Instead of parsing all files in one go and checking the compatible,
create a list and iterate over it to check the compatible. This is a
preparation to not only account for the top-level barebox compatible,
but to instead use the compatible score system to find the correct
bootable device tree entry.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 common/blspec.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index 158fd1e9a2..0ea857294f 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -520,6 +520,21 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
  *
  * returns the number of entries found or a negative error value otherwise.
  */
+
+struct blspec_list_entry {
+	struct list_head list;
+	struct blspec_entry *entry;
+	char *name;
+};
+
+static int compare(struct list_head *a, struct list_head *b)
+{
+	char *na = (char *)list_entry(a, struct blspec_list_entry, list)->name;
+	char *nb = (char *)list_entry(b, struct blspec_list_entry, list)->name;
+
+	return strcmp(na, nb);
+}
+
 int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 {
 	struct blspec_entry *entry;
@@ -529,6 +544,11 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 	int ret, found = 0;
 	const char *dirname = "loader/entries";
 	char *nfspath = NULL;
+	struct list_head entry_list;
+	struct blspec_list_entry *lentry;
+	struct blspec_list_entry *temp;
+
+	INIT_LIST_HEAD(&entry_list);
 
 	nfspath = parse_nfs_url(root);
 	if (!IS_ERR(nfspath))
@@ -549,7 +569,6 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 		char *configname;
 		struct stat s;
 		char *dot;
-		char *devname = NULL, *hwdevname = NULL;
 
 		if (*d->d_name == '.')
 			continue;
@@ -593,13 +612,29 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 		entry->configpath = configname;
 		entry->cdev = get_cdev_by_mountpath(root);
 
+		lentry = calloc(1, sizeof(*lentry));
+		lentry->entry = entry;
+		lentry->name = d->d_name;
+
+		list_add_sort(&entry_list, &lentry->list, compare);
+	}
+
+	list_for_each_entry_safe(lentry, temp, &entry_list, list) {
+		char *devname = NULL, *hwdevname = NULL;
+
+		entry = lentry->entry;
+
 		if (!entry_is_of_compatible(entry)) {
 			blspec_entry_free(&entry->entry);
+			list_del(&lentry->list);
+			free(lentry);
 			continue;
 		}
 
 		if (!entry_is_match_machine_id(entry)) {
 			blspec_entry_free(&entry->entry);
+			list_del(&lentry->list);
+			free(lentry);
 			continue;
 		}
 
@@ -612,7 +647,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 		}
 
 		entry->entry.title = xasprintf("%s (%s)", blspec_entry_var_get(entry, "title"),
-					       configname);
+					       entry->configpath);
 		entry->entry.description = basprintf("blspec entry, device: %s hwdevice: %s",
 						    devname ? devname : "none",
 						    hwdevname ? hwdevname : "none");
@@ -623,6 +658,8 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 		entry->entry.release = blspec_entry_free;
 
 		bootentries_add_entry(bootentries, &entry->entry);
+		list_del(&lentry->list);
+		free(lentry);
 	}
 
 	ret = found;
-- 
2.35.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-03-04  6:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04  6:24 [RFC Patch 0/3] BLSpec device-tree fallback handling Rouven Czerwinski
2022-03-04  6:24 ` Rouven Czerwinski [this message]
2022-03-04  6:24 ` [RFC Patch 2/3] blspec: take compatible name as argument Rouven Czerwinski
2022-03-04  6:24 ` [RFC Patch 3/3] blspec: allow setting compatible depth Rouven Czerwinski
2022-03-08  8:11   ` 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=20220304062412.1248657-2-r.czerwinski@pengutronix.de \
    --to=r.czerwinski@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