public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] Does u-boot relocate absolute symbols?
@ 2005-07-01  7:57 Andreas Block
  2005-07-01 14:35 ` Jerry Van Baren
  0 siblings, 1 reply; 15+ messages in thread
From: Andreas Block @ 2005-07-01  7:57 UTC (permalink / raw)
  To: u-boot

Jerry: I'm sorry for the inconvenience, but sent this mail to you instead  
of the U-Boot mailinglist.

I'm not quite sure, what happened on your side.
Here's the result on my side (together with the source as it ought look):

--- BEGIN OF CONSOLE OUTPUT
andreas at pc-linux-dev:~/arrtest> cat common.h
int showwrong(void);

andreas at pc-linux-dev:~/arrtest> cat common.c
#include <stdio.h>

extern const unsigned char test[];

int showwrong(void)
{
         printf("test[]: 0x%08X\n", (int)test);
         return 0;
}

andreas at pc-linux-dev:~/arrtest> cat array.c
#include "common.h"

const unsigned char *test = (unsigned char*)0x40000;

int main(void)
{
         printf("*test: 0x%08X\n", (int)test);
         showwrong();
         return 0;
}
andreas at pc-linux-dev:~/arrtest> gcc -o arrtest -I ./ ./common.c ./array.c
andreas at pc-linux-dev:~/arrtest> ./arrtest
*test: 0x00040000
test[]: 0x080494E4
--- END OF CONSOLE OUTPUT

What buffles me is, that on your side, the *test-output isn't 0x40000,  
because the
pointer is initialized directly in that object and used as pointer. And on  
the other
hand, the output can't be the same:
extern char test[]; ==> results in a symbol at the start address of the  
array.
char *test; ==> is a pointer containing the start-address of the array.  
This means one
more level of reference.

Could you please show your source files as they were used for your test to  
us. I'm
still sure, both notations are not the same, although they work the same  
in most cases.

Regards,
Andreas


30.06.2005 19:28:32, Jerry Van Baren  
<gerald.vanbaren@smiths-aerospace.com> wrote:

> Rune Torgersen wrote:
>> Wow.... This surprises me...
>> I have alwayts thought that *test and test[] would be the same thing.
>> Only solutionI can see is to change the definition in common.c to be
>> *test, this will still get the address of test[] defined elsewhere.
>> (See attached files)
>>
>>> Sure, I've tried this. This is the point, where my problemarose.  
>>> Attached you find twosmall files, you can easily compile under linux  
>>> (gcc -oarrtest -I ./ ./common.c./array.c). The file "common.c"  
>>> represents the code I can't(don't want to) touch."array.c" represents  
>>> my project dependent code. If you runarrtest it will show to you,
>
> With the patch in place (previously sent to the list), it works for  
> linux:
>
> vanbaren at sherwood:~/x> ll
> total 32
> -rwxr-----  1 vanbaren users  200 Jun 30 13:24 array.c
> -rwxr-xr-x  1 vanbaren users 8963 Jun 30 13:26 arrtest
> -rwxr-----  1 vanbaren users  132 Jun 30 08:03 common.c
> -rwxr-----  1 vanbaren users  121 Jun 30 08:03 common.c-original
> -rw-r--r--  1 vanbaren users  237 Jun 30 08:04 common.c.diff
> -rwxr-----  1 vanbaren users   24 Jun 30 13:23 common.h
> vanbaren at sherwood:~/x> gcc -o arrtest -I ./ ./common.c ./array.c
> vanbaren at sherwood:~/x> ./arrtest
> *test: 0x08048558
> test[]: 0x08048558
>
> gvb
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> U-Boot-Users mailing list
> U-Boot-Users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/u-boot-users
>
>
>

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [U-Boot-Users] Does u-boot relocate absolute symbols?
@ 2005-07-01  8:01 Andreas Block
  0 siblings, 0 replies; 15+ messages in thread
From: Andreas Block @ 2005-07-01  8:01 UTC (permalink / raw)
  To: u-boot

Rune: I'm sorry for the inconvenience, but I sent this mail to you instead  
of the U-Boot mailinglist.

And WD already slapped me for sending this example...

30.06.2005 18:54:40, "Rune Torgersen" <runet@innovsys.com> wrote:

> Wow.... This surprises me...
> I have alwayts thought that *test and test[] would be the same thing.
>
> Only solutionI can see is to change the definition in common.c to be
> *test, this will still get the address of test[] defined elsewhere.
> (See attached files)

Thanks, for your effort. Actually your suggestion is the way it's  
currently working
here, but as I described in my first post, I'm looking for a way, which  
leaves the
common code untouched. In my first post on 24.06.05 I've another solution,  
which is
working for Linux, but does not in U-Boot.

Regards,
Andreas


>> Sure, I've tried this. This is the point, where my problemarose.  
>> Attached you find twosmall files, you can easily compile under linux  
>> (gcc -oarrtest -I ./ ./common.c./array.c). The file "common.c"  
>> represents the code I can't(don't want to) touch."array.c" represents  
>> my project dependent code. If you runarrtest it will show to you,
>

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [U-Boot-Users] Does u-boot relocate absolute symbols?
@ 2005-06-30 16:54 Rune Torgersen
  2005-06-30 17:28 ` Jerry Van Baren
  0 siblings, 1 reply; 15+ messages in thread
From: Rune Torgersen @ 2005-06-30 16:54 UTC (permalink / raw)
  To: u-boot

Wow.... This surprises me...
I have alwayts thought that *test and test[] would be the same thing.

Only solutionI can see is to change the definition in common.c to be
*test, this will still get the address of test[] defined elsewhere.
(See attached files)

> Sure, I've tried this. This is the point, where my problem 
> arose. Attached you find two 
> small files, you can easily compile under linux (gcc -o 
> arrtest -I ./ ./common.c 
> ./array.c). The file "common.c" represents the code I can't 
> (don't want to) touch. 
> "array.c" represents my project dependent code. If you run 
> arrtest it will show to you, 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: common.h
Type: application/octet-stream
Size: 24 bytes
Desc: common.h
Url : http://lists.denx.de/pipermail/u-boot/attachments/20050630/fe93c658/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array.c
Type: application/octet-stream
Size: 200 bytes
Desc: array.c
Url : http://lists.denx.de/pipermail/u-boot/attachments/20050630/fe93c658/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: common.c
Type: application/octet-stream
Size: 137 bytes
Desc: common.c
Url : http://lists.denx.de/pipermail/u-boot/attachments/20050630/fe93c658/attachment-0002.obj 

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [U-Boot-Users] Does u-boot relocate absolute symbols?
@ 2005-06-29 15:46 Rune Torgersen
  2005-06-30  7:45 ` Andreas Block
  0 siblings, 1 reply; 15+ messages in thread
From: Rune Torgersen @ 2005-06-29 15:46 UTC (permalink / raw)
  To: u-boot

I just have to comment on this.

> It does not work (because it's simply wrong) to declare 
> fpgadata as follows in pf5200.c 
> (although looking good in the first place, if you think about 
> it, the compiler needs to 
> handle both declarations differently):
> 
> const unsigned char *fpgadata = 0x400000; /* (with 0x400000 
> being the address to store 
> the image with TFTP at) */
> 

Have you tried to do this?
Because it should work (even if one is declared char [] and the other
char *)

I use something similar to access a FPGA binary image stored in flash
(after U-Boot relocation) and it works.

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [U-Boot-Users] Does u-boot relocate absolute symbols?
@ 2005-06-14  9:47 Andreas Block
  0 siblings, 0 replies; 15+ messages in thread
From: Andreas Block @ 2005-06-14  9:47 UTC (permalink / raw)
  To: u-boot

Hi,

I'm not quite sure, if this is a bug or a feature, but I tried to do the following and 
it didn't work:

Here at esd, we've some code common for all our boards (used to program FPGAs or CPLDs 
in u-boot). Up to now, the respective CPLD/FPGA-image was included into u-boot as an 
array, declared as follows in a board-dependent file (e.g. pf5200.c):

const unsigned char fpgadata[] = {
  #include "fpgadata.c"
};

The common code (located in micro.c or ports.c in esd/common/) accesses the image via 
fpgadata using the following extern-declaration:

extern const unsigned char fpgadata[];

This far everything's fine. With a new hardware, we've the following problem:
The CPLD image is too large to fit within u-boot and I'd like to retrieve the CPLD 
image at runtime via TFTP. And I'd like to do this without the need to change any of 
the common code (like the above mentioned extern-declaration), which of course would 
mean to test all other hardware using the common-code again.

It does not work (because it's simply wrong) to declare fpgadata as follows in pf5200.c 
(although looking good in the first place, if you think about it, the compiler needs to 
handle both declarations differently):

const unsigned char *fpgadata = 0x400000; /* (with 0x400000 being the address to store 
the image with TFTP at) */

So I tried a different approach (since all I need is to get access to the array at a 
certain memory location). I didn't declare fpgadata in pf5200.c at all, but instead 
wrote a small fpgadata.S containing the following:

.globl fpgadata
.data
.set fpgadata, 0x400000

It's supposed to generate the symbol fpgadata.c and locate it at the right absolute 
address in memory. One can try this with some small test-code under Linux and it works 
as it's supposed to. Also the output of nm "fpgadata.o" looks beautiful:

00400000 A fpgadata

But when used in u-boot the address of fpgadata is not 0x400000, but something 
different. I assume this is related to u-boot booting from flash and relocating itself 
into RAM. And this is the point, I'm not sure about. Is this the way one wants it work. 
Does one want u-boot to relocate absolute addresses, or is this behaviour even needed 
for u-boot to work at all? Or is it a bug and u-boot doesn't pay attention to the 
absolute flag as it's supposed to? Wouldn't it be nice in a boot-loader to be able to 
locate something at certain memory locations at link time?

Best regards,
Andreas Block

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

end of thread, other threads:[~2005-07-01 15:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-01  7:57 [U-Boot-Users] Does u-boot relocate absolute symbols? Andreas Block
2005-07-01 14:35 ` Jerry Van Baren
2005-07-01 15:06   ` Andreas Block
  -- strict thread matches above, loose matches on Subject: below --
2005-07-01  8:01 Andreas Block
2005-06-30 16:54 Rune Torgersen
2005-06-30 17:28 ` Jerry Van Baren
2005-06-29 15:46 Rune Torgersen
2005-06-30  7:45 ` Andreas Block
2005-06-30 10:46   ` Wolfgang Denk
2005-06-30 11:42     ` Andreas Block
2005-06-30 12:40       ` Wolfgang Denk
2005-06-30 13:38         ` Andreas Block
2005-06-30 12:05   ` Jerry Van Baren
2005-06-30 12:44     ` Andreas Block
2005-06-14  9:47 Andreas Block

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