Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mips32, big-endian: stage3, crossdev arguments
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on Alternative Architectures
View previous topic :: View next topic  
Author Message
sbar
n00b
n00b


Joined: 05 Nov 2008
Posts: 6

PostPosted: Mon Sep 05, 2011 6:36 pm    Post subject: mips32, big-endian: stage3, crossdev arguments Reply with quote

Hello. I've got a router TP-Link MR3420. It runs OpenWrt now, it's been installed using this document.
Code:
sbar@router:~$ cat /proc/cpuinfo
system type             : Atheros AR7241 rev 1
machine                 : TP-LINK TL-MR3420
processor               : 0
cpu model               : MIPS 24Kc V7.4
BogoMIPS                : 265.42
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 16
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0000, 0x0bc0, 0x0c30, 0x0f98]
ASEs implemented        : mips16
shadow register sets    : 1
kscratch registers      : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available
sbar@router:~$ file `which busybox`
/bin/busybox: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size
sbar@router:~$ uname -a
Linux router 2.6.39.4 #1 Mon Aug 22 10:18:45 CEST 2011 mips GNU/Linux
It boots a flashed kernel and uses a root filesystem from the usb flash (via extroot). I wanna run Gentoo the same way (using the same flashed kernel).

I've got a toolkit, that comes with original firmware, that compiles mips32 big-endian files, that run fine on it. Can I use it to create my own stage3? How (any doc, please?)?
Code:
sbar@laptop /var/tmp $ wget -q https://raw.github.com/sbar/data_structures/master/utils/memview.c
sbar@laptop /var/tmp $ ~/router/mr3420_3220v1/build/gcc-3.4.4-2.16.1/build_mips/bin/mips-linux-uclibc-gcc memview.c -o memview
sbar@laptop /var/tmp $ file memview
memview: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped
sbar@laptop /var/tmp $ scp -P 55 memview root@router:/root/
memview                                 100% 7970     7.8KB/s   7.8KB/s   00:00
sbar@laptop /var/tmp $ ssh -p 55 root@router /root/memview
4 bytes of memory from 0x7fc9d560 address:
11111111(ff) 11111111(ff) 11111111(ff) 11111010(fa)  // this is "-6" in the memory
...


I've tried all available mips-related stage3 archives (copyied some binary files to router from them) but without any success. Some of googled stage3s too.

I've also tried to compile my own toolkit via crossdev (used those documents: one, two):
Code:
LANG=C CBUILD=i686-pc-linux-gnu crossdev --without-headers --binutils 2.20.1-r1 --libc 2.11.2 --target mips-softfloat-linux-gnu
It cannot compile even "hello world" in C, but it worked with a small assembler program:
Code:
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc test.c -o test
as: unrecognized option '-EB'
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-as ~/hello.S -o hello
sbar@desktop ~/router/gentoo $ ls -l hello
-rw-r--r-- 1 sbar sbar 948 2011-09-05 21:18 hello
sbar@desktop ~/router/gentoo $ file hello
hello: ELF 32-bit MSB relocatable, MIPS, MIPS-I version 1 (SYSV), not stripped

But anyway it doesn't work at my router
Code:
sbar@router:~$ /tmp/hello
-bash: /tmp/hello: cannot execute binary file


I need something from
Code:
ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped

ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size


How to use a crossdev to get output files like that?

Thank you.
Back to top
View user's profile Send private message
roarinelk
Guru
Guru


Joined: 04 Mar 2004
Posts: 445

PostPosted: Tue Sep 06, 2011 6:14 am    Post subject: Reply with quote

the router runs ucLibc, but you built glibc-based cross toolchain. Have you tried
linking your "hello" program statically (for testing)?

"gcc -mips32r2" should get you the desired "MIPS32 rel2 version 1" . Not that it matters:
mips32r2 is a superset of mips32 which is a superset of mips1.
Back to top
View user's profile Send private message
sbar
n00b
n00b


Joined: 05 Nov 2008
Posts: 6

PostPosted: Tue Sep 06, 2011 4:55 pm    Post subject: Reply with quote

