[PATCH 1/2] blspec: honour default/once entries again and move them to a different place

Marc Kleine-Budde mkl at pengutronix.de
Tue May 26 05:46:20 PDT 2015


From: Sascha Hauer <s.hauer at pengutronix.de>

Support for default/once entries was lost earlier. This fixes this
and also looks for default/once entries in the loader directory instead
of the loader parent directory. This keeps the bootloader spec files
together under a common loader directory.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl at pengutronix.de>
---
 common/blspec.c          | 35 ++++++++++++++++++++++++++++-------
 scripts/kernel-install.c |  2 +-
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index 3506388eb5fb..11e2a8a53698 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -308,6 +308,29 @@ out:
 	return ret;
 }
 
+static char *read_default_once(const char *root, const char *name)
+{
+	char *str, *res;
+
+	/* Compat: default/once was under root directly */
+	str = read_file_line("%s/%s", root, name);
+
+	if (!str)
+		str = read_file_line("%s/loader/%s", root, name);
+
+	if (!str)
+		return NULL;
+
+	res = strrchr(str, '/');
+	if (!res)
+		return str;
+
+	res = xstrdup(res);
+	free(str);
+
+	return res;
+}
+
 /*
  * blspec_scan_directory - scan over a directory
  *
@@ -323,7 +346,7 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
 	char *abspath;
 	int ret, found = 0;
 	const char *dirname = "loader/entries";
-	char *entry_default = NULL, *entry_once = NULL, *name, *nfspath = NULL;
+	char *entry_default = NULL, *entry_once = NULL, *nfspath = NULL;
 
 	nfspath = parse_nfs_url(root);
 	if (!IS_ERR(nfspath))
@@ -331,8 +354,8 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
 
 	pr_info("%s: %s %s\n", __func__, root, dirname);
 
-	entry_default = read_file_line("%s/default", root);
-	entry_once = read_file_line("%s/once", root);
+	entry_default = read_default_once(root, "default");
+	entry_once = read_default_once(root, "once");
 
 	abspath = asprintf("%s/%s", root, dirname);
 
@@ -398,12 +421,10 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
 
 		found++;
 
-		name = asprintf("%s/%s", dirname, d->d_name);
-		if (entry_default && !strcmp(name, entry_default))
+		if (entry_default && !strcmp(d->d_name, entry_default))
 			entry->boot_default = true;
-		if (entry_once && !strcmp(name, entry_once))
+		if (entry_once && !strcmp(d->d_name, entry_once))
 			entry->boot_once = true;
-		free(name);
 
 		if (entry->cdev) {
 			devname = xstrdup(dev_name(entry->cdev->dev));
diff --git a/scripts/kernel-install.c b/scripts/kernel-install.c
index d943f0288f39..d26864066583 100644
--- a/scripts/kernel-install.c
+++ b/scripts/kernel-install.c
@@ -1118,7 +1118,7 @@ static int do_set_once_default(const char *name, int entry)
 		return -errno;
 	}
 
-	dprintf(fd, "loader/entries/%s\n", e->config_file);
+	dprintf(fd, "%s\n", e->config_file);
 
 	ret = close(fd);
 	if (ret)
-- 
2.1.4




More information about the barebox mailing list