Reputation: 821
I am trying to set up a scratchbox2 configuration to cross-compile rasberry pi software using a root partition that contains a copy of the real raspian distribution. This seems to work OK overall as I can run arm executables but because I am trying to use gcc within the copied root partition that doesn't have a prefix the name translation isn't working. How can I chroot the scratchbox session? Running chroot after running sb2 doesn't seem to work.
Upvotes: 3
Views: 1555
Reputation: 546
You need not chroot after initializing scratchbox2!. What you expect can be achieved using the following procedure:
Make sure you have a cross compiling tools set up on the host system. Assuming you are on a linux host (Ubuntu), you can install one by using:
sudo apt-get install gcc-arm-linux-gnueabihf
(hard float) OR
sudo apt-get install gcc-arm-linux-gnueabi
If you are on a different host machine or you have a different tool-chain for cross compiling like codesourcery's toolchain, just make sure you install the appropriate version (hardfloat/soft float) and export the path of the compiler to the $PATH and note down the name (prefix).
Make sure you have Qemu installed.
Since you have already installed scratchbox2, assuming the path to the copy of your Rapberrypi's rootfs on the host pc is stored in the variable $raspirootfs,
cd $raspirootfs
Now initialise sb2 using:
sb2-init raspberrypi arm-linux-gnueabi-gcc
Where raspberrypi
is just a name for the target configuration. replace arm-linux-gnuabi-gcc
with your cross compiler prefix.
If this is your first target configuration (if this is the first time your are running sb2-init), you can start sb2 with the default target configuration by entering:
sb2 -eR
This should give you a prompt like:
[SB2 emulate raspberrypi] user@pc #
Now the sb2 is in emulate mode and not in normal mode and it will try to stay away from your host binaries and executes the binaries in your $raspirootfs using qemu.
Enter sb2-show path /etc/apt
in the terminal to see how /etc/apt is mapped. It should show something like /etc/apt --> $raspirootfs/etc/apt
(and not the host system's /etc/apt).
To Install into emulated system:
Just do as you would on you host system. Example:
apt-get install build-essential
To cross compile some source:
cd sourcedir
sb2 ./configure
sb2 make -jN
sb2 make install DESTDIR=$raspirootfs
For those of you trying to set up a cross compiling environment using scratchbox2, I have made a post here :http://praveenp.com/setting-up-a-cross-compiling-environment-to-build-linux-applications-for-embedded-targets/ . For cross compiling using chroot, you can refer to this post :http://praveenp.com/setting-up-an-environment-using-chroot-for-developing-applications-for-embedded-targets/
Upvotes: 4