relocation: fixup cmdtable
Subsystems (3)
RFC PATCH 2/19 relocation: fixup cmdtable
fixup_cmdtable() did all work for fixing up the cmdtable, if CONFIG_RELOC_FIXUP_WORKS is not defined.
--- common/command.c | 33 +++++++++++++++++++++++++++++++++ include/command.h | 3 +++ 2 files changed, 36 insertions(+), 0 deletions(-)
common/command.c +33 -0
@@ -464,3 +464,36 @@ int cmd_get_data_size(char* arg, int default_size)return default_size; }#endif + +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +DECLARE_GLOBAL_DATA_PTR ; + +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size) +{ +int i; + +if (gd->reloc_off ==0 ) +return ; + +for (i =0 ; i < size; i++) { +ulong addr; + + addr = (ulong) (cmdtp->cmd) + gd->reloc_off; + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *,int ,int ,char *const []))addr; + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; +if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr; + } +#ifdef CONFIG_SYS_LONGHELP +if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + } +#endif + cmdtp++; + } +} +#endif
include/command.h +3 -0
@@ -125,4 +125,7 @@ cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}#endif /* CONFIG_SYS_LONGHELP */ +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size); +#endif #endif /* __COMMAND_H */
Signature · 5 lines
1.6.2.5 -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
RFC PATCH 2/19 relocation: fixup cmdtable
Quoted 22 lines
common/command.c +21
-0+#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +DECLARE_GLOBAL_DATA_PTR ; + +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size) +{ +int i; + +if (gd->reloc_off ==0 ) +return ; + +for (i =0 ; i < size; i++) { +ulong addr; + + addr = (ulong) (cmdtp->cmd) + gd->reloc_off; + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *,int ,int ,char *const []))addr; + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; +if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr;
common/command.c int cmd_get_data_size(char* arg, int default_size) · line 498
Quoted 10 lines
common/command.c +10
-0+ } +#ifdef CONFIG_SYS_LONGHELP +if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + } +#endif + cmdtp++; + } +}
A number of other arches have this same logic in arch-specific code, eg arch/mips/lib/board.c. Could you also convert them to use the new fixup_cmdtable() in this patch?
Best,
Peter
RFC PATCH 2/19 relocation: fixup cmdtable
Hello Peter,
Quoted 27 lines · Peter Tyser
Quoted 27 lines
common/command.c +27
-0+#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +DECLARE_GLOBAL_DATA_PTR ; + +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size) +{ +int i; + +if (gd->reloc_off ==0 ) +return ; + +for (i =0 ; i < size; i++) { +ulong addr; + + addr = (ulong) (cmdtp->cmd) + gd->reloc_off; + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *,int ,int ,char *const []))addr; + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; +if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr; + } +#ifdef CONFIG_SYS_LONGHELP +if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + }
Quoted 8 lines
common/command.c int cmd_get_data_size(char* arg, int default_size) · line 498
Quoted 4 lines
common/command.c +4
-0+#endif + cmdtp++; + } +}A number of other arches have this same logic in arch-specific code, eg
arch/mips/lib/board.c. Could you also convert them to use the newfixup_cmdtable()in this patch?
Ah, Ok, I can try it. This will then result, that this patch can go direct to mainline, right?
As I see in the code, this should be possible for the following architectures:
avr32
m68k
mips
I make a patch for this, but couldn;t test it ...
bye
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
RFC PATCH 2/19 relocation: fixup cmdtable
Quoted 39 lines · Heiko Schocher
Hello Peter,
Quoted 27 lines · Peter Tyser
Quoted 27 lines
common/command.c +27
-0+#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +DECLARE_GLOBAL_DATA_PTR ; + +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size) +{ +int i; + +if (gd->reloc_off ==0 ) +return ; + +for (i =0 ; i < size; i++) { +ulong addr; + + addr = (ulong) (cmdtp->cmd) + gd->reloc_off; + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *,int ,int ,char *const []))addr; + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; +if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr; + } +#ifdef CONFIG_SYS_LONGHELP +if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + }Quoted 8 lines
common/command.c int cmd_get_data_size(char* arg, int default_size) · line 498
Quoted 4 lines
common/command.c +4
-0+#endif + cmdtp++; + } +}A number of other arches have this same logic in arch-specific code, eg
arch/mips/lib/board.c. Could you also convert them to use the newfixup_cmdtable()in this patch?
Quoted 2 lines
Ah, Ok, I can try it. This will then result, that this patch can go direct to mainline, right?
Yes, I'd think this patch would be accepted regardless of the other ARM relocation changes as its a general improvement.
Quoted 6 lines
As I see in the code, this should be possible for the following architectures:
avr32
m68k
mips
I believe sparc should also be included.
Best,
Peter
RFC PATCH v2 2/19 relocation: fixup cmdtable
fixup_cmdtable() did all work for fixing up the cmdtable, if CONFIG_RELOC_FIXUP_WORKS is not defined.
---
- changes since v1
add comment from Peter Tyser
- as this code is also "copied" in avr32, m68k and mips plattforms, use this common function fixup_cmdtable() on this architectures too.
I couldn;t test this, so please test and report
arch/avr32/lib/board.c | 25 ++++--------------------- arch/m68k/lib/board.c | 27 ++++----------------------- arch/mips/lib/board.c | 28 ++++------------------------ arch/sparc/lib/board.c | 28 ++++------------------------ common/command.c | 37 +++++++++++++++++++++++++++++++++++++ include/command.h | 3 +++ 6 files changed, 56 insertions(+), 92 deletions(-)
arch/avr32/lib/board.c +4 -21
@@ -269,30 +269,13 @@ void board_init_r(gd_t *new_gd, ulong dest_addr) monitor_flash_len = _edata - _text; +#if !defined(CONFIG_RELOC_FIXUP_WORKS )/* * We have to relocate the command table manually */ -for (cmdtp = &__u_boot_cmd_start; - cmdtp != &__u_boot_cmd_end; cmdtp++) { -unsigned long addr; - - addr = (unsigned long )cmdtp->cmd + gd->reloc_off; - cmdtp->cmd = (typeof(cmdtp->cmd))addr; - - addr = (unsigned long )cmdtp->name + gd->reloc_off; - cmdtp->name = (typeof(cmdtp->name))addr; - -if (cmdtp->usage) { - addr = (unsigned long )cmdtp->usage + gd->reloc_off; - cmdtp->usage = (typeof(cmdtp->usage))addr; - } -#ifdef CONFIG_SYS_LONGHELP -if (cmdtp->help) { - addr = (unsigned long )cmdtp->help + gd->reloc_off; - cmdtp->help = (typeof(cmdtp->help))addr; - } -#endif - } +fixup_cmdtable (&__u_boot_cmd_start, + (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); +#endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */ /* there are some other pointer constants we must deal with */ #ifndef CONFIG_ENV_IS_NOWHERE
arch/m68k/lib/board.c +4 -23
@@ -433,33 +433,14 @@ void board_init_r (gd_t *id, ulong dest_addr) monitor_flash_len = (ulong )&__init_end - dest_addr; +#if !defined(CONFIG_RELOC_FIXUP_WORKS )/* * We have to relocate the command table manually */ -for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { -ulong addr; - addr = (ulong) (cmdtp->cmd) + gd->reloc_off; -#if 0 -printf ("Command \"%s\": 0x%08lx => 0x%08lx\n" , - cmdtp->name, (ulong) (cmdtp->cmd), addr); -#endif - cmdtp->cmd = - (int (*)(struct cmd_tbl_s *,int ,int ,char *[]))addr; +fixup_cmdtable (&__u_boot_cmd_start, + (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); +#endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */ - addr = (ulong)(cmdtp->name) + gd->reloc_off; - cmdtp->name = (char *)addr; - -if (cmdtp->usage) { - addr = (ulong)(cmdtp->usage) + gd->reloc_off; - cmdtp->usage = (char *)addr; - } -#ifdef CONFIG_SYS_LONGHELP -if (cmdtp->help) { - addr = (ulong)(cmdtp->help) + gd->reloc_off; - cmdtp->help = (char *)addr; - } -#endif - }/* there are some other pointer constants we must deal with */ #ifndef CONFIG_ENV_IS_NOWHERE env_name_spec += gd->reloc_off;
arch/mips/lib/board.c +4 -24
@@ -304,34 +304,14 @@ void board_init_r (gd_t *id, ulong dest_addr) monitor_flash_len = (ulong )&uboot_end_data - dest_addr; +#if !defined(CONFIG_RELOC_FIXUP_WORKS )/* * We have to relocate the command table manually */ -for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { -ulong addr; +fixup_cmdtable (&__u_boot_cmd_start, + (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); +#endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */ - addr = (ulong) (cmdtp->cmd) + gd->reloc_off; -#if 0 -printf ("Command \"%s\": 0x%08lx => 0x%08lx\n" , - cmdtp->name, (ulong) (cmdtp->cmd), addr); -#endif - cmdtp->cmd = - (int (*)(struct cmd_tbl_s *,int ,int ,char *[]))addr; - - addr = (ulong)(cmdtp->name) + gd->reloc_off; - cmdtp->name = (char *)addr; - -if (cmdtp->usage) { - addr = (ulong)(cmdtp->usage) + gd->reloc_off; - cmdtp->usage = (char *)addr; - } -#ifdef CONFIG_SYS_LONGHELP -if (cmdtp->help) { - addr = (ulong)(cmdtp->help) + gd->reloc_off; - cmdtp->help = (char *)addr; - } -#endif - }/* there are some other pointer constants we must deal with */ #ifndef CONFIG_ENV_IS_NOWHERE env_name_spec += gd->reloc_off;
arch/sparc/lib/board.c +4 -24
@@ -252,33 +252,13 @@ void board_init_f(ulong bootflag)post_run (NULL ,POST_ROM |post_bootmode_get (0 ));#endif +#if !defined(CONFIG_RELOC_FIXUP_WORKS )/* * We have to relocate the command table manually */ -for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { -ulong addr; - addr = (ulong) (cmdtp->cmd) + gd->reloc_off; -#if DEBUG_COMMANDS -printf ("Command \"%s\": 0x%08lx => 0x%08lx\n" , - cmdtp->name, (ulong) (cmdtp->cmd), addr); -#endif - cmdtp->cmd = - (int (*)(struct cmd_tbl_s *,int ,int ,char *[]))addr; - - addr = (ulong) (cmdtp->name) + gd->reloc_off; - cmdtp->name = (char *)addr; - -if (cmdtp->usage) { - addr = (ulong) (cmdtp->usage) + gd->reloc_off; - cmdtp->usage = (char *)addr; - } -#ifdef CONFIG_SYS_LONGHELP -if (cmdtp->help) { - addr = (ulong) (cmdtp->help) + gd->reloc_off; - cmdtp->help = (char *)addr; - } -#endif - } +fixup_cmdtable (&__u_boot_cmd_start, + (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); +#endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */ #if defined(CONFIG_CMD_AMBAPP ) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP )puts ("AMBA:\n" );
common/command.c +37 -0
@@ -464,3 +464,40 @@ int cmd_get_data_size(char* arg, int default_size)return default_size; }#endif + +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +DECLARE_GLOBAL_DATA_PTR ; + +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size) +{ +int i; + +if (gd->reloc_off ==0 ) +return ; + +for (i =0 ; i < size; i++) { +ulong addr; + + addr = (ulong) (cmdtp->cmd) + gd->reloc_off; +#if DEBUG_COMMANDS +printf ("Command \"%s\": 0x%08lx => 0x%08lx\n" , + cmdtp->name, (ulong) (cmdtp->cmd), addr); +#endif + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *,int ,int ,char *const []))addr; + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; +if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr; + } +#ifdef CONFIG_SYS_LONGHELP +if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + } +#endif + cmdtp++; + } +} +#endif
include/command.h +3 -0
@@ -125,4 +125,7 @@ cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}#endif /* CONFIG_SYS_LONGHELP */ +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +void fixup_cmdtable (cmd_tbl_t *cmdtp,int size); +#endif #endif /* __COMMAND_H */
Signature · 4 lines
1.6.2.5 -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany