mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] magic variables
@ 2011-11-27 12:09 Sascha Hauer
  2011-11-27 12:09 ` [PATCH 1/5] add magicvar command Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

I don't like magic variables that much, but we have them and they are at
times very convenient to use. The problem with those variables is that
we don't know which variables exist in a running binary, so this patchset
adds a 'magicvar' command which prints information about the magic variables.
The description for magic variables can be put next to their user and
the description completely compiles away when the magicvar command is not
selected.

Sascha Hauer (5):
      add magicvar command
      bootm: Add bootargs magicvar
      ARM i.MX boot: Add barebox_loc magicvar
      hush: Add magicvars
      dhcp: Add magicvars

 arch/arm/lib/barebox.lds.S                |    4 +++
 arch/arm/mach-imx/boot.c                  |    3 ++
 arch/blackfin/boards/ipe337/barebox.lds.S |    4 +++
 arch/mips/lib/barebox.lds.S               |    4 +++
 arch/nios2/cpu/barebox.lds.S              |    4 +++
 arch/ppc/boards/pcm030/barebox.lds.S      |    4 +++
 arch/sandbox/board/barebox.lds.S          |    5 ++++
 arch/x86/lib/barebox.lds.S                |    9 +++++++-
 commands/Kconfig                          |   14 ++++++++++++
 commands/Makefile                         |    1 +
 commands/bootm.c                          |    3 ++
 commands/magicvar.c                       |   20 ++++++++++++++++++
 common/hush.c                             |    8 +++++++
 include/asm-generic/barebox.lds.h         |    2 +
 include/magicvar.h                        |   32 +++++++++++++++++++++++++++++
 net/dhcp.c                                |    6 +++++
 16 files changed, 122 insertions(+), 1 deletions(-)
 create mode 100644 commands/magicvar.c
 create mode 100644 include/magicvar.h

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

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

* [PATCH 1/5] add magicvar command
  2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
@ 2011-11-27 12:09 ` Sascha Hauer
  2011-11-27 12:09 ` [PATCH 2/5] bootm: Add bootargs magicvar Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

The magicvar command gives an overview about all environment variables
with a special meaning.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/barebox.lds.S                |    4 +++
 arch/blackfin/boards/ipe337/barebox.lds.S |    4 +++
 arch/mips/lib/barebox.lds.S               |    4 +++
 arch/nios2/cpu/barebox.lds.S              |    4 +++
 arch/ppc/boards/pcm030/barebox.lds.S      |    4 +++
 arch/sandbox/board/barebox.lds.S          |    5 ++++
 arch/x86/lib/barebox.lds.S                |    9 +++++++-
 commands/Kconfig                          |   14 ++++++++++++
 commands/Makefile                         |    1 +
 commands/magicvar.c                       |   20 ++++++++++++++++++
 include/asm-generic/barebox.lds.h         |    2 +
 include/magicvar.h                        |   32 +++++++++++++++++++++++++++++
 12 files changed, 102 insertions(+), 1 deletions(-)
 create mode 100644 commands/magicvar.c
 create mode 100644 include/magicvar.h

diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index 81a9123..f05f345 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -80,6 +80,10 @@ SECTIONS
 	.barebox_cmd : { BAREBOX_CMDS }
 	__barebox_cmd_end = .;
 
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
 	__barebox_initcalls_start = .;
 	.barebox_initcalls : { INITCALLS }
 	__barebox_initcalls_end = .;
diff --git a/arch/blackfin/boards/ipe337/barebox.lds.S b/arch/blackfin/boards/ipe337/barebox.lds.S
index 571eeb1..25ca988 100644
--- a/arch/blackfin/boards/ipe337/barebox.lds.S
+++ b/arch/blackfin/boards/ipe337/barebox.lds.S
@@ -71,6 +71,10 @@ SECTIONS
 	.barebox_cmd : { BAREBOX_CMDS }
 	___barebox_cmd_end = .;
 
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
 	___barebox_initcalls_start = .;
 	.barebox_initcalls : { INITCALLS }
 	___barebox_initcalls_end = .;
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index ba4c0af..7746ea0 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -56,6 +56,10 @@ SECTIONS
 	.barebox_cmd : { BAREBOX_CMDS }
 	__barebox_cmd_end = .;
 
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
 	__barebox_initcalls_start = .;
 	.barebox_initcalls : { INITCALLS }
 	__barebox_initcalls_end = .;
diff --git a/arch/nios2/cpu/barebox.lds.S b/arch/nios2/cpu/barebox.lds.S
index 2b626fb..934eaf7 100644
--- a/arch/nios2/cpu/barebox.lds.S
+++ b/arch/nios2/cpu/barebox.lds.S
@@ -56,6 +56,10 @@ SECTIONS
 	.barebox_cmd : { BAREBOX_CMDS }
 	__barebox_cmd_end = .;
 
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
 	__barebox_initcalls_start = .;
 	.barebox_initcalls : { INITCALLS }
 	__barebox_initcalls_end = .;
diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 4aacfc5..7dda039 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -102,6 +102,10 @@ SECTIONS
   .barebox_cmd : { BAREBOX_CMDS }
   __barebox_cmd_end = .;
 
+  __barebox_magicvar_start = .;
+  .barebox_magicvar : { BAREBOX_MAGICVARS }
+  __barebox_magicvar_end = .;
+
   __barebox_initcalls_start = .;
   .barebox_initcalls : { INITCALLS }
   __barebox_initcalls_end = .;
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 76975ee..db5b7de 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -8,6 +8,11 @@ SECTIONS
 	__barebox_initcalls_end = .;
 
 	. = ALIGN(64);
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
+	. = ALIGN(64);
 	__barebox_cmd_start = .;
 	__barebox_cmd : { BAREBOX_CMDS }
 	__barebox_cmd_end = .;
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
index fffc3a5..716cea6 100644
--- a/arch/x86/lib/barebox.lds.S
+++ b/arch/x86/lib/barebox.lds.S
@@ -170,7 +170,14 @@ SECTIONS
 		. = ALIGN(4);
 	} > barebox
 
-	.barebox_initcalls : AT ( LOADADDR(.barebox_cmd) + SIZEOF (.barebox_cmd) ) {
+	.barebox_magicvars : AT ( LOADADDR(.barebox_cmd) + SIZEOF (.barebox_cmd) ) {
+		__barebox_magicvar_start = .;
+		.barebox_magicvar : { BAREBOX_MAGICVARS }
+		__barebox_magicvar_end = .;
+		. = ALIGN(4);
+	} > barebox
+
+	.barebox_initcalls : AT ( LOADADDR(.barebox_magicvars) + SIZEOF (.barebox_magicvars) ) {
 		__barebox_initcalls_start = .;
 		INITCALLS
 		__barebox_initcalls_end = .;
diff --git a/commands/Kconfig b/commands/Kconfig
index 18ab840..78b9d2a 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -383,6 +383,20 @@ config CMD_HELP
 	default y
 	prompt "help"
 
+config CMD_MAGICVAR
+	tristate
+	prompt "magicvar"
+	help
+	  barebox has some shell variables with special meanings. This
+	  command shows the available magic variables.
+
+config CMD_MAGICVAR_HELP
+	bool
+	prompt "display description"
+	depends on CMD_MAGICVAR
+	help
+	  Also display a description to the magic variables
+
 config CMD_DEVINFO
 	tristate
 	default y
diff --git a/commands/Makefile b/commands/Makefile
index 5c51916..9b3a349 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -58,3 +58,4 @@ obj-$(CONFIG_CMD_LED_TRIGGER)	+= trigger.o
 obj-$(CONFIG_CMD_USB)		+= usb.o
 obj-$(CONFIG_CMD_TIME)		+= time.o
 obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
+obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
diff --git a/commands/magicvar.c b/commands/magicvar.c
new file mode 100644
index 0000000..31606d2
--- /dev/null
+++ b/commands/magicvar.c
@@ -0,0 +1,20 @@
+#include <common.h>
+#include <command.h>
+#include <magicvar.h>
+
+static int do_magicvar(struct command *cmdtp, int argc, char *argv[])
+{
+	struct magicvar *m;
+
+	for (m = &__barebox_magicvar_start;
+			m != &__barebox_magicvar_end;
+			m++)
+		printf("%-32s %s\n", m->name, m->description);
+
+	return 0;
+}
+
+BAREBOX_CMD_START(magicvar)
+	.cmd		= do_magicvar,
+	.usage		= "List information about magic variables",
+BAREBOX_CMD_END
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 8aee5d2..5467d3a 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -24,3 +24,5 @@
 #define BAREBOX_CMDS	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))
 
 #define BAREBOX_SYMS	KEEP(*(__usymtab))
+
+#define BAREBOX_MAGICVARS	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))
diff --git a/include/magicvar.h b/include/magicvar.h
new file mode 100644
index 0000000..b119a75
--- /dev/null
+++ b/include/magicvar.h
@@ -0,0 +1,32 @@
+#ifndef __MAGIC_VARS_H
+#define __MAGIC_VARS_H
+
+#include <linux/stringify.h>
+
+struct magicvar {
+	const char *name;
+	const char *description;
+};
+
+extern struct magicvar __barebox_magicvar_start;
+extern struct magicvar __barebox_magicvar_end;
+
+#ifdef CONFIG_CMD_MAGICVAR_HELP
+#define MAGICVAR_DESCRIPTION(d)		(d)
+#else
+#define MAGICVAR_DESCRIPTION(d)		NULL
+#endif
+
+#ifdef CONFIG_CMD_MAGICVAR
+#define BAREBOX_MAGIC_VAR(_name, _description)			\
+extern const struct magicvar __barebox_magicvar_##_name;	\
+const struct magicvar __barebox_magicvar_##_name		\
+        __attribute__ ((unused,section (".barebox_magicvar_" __stringify(_name)))) = {	\
+        .name	= #_name,					\
+	.description = MAGICVAR_DESCRIPTION(_description),	\
+};
+#else
+#define BAREBOX_MAGICVAR(_name, _description)
+#endif
+
+#endif /* __MAGIC_VARS_H */
-- 
1.7.7.1


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

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

* [PATCH 2/5] bootm: Add bootargs magicvar
  2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
  2011-11-27 12:09 ` [PATCH 1/5] add magicvar command Sascha Hauer