roarinelk wrote:
"gcc -mips32r2" should get you the desired "MIPS32 rel2 version 1"
Thank you, that worked:
Code:
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-as -mips32r2 -o hello hello.S -non_shared
sbar@desktop ~/router/gentoo $ file hello
hello: ELF 32-bit MSB relocatable, MIPS, MIPS32 rel2 version 1 (SYSV), not stripped
But I can't make it work at the router anyway:
Code:
sbar@router:/tmp$ ./hello
-bash: ./hello: cannot execute binary file
sbar@router:/tmp$ strace ./hello
execve("./hello", ["./hello"], [/* 15 vars */]) = -1 ENOEXEC (Exec format error)
write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
) = 32
exit_group(1)                           = ?

Is that because I built a glibc-based toolchain? Or it's all 'cause of code. I've forgotten, that I've commented some lines in this googled hello world, to make it compilable, sorry:
Code:
sbar@desktop ~/router/gentoo $ cat hello.S
# hello.S   by Spencer T. Parkin

# This is my first MIPS-RISC assembly program!
# To compile this program type:
# > gcc -o hello hello.S -non_shared

# This program compiles without errors or warnings
# on a PlayStation2 MIPS R5900 (EE Core).
# EE stands for Emotion Engine...lame!

# The -non_shared option tells gcc that we`re
# not interrested in compiling relocatable code.
# If we were, we would need to follow the PIC-
# ABI calling conventions and other protocols.

#include <asm/regdef.h>     // ...for human readable register names
#include <asm/unistd.h>     // ...for system serivices         

        .rdata                  # begin read-only data segment
        .align      2           # because of the way memory is built
hello:      .asciz      "Hello, world!\n"   # a null terminated string
        .align      4           # because of the way memory is built
length:     .word       . - hello       # length = IC - (hello-addr)
        .text                   # begin code segment
        .globl      main            # for gcc/ld linking
        .ent        main            # for gdb debugging info.
main:       # We must specify -non_shared to gcc or we`ll need these 3 lines that fallow.
       .set        noreorder       # disable instruction reordering
       .cpload     t9          # PIC ABI crap (function prologue)
       .set        reorder         # re-enable instruction reordering
        #move        a0,0           # load stdout fd
        #la      a1,hello        # load string address
        #lw      a2,length       # load string length
        #li      v0,__NR_write       # specify system write service
        #syscall                 # call the kernel (write string)
        #li      v0,0            # load return code
        j       ra          # return to caller
        .end        main            # for dgb debugging info.
I've got this, if uncomment them back:
Code:
hello.S: Assembler messages:
hello.S:31: Error: illegal operands `move a0,0'
hello.S:32: Error: illegal operands `la a1,hello'
hello.S:33: Error: illegal operands `lw a2,length'
hello.S:34: Error: illegal operands `li v0,__NR_write'
hello.S:36: Error: illegal operands `li v0,0'
Also, if I try to compile it with "gcc" (not with "as") I get this:
Code:
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -mips32r2 -o hello hello.S -non_shared
mips-softfloat-linux-gnu-gcc: unrecognized option '-non_shared'
hello.S:16:68: fatal error: asm/regdef.h: No such file or directory
compilation terminated.
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -mips32r2 -o hello hello.S
hello.S:16:68: fatal error: asm/regdef.h: No such file or directory
compilation terminated.


roarinelk wrote:
Have you tried linking your "hello" program statically (for testing)?
I don't know how (using -static flag?)
Code:
sbar@desktop ~/router/gentoo $ cat test.c
#include <unistd.h>

int main(int argc, char* argv[])
{
  char str[] = "Hello, world!\n";
  write(1, str, sizeof(str) - 1);
  _exit(0);
}
sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -static -o test test.c 
as: unrecognized option '-EB'
sbar@desktop ~/router/gentoo $ cat > test1.c
#include <stdio.h>

int main() {
  printf("hello\n");
  return 0;
}

sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -static -o test1 test1.c
as: unrecognized option '-EB'
Back to top
View user's profile Send private message
mattst88
Developer
Developer


Joined: 28 Oct 2004
Posts: 363

PostPosted: Tue Sep 06, 2011 5:29 pm    Post subject: Re: mips32, big-endian: stage3, crossdev arguments Reply with quote

sbar wrote:
Can I use it to create my own stage3?


It's possible, but I wouldn't count on it.

mips32/big-endian stages are on my TODO list, but I haven't gotten there yet. I'm really not sure of the value of dealing with uclibc either.
_________________
My 1U Dual 833 MHz Alphaserver DS20L
The AlphaLinux.org Wiki
Back to top
View user's profile Send private message
sbar
n00b
n00b


Joined: 05 Nov 2008
Posts: 6

PostPosted: Tue Sep 06, 2011 8:04 pm    Post subject: Reply with quote

I've tried to compile the same crosscompiler but with uClibc. It's been failed at uClibc:
Code:

desktop ~ # LANG=C CBUILD=i686-pc-linux-gnu crossdev --without-headers --binutils 2.20.1-r1 --target mips-softfloat-linux-uclibc
 * Forcing the latest versions of {binutils,gcc}-config/gnuconfig ...         [ ok ]
 * Log: /var/log/portage/cross-mips-softfloat-linux-uclibc-binutils.log
 * Emerging cross-binutils ...                                                [ ok ]
 * Log: /var/log/portage/cross-mips-softfloat-linux-uclibc-gcc-stage1.log
 * Emerging cross-gcc-stage1 ...                                      [ ok ]
 * Log: /var/log/portage/cross-mips-softfloat-linux-uclibc-linux-headers.log
 * Emerging cross-linux-headers ...                                       [ ok ]
 * Log: /var/log/portage/cross-mips-softfloat-linux-uclibc-uclibc.log
 * Emerging cross-uclibc ...

 * uclibc failed :(
 * If you file a bug, please attach the following logfiles:
 * /var/log/portage/cross-mips-softfloat-linux-uclibc-info.log
 * /var/log/portage/cross-mips-softfloat-linux-uclibc-uclibc.log

desktop ~ # tail /var/log/portage/cross-mips-softfloat-linux-uclibc-uclibc.log -n30
  LN include/sys/sysmips.h
  LN include/sys/tas.h
  LN include/sys/ucontext.h
  LN include/sys/user.h
make -j2 -l2
  GEN include/bits/sysnum.h
  AS lib/crt1.o
as: unrecognized option '-EB'
make: *** [lib/crt1.o] Error 1
make: *** Waiting for unfinished jobs....
emake failed
 * ERROR: cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1 failed (compile phase):
 *   make failed
 *
 * Call stack:
 *     ebuild.sh, line  56:  Called src_compile
 *   environment, line 2886:  Called die
 * The specific snippet of code:
 *       emake || die "make failed";
 *
 * If you need support, post the output of 'emerge --info =cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1',
 * the complete build log and the output of 'emerge -pqv =cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1'.
 * This ebuild is from an overlay named 'arcon': '/var/lib/layman/arcon/'
 * The complete build log is located at '/var/tmp/portage/cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1/temp/environment'.
 * S: '/var/tmp/portage/cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1/work/uClibc-0.9.30.1'

>>> Failed to emerge cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1, Log file:

>>>  '/var/tmp/portage/cross-mips-softfloat-linux-uclibc/uclibc-0.9.30.1-r1/temp/build.log'
Code:
as: unrecognized option '-EB'

This error again. Complete information: build.log, cross-mips-softfloat-linux-uclibc-info.log, cross-mips-softfloat-linux-uclibc-uclibc.log.
Is there any solution?
Back to top
View user's profile Send private message
roarinelk
Guru
Guru


Joined: 04 Mar 2004
Posts: 445

PostPosted: Wed Sep 07, 2011 6:59 am    Post subject: Reply with quote

sbar wrote:
Code:

sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -static -o test1 test1.c
as: unrecognized option '-EB'


That error looks suspicious. MIPS "as" should understand both -EB and -EL.
Please rebuild mips binutils and make sure your cross gcc calls the cross-as,
not the native (x86/x64) one.
Back to top
View user's profile Send private message
sbar
n00b
n00b


Joined: 05 Nov 2008
Posts: 6

PostPosted: Wed Sep 07, 2011 11:00 pm    Post subject: Reply with quote

roarinelk wrote:
sbar wrote:
Code:

sbar@desktop ~/router/gentoo $ mips-softfloat-linux-gnu-gcc -static -o test1 test1.c
as: unrecognized option '-EB'


That error looks suspicious. MIPS "as" should understand both -EB and -EL.
Please rebuild mips binutils and make sure your cross gcc calls the cross-as,
not the native (x86/x64) one.
Thank you! I've made /usr/bin/as pointing to mips' assembler, restarted crossdev and gcc worked! But g++ was reporting: "/usr/mips-linux-uclibc/gcc-bin/4.4.2/../../../../usr/lib/gcc/mips-linux-uclibc/4.4.2/libstdc++.so: undefined reference to `__tls_get_addr'" — rebuilding with USE=-nptl fixed it.

