linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC DTC PATCH] dtc: add symlink (-L) output to dtbs
@ 2013-11-11 20:29 Jason Cooper
       [not found] ` < 20131115121215.901EFC40885@trevor.secretlab.ca>
                   ` (13 more replies)
  0 siblings, 14 replies; 94+ messages in thread
From: Jason Cooper @ 2013-11-11 20:29 UTC (permalink / raw)
  To: linux-arm-kernel

Consumers of the Linux kernel's build products are beginning to hardcode
the filenames of the dtbs generated.  Since the dtb filenames are
currently the dts filename s/dts/dtb/, this prevents the kernel
community from renaming dts files as needed.

Let's provide a consistent naming structure for consumers to script
against.  Or at least, as consistent as the dts properties themselves.

With this patch, adding the '-L' option to the dtc commandline will
cause dtc to create a symlink to the generated dtb, using the board
compatible string as the filename, eg:

  globalscale,mirabox.dtb -> armada-370-mirabox.dtb

Signed-off-by: Jason Cooper <jason@lakedaemon.net>
---
All,

I'm sending this RFC to see if this is how we want to go about this.  If it's
acceptable, I'll resend to the dtc maintainers

thx,

Jason.

 dtc.c      | 12 ++++++++++--
 dtc.h      |  1 +
 flattree.c | 30 ++++++++++++++++++++++++++++++
 srcpos.c   | 20 ++++++++++++++++++--
 srcpos.h   |  2 ++
 5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/dtc.c b/dtc.c
index e3c96536fd9d..cb2bb1b7ce1f 100644
--- a/dtc.c
+++ b/dtc.c
@@ -49,7 +49,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 
 /* Usage related data. */
 static const char usage_synopsis[] = "dtc [options] <input file>";
-static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
+static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:Lhv";
 static struct option const usage_long_opts[] = {
 	{"quiet",            no_argument, NULL, 'q'},
 	{"in-format",         a_argument, NULL, 'I'},
@@ -67,6 +67,7 @@ static struct option const usage_long_opts[] = {
 	{"phandle",           a_argument, NULL, 'H'},
 	{"warning",           a_argument, NULL, 'W'},
 	{"error",             a_argument, NULL, 'E'},
+	{"sym-link",         no_argument, NULL, 'L'},
 	{"help",             no_argument, NULL, 'h'},
 	{"version",          no_argument, NULL, 'v'},
 	{NULL,               no_argument, NULL, 0x0},
@@ -97,6 +98,7 @@ static const char * const usage_opts_help[] = {
 	 "\t\tboth   - Both \"linux,phandle\" and \"phandle\" properties",
 	"\n\tEnable/disable warnings (prefix with \"no-\")",
 	"\n\tEnable/disable errors (prefix with \"no-\")",
+	"\n\tCreate a symlink to the dtb named by board compatible string",
 	"\n\tPrint this help and exit",
 	"\n\tPrint version and exit",
 	NULL,
@@ -109,7 +111,7 @@ int main(int argc, char *argv[])
 	const char *outform = "dts";
 	const char *outname = "-";
 	const char *depname = NULL;
-	int force = 0, sort = 0;
+	int force = 0, sort = 0, mksymlink = 0;
 	const char *arg;
 	int opt;
 	FILE *outf = NULL;
@@ -184,6 +186,9 @@ int main(int argc, char *argv[])
 		case 'E':
 			parse_checks_option(false, true, optarg);
 			break;
+		case 'L':
+			mksymlink = 1;
+			break;
 
 		case 'h':
 			usage(NULL);
@@ -247,6 +252,9 @@ int main(int argc, char *argv[])
 		dt_to_source(outf, bi);
 	} else if (streq(outform, "dtb")) {
 		dt_to_blob(outf, bi, outversion);
+		if (mksymlink) {
+			dt_to_symlink(bi, outname);
+		}
 	} else if (streq(outform, "asm")) {
 		dt_to_asm(outf, bi, outversion);
 	} else if (streq(outform, "null")) {
diff --git a/dtc.h b/dtc.h
index 264a20cf66a8..0cdb558fead1 100644
--- a/dtc.h
+++ b/dtc.h
@@ -254,6 +254,7 @@ void process_checks(int force, struct boot_info *bi);
 
 void dt_to_blob(FILE *f, struct boot_info *bi, int version);
 void dt_to_asm(FILE *f, struct boot_info *bi, int version);
+void dt_to_symlink(struct boot_info *bi, const char *outname);
 
 struct boot_info *dt_from_blob(const char *fname);
 
diff --git a/flattree.c b/flattree.c
index 665dad7bb465..e1720dec4389 100644
--- a/flattree.c
+++ b/flattree.c
@@ -577,6 +577,36 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
 	data_free(strbuf);
 }
 
+void dt_to_symlink(struct boot_info *bi, const char *outname)
+{
+	struct property *prop;
+	const char *board;
+	int symlen;
+	char *symname;
+	char *dname;
+	char *bname;
+
+	prop = get_property(bi->dt, "compatible");
+	board = prop->val.val;
+
+	symlen = strlen(outname) + prop->val.len;
+	symname = xmalloc(symlen);
+
+	dname = xdirname(outname);
+	bname = xbasename(outname);
+
+	snprintf(symname, symlen, "%s/%s.dtb", dname, board);
+
+	/* create the symlink */
+	if (symlink(bname, symname) == -1) {
+		die("Couldn't create symlink %s: %s\n", symlink, strerror(errno));
+	}
+
+	free(symname);
+	free(dname);
+	free(bname);
+}
+
 struct inbuf {
 	char *base, *limit, *ptr;
 };
diff --git a/srcpos.c b/srcpos.c
index c20bc5315bc1..5f9e032330ea 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -34,7 +34,7 @@ struct search_path {
 static struct search_path *search_path_head, **search_path_tail;
 
 
-static char *dirname(const char *path)
+char *xdirname(const char *path)
 {
 	const char *slash = strrchr(path, '/');
 
@@ -49,6 +49,22 @@ static char *dirname(const char *path)
 	return NULL;
 }
 
+char *xbasename(const char *path)
+{
+	const char *slash = strrchr(path, '/');
+
+	if (slash) {
+		int len = strlen(path) - (slash - path);
+		char *base = xmalloc(len + 1);
+
+		memcpy(base, slash + 1, len);
+		base[len] = '\0';
+		return base;
+	}
+
+	return NULL;
+}
+
 FILE *depfile; /* = NULL */
 struct srcfile_state *current_srcfile; /* = NULL */
 
@@ -150,7 +166,7 @@ void srcfile_push(const char *fname)
 	srcfile = xmalloc(sizeof(*srcfile));
 
 	srcfile->f = srcfile_relative_open(fname, &srcfile->name);
-	srcfile->dir = dirname(srcfile->name);
+	srcfile->dir = xdirname(srcfile->name);
 	srcfile->prev = current_srcfile;
 
 	srcfile->lineno = 1;
diff --git a/srcpos.h b/srcpos.h
index 93a27123c2e9..a6b6ad308d52 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -57,6 +57,8 @@ FILE *srcfile_relative_open(const char *fname, char **fullnamep);
 void srcfile_push(const char *fname);
 int srcfile_pop(void);
 
+char *xdirname(const char *path);
+char *xbasename(const char *path);
 /**
  * Add a new directory to the search path for input files
  *
-- 
1.8.4.2

^ permalink raw reply related	[flat|nested] 94+ messages in thread

end of thread, other threads:[~2015-03-29 21:04 UTC | newest]

Thread overview: 94+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-11 20:29 [RFC DTC PATCH] dtc: add symlink (-L) output to dtbs Jason Cooper
     [not found] ` < 20131115121215.901EFC40885@trevor.secretlab.ca>
     [not found] ` < 52814AFB.3070600@wwwdotorg.org>
     [not found]   ` < CAL_Jsq+mAoN2Lbg+uqfLMTZBvgz28E-EioiaU4BUSL_7rS5JjA@mail.gmail.com>
     [not found]     ` < 528275B7.6050209@wwwdotorg.org>
     [not found] ` < 1384896475-8744-1-git-send-email-jason@lakedaemon.net>
     [not found] ` < 1385942188-21831-1-git-send-email-jason@lakedaemon.net>
     [not found] ` < 1385062552-9882-1-git-send-email-jason@lakedaemon.net>
     [not found]   ` < 653B066B-5B24-4817-86EF-D4D9F129123D@codeaurora.org>
2013-11-11 21:24 ` Stephen Warren
2013-11-12 14:51   ` Jason Cooper
2013-11-12 15:29   ` Rob Herring
2013-11-12 18:38     ` Stephen Warren
2013-11-12 19:30       ` Jason Cooper
2013-11-12 19:40         ` Andrew Lunn
2013-11-12 20:08           ` Jason Cooper
2013-11-12 20:15         ` Stephen Warren
2013-11-14 16:28           ` Jason Cooper
2013-11-14 19:00             ` Stephen Warren
2013-11-14 19:16               ` Jason Gunthorpe
2013-11-14 19:34                 ` Russell King - ARM Linux
2013-11-14 21:37                 ` Stephen Warren
2013-11-14 22:12                   ` Matt Sealey
2013-11-15 16:14                   ` Grant Likely
2013-11-14 19:26             ` Russell King - ARM Linux
2013-11-15 15:23               ` Jason Cooper
2013-11-15 17:09                 ` Javier Martinez Canillas
2013-11-15 21:38                   ` Jason Cooper
2013-11-15 12:12 ` Grant Likely
2013-11-15 15:21   ` Jason Cooper
2013-11-18 12:56     ` Grant Likely
2013-11-18 18:38 ` [RFC PATCH V2 0/2] Add 'make dtbs_install' Jason Cooper
2013-11-18 18:38   ` [RFC PATCH V2 1/2] dtc: add 'compat' output option, prints board string Jason Cooper
2013-11-18 19:01     ` Stephen Warren
2013-11-18 19:21       ` Jason Cooper
2013-11-18 20:24       ` Jason Cooper
2013-11-18 18:38   ` [RFC PATCH V2 2/2] kbuild: dtbs_install: new make target Jason Cooper
2013-11-18 19:09     ` Stephen Warren
2013-11-18 19:19       ` Jason Cooper
2013-11-18 19:23         ` Stephen Warren
2013-11-18 19:28           ` Jason Cooper
2013-11-18 19:38             ` Stephen Warren
2013-11-18 19:52               ` Jason Cooper
     [not found]                 ` < 528A98C8.9040803@wwwdotorg.org>
2013-11-18 22:46                 ` Stephen Warren
     [not found]                   ` <20131119122801. GL16735@n2100.arm.linux.org.uk>
2013-11-19 12:28                   ` Russell King - ARM Linux
2013-11-19 14:23                     ` Jason Cooper
     [not found]                       ` < 20131119150212.GM16735@n2100.arm.linux.org.uk>
2013-11-19 15:02                       ` Russell King - ARM Linux
     [not found]                         ` <20131119152047. GB28859@titan.lakedaemon.net>
2013-11-19 15:20                         ` Jason Cooper
2013-11-19 15:21                           ` Russell King - ARM Linux
     [not found]                             ` < 20131119192246.GP16735@n2100.arm.linux.org.uk>
2013-11-19 19:22                             ` Russell King - ARM Linux
2013-11-19 19:54                               ` Jason Cooper
2013-11-20 13:10                               ` Grant Likely
2013-11-20 13:56                                 ` Russell King - ARM Linux
2013-11-21  7:50                                   ` Grant Likely
2013-11-20 16:38                                 ` Jason Cooper
2013-11-19 18:40                       ` Stephen Warren
2013-11-19 18:43                         ` Jason Cooper
2013-11-19 18:42                     ` Stephen Warren
2013-11-19 18:52                       ` Russell King - ARM Linux
2013-11-19 19:27                         ` Stephen Warren
2013-11-19 19:53                           ` Russell King - ARM Linux
2013-11-19 18:57                       ` Jason Cooper
2013-11-19 19:53                         ` Stephen Warren
2013-11-19 20:39                           ` Jason Cooper
2013-11-19 21:06                             ` Stephen Warren
2013-11-20 13:18                               ` Grant Likely
2013-11-18 21:21 ` [RFC PATCH V3 0/2] Add 'make dtbs_install' Jason Cooper
2013-11-18 21:21   ` [RFC PATCH V3 1/2] scripts: dtc: build fdtget for extracting properties from dtbs Jason Cooper
2013-11-18 22:54     ` Stephen Warren
2013-11-19 14:17       ` Grant Likely
2013-11-18 21:21   ` [RFC PATCH V3 2/2] kbuild: dtbs_install: new make target Jason Cooper
     [not found] ` <cover. 1384798508.git.jason@lakedaemon.net>
     [not found]   ` < 728deb9bbeab491a728da077aa5e47c0e01bccf8.1384798508.git.jason@lakedaemon. net>
     [not found]     ` <728deb9bbeab491a728da077aa5e47c0e01bccf8.1384798508.git.jason@lakedaemon.n et>
2013-11-19 13:58       ` [RFC PATCH V2 1/2] dtc: add 'compat' output option, prints board string Grant Likely
     [not found] ` <cover. 1384809305.git.jason@lakedaemon.net>
     [not found]   ` < 13f06582c166343c055b8793305d4b9a00b2172e.1384809305.git.jason@lakedaemon. net>
     [not found]     ` <13f06582c166343c055b8793305d4b9a00b2172e.1384809305.git.jason@lakedaemon.n et>
2013-11-19 14:22       ` [RFC PATCH V3 2/2] kbuild: dtbs_install: new make target Grant Likely
2013-11-19 21:27 ` [PATCH V4] " Jason Cooper
2013-11-19 21:58   ` Stephen Warren
2013-11-20 13:21     ` Grant Likely
2013-11-20 17:22       ` Jason Cooper
2013-11-20 17:08     ` Jason Cooper
2013-11-20 17:21       ` Stephen Warren
2013-11-21  7:48       ` Grant Likely
2013-11-21 19:35 ` [PATCH V5] " Jason Cooper
2013-11-21 19:55   ` Stephen Warren
2013-11-21 23:31   ` Kumar Gala
2013-11-21 23:36     ` Olof Johansson
2013-11-22  7:42       ` Grant Likely
2013-11-22 13:31         ` Jason Cooper
2013-11-22 13:19     ` Jason Cooper
2013-12-01 23:40     ` Jason Cooper
2013-11-22  7:44   ` Grant Likely
2013-11-22 13:33     ` Jason Cooper
2013-12-01 23:56 ` [PATCH V6] " Jason Cooper
2013-12-03 17:37   ` Stephen Warren
2013-12-03 17:41     ` Russell King - ARM Linux
2014-01-10 18:29   ` Jason Cooper
2014-02-04 12:40     ` Grant Likely
2015-03-28 13:23   ` Russell King - ARM Linux
2015-03-28 13:37     ` [PATCH] dtbsinstall: don't move target directory out of the way Russell King
2015-03-28 15:59       ` Jason Cooper
2015-03-28 15:58     ` [PATCH V6] kbuild: dtbs_install: new make target Jason Cooper
2015-03-29 20:34       ` Olof Johansson
2015-03-29 20:58         ` Russell King - ARM Linux
2015-03-29 21:04         ` Jason Cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).