common: Convert the U-Boot commands to LG-arrays

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>
This commit is contained in:
Marek Vasut 2012-10-12 10:27:04 +00:00 committed by Tom Rini
parent 556751427b
commit 6c7c946cad
10 changed files with 50 additions and 42 deletions

View File

@ -24,6 +24,7 @@
#include <asm/io.h> #include <asm/io.h>
#include <asm/imx-common/boot_mode.h> #include <asm/imx-common/boot_mode.h>
#include <malloc.h> #include <malloc.h>
#include <command.h>
static const struct boot_mode *modes[2]; static const struct boot_mode *modes[2];
@ -103,9 +104,11 @@ void add_board_boot_modes(const struct boot_mode *p)
int size; int size;
char *dest; char *dest;
if (__u_boot_cmd_bmode.usage) { cmd_tbl_t *entry = ll_entry_get(cmd_tbl_t, bmode, cmd);
free(__u_boot_cmd_bmode.usage);
__u_boot_cmd_bmode.usage = NULL; if (entry->usage) {
free(entry->usage);
entry->usage = NULL;
} }
modes[0] = p; modes[0] = p;
@ -114,6 +117,6 @@ void add_board_boot_modes(const struct boot_mode *p)
dest = malloc(size); dest = malloc(size);
if (dest) { if (dest) {
create_usage(dest); create_usage(dest);
__u_boot_cmd_bmode.usage = dest; entry->usage = dest;
} }
} }

View File

@ -272,8 +272,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
/* /*
* We have to relocate the command table manually * We have to relocate the command table manually
*/ */
fixup_cmdtable(&__u_boot_cmd_start, fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); ll_entry_count(cmd_tbl_t, cmd));
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
/* there are some other pointer constants we must deal with */ /* there are some other pointer constants we must deal with */

View File

@ -416,8 +416,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
/* /*
* We have to relocate the command table manually * We have to relocate the command table manually
*/ */
fixup_cmdtable(&__u_boot_cmd_start, fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); ll_entry_count(cmd_tbl_t, cmd));
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
/* there are some other pointer constants we must deal with */ /* there are some other pointer constants we must deal with */

View File

@ -266,8 +266,8 @@ void board_init_r(gd_t *id, ulong dest_addr)
/* /*
* We have to relocate the command table manually * We have to relocate the command table manually
*/ */
fixup_cmdtable(&__u_boot_cmd_start, fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); ll_entry_count(cmd_tbl_t, cmd));
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
/* there are some other pointer constants we must deal with */ /* there are some other pointer constants we must deal with */

View File

@ -320,8 +320,8 @@ void board_init_r(gd_t *id, ulong dest_addr)
/* /*
* We have to relocate the command table manually * We have to relocate the command table manually
*/ */
fixup_cmdtable(&__u_boot_cmd_start, fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); ll_entry_count(cmd_tbl_t, cmd));
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
serial_initialize(); serial_initialize();

View File

@ -246,8 +246,8 @@ void board_init_f(ulong bootflag)
/* /*
* We have to relocate the command table manually * We have to relocate the command table manually
*/ */
fixup_cmdtable(&__u_boot_cmd_start, fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
(ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); ll_entry_count(cmd_tbl_t, cmd));
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
#if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP) #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)

View File

@ -26,9 +26,9 @@
int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{ {
return _do_help(&__u_boot_cmd_start, cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
&__u_boot_cmd_end - &__u_boot_cmd_start, const int len = ll_entry_count(cmd_tbl_t, cmd);
cmdtp, flag, argc, argv); return _do_help(start, len, cmdtp, flag, argc, argv);
} }
U_BOOT_CMD( 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 */ /* 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, "?", CONFIG_SYS_MAXARGS, 1, do_help,
"alias for 'help'", "alias for 'help'",
#ifdef CONFIG_SYS_LONGHELP #ifdef CONFIG_SYS_LONGHELP

View File

@ -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) cmd_tbl_t *find_cmd (const char *cmd)
{ {
int len = &__u_boot_cmd_end - &__u_boot_cmd_start; cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
return find_cmd_tbl(cmd, &__u_boot_cmd_start, len); 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) 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[]) 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; const char *p;
int len, clen; int len, clen;
int n_found = 0; 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) { if (argc == 0) {
/* output full list of commands */ /* 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) { if (n_found >= maxv - 2) {
cmdv[n_found++] = "..."; cmdv[n_found] = "...";
break; break;
} }
cmdv[n_found++] = cmdtp->name; cmdv[n_found] = cmdtp->name;
} }
cmdv[n_found] = NULL; cmdv[n_found] = NULL;
return n_found; return n_found;
@ -228,7 +231,7 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
len = p - cmd; len = p - cmd;
/* return the partial matches */ /* return the partial matches */
for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { for (; cmdtp != cmdend; cmdtp++) {
clen = strlen(cmdtp->name); clen = strlen(cmdtp->name);
if (clen < len) if (clen < len)

View File

@ -15,12 +15,12 @@ help: Long description. This is a string
**** Behind the scene ****** **** 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. and placed by the linker in a special section.
This makes it possible for the final link to extract all commands This makes it possible for the final link to extract all commands
compiled into any object code and construct a static array so the 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 at _u_boot_list_cmd__start.
To ensure that the linker does not discard these symbols when linking 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 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 by writing in u-boot.lds ($(TOPDIR)/board/boardname/u-boot.lds) these
3 lines: 3 lines:
__u_boot_cmd_start = .; .u_boot_list : {
.u_boot_cmd : { *(.u_boot_cmd) } #include "u-boot.lst";
__u_boot_cmd_end = .; }

View File

@ -28,6 +28,7 @@
#define __COMMAND_H #define __COMMAND_H
#include <config.h> #include <config.h>
#include <linker_lists.h>
#ifndef NULL #ifndef NULL
#define NULL 0 #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_REPEAT 0x0001 /* repeat last command */
#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */ #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
#define Struct_Section __attribute__((unused, section(".u_boot_cmd"), \
aligned(4)))
#ifdef CONFIG_AUTO_COMPLETE #ifdef CONFIG_AUTO_COMPLETE
# define _CMD_COMPLETE(x) x, # define _CMD_COMPLETE(x) x,
#else #else
@ -167,18 +165,22 @@ int cmd_process(int flag, int argc, char * const argv[],
# define _CMD_HELP(x) # define _CMD_HELP(x)
#endif #endif
#define U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \ #define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
{#name, maxargs, rep, cmd, usage, _CMD_HELP(help) _CMD_COMPLETE(comp)} _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) \ #define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \
U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL) U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
_usage, _help, NULL)
#define U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \ #define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = \ ll_entry_declare(cmd_tbl_t, _name, cmd, cmd) = \
U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
_usage, _help, _comp);
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \ #define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \
U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL) U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
#if defined(CONFIG_NEEDS_MANUAL_RELOC) #if defined(CONFIG_NEEDS_MANUAL_RELOC)
void fixup_cmdtable(cmd_tbl_t *cmdtp, int size); void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);