@ 2011-11-27 12:09 ` Sascha Hauer
  2011-11-27 12:09 ` [PATCH 3/5] ARM i.MX boot: Add barebox_loc magicvar Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index f11138a..55c964a 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -42,6 +42,7 @@
 #include <boot.h>
 #include <rtc.h>
 #include <init.h>
+#include <magicvar.h>
 #include <asm-generic/memory_layout.h>
 
 /*
@@ -367,6 +368,8 @@ BAREBOX_CMD_START(bootm)
 	BAREBOX_CMD_HELP(cmd_bootm_help)
 BAREBOX_CMD_END
 
+BAREBOX_MAGIC_VAR(bootargs, "Linux Kernel parameters");
+
 /**
  * @page bootm_command
 
-- 
1.7.7.1


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

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

* [PATCH 3/5] ARM i.MX boot: Add barebox_loc magicvar
  2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
  2011-11-27 12:09 ` [PATCH 1/5] add magicvar command Sascha Hauer
  2011-11-27 12:09 ` [PATCH 2/5] bootm: Add bootargs magicvar Sascha Hauer
@ 2011-11-27 12:09 ` Sascha Hauer
  2011-11-27 12:09 ` [PATCH 4/5] hush: Add magicvars Sascha Hauer
  2011-11-27 12:09 ` [PATCH 5/5] dhcp: " Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/boot.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index f13d956..5e5a8bb 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -18,6 +18,7 @@
 #include <common.h>
 #include <environment.h>
 #include <init.h>
+#include <magicvar.h>
 
 #include <io.h>
 #include <mach/imx-regs.h>
@@ -88,4 +89,6 @@ static int imx_25_35_boot_save_loc(void)
 
 coredevice_initcall(imx_25_35_boot_save_loc);
 
+BAREBOX_MAGIC_VAR(barebox_loc, "The source barebox has been booted from");
+
 #endif
-- 
1.7.7.1


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

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

* [PATCH 4/5] hush: Add magicvars
  2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-11-27 12:09 ` [PATCH 3/5] ARM i.MX boot: Add barebox_loc magicvar Sascha Hauer
@ 2011-11-27 12:09 ` Sascha Hauer
  2011-11-27 12:09 ` [PATCH 5/5] dhcp: " Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index 573bd3e..c70c274 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -122,6 +122,7 @@
 #include <glob.h>
 #include <getopt.h>
 #include <libbb.h>
+#include <magicvar.h>
 #include <linux/list.h>
 
 /*cmd_boot.c*/
@@ -540,6 +541,8 @@ static int builtin_getopt(struct p_context *ctx, struct child_prog *child)
 
 	return 0;
 }
+
+BAREBOX_MAGIC_VAR(OPTARG, "optarg for hush builtin getopt");
 #endif
 
 /* run_pipe_real() starts all the jobs, but doesn't wait for anything
@@ -1721,6 +1724,11 @@ BAREBOX_CMD_START(getopt)
 BAREBOX_CMD_END
 #endif
 
+BAREBOX_MAGIC_VAR(PATH, "colon seperated list of pathes to search for executables");
+#ifdef CONFIG_HUSH_FANCY_PROMPT
+BAREBOX_MAGIC_VAR(PS1, "hush prompt");
+#endif
+
 /**
  * @file
  * @brief A prototype Bourne shell grammar parser
-- 
1.7.7.1


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

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

* [PATCH 5/5] dhcp: Add magicvars
  2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
                   ` (3 preceding siblings ...)
  2011-11-27 12:09 ` [PATCH 4/5] hush: Add magicvars Sascha Hauer
@ 2011-11-27 12:09 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-11-27 12:09 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/dhcp.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index d1781bc..954c52e 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -15,6 +15,7 @@
 #include <net.h>
 #include <libbb.h>
 #include <errno.h>
+#include <magicvar.h>
 #include <linux/err.h>
 
 #define OPT_SIZE 312	/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
@@ -482,3 +483,8 @@ BAREBOX_CMD_START(dhcp)
 	.usage		= "invoke dhcp client to obtain ip/boot params",
 BAREBOX_CMD_END
 
+BAREBOX_MAGIC_VAR(bootfile, "bootfile returned from DHCP request");
+BAREBOX_MAGIC_VAR(nameserver, "Nameserver returned from DHCP request");
+BAREBOX_MAGIC_VAR(hostname, "hostname returned from DHCP request");
+BAREBOX_MAGIC_VAR(domainname, "domainname returned from DHCP request");
+BAREBOX_MAGIC_VAR(rootpath, "rootpath returned from DHCP request");
-- 
1.7.7.1


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

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

end of thread, other threads:[~2011-11-27 12:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-27 12:09 [PATCH] magic variables Sascha Hauer
2011-11-27 12:09 ` [PATCH 1/5] add magicvar command Sascha Hauer
2011-11-27 12:09 ` [PATCH 2/5] bootm: Add bootargs magicvar Sascha Hauer
2011-11-27 12:09 ` [PATCH 3/5] ARM i.MX boot: Add barebox_loc magicvar Sascha Hauer
2011-11-27 12:09 ` [PATCH 4/5] hush: Add magicvars Sascha Hauer
2011-11-27 12:09 ` [PATCH 5/5] dhcp: " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox