public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] Can not access global variable in uboot command function?
@ 2009-10-11  3:10 wilbur.chan
  2009-10-12  1:28 ` Jerry Van Baren
  0 siblings, 1 reply; 2+ messages in thread
From: wilbur.chan @ 2009-10-11  3:10 UTC (permalink / raw)
  To: u-boot

mips64 , xlr732


I've added a test command in uboot, say,
U_BOOT_CMD(test_globa,...do_test_global)  ,which is  in cmd_command.c
.


And in cmd_command.c, there is also a global string array ,say ,char*
p = "test";




In do_test_global,  I used pointer to access elements of array p like this:

char c = *(char*)p;

it seemd that , the code above caused uboot dead and print nothing ,I
guess that,maybe there was a memory access violation.

Any suggestions on how could this happended? Thank you in advance





my code is like this:

/* cmd_command.c*/

char* p = "test";

U_BOOT_CMD(test_globa,do_test_global)  ;

int do_test_global()
{
char c = *(char*)p;    //when called , uboot was dead here...
return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [U-Boot] Can not access global variable in uboot command function?
  2009-10-11  3:10 [U-Boot] Can not access global variable in uboot command function? wilbur.chan
@ 2009-10-12  1:28 ` Jerry Van Baren
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry Van Baren @ 2009-10-12  1:28 UTC (permalink / raw)
  To: u-boot

Hi Wilbur,

wilbur.chan wrote:
> mips64 , xlr732
> 
> I've added a test command in uboot, say,
> U_BOOT_CMD(test_globa,...do_test_global)  ,which is  in cmd_command.c
> 
> And in cmd_command.c, there is also a global string array ,say ,char*
> p = "test";
> 
> In do_test_global,  I used pointer to access elements of array p like this:
> 
> char c = *(char*)p;
> 
> it seemd that , the code above caused uboot dead and print nothing ,I
> guess that,maybe there was a memory access violation.
> 
> Any suggestions on how could this happended? Thank you in advance

Just a guess, but I suspect your are getting bitten by the manual 
pointer relocation issue.

Your char *p is pointing into flash, but you are dereferencing the 
pointer after relocation to RAM, running out of RAM with a different 
memory map than power-on-reset (initialization has completed).  I 
suspect your flash image is no longer where it was on release of reset 
and thus dereferencing *p now tries to read an invalid memory location, 
causing your "hang."

If you really need the pointers, you need to manually relocate them. 
See ./include/asm-mips/global_data.h and the function
   void board_init_r (gd_t *id, ulong dest_addr)
in lib_mips/board.c.

The bottom line is that you probably need to add gd->reloc_off to your 
compiled-in pointers:
   *(p + gd->reloc_off)

[snip]

gvb

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-12  1:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-11  3:10 [U-Boot] Can not access global variable in uboot command function? wilbur.chan
2009-10-12  1:28 ` Jerry Van Baren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox