Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
qemu-user mipsel chroot problems
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
Stolz
Moderator
Moderator


Joined: 19 Oct 2003
Posts: 2953
Location: Valencia, Spain

PostPosted: Fri May 31, 2013 6:12 pm    Post subject: qemu-user mipsel chroot problems Reply with quote

I'm trying to install Gentoo in my old media player (MIPS 4KEc V6.9 32bits) following the Gentoo Embedded Handbook. I successfully created a toolchain with crossdev which works well for compiling small packages (nano, colordiff,...) but when it comes to bigger packages it's a P.I.T.A.. because I get compile errors for almost all packages I've tried (python, php, ...).

So now I'm trying to compile everything using the qemu-user chroot approach.

Everything seems to be properly set up but I can't get the chroot to work:

Code:

# QEMU_USER_TARGETS="mipsel" emerge app-emulation/qemu-user -b1
# /etc/init.d/qemu-binfmt start
# cat /proc/sys/fs/binfmt_misc/mipsel
enabled
interpreter /usr/bin/qemu-static-mipsel-binfmt
flags: P
offset 0
magic 7f454c4601010100000000000000000002000800
mask ffffffffffffff00fffffffffffffffffeffffff

# cd $CHROOT
# mkdir -p usr/portage
# ROOT=$PWD/ emerge -K qemu-user
# mount --bind /usr/portage usr/portage
# mount --bind /proc proc
# mount --bind /sys sys
# chroot . /bin/busybox mdev -s
# chroot . /bin/bash --login
/bin/bash: can't load library 'libgcc_s.so.1'


I'm using app-emulation/qemu-user-1.4.0 and stage3-mipsel3-uclibc-vanilla-20130520.

Any clue on what is going on?

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


Joined: 04 Mar 2004
Posts: 444

PostPosted: Sat Jun 01, 2013 10:18 am    Post subject: Reply with quote

Hi,

it may be a problem with your MIPS environment. I just tried your approach on my own mipsel environment,
and it works as it should.

you can get it here: http://mlau.at/files/mips32-linux/mips32elsf-gentoo-rootfs-120908.tar.xz
Back to top
View user's profile Send private message
Stolz
Moderator
Moderator


Joined: 19 Oct 2003
Posts: 2953
Location: Valencia, Spain

PostPosted: Sat Jun 01, 2013 7:06 pm    Post subject: Reply with quote

Thanks for your interest roarinelk. I figured it out. The problem was using "emerge -K" as the docs suggested. If I copy by hand the qemu binaries it works.

So in case anyone has the same problem, instead of
Code:
# ROOT=$PWD/ emerge -K qemu-user
just do
Code:
# cp /usr/bin/qemu-static-mipsel /usr/bin/qemu-static-mipsel-binfmt $CHROOT/usr/bin/


Also, to get rid of error messages complaining about no write access to /dev/null instead of
Code:
# chroot . /bin/busybox mdev -s
I did
Code:
# mount --bind /dev dev


Now the chroot with Qemu is working but I'm facing the same enormous number of compile errors I got with crossdev (but now they are almost always "configure: error: C compiler cannot create executables", which seems to be quite generic problem).

My media player boots from a read only NAND so the only way to run Gentoo on it is via chroot. I tried your rootfs in my media player but I'm not able to chroot into it from within my media player. I can chroot using Qemu in my computer but when I try from the media player I get:
Quote:
# chroot . /bin/bash
FATAL: kernel too old


I'm not sure what ¡the problem is. The kernel that comes with the player is ancient (Dec 2010) but it's what I have and I have no problems using it to chroot into my my rootfs created from the latest mipsel stage3 (2013-05-20).

Code:
# uname -a
Linux HDX 2.6.15-sigma #3265 PREEMPT Fri Dec 17 12:23:32 MYT 2010 mips GNU/Linux


It's a pity because the number of installed packages in your rootfs is huge. As I said I have no problems chrooting into my own rootfs from within the media player but of course it's almost empty and therefore useless.

I thought I would be easier to have minimum Gentoo system in my little multimedia player. My goal is to use it as NFS server, vsftpd, git server and a web server (nginx or lighttpd) with PHP and embedded MySQL support. I have no skills to overcome the compile errors so I feel kind of discouraged right now. May be I have to try with different CHOST or CFLAGS. At least I've learned a lot about embedded systems and crosscompiling.
Back to top
View user's profile Send private message
roarinelk
Guru
Guru


Joined: 04 Mar 2004
Posts: 444

PostPosted: Sat Jun 01, 2013 7:43 pm    Post subject: Reply with quote

I had the "C compiler cannot create execiutables" errors as well; I have some binaries which
have different "ABI" field in the ELF header. Can be easily fixed by modifying the 9th mask byte
in the binfmt registration (from 0xff to 0x00).

compare the elf headers of e.g. /bin/busybox with a newly compiled hello world binary.

However qemu-user-1.4.0 is very crashy, I tried to compile gcc-4.8 in the chroot multiple times
but it segfaults at arbitrary points. Looks like a major headache :)
Back to top
View user's profile Send private message
Stolz
Moderator
Moderator


Joined: 19 Oct 2003
Posts: 2953
Location: Valencia, Spain

PostPosted: Sun Jun 02, 2013 11:48 am    Post subject: Reply with quote

Thanks roarinelk, you were right
Code:
echo 'int main(){return 0;}' > test.c
gcc -Wall test.c -o test
readelf -h test /bin/busybox | grep Magic
Magic:   7f 45 4c 46 01 01 01 00 01 00 00 00 00 00 00 00
Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00


I've updated the binfmt mask and now everything seems to compile pretty straightforward.Without you I would never be able to figure out what was the problem. Thanks again.

Now the next challenge is make everything work together with only 88Mb of RAM.

BTW, I'm using gcc-4.8 in my chroot environment. It was provided by the stage3 I downloaded. Couldn't you get it from there?
Back to top
View user's profile Send private message
roarinelk
Guru
Guru


Joined: 04 Mar 2004
Posts: 444

PostPosted: Sun Jun 02, 2013 2:50 pm    Post subject: Reply with quote

I have a working gcc-4.8 git version from yesterday, but I was trying to speed compilation up a bit
with the qemu environment, it takes ~24 hours on my MIPS targets to fully build gcc.

How stable is your qemu? Mine segfaults randomly while unpacking the source tarball, or
during the configure run, ... It's just stable enough to run a few simple things.
Did you set any parameters? (QEMU_CPU, ...) Which version? 64bit host?
Back to top
View user's profile Send private message
Stolz
Moderator
Moderator


Joined: 19 Oct 2003
Posts: 2953
Location: Valencia, Spain

PostPosted: Sun Jun 02, 2013 4:28 pm    Post subject: Reply with quote

My qemu-user-1.4.0 seems stable so far but my system packages list is modest compared with yours. I've compiled w/o problems: colordiff eix pydf joe htop screen nginx atool git mediainfo php and gentoolkit. Right now I'm still running an "emerge -e system" and only a few packages have failed (none of them with segfault) but lets see because more than 50% of system packages are still left.

I didn't set up any parameter for qemu. This is what I did:

- downgrade sys-apps/texinfo from 5.1 to 4.13-r2.
- echo "QEMU_USER_TARGETS=mipsel" >> /etc/portage/make.conf
- emerge app-emulation/qemu-user
- cp /usr/bin/qemu-static-mipsel /usr/bin/qemu-static-mipsel-binfmt $CHROOT/usr/bin/
- Edit /etc/init.d/qemu-binfmt to remove all lines related to archs other than mips plus the ELF mask edit you suggested before
- /etc/init.d/qemu-binfmt start
- bind mount and chroot

My build host is x86_64-pc-linux-gnu and qemu was built with gcc-4.7.2-r1
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