The Mer Wiki now uses your Mer user account and password (create account on https://bugs.merproject.org/)


Platform SDK and SB2

From Mer Wiki
(Difference between revisions)
Jump to: navigation, search
(Note on target naming)
(Example of building one of Nemo's RPM packages)
 
(69 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 
The most straightforward way to use Scratchbox2 is within the Mer [[Platform SDK]].  
 
The most straightforward way to use Scratchbox2 is within the Mer [[Platform SDK]].  
This page will go through the steps of using SB2 to compile a simple program.
+
This page will go through the steps of using SB2 to compile a simple program in a tutorial-like manner.
  
 
= Prerequisites =
 
= Prerequisites =
  
 
* A properly setup SDK
 
* A properly setup SDK
* Scratchbox2 pre-installed (see [[#Installation|SB2 Installation]] if not)
+
* Scratchbox2 pre-installed (see [[Platform_SDK#Compiling_with_the_SDK|SB2 Installation]] if not)
 
* Your home directory is in /home/<username> (otherwise see [[#Directory Mappings| directory mappings]])
 
* Your home directory is in /home/<username> (otherwise see [[#Directory Mappings| directory mappings]])
  
Line 27: Line 27:
  
 
This gets:
 
This gets:
   sb2: Error: Invalid target specified, aborting.
+
   sb2: Error: No target specified and none set as default, aborting.
  
 
When sb2 runs it needs to know where to get header files and libraries and what architecture and cross-compiler to use. This is called a 'target'. SB2 can be configured to run against multiple named targets.
 
When sb2 runs it needs to know where to get header files and libraries and what architecture and cross-compiler to use. This is called a 'target'. SB2 can be configured to run against multiple named targets.
  
= SB2 Setup =
+
= Setup a new target for sb2 =
 
== Target Preparation ==
 
== Target Preparation ==
  
 
A target is a rootfs that contains development files like headers, libraries and possibly programs. Notably it does *not* need to contain compilers, linkers etc.
 
A target is a rootfs that contains development files like headers, libraries and possibly programs. Notably it does *not* need to contain compilers, linkers etc.
 +
 +
You can either make your own or (eventually) download a target.
 +
 +
== Make your own target ==
 +
 +
'''NOTE:''' this needs mer-core >= 0.20130124.1, check that with sdk-version cmd.
  
 
Still running in the sdk we'll create a target in the recommended /srv/mer/targets/ area.
 
Still running in the sdk we'll create a target in the recommended /srv/mer/targets/ area.
Line 41: Line 47:
 
  sudo chown -R $USER /parentroot/srv/mer/targets
 
  sudo chown -R $USER /parentroot/srv/mer/targets
  
Now we need a kickstart file and then we can use mic to create the target
+
Also make sure that /sbin is included in your PATH environment variable.
 +
 
 +
Now we need a kickstart file. We will generate this with mer-kickstarter
 +
 
 +
cd /tmp
 +
sudo zypper install mer-kickstarter mer-kickstarter-configs
 +
mer-kickstarter -c /usr/share/kickstarter-configs/mer-reference-images/00reference.yaml -e /usr/share/kickstarter-configs/mer-reference-images/
 +
 
 +
You now have a large number of kickstart files - we're primarily interested in the mer-target-<arch> ones.
 +
 
 +
The .ks files created contain what is known as a 'token'; in this case it is the text @MER_RELEASE@. When running mic the --tokenmap option is used to provide a value.
  
  cd /tmp
+
After the kickstart file is created the image build can be started
  curl -O http://releases.merproject.org/releases/0.20120315.1/kickstarts/mer-core-armv7hl-xorg-basic-qmlviewer.ks
+
sudo mic create fs mer-target-armv7hl.ks -o /parentroot/srv/mer/targets --pkgmgr=zypp --arch=armv7hl --tokenmap=MER_RELEASE:latest
  sudo mic create fs mer-core-armv7hl-xorg-basic-qmlviewer.ks -o /parentroot/srv/mer/targets --pkgmgr=yum --arch armv7hl
+
  
(Note: if you use a kickstart with @BUILD_ID@ and use the --release= option to mic then mic creates a slightly different structure and your rootfs will end up in /parentroot/srv/mer/targets/<release>/images/<name> and you'll have to move it)
+
Next we need to make sure the rootfs is all owned by the user. SB2 uses fakeroot when needed and won't work if the target has root-owned files.
 +
sudo chown -R $USER /parentroot/srv/mer/targets/mer-target-armv7hl/*
  
The final step is to make sure the rootfs is all owned by the user. SB2 uses fakeroot when needed and won't work if the target has root-owned files.
+
Finally some commands (notably rpmbuild) need to know about your username/userid mapping so we'll add that. Make absolutely sure you are at the top of the sdkroot and don't use a leading / :
  sudo chown -R $USER /parentroot/srv/mer/targets/*
+
cd /parentroot/srv/mer/targets/mer-target-armv7hl/
 +
grep :$(id -u): /etc/passwd >> etc/passwd
 +
grep :$(id -g): /etc/group >> etc/group
  
This target could be any suitable rootfs such as a Nemo or PA rootfs.
+
This target could be any suitable rootfs such as a Nemo or PA rootfs and there are some alternate targets presented lower down the page.
  
== Target Setup ==
+
== Initialize Target in SB2 ==
  
To tell SB2 about the target we use sb2-init which gives the target a name - in this case "mer-core".
+
To tell SB2 about the target we use sb2-init which gives the target a name - in this case "mer-target-armv7hl".
  
 
'''IMPORTANT''' : You must change directory to the target rootfs before running sb2-init.
 
'''IMPORTANT''' : You must change directory to the target rootfs before running sb2-init.
  
  cd /parentroot/srv/mer/targets/mer-core-armv7hl-xorg-basic-qmlviewer
+
cd /parentroot/srv/mer/targets/mer-target-armv7hl
  sb2-init -d -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / mer-core /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
+
sb2-init -d -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / mer-target-armv7hl /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
  
Note - running sb2-init again with the same name will just change the values for that name - make sure each target is named uniquely.
+
Notes
 +
* some messages about "cannot find 'ld'" and "no gcc" are expected.
 +
* running sb2-init again with the same name will just change the values for that name - make sure each target is named uniquely.
  
We now need to work around [https://bugs.merproject.org/show_bug.cgi?id=238 bug #238]:
+
We now need to work around [https://bugs.merproject.org/show_bug.cgi?id=238 bug #238] (note lack of leading /):
  echo -n "armv7hl-meego-linux" > etc/rpm/platform
+
echo -n "armv7hl-meego-linux" > etc/rpm/platform
 
Note that this may not affect all targets and will need an appropriate value for the target architecture until the bug is resolved.
 
Note that this may not affect all targets and will need an appropriate value for the target architecture until the bug is resolved.
  
 
And prepare the target for installation (all these steps will eventually be handled by a target preparation script or similar):
 
And prepare the target for installation (all these steps will eventually be handled by a target preparation script or similar):
  sb2 -t mer-core -m sdk-install -R rpm --rebuilddb
+
sb2 -t mer-target-armv7hl -m sdk-install -R rpm --rebuilddb
  sb2 -t mer-core -m sdk-install -R zypper ref --force
+
sb2 -t mer-target-armv7hl -m sdk-install -R zypper ref --force
  
 
The target is now ready to be used by sb2.
 
The target is now ready to be used by sb2.
 +
 +
If zypper fails with "Cant open /var/run/zypp.pid in mode w" you can fix it with:
 +
 +
cd /srv/mer/targets/<target_name>/var
 +
rm run && mkdir run
  
 
= Compile the simple C program =
 
= Compile the simple C program =
  
 
Again run:
 
Again run:
  sb2 gcc ~/src/hello.c -o ~/src/hello
+
sb2 -t mer-target-armv7hl gcc ~/src/hello.c -o ~/src/hello
  
 
This time:
 
This time:
  ~/src/hello.c:1:19: fatal error: stdio.h: No such file or directory
+
~/src/hello.c:1:19: fatal error: stdio.h: No such file or directory
  
 
This is because the target has no development header files in it.
 
This is because the target has no development header files in it.
Line 88: Line 113:
 
Note the important use of the "-m sdk-install" and the "-R". The -m tells sb2 to use a mapping mode that permit the updating of the target and -R tells sb2 to run as fake root.
 
Note the important use of the "-m sdk-install" and the "-R". The -m tells sb2 to use a mapping mode that permit the updating of the target and -R tells sb2 to run as fake root.
  
  cd /parentroot/srv/mer/targets/mer-core-armv7hl-xorg-basic-qmlviewer
+
cd /parentroot/srv/mer/targets/mer-target-armv7hl
  sb2 -m sdk-install -R zypper in glibc-devel
+
sb2 -t mer-target-armv7hl -m sdk-install -R zypper in glibc-devel
  
 
You'll need to do this for any build requirements of your code.
 
You'll need to do this for any build requirements of your code.
Line 105: Line 130:
 
   -N : don't do localisation for the target
 
   -N : don't do localisation for the target
 
   -t : the location of the build tools
 
   -t : the location of the build tools
   mer-core : The name of the target
+
   mer-target-armv7hl : The name of the target
 
   /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc : the cross-compiler to use
 
   /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc : the cross-compiler to use
  
 
= Alternate targets =
 
= Alternate targets =
  
== N950 Nemo ==
+
== Creating an SB2 Target for any (non-x86) Mer OBS package (draft) ==
 +
 
 +
osc provides the ability to do a "local build" where it creates a chroot within the SDK suitable for building a package.
 +
 
 +
When SB2 is enabled on the OBS (as it is in the MeeGo public OBS) then it also creates a suitable SB2 'target'.
 +
 
 +
So checkout the package from OBS, start a local build, setup the SB2 target:
 +
 
 +
osc co PROJECT PACKAGE
 +
cd PROJECT/PACKAGE
 +
 
 +
determine which repository/architecture to build for
 +
osc repos
 +
 
 +
Then run a build
 +
osc build --chroot-only REPO ARCH
 +
 
 +
Note the build root from the above command or use this to find it:
 +
osc chroot
 +
 
 +
Check the directory of the osc chroot and use the ./target/ directory in there for your SB2 target:
 +
 
 +
  cd CHROOT/target
 +
  sb2-init -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / TARGETNAME /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
 +
 
 +
(If you like you could move this to /srv/mer/targets/ before running the cd/sb2-init commands but then osc build wouldn't upgrade it anymore)
 +
 
 +
At this point you can go to your ~/src/package.git/ directory and run
 +
 
 +
sb2 -t TARGETNAME make
 +
 
 +
The advantage of this approach over a full rootfs target are that:
 +
* it's smaller
 +
* it uses the osc package cache so can be updated with smaller downloads
 +
* it works with packages that are changing on the OBS (so can be run against branched projects)
 +
* it's probably more suitable for working with other people and collaborating via the OBS
 +
* the rootfs can be upgraded and packages added using osc (especially the -x option)
 +
 
 +
The disadvantages are
 +
* it is currently more manual
 +
* it only installs the development packages that are listed by the spec file as build-dependencies
 +
* it's not as re-useable across multiple packages
 +
 
 +
== N950 Nemo Mobile ==
 +
Nemo/N950 rootfs can be found at: http://releases.nemomobile.org/snapshots/ (choose the armv7hl-n950 images).
 +
 
 
To setup cross compiling for N950 (armv7hl) do the following inside the sdk chroot
 
To setup cross compiling for N950 (armv7hl) do the following inside the sdk chroot
  
Line 117: Line 187:
 
Extract the Nemo N950 rootfs as a target and set file permissions:
 
Extract the Nemo N950 rootfs as a target and set file permissions:
  
  mkdir -p /srv/mer/targets/n950rootfs
+
  sudo mkdir -p /srv/mer/targets/n950rootfs
 
  cd /srv/mer/targets/n950rootfs
 
  cd /srv/mer/targets/n950rootfs
 
  sudo tar xjvf /path/to/nemo-n950-image.tar.bz2
 
  sudo tar xjvf /path/to/nemo-n950-image.tar.bz2
 
  sudo chown -R $USER .
 
  sudo chown -R $USER .
 +
 +
note: if you're doing this as the root user and not with sudo, remember to replace $USER with your regular username.
  
 
=== Initialize scratchbox2 ===
 
=== Initialize scratchbox2 ===
Line 127: Line 199:
 
  sb2-init  -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / nemo-n950 /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
 
  sb2-init  -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / nemo-n950 /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
  
The compiler should now work but you are still missing libraries to compile against. Install what you need into the n950 rootfs by
+
'''Note:''' If you installed the mer-target-armv7hl target earlier, that will be your default target. If you, however, like the nemo-n950 to be your default target, add the '''-d''' switch to the command line above.
 +
 
 +
Notes
 +
* some messages about "cannot find 'ld'" and "no gcc" are expected.
 +
* running sb2-init again with the same name will just change the values for that name - make sure each target is named uniquely.
 +
 
 +
We now need to work around [https://bugs.merproject.org/show_bug.cgi?id=238 bug #238] (note lack of leading /):
 +
echo -n "armv7hl-meego-linux" > etc/rpm/platform
 +
Note that this may not affect all targets and will need an appropriate value for the target architecture until the bug is resolved.
 +
 
 +
The compiler should now work but you are still missing libraries to compile against. Install what you need into the n950 rootfs. For example:
 +
 
 +
sb2 -t nemo-n950 -m sdk-install -R ssu ur
 +
sb2 -t nemo-n950 -m sdk-install -R zypper ref -f
 +
sb2 -t nemo-n950 -m sdk-install -R zypper dup
 +
sb2 -t nemo-n950 -m sdk-install -R zypper install gcc-c++
 +
 
 +
Whenever you see message about dbus connection failed on sdk installs, just do 'i' for ignore. For example:
 +
Installation of openssh-5.6p1-1.1.84 failed:
 +
  (with --nodeps --force) Error: Subprocess failed. Error: RPM failed: Failed to get D-Bus connection: No connection to service manager.
 +
 
 +
If zypper fails with "Cant open /var/run/zypp.pid in mode w" you can fix it with:
  
  sb2 -m sdk-install -R zypper ref
+
  cd /srv/mer/targets/n950rootfs/var
  sb2 -m sdk-install -R zypper install  ...  (eg qt-devel)
+
  rm run && mkdir run
  
 
If the installation fails due to permission errors give your user write permissions to the places the packages are being installed and retry. After this you can compile for example a c hello world by
 
If the installation fails due to permission errors give your user write permissions to the places the packages are being installed and retry. After this you can compile for example a c hello world by
Line 152: Line 245:
 
  $ file hello
 
  $ file hello
 
  hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped
 
  hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped
  $ sb2 ./hello  
+
  $ sb2 -t nemo-n950 ./hello  
 
  Hello
 
  Hello
  
Line 159: Line 252:
 
   sb2 -t nemo-n950 make
 
   sb2 -t nemo-n950 make
  
== Vivaldi ==
+
=== Example of building one of Nemo's RPM packages ===
  
Place here any Vivaldi specific instructions for Plasma Active or Nemo development
+
Here's an example of building RPM of QmlCalc:
  
=== Plasma Active ===
+
git clone https://github.com/nemomobile/qmlcalc.git
 +
cd qmlcalc/
 +
mb2 -t nemo-n950 build
  
Plasma Active rootfs can be found here (built 25 March 2012) - https://img.merproject.org/images/web/vgrade/6-20120325-173308/plasmaactive-armv7l-c71-devel-rootfs.tar.bz2
+
==== Troubleshooting ====
 +
If
 +
.../armv7hl-meego-linux-gnueabi/bits/os_defines.h:40:22: fatal error: features.h: No such file or directory
 +
then
 +
sb2 -t mer-target-armv7hl -m sdk-install -Rzypper in glibc-devel
  
=== Nemo Mobile ===
+
If
 +
/var/tmp/rpm-tmp. .... : line 44: /usr/lib/rpm/meego/find-docs.sh: No such file or directory
 +
then
 +
sb2 -t mer-target-armv7hl -m sdk-install -R zypper in meego-rpm-config
 +
 
 +
If magic file issues:
 +
error: magic_load failed: File 5.4 supports only version 7 magic files. `/usr/share/misc/magic.mgc' is version 10
 +
then
 +
# Save the target magic.mgc file (just in case) and use the one from the MerSDK
 +
mv /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc.orig
 +
cp /usr/share/misc/magic.mgc /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc
 +
 
 +
== Plasma Active ==
 +
 
 +
Plasma Active can run on various devices, such as Nexus 7, the Flying Squirrel (in previous iteration - Vivaldi) and so on.
 +
 
 +
* Rootfs for PlasmaActive/Vivaldi can be found here (built 25 March 2012) - https://img.merproject.org/images/web/vgrade/6-20120325-173308/plasmaactive-armv7l-c71-devel-rootfs.tar.bz2
 +
Note that Vivaldi tablet is already obsolete, and Plasma Active project is shifting to other reference platform.
 +
 
 +
* Plasma Active rootfs for Asus Nexus 7 can be found at: http://download.kde.org/unstable/active/3.0/images/nexus7/plasma-active-nexus7-testing-mer-latest-2012-12-20.tar.bz2
 +
 
 +
In the future there might be smaller rootfs releases, targeted specifically to be used with SDK and containing the minimized set of development tools.
 +
=== Setup target ===
 +
 
 +
'''Important Note:''' review potential issues in the [[Platform_SDK_and_SB2#Target_Setup|mer-target-armv7hl target example]]. They apply to setting up other targets as well.
 +
 
 +
Extract the PlasmaActive rootfs as a target and set file permissions (in this example we are taking a Nexus 7 tablet, where PA uses armv7hl build. For other targets and potential armv7l versions, adjust the instructions below accordingly:
 +
 
 +
target_device='nexus7'
 +
arch='armv7hl'
 +
rootfs='/path/to/plasma-active-nexus7-testing-mer-latest-2012-12-20.tar.bz2'
 +
sudo mkdir -p "/srv/mer/targets/plasmaactive-${target_device}-rootfs"
 +
cd /srv/mer/targets/plasmaactive-${target_device}-rootfs
 +
sudo tar xjvf $rootfs
 +
sudo chown -R $USER .
 +
 
 +
=== Initialize scratchbox2 ===
 +
cd /srv/mer/targets/plasmaactive-${target_device}-rootfs
 +
sb2-init -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / plasmaactive-${target_device} /opt/cross/bin/${arch}-meego-linux-gnueabi-gcc
 +
 
 +
=== Install some tools ===
 +
sb2 -t plasmaactive-${target_device} -m sdk-install -R zypper refresh
 +
sb2 -t plasmaactive-${target_device} -m sdk-install -R zypper install gcc-c++
 +
 
 +
=== Cross compilation ===
 +
Create some source: hello.cpp:
 +
 
 +
<pre>
 +
#include <iostream>
 +
 
 +
int main(int argc, char* argv[])
 +
{
 +
  std::cout << "Hello World!\n";
 +
  return 0;
 +
}
 +
</pre>
 +
 
 +
Compile it:
 +
  sb2 -t plasmaactive-${target_device} g++ hello.cpp -o hello
 +
 
 +
Run:
 +
  sb2 -t plasmaactive-${target_device} ./hello
 +
  Hello World!
 +
 
 +
Check architecture:
 +
  file hello
 +
  hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped
  
 
= Additional Notes =
 
= Additional Notes =
Line 188: Line 353:
  
 
Additional entries can be made if your source lives elsewhere (eg /media or /data etc).
 
Additional entries can be made if your source lives elsewhere (eg /media or /data etc).
 +
 +
==Using multiple targets==
 +
You can use multiple targets with the SDK. Set up each target as described above.
 +
To perform some action for a specific target add the -t option: <pre>sb2 -t <target> ...</pre>
 +
To list all set targets: <pre>sb2-config -l</pre>
 +
To set up a default target: <pre>sb2-config -d <target></pre>
 +
 +
==Removing targets==
 +
When targets are created the information about target is put to ~/.scratchbox2/ directory, so in order to remove target one can just remove directories from there:
 +
rm -r ~/.scratchbox2/<target_name>
  
 
[[Category:sdk]]
 
[[Category:sdk]]

Latest revision as of 11:35, 23 May 2014

The most straightforward way to use Scratchbox2 is within the Mer Platform SDK. This page will go through the steps of using SB2 to compile a simple program in a tutorial-like manner.

Contents

[edit] Prerequisites

[edit] Create a simple C program

We'll use ~/src/hello.c as the location of our code.

mkdir ~/src
cat <<EOF >~/src/hello.c
#include <stdio.h>
int main(int argc, char **argv)
{
   printf("Hello World\n");
   return 0;
}
EOF

And now to compile it:

sb2 gcc ~/src/hello.c -o ~/src/hello

This gets:

 sb2: Error: No target specified and none set as default, aborting.

When sb2 runs it needs to know where to get header files and libraries and what architecture and cross-compiler to use. This is called a 'target'. SB2 can be configured to run against multiple named targets.

[edit] Setup a new target for sb2

[edit] Target Preparation

A target is a rootfs that contains development files like headers, libraries and possibly programs. Notably it does *not* need to contain compilers, linkers etc.

You can either make your own or (eventually) download a target.

[edit] Make your own target

NOTE: this needs mer-core >= 0.20130124.1, check that with sdk-version cmd.

Still running in the sdk we'll create a target in the recommended /srv/mer/targets/ area.

sudo mkdir -p /parentroot/srv/mer/targets
sudo chown -R $USER /parentroot/srv/mer/targets

Also make sure that /sbin is included in your PATH environment variable.

Now we need a kickstart file. We will generate this with mer-kickstarter

cd /tmp
sudo zypper install mer-kickstarter mer-kickstarter-configs
mer-kickstarter -c /usr/share/kickstarter-configs/mer-reference-images/00reference.yaml -e /usr/share/kickstarter-configs/mer-reference-images/

You now have a large number of kickstart files - we're primarily interested in the mer-target-<arch> ones.

The .ks files created contain what is known as a 'token'; in this case it is the text @MER_RELEASE@. When running mic the --tokenmap option is used to provide a value.

After the kickstart file is created the image build can be started

sudo mic create fs mer-target-armv7hl.ks -o /parentroot/srv/mer/targets --pkgmgr=zypp --arch=armv7hl --tokenmap=MER_RELEASE:latest

Next we need to make sure the rootfs is all owned by the user. SB2 uses fakeroot when needed and won't work if the target has root-owned files.

sudo chown -R $USER /parentroot/srv/mer/targets/mer-target-armv7hl/*

Finally some commands (notably rpmbuild) need to know about your username/userid mapping so we'll add that. Make absolutely sure you are at the top of the sdkroot and don't use a leading / :

cd /parentroot/srv/mer/targets/mer-target-armv7hl/
grep :$(id -u): /etc/passwd >> etc/passwd
grep :$(id -g): /etc/group >> etc/group

This target could be any suitable rootfs such as a Nemo or PA rootfs and there are some alternate targets presented lower down the page.

[edit] Initialize Target in SB2

To tell SB2 about the target we use sb2-init which gives the target a name - in this case "mer-target-armv7hl".

IMPORTANT : You must change directory to the target rootfs before running sb2-init.

cd /parentroot/srv/mer/targets/mer-target-armv7hl
sb2-init -d -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / mer-target-armv7hl /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc

Notes

  • some messages about "cannot find 'ld'" and "no gcc" are expected.
  • running sb2-init again with the same name will just change the values for that name - make sure each target is named uniquely.

We now need to work around bug #238 (note lack of leading /):

echo -n "armv7hl-meego-linux" > etc/rpm/platform

Note that this may not affect all targets and will need an appropriate value for the target architecture until the bug is resolved.

And prepare the target for installation (all these steps will eventually be handled by a target preparation script or similar):

sb2 -t mer-target-armv7hl -m sdk-install -R rpm --rebuilddb
sb2 -t mer-target-armv7hl -m sdk-install -R zypper ref --force

The target is now ready to be used by sb2.

If zypper fails with "Cant open /var/run/zypp.pid in mode w" you can fix it with:

cd /srv/mer/targets/<target_name>/var
rm run && mkdir run

[edit] Compile the simple C program

Again run:

sb2 -t mer-target-armv7hl gcc ~/src/hello.c -o ~/src/hello

This time:

~/src/hello.c:1:19: fatal error: stdio.h: No such file or directory

This is because the target has no development header files in it.

We need to be at the target root (this is bug #239) and then we can install some basic header files: Note the important use of the "-m sdk-install" and the "-R". The -m tells sb2 to use a mapping mode that permit the updating of the target and -R tells sb2 to run as fake root.

cd /parentroot/srv/mer/targets/mer-target-armv7hl
sb2 -t mer-target-armv7hl -m sdk-install -R zypper in glibc-devel

You'll need to do this for any build requirements of your code.

[edit] SB2 Detailed setup information

The sb2-init options mean:

  -d : make this the default target
  -L : linker options
  -C : compiler options
  -c : which qemu to use
  -m : which mapping to use by default
  -n : don't build libtool
  -N : don't do localisation for the target
  -t : the location of the build tools
  mer-target-armv7hl : The name of the target
  /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc : the cross-compiler to use

[edit] Alternate targets

[edit] Creating an SB2 Target for any (non-x86) Mer OBS package (draft)

osc provides the ability to do a "local build" where it creates a chroot within the SDK suitable for building a package.

When SB2 is enabled on the OBS (as it is in the MeeGo public OBS) then it also creates a suitable SB2 'target'.

So checkout the package from OBS, start a local build, setup the SB2 target:

osc co PROJECT PACKAGE
cd PROJECT/PACKAGE

determine which repository/architecture to build for

osc repos

Then run a build

osc build --chroot-only REPO ARCH

Note the build root from the above command or use this to find it:

osc chroot

Check the directory of the osc chroot and use the ./target/ directory in there for your SB2 target:

 cd CHROOT/target
 sb2-init -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / TARGETNAME /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc

(If you like you could move this to /srv/mer/targets/ before running the cd/sb2-init commands but then osc build wouldn't upgrade it anymore)

At this point you can go to your ~/src/package.git/ directory and run

sb2 -t TARGETNAME make

The advantage of this approach over a full rootfs target are that:

  • it's smaller
  • it uses the osc package cache so can be updated with smaller downloads
  • it works with packages that are changing on the OBS (so can be run against branched projects)
  • it's probably more suitable for working with other people and collaborating via the OBS
  • the rootfs can be upgraded and packages added using osc (especially the -x option)

The disadvantages are

  • it is currently more manual
  • it only installs the development packages that are listed by the spec file as build-dependencies
  • it's not as re-useable across multiple packages

[edit] N950 Nemo Mobile

Nemo/N950 rootfs can be found at: http://releases.nemomobile.org/snapshots/ (choose the armv7hl-n950 images).

To setup cross compiling for N950 (armv7hl) do the following inside the sdk chroot

[edit] Setup target

Extract the Nemo N950 rootfs as a target and set file permissions:

sudo mkdir -p /srv/mer/targets/n950rootfs
cd /srv/mer/targets/n950rootfs
sudo tar xjvf /path/to/nemo-n950-image.tar.bz2
sudo chown -R $USER .

note: if you're doing this as the root user and not with sudo, remember to replace $USER with your regular username.

[edit] Initialize scratchbox2

cd /srv/mer/targets/n950rootfs
sb2-init  -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / nemo-n950 /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc

Note: If you installed the mer-target-armv7hl target earlier, that will be your default target. If you, however, like the nemo-n950 to be your default target, add the -d switch to the command line above.

Notes

  • some messages about "cannot find 'ld'" and "no gcc" are expected.
  • running sb2-init again with the same name will just change the values for that name - make sure each target is named uniquely.

We now need to work around bug #238 (note lack of leading /):

echo -n "armv7hl-meego-linux" > etc/rpm/platform

Note that this may not affect all targets and will need an appropriate value for the target architecture until the bug is resolved.

The compiler should now work but you are still missing libraries to compile against. Install what you need into the n950 rootfs. For example:

sb2 -t nemo-n950 -m sdk-install -R ssu ur
sb2 -t nemo-n950 -m sdk-install -R zypper ref -f
sb2 -t nemo-n950 -m sdk-install -R zypper dup
sb2 -t nemo-n950 -m sdk-install -R zypper install gcc-c++ 

Whenever you see message about dbus connection failed on sdk installs, just do 'i' for ignore. For example:

Installation of openssh-5.6p1-1.1.84 failed:
 (with --nodeps --force) Error: Subprocess failed. Error: RPM failed: Failed to get D-Bus connection: No connection to service manager.

If zypper fails with "Cant open /var/run/zypp.pid in mode w" you can fix it with:

cd /srv/mer/targets/n950rootfs/var
rm run && mkdir run

If the installation fails due to permission errors give your user write permissions to the places the packages are being installed and retry. After this you can compile for example a c hello world by

cd
cat << "EOF" > hello.c
#include <stdio.h>
int main(int argc, char **argv)
{
   printf("Hello\n");
   return 0;
}
EOF

To run a simple compile, tell sb2 what target to use (ie the name used in the sb2-init):

sb2 -t nemo-n950 gcc hello.c -o hello

Verify that the compilation worked

$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped
$ sb2 -t nemo-n950 ./hello 
Hello

More typically you'll use

 sb2 -t nemo-n950 make

[edit] Example of building one of Nemo's RPM packages

Here's an example of building RPM of QmlCalc:

git clone https://github.com/nemomobile/qmlcalc.git
cd qmlcalc/
mb2 -t nemo-n950 build 

[edit] Troubleshooting

If

.../armv7hl-meego-linux-gnueabi/bits/os_defines.h:40:22: fatal error: features.h: No such file or directory

then

sb2 -t mer-target-armv7hl -m sdk-install -Rzypper in glibc-devel

If

/var/tmp/rpm-tmp. .... : line 44: /usr/lib/rpm/meego/find-docs.sh: No such file or directory

then

sb2 -t mer-target-armv7hl -m sdk-install -R zypper in meego-rpm-config

If magic file issues:

error: magic_load failed: File 5.4 supports only version 7 magic files. `/usr/share/misc/magic.mgc' is version 10

then

# Save the target magic.mgc file (just in case) and use the one from the MerSDK
mv /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc.orig
cp /usr/share/misc/magic.mgc /parentroot/srv/mer/targets/nemo-i486-vm-wayland_SB2/usr/share/misc/magic.mgc

[edit] Plasma Active

Plasma Active can run on various devices, such as Nexus 7, the Flying Squirrel (in previous iteration - Vivaldi) and so on.

Note that Vivaldi tablet is already obsolete, and Plasma Active project is shifting to other reference platform.

In the future there might be smaller rootfs releases, targeted specifically to be used with SDK and containing the minimized set of development tools.

[edit] Setup target

Important Note: review potential issues in the mer-target-armv7hl target example. They apply to setting up other targets as well.

Extract the PlasmaActive rootfs as a target and set file permissions (in this example we are taking a Nexus 7 tablet, where PA uses armv7hl build. For other targets and potential armv7l versions, adjust the instructions below accordingly:

target_device='nexus7'
arch='armv7hl'
rootfs='/path/to/plasma-active-nexus7-testing-mer-latest-2012-12-20.tar.bz2'
sudo mkdir -p "/srv/mer/targets/plasmaactive-${target_device}-rootfs"
cd /srv/mer/targets/plasmaactive-${target_device}-rootfs
sudo tar xjvf $rootfs
sudo chown -R $USER .

[edit] Initialize scratchbox2

cd /srv/mer/targets/plasmaactive-${target_device}-rootfs
sb2-init -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / plasmaactive-${target_device} /opt/cross/bin/${arch}-meego-linux-gnueabi-gcc

[edit] Install some tools

sb2 -t plasmaactive-${target_device} -m sdk-install -R zypper refresh
sb2 -t plasmaactive-${target_device} -m sdk-install -R zypper install gcc-c++

[edit] Cross compilation

Create some source: hello.cpp:

#include <iostream>

int main(int argc, char* argv[])
{
   std::cout << "Hello World!\n";
   return 0;
}

Compile it:

 sb2 -t plasmaactive-${target_device} g++ hello.cpp -o hello

Run:

 sb2 -t plasmaactive-${target_device} ./hello
 Hello World!

Check architecture:

 file hello
 hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped

[edit] Additional Notes

[edit] Installation

If your SDK did not have the SB2 tools installed then you can do:

 sudo zypper ar http://releases.merproject.org/releases/latest/builds/i486/cross mer-cross-tools
 sudo zypper ref
 sudo zypper in sdk-sb2-config qemu-usermode mpc cross-armv6l-gcc cross-armv6l-binutils cross-armv7l-gcc cross-armv7l-binutils cross-mipsel-gcc cross-mipsel-binutils cross-armv7hl-gcc cross-armv7hl-binutils

[edit] Directory Mappings

SB2 uses a sophisticated file mapping system to access the right tools and the right source code. The definitions are stored in /usr/share/scratchbox2/modes/sdk-build/fs_rules.lua

The current SDK definitions recognises a few filesystems:

/home
/mer
/maemo
/everything

Additional entries can be made if your source lives elsewhere (eg /media or /data etc).

[edit] Using multiple targets

You can use multiple targets with the SDK. Set up each target as described above.

To perform some action for a specific target add the -t option:
sb2 -t <target> ...
To list all set targets:
sb2-config -l
To set up a default target:
sb2-config -d <target>

[edit] Removing targets

When targets are created the information about target is put to ~/.scratchbox2/ directory, so in order to remove target one can just remove directories from there:

rm -r ~/.scratchbox2/<target_name>
Personal tools