[U-Boot] Help Request - Command parsing, find_cmd (), possible linker script problem

Jerry Van Baren gvb.uboot at gmail.com
Sat Sep 20 15:57:17 CEST 2008


Graeme Russ wrote:
> Hi All,
> 
> So far I have my sc520 board booting into main_loop (), DRAM configured
> and serial ports working. Now I seem to be stuck on getting commands
> to execute (even help). Using printf() I have traced my problem into
> find_cmd (). I added the following into find_cmd() just before the for
> loop:
>
> printf ("Searching for Command '%s'\n", cmd);
> printf ("Command Table Start : %08lx\n", (ulong)&__u_boot_cmd_start);
> printf ("Command Table End   : %08lx\n", (ulong)&__u_boot_cmd_end);
> printf ("sizeof(int)         : %x\n", sizeof(int));
> printf ("sizeof(cmd_tbl_t)   : %x\n", sizeof(cmd_tbl_t));

Aaargh, you printed %x, not 0x%x.  That really threw me on the printout 
of sizeof(cmd_tbl_t).

[snip]

> The output is (there are a few other printf()'s leadinf up to
> find_cmd () as well):
> 
> boot > help
> 
> [RUN_COMMAND] cmd[00400ccc]="help"
> [PROCESS_SEPARATORS] help
> token: "help"
> 
> Processing Macros...
> [PROCESS_MACROS] INPUT len 4: "help"
> [PROCESS_MACROS] OUTPUT len 4: "help"
> Extracting Arguments...
> parse_line: "help"
> 
> parse_line: nargs=1
> Looking up Command...
> Searching for Command 'help'
> Command Table Start : 0000053e
> Command Table End   : 00000870

0x870 - 0x53e = 0x332 = 818.  818 / 24 = 34 with a remainder of 2.  I 
believe this is your problem.  I bet you need to word-align the start of 
your table... the end label is getting word aligned which is padding out 
your end so your loop doesn't end.

I suspect this is the problem with not recognizing the commands as well? 
  Perhaps the processor/compiler doesn't like having the table poorly 
aligned so one of the pointers is getting messed up?

> sizeof(int)         : 4
> sizeof(cmd_tbl_t)   : 18

0x18 == 24

> Checking : 0000053e
> Checking : 00000556

0x56 - 0x3e == 0x18 == 24 (check)

> Checking : 0000056e
> .
> .
> .
> Checking : 00000856
> Checking : 0000086e

0x86e is the proper table end given 34 commands and 24 bytes per table 
entry.

> Checking : 00000886
> Checking : 0000089e
> Checking : 000008b6
> 
> There are a few weird things going on...
> 
> a) sizeof(cmd_tbl_t) is 18, but the loop is incrementing by 24 (I would
> have thought a 4 byte alignment would push it to 20 maybe)

Nope, just radix issues (see above).

> 
> b) The loop never completes since cmdtp never actually equals
> &__u_boot_cmd_end

Alignment padding problems are preventing it (see above).

[snip]

> Can anyone point me an a rough direction to look? Any help at all
> would be greatly appreciated

I think you need a 4 byte alignment before the command table in the 
linker control file (below)

> Regards,
> 
> Graeme
> 
> u-boot.lds:

[snip]

> 	/* 16bit BIOS emulation code (just enough to boot Linux) */
> 	.bios 0 : AT ( LOADADDR(.realmode) + SIZEOF(.realmode) ) { *(.bios) }
> 
> 	_i386boot_bios = LOADADDR(.bios);
> 	_i386boot_bios_size = SIZEOF(.bios);
> 
> 
>   . = .;


I think you need to add
. = ALIGN(2);
here

(ALIGN(4)? IIRC, the ALIGN is 2^n so ALIGN(2) is 4-byte alignment)

>   __u_boot_cmd_start = .;
>   .u_boot_cmd : { *(.u_boot_cmd) }
>   __u_boot_cmd_end = .;

[snip]

HTH,
gvb


More information about the U-Boot mailing list