linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Cross compiling : problem linking
@ 2003-10-02 12:56 Toni Van Remortel
  2003-10-02 13:26 ` Toni Van Remortel
  2003-10-02 13:35 ` Wolfgang Denk
  0 siblings, 2 replies; 9+ messages in thread
From: Toni Van Remortel @ 2003-10-02 12:56 UTC (permalink / raw)
  To: linuxppc-embedded


Hi all,

I try to cross compile a small test program for the EP505 board. I use
ELDK as compiler set.

When using this compile command:

ppc_4xx-gcc -O -v -nostdlib -nostartfiles -mno-eabi -fno-exceptions \
-fno-builtin -Wl,-Tscript.ld,-N -o rt_mod rt_mod.c

I get after a while:

/opt/eldk/usr/ppc-linux/bin/ld: cannot open linker script file \
script.ld: Onbekend bestand of map
collect2: ld returned 1 exit status

I don't know what is wrong, but 'script.ld' isn't anywhere on my system.

Side note: I used the compiler set already to cross compile a kernel,
XFree and FLTK, so it works.

Any idea?

PS: the program currently should make a square wave on EBC P1 D1
--
                           Toni Van Remortel
              Wetenschappelijk Medewerker - D-science lab
  Real time Linux for embedded systems: http://linemb.d-sciencelab.com
              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: t.vanremortel@ha.be


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* Re: Cross compiling : problem linking
  2003-10-02 12:56 Toni Van Remortel
@ 2003-10-02 13:26 ` Toni Van Remortel
  2003-10-02 13:37   ` Wolfgang Denk
  2003-10-02 13:35 ` Wolfgang Denk
  1 sibling, 1 reply; 9+ messages in thread
From: Toni Van Remortel @ 2003-10-02 13:26 UTC (permalink / raw)
  To: linuxppc-embedded


Reduced the error to:

toni rt_mod # make
ppc_4xx-gcc -g -O -Werror   -c -o rt_mod.o rt_mod.c
ppc_4xx-gcc -nostartfiles -fno-exceptions -fno-builtin  -o rt_mod
rt_mod.o
/opt/eldk/usr/ppc-linux/bin/ld: warning: cannot find entry symbol
_start; defaulting to 10000184
rt_mod.o: In function `block_wave':
/ppc/rt_mod/rt_mod.c:14: undefined reference to `outb'
/ppc/rt_mod/rt_mod.c:14: relocation truncated to fit: R_PPC_REL24 outb
rt_mod.o: In function `main':
/ppc/rt_mod/rt_mod.c:21: undefined reference to `iopl'
/ppc/rt_mod/rt_mod.c:21: relocation truncated to fit: R_PPC_REL24 iopl
collect2: ld returned 1 exit status
make: *** [rt_mod] Fout 1

Somebody?
--
                           Toni Van Remortel
              Wetenschappelijk Medewerker - D-science lab
  Real time Linux for embedded systems: http://linemb.d-sciencelab.com
              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: t.vanremortel@ha.be


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* Re: Cross compiling : problem linking
  2003-10-02 12:56 Toni Van Remortel
  2003-10-02 13:26 ` Toni Van Remortel
@ 2003-10-02 13:35 ` Wolfgang Denk
  1 sibling, 0 replies; 9+ messages in thread
From: Wolfgang Denk @ 2003-10-02 13:35 UTC (permalink / raw)
  To: linuxppc-embedded


In message <1065099415.10206.5.camel@toni> you wrote:
>
> I try to cross compile a small test program for the EP505 board. I use
> ELDK as compiler set.
>
> When using this compile command:
>
> ppc_4xx-gcc -O -v -nostdlib -nostartfiles -mno-eabi -fno-exceptions \
> -fno-builtin -Wl,-Tscript.ld,-N -o rt_mod rt_mod.c

Well, I guess you know what you are  douing  here,  i.  e.  what  the
linker options mean?

I wonder where you got this command line from...

> I get after a while:
>
> /opt/eldk/usr/ppc-linux/bin/ld: cannot open linker script file \
> script.ld: Onbekend bestand of map
> collect2: ld returned 1 exit status
>
> I don't know what is wrong, but 'script.ld' isn't anywhere on my system.

Well, if you don't have such a linker script, why do  you  then  tell
the linker to use it?

> PS: the program currently should make a square wave on EBC P1 D1

In which sort of environment? As standalone program? As Linux  kernel
module? As Linux user-land application? Or what?

Best regards,

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
Uncertain fortune is thoroughly mastered by the equity of the  calcu-
lation.                                               - Blaise Pascal

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* Re: Cross compiling : problem linking
  2003-10-02 13:26 ` Toni Van Remortel
@ 2003-10-02 13:37   ` Wolfgang Denk
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Denk @ 2003-10-02 13:37 UTC (permalink / raw)
  To: t.vanremortel; +Cc: linuxppc-embedded


In message <1065101196.10206.7.camel@toni> you wrote:
>
> Reduced the error to:
>
> toni rt_mod # make
> ppc_4xx-gcc -g -O -Werror   -c -o rt_mod.o rt_mod.c
> ppc_4xx-gcc -nostartfiles -fno-exceptions -fno-builtin  -o rt_mod
> rt_mod.o
> /opt/eldk/usr/ppc-linux/bin/ld: warning: cannot find entry symbol
> _start; defaulting to 10000184
> rt_mod.o: In function `block_wave':
> /ppc/rt_mod/rt_mod.c:14: undefined reference to `outb'
> /ppc/rt_mod/rt_mod.c:14: relocation truncated to fit: R_PPC_REL24 outb
> rt_mod.o: In function `main':
> /ppc/rt_mod/rt_mod.c:21: undefined reference to `iopl'
> /ppc/rt_mod/rt_mod.c:21: relocation truncated to fit: R_PPC_REL24 iopl
> collect2: ld returned 1 exit status
> make: *** [rt_mod] Fout 1

The header files and/or compiler and linker options you are using are
not correct for the target environment you have.

Without more information (i. e. what sort of code this is and how you
intend it to run - stdandalone, in kernel or in user context)  nobody
can help you.

Best regards,

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
Sorry, but my karma just ran over your dogma.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* Re: Cross compiling : problem linking
       [not found] <1065104646.13376.8.camel@toni>
@ 2003-10-02 15:01 ` Wolfgang Denk
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Denk @ 2003-10-02 15:01 UTC (permalink / raw)
  To: linuxppc-embedded


In message <1065104646.13376.8.camel@toni> you wrote:
>
> > Without more information (i. e. what sort of code this is and how you
> > intend it to run - stdandalone, in kernel or in user context)  nobody
> > can help you.
>
> Final goal is a kernel module, but now I'm writing a test program in
> user space (standalone, dynamic compiled).

These are two completely different issues.

> Code is quite simple (but I'm unsure about the correctness, due to the
> fact that my C knowledge has collapsed since I didn't use it anymore
> last 2 years):
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <asm/io.h>

You're including a kernel header file here. You must not do this. The
functions / macros you're looking for are not available in user space
(for example, outb is #defined only when __KERNEL__ is defined  which
is never the case for user space applications.)

> So somewhere, there is a linker problem.

No, it's a misunderstanding on your side. You cannot run kernel  code
in user space or vice versa.


Best regards,

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
I have yet to add the ESP-driver to the kernel to read  the  mind  of
the user...                                       - Linus Torvalds in
      <Pine.LNX.3.91.960426110644.24860I-100000@linux.cs.Helsinki.FI>

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* RE: Cross compiling : problem linking
@ 2003-10-02 16:34 Fillod Stephane
  2003-10-02 21:26 ` Wolfgang Denk
  2003-10-03  8:26 ` Toni Van Remortel
  0 siblings, 2 replies; 9+ messages in thread
From: Fillod Stephane @ 2003-10-02 16:34 UTC (permalink / raw)
  To: 'linuxppc-embedded@lists.linuxppc.org'


Note to the list: sorry for the RFC2822

> Do you know the replacement for iopl to work on PowerPC?

There's no such crap on PowerPC. No separate IO bus either.


> Final goal is a kernel module, but now I'm writing a test program in
> user space (standalone, dynamic compiled).

Okay, let's use ESP for once :)

Toni, I don't know what's your "base" address, but it is really odd
(well, both ways :) on a PowerPC system. You should borrow some help
from your D-science lab, or have something like a PPC Linux training.


Wolfgang, you've got my agreement to put the following in the FAQ
if it's not already.


This code is for accessing hardware registers from *userland*.
You need CAP_SYS_RAWIO and /dev/mem permissions.

Basically:
	volatile void *p = ioremap(MY_HARD_REG_ADDR, 4096);
	...
	out_8(p, state ^= 0x1);




#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>

#ifdef __PPC__
extern inline void out_8(volatile unsigned char *addr, int val)
{
        __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r"
(val));
}
#else
extern inline void out_8(volatile unsigned char *addr, int val)
{
        *add = val & 0xff;
}
#endif

extern inline volatile void * ioremap(unsigned long physaddr, unsigned size)
{
    static int axs_mem_fd = -1;
    unsigned long page_addr, ofs_addr, reg, pgmask;
    void* reg_mem = NULL;

    /*
     * looks like mmap wants aligned addresses?
     */
    pgmask = getpagesize()-1;
    page_addr = physaddr & ~pgmask;
    ofs_addr  = physaddr & pgmask;

    /*
     * Don't forget O_SYNC, esp. if address is in RAM region.
     * Note: if you do know you'll access in Read Only mode,
     *    pass O_RDONLY to open, and PROT_READ only to mmap
     */
    if (axs_mem_fd == -1) {
        axs_mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
        if (axs_mem_fd < 0) {
                perror("AXS: can't open /dev/mem");
                return NULL;
        }
    }

    /* memory map */
    reg_mem = mmap(
        (caddr_t)reg_mem,
        size+ofs_addr,
        PROT_READ|PROT_WRITE,
        MAP_SHARED,
        axs_mem_fd,
        page_addr
    );
    if (reg_mem == MAP_FAILED) {
        perror("AXS: mmap error");
        close(axs_mem_fd);
        return NULL;
    }

    reg = (unsigned long )reg_mem + ofs_addr;
    return (volatile void *)reg;
}

extern inline int iounmap(volatile void *start, size_t length)
{
    unsigned long ofs_addr;
    ofs_addr = (unsigned long)start & (getpagesize()-1);

    /* do some cleanup when you're done with it */
    return munmap((void*)start-ofs_addr, length+ofs_addr);
}


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* Re: Cross compiling : problem linking
  2003-10-02 16:34 Cross compiling : problem linking Fillod Stephane
@ 2003-10-02 21:26 ` Wolfgang Denk
  2003-10-03  8:26 ` Toni Van Remortel
  1 sibling, 0 replies; 9+ messages in thread
From: Wolfgang Denk @ 2003-10-02 21:26 UTC (permalink / raw)
  To: Fillod Stephane; +Cc: 'linuxppc-embedded@lists.linuxppc.org'


Dear Stephane,

in message <2C1BAF8F8E1DD611862B0002A5D4C3FC01BC068F@renexch3.rennes.thmulti.com> you wrote:
>
> Wolfgang, you've got my agreement to put the following in the FAQ
> if it's not already.

AFAIK it's not.

> This code is for accessing hardware registers from *userland*.
> You need CAP_SYS_RAWIO and /dev/mem permissions.

Thanks!

Or do you want to add it yourself? All you have to do is  registering
at  http://www.denx.de/twiki/bin/view/TWiki/TWikiRegistration ...

Then you can edit / add to the U-Boot and Linux Guide at
http://www.denx.de/twiki/bin/view/DULG/WebHome yourself...


Hint: _anybody_ is welcome to contribute.


Best regards,

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
Never worry about theory as long as  the  machinery  does  what  it's
supposed to do.                                      - R. A. Heinlein

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* RE: Cross compiling : problem linking
  2003-10-02 16:34 Cross compiling : problem linking Fillod Stephane
  2003-10-02 21:26 ` Wolfgang Denk
@ 2003-10-03  8:26 ` Toni Van Remortel
  1 sibling, 0 replies; 9+ messages in thread
From: Toni Van Remortel @ 2003-10-03  8:26 UTC (permalink / raw)
  To: Fillod Stephane; +Cc: 'linuxppc-embedded@lists.linuxppc.org'


Op do 02-10-2003, om 18:34 schreef Fillod Stephane:
> Note to the list: sorry for the RFC2822
>
> > Do you know the replacement for iopl to work on PowerPC?
>
> There's no such crap on PowerPC. No separate IO bus either.

Darn. I've once seen an example somewhere on the net on controlling an
output pin on the EP405 (from kernel space), but I can't remember where
:(

> > Final goal is a kernel module, but now I'm writing a test program in
> > user space (standalone, dynamic compiled).

Now I know that the difference between user and kernel space is so
different, I'll only try to go for the final result: a kernel module.

> Okay, let's use ESP for once :)

What is ESP?

> Toni, I don't know what's your "base" address, but it is really odd
> (well, both ways :) on a PowerPC system. You should borrow some help
> from your D-science lab, or have something like a PPC Linux training.

I'm afraid I should go for the last one. The D-science lab is actually
specialized in usability and product design testing. There is only one
technological project running, namely mine, which is about embedded
Linux. I started working on this project when I was just about half a
year graduated as industrial engineer. So my Linux knowledge was limited
to desktop use and installation.
You'll probably think I'm asking things that every embedded Linux
developer knows, but I'm not one, I'm just trying to understand
everything. Aside that, my platform knowledge is zero. That's why I come
up with code for x86 to run on PPC ;)

PS: that "base" address was fetched from ibm405gp.h (the ECB base
address).
--
                           Toni Van Remortel
              Wetenschappelijk Medewerker - D-science lab
  Real time Linux for embedded systems: http://linemb.d-sciencelab.com
              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: t.vanremortel@ha.be


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

* RE: Cross compiling : problem linking
@ 2003-10-06 13:09 Fillod Stephane
  0 siblings, 0 replies; 9+ messages in thread
From: Fillod Stephane @ 2003-10-06 13:09 UTC (permalink / raw)
  To: 'linuxppc-embedded@lists.linuxppc.org'


Dear Wolfgang,

> Then you can edit / add to the U-Boot and Linux Guide at
> http://www.denx.de/twiki/bin/view/DULG/WebHome yourself...

It seems like I have no permission to mess with DULG,
so I've added it to PPCEmbedded HOWTO:
 http://www.denx.de/twiki/bin/view/PPCEmbedded/DeviceDrivers

Feel free to move it around as needed.

Regards,
Stephane

PS: still sorry for the RFC2822 and References, should be fixed after xmas.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

end of thread, other threads:[~2003-10-06 13:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-02 16:34 Cross compiling : problem linking Fillod Stephane
2003-10-02 21:26 ` Wolfgang Denk
2003-10-03  8:26 ` Toni Van Remortel
  -- strict thread matches above, loose matches on Subject: below --
2003-10-06 13:09 Fillod Stephane
     [not found] <1065104646.13376.8.camel@toni>
2003-10-02 15:01 ` Wolfgang Denk
2003-10-02 12:56 Toni Van Remortel
2003-10-02 13:26 ` Toni Van Remortel
2003-10-02 13:37   ` Wolfgang Denk
2003-10-02 13:35 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).