Also, I've rebuilt everything with uClibc — now output compiler programs run good at router. So, this way of crosscompiler compilation works for me: "USE=-nptl LANG=C CBUILD=i686-pc-linux-gnu CTARGET=mips-linux-uclibc crossdev -t mips-linux-uclibc --b 2.19.1"

I'll ask there some questions about stage3 compilation later, if there will be any.
Back to top
View user's profile Send private message
sbar
n00b
n00b


Joined: 05 Nov 2008
Posts: 6

PostPosted: Sun Sep 11, 2011 5:19 pm    Post subject: Reply with quote

I'm getting some linker errors from different packages, like this (build.log):
Code:
/usr/bin/mips-linux-uclibc-ld: cannot open linker script file /usr/mips-linux-uclibc/gcc-bin/4.4.3/../../../../usr/mips-linux-uclibc/lib/libncursesw.so.5: No such file or directory
How to resolve them? I've got those files:
Code:

desktop ~ # cd /usr/mips-linux-uclibc/gcc-bin/4.4.3/../../../../usr/mips-linux-uclibc/lib/
desktop lib # pwd
/usr/mips-linux-uclibc/lib
desktop lib # ls -l *curses*
-rw-r--r-- 1 root root  17 Sep 11 20:09 libcurses.a
lrwxrwxrwx 1 root root  11 Sep 11 20:13 libncurses.a -> libcurses.a
lrwxrwxrwx 1 root root  12 Sep 11 20:55 libncurses.a.5 -> libncurses.a
-rwxr-xr-x 1 root root 532 Sep  8 20:30 libncurses.so
lrwxrwxrwx 1 root root  13 Sep 11 19:51 libncurses.so.5 -> libncurses.so
lrwxrwxrwx 1 root root  13 Sep 11 20:52 libncursesw.5.a -> libncursesw.a
-rw-r--r-- 1 root root  18 Sep 11 20:49 libncursesw.a
-rwxr-xr-x 1 root root 533 Sep  8 20:30 libncursesw.so
lrwxrwxrwx 1 root root  14 Sep 11 20:48 libncursesw.so.5 -> libncursesw.so


I've found different similar problems (one unresolved, two), made this symlink — nothing changed:
Code:
sbar@desktop /usr/i686-pc-linux-gnu/lib $ ls -l /usr/lib/binutils/mips-linux-uclibc/2.18/
total 4
drwxr-xr-x 2 root root 4096 2011-09-07 20:32 include
lrwxrwxrwx 1 root root   52 2011-09-11 21:11 ldscripts -> /usr/lib/binutils/i686-pc-linux-gnu/2.20.1/ldscripts
Back to top
View user's profile Send private message
puchuu
n00b
n00b


Joined: 15 Aug 2012
Posts: 4

PostPosted: Fri Aug 02, 2013 8:13 am    Post subject: Reply with quote

Why do you want to run binary in openwrt? You can chroot to external hdd, enable big swap in the center of it and use usual gentoo.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on Alternative Architectures All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum