[U-Boot] [RFC] [PATCH 2/2] crazy: Sort u_boot_cmd at runtime
Marek Vasut
marex at denx.de
Sat Jul 28 15:47:59 CEST 2012
This shall eliminate the need for bubblesorting of commands at runtime.
Every command definition structure is now put into it's own subsection
of section .u_boot_cmd, that is .u_boot_cmd.<name> . These are then put
into .u_boot_cmd by linker and lastly, linker uses SORT() over these
subsections to make proper order on them. This shall eliminate some
runtime overhead.
Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
Cc: Mike Frysinger <vapier at gentoo.org>
---
arch/arm/cpu/u-boot.lds | 2 +-
common/cmd_help.c | 2 +-
include/command.h | 9 ++++++---
3 files changed, 8 insertions(+), 5 deletions(-)
********
* NOTE * THIS PATCH IS CRAZY
********
Further notes:
- This is only compile-tested with gcc-4.7 (debian 4.7.1-5, binutils 2.22)
- This patch affects only arm926t, obviously to make it proper, every
linkerscript would have to be adjusted
- I'm not sure at all the macro logic is correct, please check
- Can this crash on *BSD or with older linker/cpp?
- Please don't rip me limb to limb ;-)
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index e49ca0c..c39193b 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -50,7 +50,7 @@ SECTIONS
. = .;
__u_boot_cmd_start = .;
- .u_boot_cmd : { *(.u_boot_cmd) }
+ .u_boot_cmd : { *(SORT(.u_boot_cmd.*)) }
__u_boot_cmd_end = .;
. = ALIGN(4);
diff --git a/common/cmd_help.c b/common/cmd_help.c
index 8c8178e..5d778f5 100644
--- a/common/cmd_help.c
+++ b/common/cmd_help.c
@@ -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 = {
+cmd_tbl_t __u_boot_cmd_question_mark Struct_Section(?) = {
"?", CONFIG_SYS_MAXARGS, 1, do_help,
"alias for 'help'",
#ifdef CONFIG_SYS_LONGHELP
diff --git a/include/command.h b/include/command.h
index 6e1bdc2..42b4c6a 100644
--- a/include/command.h
+++ b/include/command.h
@@ -149,8 +149,11 @@ 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)))
+#define __sectstr(__cmd,__name) .__cmd.__name
+#define sectstr(type, __name) __stringify(__sectstr(type, __name))
+
+#define Struct_Section(__name) \
+ __attribute__((unused, section(sectstr(u_boot_cmd, __name)), aligned(4)))
#ifdef CONFIG_AUTO_COMPLETE
# define _CMD_COMPLETE(x) x,
@@ -170,7 +173,7 @@ int cmd_process(int flag, int argc, char * const argv[],
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 = \
+ cmd_tbl_t __u_boot_cmd_##name Struct_Section(name) = \
U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp)
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
--
1.7.10.4
More information about the U-Boot
mailing list