Meego Wiki
Views

Developing With The Aava

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
(Resizing an Aava Image to use your entire SD card)
(merge with setting up aava)
 
(2 intermediate revisions not shown)
Line 1: Line 1:
 +
{{Merge|SDK/Docs/1.1/Setting up Aava}}
[[Category:devguide]]
[[Category:devguide]]
These are some of the notes that we keep and use to make our development easier at Intel.  Feel free to edit/modify/correct as needed.
These are some of the notes that we keep and use to make our development easier at Intel.  Feel free to edit/modify/correct as needed.
Line 134: Line 135:
First, make the "drive" larger.  Below we grow it to 4 G (4096 * 1 M) by seeking 4095 M into the file, and writing 1 M of zeros.
First, make the "drive" larger.  Below we grow it to 4 G (4096 * 1 M) by seeking 4095 M into the file, and writing 1 M of zeros.
  dd if=/dev/zero of=${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin bs=1M seek=4095 count=1
  dd if=/dev/zero of=${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin bs=1M seek=4095 count=1
 +
 +
'''NOTE:'''The dd command resizing the image file to your target sd card assumes that you have an sdcard with no bad sectors. It is better to subtract 128 from the seek argument. Otherwise if your sdcard has bad sectors it will complain that there is no more space on disk. Noel Paz
Now, use parted on the file to grow the partition to the full file size:
Now, use parted on the file to grow the partition to the full file size:
Line 139: Line 142:
  OFFSET=${VALUE[1]/B}
  OFFSET=${VALUE[1]/B}
  echo -e "rm 1\nmkpart primary ext3 ${OFFSET}b -1\nq" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin
  echo -e "rm 1\nmkpart primary ext3 ${OFFSET}b -1\nq" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin
 +
 +
'''NOTE:'''  While the above commands may sometimes work, it is best to run parted interactively.  The first line of commands is to see the starting byte of the partition. Change the unit to b then print the partition table and get the starting byte which is usually 512. The second line of commands removes the existing partition and the creates another one that says start at the beginning offset from the first command and end at the end or -1. The problem is that parted may complain that the bytes are not aligned for best performance and you need to say ignore. The input to parted doesn't account for that and what happens is that the mkpart command will not be executed leaving you with an image that has no partition at all. Noel Paz
Finally, mount the partition and resize it:
Finally, mount the partition and resize it:
Line 166: Line 171:
The easiest way to build a new kernel for the Aava is to mic-chroot into the filesystem from your development machine using the steps above.  For a more detailed process on general development for MeeGo, see [http://wiki.meego.com/Developing_in_a_Meego_Environment this guide].  If you want the "quick steps", follow this guide.
The easiest way to build a new kernel for the Aava is to mic-chroot into the filesystem from your development machine using the steps above.  For a more detailed process on general development for MeeGo, see [http://wiki.meego.com/Developing_in_a_Meego_Environment this guide].  If you want the "quick steps", follow this guide.
-
The steps below are all to be performed within the mic-chroot'd environment, assuming you've installed all of the development tools and libraries listed above (including yum-utils).
+
The steps below are to be performed within the meego-sdk-chroot'd environment.
-
 
+
-
'''NOTE:''' Building the kernel image requires a much larger filesystem than the default 2 G image.  You will need to resize your image to perform the following.  You can see the steps above to perform the image resize.
+
-
The Aava system uses the 'kernel-mrst' packageTo build a new kernel and modules, you need all the build dependencies installed into the OS:
+
'''NOTE:''' Building the kernel image requires a larger filesystem than the default 2 G imageYou will need to resize your image to perform the following. You can see the steps above to perform the image resize.
-
  sudo yum-builddep -y kernel-mrst
+
-
sudo yum -y install rpm-build
+
-
Now, you are going to do some development... so switch to the 'meego' user:
+
Switch to the 'meego' user:
  su - meego
  su - meego
And now kick-start your development by downloading and installing the source for the kernel RPM.
And now kick-start your development by downloading and installing the source for the kernel RPM.
 +
'''NOTE''' You may need to enable the source repository in /etc/zypp/repos.d/core.repo.  Once enabled, you can run the following:
  cd ~
  cd ~
-
  yumdownloader --source kernel-mrst
+
  sudo zypper si kernel-mrst
 +
sudo zypper install rpm-build
  mkdir -p rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}
  mkdir -p rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}
  cd rpmbuild/SOURCES
  cd rpmbuild/SOURCES

Latest revision as of 13:36, 7 January 2011

Wmerge2.png
It has been suggested that this page or section should be merged with "SDK/Docs/1.1/Setting up Aava". If you disagree, please remove tag and explain why on edit summary.

These are some of the notes that we keep and use to make our development easier at Intel. Feel free to edit/modify/correct as needed.

Contents

Downloading the Image

You can find which build image you may want by navigating to the MeeGo Build Download page. The build image is consistently named with a sequential magic build number stamped in the middle.

For example, in meego-handset-ia32-aava-mtf-1.0.80.13.20100803.2-mrstnand.tar.bz2, 1.0.80.13.20100803.2 is the build number. To simplify the commands later, we export that value, and the base image name, to two environment variables. We are doing some wget/sed trickery to automatically grab the most recent image produced. You can hardcode to a specific version by changing STAMP to point to a specific version.

export IMAGE=meego-handset-ia32-aava-mtf
export STAMP=$(wget -qO - http://repo.meego.com/MeeGo/builds/trunk/ | sed -ne 's,^.*<a href="\(1\.0\.80\.[^/]*\).*$,\1,p' | tail -n 1)
echo "Found stamp: ${STAMP}"

You can then perform the following:

cd
wget http://repo.meego.com/MeeGo/builds/trunk/${STAMP}/handset/images/${IMAGE}/${IMAGE}-${STAMP}-mrstnand.tar.bz2
tar xvf ${IMAGE}-${STAMP}-mrstnand.tar.bz2

The above will create a directory called ${IMAGE}-${STAMP}-mrstnand which contains the filesystem that will eventually end up on the SD card.

Mounting/Chrooting

Its easiest to work with the image file system on a development system, and then write to the SD card.

Due to how some of the images are created, the start sector is non-deterministic and must be calculated for each image created.

cd
VALUE=($(echo -ne "u b\np\nq\n" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin | grep ext3\$))
OFFSET=${VALUE[1]/B}

NOTE: The double parenthesis syntax above is correct above for bash to declare VALUE as an array. If the syntax doesn't work in your shell, please verify all steps continue to function correctly when copy/pasted to a terminal before changing.

The following snippet will mount the image to the aava-image directory, unmounting that directory if it already exists and is mounted, or creating it if it doesn't yet exist.

[ ! -e aava-image ] && mkdir aava-image || { mount | grep -q aava-image && sudo umount aava-image ; }
sudo mount -o loop,offset=${OFFSET} ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin aava-image

You will now have the Aava image mounted on your local filesystem under the directory aava-image.

sudo mic-chroot aava-image

At this point, you are now chroot'd into the MeeGo image, and you can install / modify the image as you want.

NOTE: Make sure you exit the chroot environment before you try and rsync or dd the updated image to your SD card. Failure to do so may result in an incomplete transfer occurring and an unusable MeeGo OS image.

Install Some Development Tools

NOTE: If yum doesn't exist (some images had zypper installed instead of yum), then you first need to install yum:

zypper install yum

You can then use yum to install new packages:

yum install rsync nano perf openssh-server screen gdb abrt{,-plugin-{logger,ccpp}} yum-utils strace git patch wget xorg-x11-utils-xinput connman-test

NOTE: The default image size might not be large enough to install all of the above. If this is the case, see Resizing_an Aava Image to use your entire SD card.

If you are going to be compiling applications on this image, you'll need developer libraries for many components. An easy way to do that is use yum-builddep (installed as part of yum-utils above) and to install the build dependencies for one of the reference applications, for example meego-handset-sms

yum-builddep meego-handset-sms

You also need build tools (like gcc):

yum groupinstall Development\ Tools

Add the Ability to 'screen' in

Once booted, if you ssh into the MeeGo system, the ssh'd user won't have access to the DBus session, or various environment variables configured within the X environment. To work around this, you can launch a screen session from within X.

Install an application launcher that kicks off a screen session:

cat << EOF > /usr/share/applications/screen.desktop
[Desktop Entry]
Name=Screen
Exec=/usr/bin/screen -dmS meego
Icon=moblin-xterm
Type=Application
EOF

To leverage the above, once you have booted the SD image on a MeeGo device, you will see an application called 'Screen'. You can launch that application, and then ssh into the device and run:

screen -dr

to attach to the screen session. From there, you can then run, under the MeeGo user session, MeeGo applications, which require access to the display, and DBus.

Finish Up

Don't forget to exit mic-chroot!

 exit

Transfer to Your SD Card

dd or rsync, as appropriate. If you haven't transferred the image to your SD card previously, you will need to dd the entire image to the SD card. If you have already dd the image and are now just installing an update, you can use rsync to transfer only those files that have changed -- which can be MUCH faster.

Syncing the full image to the SD card

The first time you use an SD card or a new image, you need to install the entire image to the SD card. You can use the dd command for this.

NOTE: The following assumes sdb is your SD card. See Finding your SD card for information on finding the correct device for your SD card.

You want to perform the following on the device itself, not to any of the partitions on it:

export DEVICE=sdb
sudo dd if=${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin of=/dev/${DEVICE} bs=10M

The above will take a while. Go get coffee. Once it has completed, you can eject the SD card and boot your Aava device to the new image.

Syncing an UPDATE to the SD card

You don't have to always start with the fresh image. You can remount the file system environment and mic-chroot back into it to perform additional updates:

VALUE=($(echo -ne "u b\np\nq\n" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin | grep ext3\$))
OFFSET=${VALUE[1]/B}
mount -o loop,offset=${OFFSET} ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin aava-image
mic-chroot aava
yum update

When you are done, you MUST exit the mic-chroot environment. If you don't, your source filesystem will be mixed with host files when transferring to the SD card.

exit

Just exit -- DO NOT unmount aava-image.

Depending on your host operating system, your SD card may already be mounted. If so, you can skip the SD mounting steps below and replace avaa-sd with the path that your distribution mounted your SD card (typically someplace in /media):

mkdir aava-sd
mount /dev/sdb1 aava-sd

NOTE: Replace sdb1 with the appropriate device ID on your system for the SD card. You want to mount the first partition and not the device itself.

And now we can rsync to push file system changes to the SD card:

sudo rsync -avprl aava-image/ aava-sd/

If you want a more aggressive sync, that attempts to make the SD card provide a "purer" image, you can use the following rsync:

sudo rsync -avprl --delete aava-image/ aava-sd/

Once the above has completed, unmount both filesystems:

unmount aava-{image,sd}

You can now eject the SD card and boot on your Aava system.

Finding your SD card

You can frequently run something like the following to find your SD card device.

Insert the SD card, wait a few seconds, and then run:

dmesg | grep -A 1 "Assuming drive cache"

You will see something like:

sd 19:0:0:0: [sdb] Assuming drive cache: write through
 sdb: sdb1

In the above, 'sdb' is the drive you want.

Resizing an Aava Image to use your entire SD card

<WARNING>

The following was last tested on August 13, 2010 using the 1.0.80.14.20100810.1 image.

If it has been a while since that date and now, these steps may have bit-rotted and be broken. Use at your own risk. If you use it and it works (or you have to try something different), please update the wiki accordingly.

You have been warned.

</WARNING>

The MeeGo images for handset default to ~1.5 G. If you have a large SD card (4 G, 8 G, etc.), you can't leverage that space by default. To do that, you can perform the following steps.

NOTE: Before beginning, make sure the image is not mounted. Then proceed.

First, make the "drive" larger. Below we grow it to 4 G (4096 * 1 M) by seeking 4095 M into the file, and writing 1 M of zeros.

dd if=/dev/zero of=${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin bs=1M seek=4095 count=1

NOTE:The dd command resizing the image file to your target sd card assumes that you have an sdcard with no bad sectors. It is better to subtract 128 from the seek argument. Otherwise if your sdcard has bad sectors it will complain that there is no more space on disk. Noel Paz

Now, use parted on the file to grow the partition to the full file size:

VALUE=($(echo -ne "u b\np\nq\n" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin | grep ext3\$))
OFFSET=${VALUE[1]/B}
echo -e "rm 1\nmkpart primary ext3 ${OFFSET}b -1\nq" | parted ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin

NOTE: While the above commands may sometimes work, it is best to run parted interactively. The first line of commands is to see the starting byte of the partition. Change the unit to b then print the partition table and get the starting byte which is usually 512. The second line of commands removes the existing partition and the creates another one that says start at the beginning offset from the first command and end at the end or -1. The problem is that parted may complain that the bytes are not aligned for best performance and you need to say ignore. The input to parted doesn't account for that and what happens is that the mkpart command will not be executed leaving you with an image that has no partition at all. Noel Paz

Finally, mount the partition and resize it:

sudo mount -o loop,offset=${OFFSET} ${IMAGE}-${STAMP}-mrstnand/${IMAGE}-${STAMP}-sda.bin aava-image
sudo resize2fs $(mount | sed -ne 's,^\([^ ]*\) .*aava-image.*$,\1,p')

NOTE: The last command just finds the loop back device that was used to mount the file to the aava-image directory

NOTE: if the image is btrfs file system (as of 1.1 it usually is), resize2fs won't work. You need to use the btrfs commands This is the resize method for btrfs file systems:

sudo btrfs filesystem resize max aava-image/

Then check it:

sudo btrfs filesystem show 

You should see something like this:

Label: none  uuid: 744839c8-5dba-45b1-bd8f-0d37a6117b73
Total devices 1 FS bytes used 978.98MB
devid    1 size 8.00GB used 1.92GB path /dev/loop0

.

You can now mic-chroot into the image:

sudo mic-chroot aava-image

Verify you have more space:

df

Building a new kernel

The easiest way to build a new kernel for the Aava is to mic-chroot into the filesystem from your development machine using the steps above. For a more detailed process on general development for MeeGo, see this guide. If you want the "quick steps", follow this guide.

The steps below are to be performed within the meego-sdk-chroot'd environment.

NOTE: Building the kernel image requires a larger filesystem than the default 2 G image. You will need to resize your image to perform the following. You can see the steps above to perform the image resize.

Switch to the 'meego' user:

su - meego

And now kick-start your development by downloading and installing the source for the kernel RPM. NOTE You may need to enable the source repository in /etc/zypp/repos.d/core.repo. Once enabled, you can run the following:

cd ~
sudo zypper si kernel-mrst
sudo zypper install rpm-build
mkdir -p rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}
cd rpmbuild/SOURCES
rpm2cpio ../../kernel-mrst-*.src.rpm | cpio -idmv --no-absolute-filenames
mv kernel-mrst.spec ../SPECS/
rpmbuild -ba ~/rpmbuild/SPECS/kernel-mrst.spec

Magnificent. You now have the MeeGo version of the kernel sources unpacked, with all of its patches applied. Now you want to modify it. Unfortunately, every time you re-build the full RPM, it is going to nuke your BUILD directory. So you need to move the BUILD directory out, and ideally revision it using GIT so that you can easily track and develop your changes:

mv ~/rpmbuild/BUILD/kernel-mrst-2.6.*/linux-2.6.* ~/kernel-mrst
cd kernel-mrst
git init
git add *
git commit -a -m 'Initial kernel version'

You can now make your changes. When you are happy, you can test your changes:

git commit -a -m 'My tweaks'
git diff HEAD^ > ~/rpmbuild/SOURCES/linux-mypatch.patch

You then need to add 'linux-mypatch.patch' to the spec file so that it will add your patch to the build. Once that is done, you can build the full RPM:

rpmbuild -ba ~/rpmbuild/SPECS/kernel-mrst.spec

The resulting RPM (if the build succeeds) will be in ~/rpmbuild/RPMS/i386. You can install this new RPM via:

sudo rpm -e kernel-mrst
sudo rpm -i ~/rpmbuild/RPMS/i386/kernel-mrst*rpm
Personal tools