All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/6 V2] common: Convert the U-Boot commands to LG-arrays
Date: Sun,  7 Oct 2012 02:06:23 +0200	[thread overview]
Message-ID: <1349568385-27173-5-git-send-email-marex@denx.de> (raw)
In-Reply-To: <1349568385-27173-1-git-send-email-marex@denx.de>

This patch converts the old method of creating a list of command
onto the new LG-arrays code. The old u_boot_cmd section is converted
to new u_boot_list_cmd subsection and LG-array macros used as needed.

Minor adjustments had to be made to the common code to work with the
LG-array macros, mostly the fixup_cmdtable() calls are now passed the
ll_entry_start and ll_entry_count instead of linker-generated symbols.

The command.c had to be adjusted as well so it would use the newly
introduced LG-array API instead of directly using linker-generated
symbols.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>

---
 arch/arm/imx-common/cmd_bmode.c |   11 +++++++----
 arch/avr32/lib/board.c          |    4 ++--
 arch/m68k/lib/board.c           |    4 ++--
 arch/mips/lib/board.c           |    4 ++--
 arch/nds32/lib/board.c          |    4 ++--
 arch/sparc/lib/board.c          |    4 ++--
 common/cmd_help.c               |    8 ++++----
 common/command.c                |   17 ++++++++++-------
 doc/README.commands             |   10 +++++-----
 include/command.h               |   26 ++++++++++++++------------
 10 files changed, 50 insertions(+), 42 deletions(-)

V2:
- Rebase on top of testing/dm-kerneldoc

diff --git a/arch/arm/imx-common/cmd_bmode.c b/arch/arm/imx-common/cmd_bmode.c
index 02fe72e..ddc14b0 100644
--- a/arch/arm/imx-common/cmd_bmode.c
+++ b/arch/arm/imx-common/cmd_bmode.c
@@ -24,6 +24,7 @@
 #include <asm/io.h>
 #include <asm/imx-common/boot_mode.h>
 #include <malloc.h>
+#include <command.h>
 
 static const struct boot_mode *modes[2];
 
@@ -103,9 +104,11 @@ void add_board_boot_modes(const struct boot_mode *p)
 	int size;
 	char *dest;
 
-	if (__u_boot_cmd_bmode.usage) {
-		free(__u_boot_cmd_bmode.usage);
-		__u_boot_cmd_bmode.usage = NULL;
+	cmd_tbl_t *entry = ll_entry_get(cmd_tbl_t, bmode, cmd);
+
+	if (entry->usage) {
+		free(entry->usage);
+		entry->usage = NULL;
 	}
 
 	modes[0] = p;
@@ -114,6 +117,6 @@ void add_board_boot_modes(const struct boot_mode *p)
 	dest = malloc(size);
 	if (dest) {
 		create_usage(dest);
-		__u_boot_cmd_bmode.usage = dest;
+		entry->usage = dest;
 	}
 }
diff --git a/arch/avr32/lib/board.c b/arch/avr32/lib/board.c
index 9d3b76e..e3287c4 100644
--- a/arch/avr32/lib/board.c
+++ b/arch/avr32/lib/board.c
@@ -272,8 +272,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
 	/*
 	 * We have to relocate the command table manually
 	 */
-	fixup_cmdtable(&__u_boot_cmd_start,
-		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
 
 	/* there are some other pointer constants we must deal with */
diff --git a/arch/m68k/lib/board.c b/arch/m68k/lib/board.c
index 67c9a13..2a694b4 100644
--- a/arch/m68k/lib/board.c
+++ b/arch/m68k/lib/board.c
@@ -415,8 +415,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	/*
 	 * We have to relocate the command table manually
 	 */
-	fixup_cmdtable(&__u_boot_cmd_start,
-		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
 
 	/* there are some other pointer constants we must deal with */
diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c
index b14b33e..7ddd778 100644
--- a/arch/mips/lib/board.c
+++ b/arch/mips/lib/board.c
@@ -266,8 +266,8 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	/*
 	 * We have to relocate the command table manually
 	 */
-	fixup_cmdtable(&__u_boot_cmd_start,
-		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
 
 	/* there are some other pointer constants we must deal with */
diff --git a/arch/nds32/lib/board.c b/arch/nds32/lib/board.c
index 89900fe..cd8d6a7 100644
--- a/arch/nds32/lib/board.c
+++ b/arch/nds32/lib/board.c
@@ -320,8 +320,8 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	/*
 	 * We have to relocate the command table manually
 	 */
-	fixup_cmdtable(&__u_boot_cmd_start,
-		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
 
 	serial_initialize();
diff --git a/arch/sparc/lib/board.c b/arch/sparc/lib/board.c
index ff0e0f2..32d025a 100644
--- a/arch/sparc/lib/board.c
+++ b/arch/sparc/lib/board.c
@@ -246,8 +246,8 @@ void board_init_f(ulong bootflag)
 	/*
 	 * We have to relocate the command table manually
 	 */
-	fixup_cmdtable(&__u_boot_cmd_start,
-		(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
 
 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
diff --git a/common/cmd_help.c b/common/cmd_help.c
index 8c8178e..3178a1a 100644
--- a/common/cmd_help.c
+++ b/common/cmd_help.c
@@ -26,9 +26,9 @@
 
 int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
-	return _do_help(&__u_boot_cmd_start,
-			&__u_boot_cmd_end - &__u_boot_cmd_start,
-			cmdtp, flag, argc, argv);
+	cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
+	const int len = ll_entry_count(cmd_tbl_t, cmd);
+	return _do_help(start, len, cmdtp, flag, argc, argv);
 }
 
 U_BOOT_CMD(
@@ -41,7 +41,7 @@ U_BOOT_CMD(
 );
 
 /* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */
-cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
+ll_entry_declare(cmd_tbl_t, question_mark, cmd, cmd) = {
 	"?",	CONFIG_SYS_MAXARGS,	1,	do_help,
 	"alias for 'help'",
 #ifdef  CONFIG_SYS_LONGHELP
diff --git a/common/command.c b/common/command.c
index aa0fb0a..50c8429 100644
--- a/common/command.c
+++ b/common/command.c
@@ -137,8 +137,9 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
 
 cmd_tbl_t *find_cmd (const char *cmd)
 {
-	int len = &__u_boot_cmd_end - &__u_boot_cmd_start;
-	return find_cmd_tbl(cmd, &__u_boot_cmd_start, len);
+	cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
+	const int len = ll_entry_count(cmd_tbl_t, cmd);
+	return find_cmd_tbl(cmd, start, len);
 }
 
 int cmd_usage(const cmd_tbl_t *cmdtp)
@@ -181,7 +182,9 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
 
 static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
 {
-	cmd_tbl_t *cmdtp;
+	cmd_tbl_t *cmdtp = ll_entry_start(cmd_tbl_t, cmd);
+	const int count = ll_entry_count(cmd_tbl_t, cmd);
+	const cmd_tbl_t *cmdend = cmdtp + count;
 	const char *p;
 	int len, clen;
 	int n_found = 0;
@@ -195,12 +198,12 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
 
 	if (argc == 0) {
 		/* output full list of commands */
-		for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
+		for (; cmdtp != cmdend; cmdtp++) {
 			if (n_found >= maxv - 2) {
-				cmdv[n_found++] = "...";
+				cmdv[n_found] = "...";
 				break;
 			}
-			cmdv[n_found++] = cmdtp->name;
+			cmdv[n_found] = cmdtp->name;
 		}
 		cmdv[n_found] = NULL;
 		return n_found;
@@ -228,7 +231,7 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
 		len = p - cmd;
 
 	/* return the partial matches */
-	for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
+	for (; cmdtp != cmdend; cmdtp++) {
 
 		clen = strlen(cmdtp->name);
 		if (clen < len)
diff --git a/doc/README.commands b/doc/README.commands
index 125f077..923418b 100644
--- a/doc/README.commands
+++ b/doc/README.commands
@@ -15,12 +15,12 @@ help:	 Long description. This is a string
 
 **** Behind the scene ******
 
-The structure created is named with a special prefix (__u_boot_cmd_)
+The structure created is named with a special prefix (__u_boot_list_cmd_)
 and placed by the linker in a special section.
 
 This makes it possible for the final link to extract all commands
 compiled into any object code and construct a static array so the
-command can be found in an array starting at __u_boot_cmd_start.
+command can be found in an array starting@_u_boot_list_cmd__start.
 
 To ensure that the linker does not discard these symbols when linking
 full U-Boot we generate a list of all the commands we have built (based
@@ -33,6 +33,6 @@ If a new board is defined do not forget to define the command section
 by writing in u-boot.lds ($(TOPDIR)/board/boardname/u-boot.lds) these
 3 lines:
 
-	__u_boot_cmd_start = .;
-	.u_boot_cmd : { *(.u_boot_cmd) }
-	__u_boot_cmd_end = .;
+	.u_boot_list : {
+	#include "u-boot.lst";
+	}
diff --git a/include/command.h b/include/command.h
index 1f06aa1..24864d5 100644
--- a/include/command.h
+++ b/include/command.h
@@ -28,6 +28,7 @@
 #define __COMMAND_H
 
 #include <config.h>
+#include <linker_lists.h>
 
 #ifndef NULL
 #define NULL	0
@@ -153,9 +154,6 @@ int cmd_process(int flag, int argc, char * const argv[],
 #define CMD_FLAG_REPEAT		0x0001	/* repeat last command		*/
 #define CMD_FLAG_BOOTD		0x0002	/* command is from bootd	*/
 
-#define Struct_Section  __attribute__((unused, section(".u_boot_cmd"), \
-		aligned(4)))
-
 #ifdef CONFIG_AUTO_COMPLETE
 # define _CMD_COMPLETE(x) x,
 #else
@@ -167,18 +165,22 @@ int cmd_process(int flag, int argc, char * const argv[],
 # define _CMD_HELP(x)
 #endif
 
-#define U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
-	{#name, maxargs, rep, cmd, usage, _CMD_HELP(help) _CMD_COMPLETE(comp)}
+#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd,		\
+				_usage, _help, _comp)			\
+		{ #_name, _maxargs, _rep, _cmd, _usage,			\
+			_CMD_HELP(_help) _CMD_COMPLETE(_comp) }
 
-#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \
-	U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
+#define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help)	\
+	U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd,		\
+					_usage, _help, NULL)
 
-#define U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
-	cmd_tbl_t __u_boot_cmd_##name Struct_Section = \
-		U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp)
+#define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \
+	ll_entry_declare(cmd_tbl_t, _name, cmd, cmd) =			\
+		U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd,	\
+						_usage, _help, _comp);
 
-#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
-	U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
+#define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help)		\
+	U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
 
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);
-- 
1.7.10.4

  parent reply	other threads:[~2012-10-07  0:06 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-30  0:17 [U-Boot] [PATCH 0/5] Linker-generated arrays (take 2) Marek Vasut
2012-09-30  0:17 ` [U-Boot] [PATCH 1/5] common: Add symbol handling for generic lists into Makefile Marek Vasut
2012-10-02 23:40   ` Joe Hershberger
2012-09-30  0:17 ` [U-Boot] [PATCH 2/5] common: Implement support for linker-generated arrays Marek Vasut
2012-10-02 23:40   ` Joe Hershberger
2012-09-30  0:17 ` [U-Boot] [PATCH 3/5] common: Add .u_boot_list into all linker files Marek Vasut
2012-10-02 23:41   ` Joe Hershberger
2012-10-03 14:55   ` Daniel Schwierzeck
2012-10-03 15:01     ` Marek Vasut
2012-10-03 15:21       ` Daniel Schwierzeck
2012-10-03 16:44         ` Marek Vasut
2012-10-03 18:05           ` Daniel Schwierzeck
2012-10-03 20:49   ` [U-Boot] [PATCH 3/5 V2] " Marek Vasut
2012-09-30  0:17 ` [U-Boot] [PATCH 4/5] common: Convert the U-Boot commands to LG-arrays Marek Vasut
2012-10-02 23:43   ` Joe Hershberger
2012-09-30  0:17 ` [U-Boot] [PATCH 5/5] common: Discard the __u_boot_cmd section Marek Vasut
2012-10-02 23:43   ` Joe Hershberger
2012-10-03 14:56   ` Daniel Schwierzeck
2012-10-03 20:50   ` [U-Boot] [PATCH 5/5 V2] " Marek Vasut
2012-10-07  0:06 ` [U-Boot] [PATCH 0/6 V2] Linker-generated arrays (take 2) Marek Vasut
2012-10-07  0:06   ` [U-Boot] [PATCH 1/6 V2] common: Add symbol handling for generic lists into Makefile Marek Vasut
2012-10-07  0:06   ` [U-Boot] [PATCH 2/6 V2] common: Implement support for linker-generated arrays Marek Vasut
2012-10-07  0:06   ` [U-Boot] [PATCH 3/6 V2] common: Add .u_boot_list into all linker files Marek Vasut
2012-10-07  0:06   ` Marek Vasut [this message]
2012-10-07  0:06   ` [U-Boot] [PATCH 5/6 V2] common: Discard the __u_boot_cmd section Marek Vasut
2012-10-07  0:06   ` [U-Boot] [PATCH 6/6 V2] kerneldoc: tmpl: Implement template for LG-arrays Marek Vasut
2012-10-12 20:27   ` [U-Boot] [PATCH 0/6 V3] Linker-generated arrays (take 2) Marek Vasut
2012-10-12 20:27     ` [U-Boot] [PATCH 1/6 V3] common: Add symbol handling for generic lists into Makefile Marek Vasut
2012-10-14 23:28       ` Daniel Schwierzeck
2012-10-15  1:49         ` Marek Vasut
2012-10-15  2:04           ` Daniel Schwierzeck
2012-10-15  2:09             ` Marek Vasut
2012-10-17 10:43       ` [U-Boot] [PATCH 1/6 V4] " Marek Vasut
2012-10-18 19:40         ` Wolfgang Denk
2012-10-19 13:19           ` Marek Vasut
2012-10-20 17:46             ` Tom Rini
2012-10-20 18:56               ` Marek Vasut
2012-10-21  5:20                 ` Tom Rini
2012-10-19 15:00         ` [U-Boot] [PATCH 1/6 V5] " Marek Vasut
2012-10-19 15:45           ` Joe Hershberger
2012-10-19 15:48           ` Joe Hershberger
2012-10-22 21:04           ` Tom Rini
2012-10-12 20:27     ` [U-Boot] [PATCH 2/6 V3] common: Implement support for linker-generated arrays Marek Vasut
2012-10-12 20:27     ` [U-Boot] [PATCH 3/6 V3] common: Add .u_boot_list into all linker files Marek Vasut
2012-10-12 20:27     ` [U-Boot] [PATCH 4/6 V3] common: Convert the U-Boot commands to LG-arrays Marek Vasut
2012-10-12 20:27     ` [U-Boot] [PATCH 5/6 V3] common: Discard the __u_boot_cmd section Marek Vasut
2012-10-17 10:45       ` [U-Boot] [PATCH 5/6 V4] " Marek Vasut
2012-10-12 20:27     ` [U-Boot] [PATCH 6/6 V3] kerneldoc: tmpl: Implement template for LG-arrays Marek Vasut

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=1349568385-27173-5-git-send-email-marex@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.