Monday, June 21, 2010

A Scratchbox Tutorial

Scratchbox is a tool that aims to provide chrooted crosscompilation environment and manages to hide the complexity in crosscompiling any app for a target platform.


1. Installing scratchbox :

Add following line to apt sources.list

deb http://scratchbox.org/debian stable main

Update repository of host machine,

#sudo apt-get update

Install following packages:

scratchbox-core
scratchbox-libs
scratchbox-devkit-qemu
scratchbox-toolchain-arm-linux-cs2009q1-203sb1
2. Setting up a target.
Now you have scratchbox folder at root of filesystem. It contains users folder in which a folder with your username will be created.
 Add your username to scratchbox's users (Never add ROOT !) on Host machine. 
#sb-adduser vaibhav

Logout and login once again

Check whether you have group privilege on Host machine.
$groups

You should see 'sbox' in the output. Now run on Host machine.
$/scratchbox/login

and then inside scratchbox:
sbox >sb-menu
Here create a new target : enter a name, select cross-toolchain, select qemu package select processor arch etc. Say no when asked whether you want to install rootstrap on the target. Say yes when scratchbox asks you whether to enable the target. Now the shell will be restarted and you'll be working in your target.

3. Extracting rootstrap:
Here we should get our respective system's rootstrap and untar it to target dir under /scratchbox/
/scratchbox/users/USERNAME/targets/TARGETNAME/

again login to scratchbox
$/scratchbox/login
4. Using apt-get inside scratchbox:
The apt-get provided with Debian's devkit should work properly. But just in case dpkg give you an error about superuser priviliges, use fakeroot with apt-get at place of sudo.

>fakeroot apt-get install gedit

Now you're ready to start programming.

Inside scratchbox you can compile all your packages from source, compile your own software - I use it to compile my GTK+ apps, and by using sbrsh can test them on target device too. Also you can install all dev libraries in scratchbox and provide only runtime libs on device.

Thus scratchbox proves to be a great tool for embedded system's development.
www.scratchbox.org

Contact me in caseof any queries.

1 comment: