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 stable main

Update repository of host machine,

#sudo apt-get update

Install following packages:

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.

You should see 'sbox' in the output. Now run on Host machine.

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/

again login to scratchbox
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.

Contact me in caseof any queries.

1 comment: