Customizing the Openmoko Distribution
From Openmoko
Contents |
What's the goal?
The goal of this page is to teach you how to take an application that you've coded (or the sample app) and properly get it included in your rootfs. This article is a bit of an aggregate page, it's going to take information from MokoMakefile Using_a_local_overlay Building_a_hello_world_application and Create_a_package_from_existing_sources. So as you can see the goal is for it to be a very thorough introduction, and will take you from "Idea to Inclusion" of your application.
Setting Up the OpenMoko Environment
This part of the tutorial is going to be pretty basic. I absolutely love MokoMakefile, it's fantastic, the creator has done and continues to do a fantastic job with this. I see absolutely no reason not to use it. However I cannot for the life of me understand why they create their working directory in /home/moko, the home directory is for home directories for users of your system, not for a development directory. I put my OpenMoko development directory in /home/bryce/mokodev/ and that works great for me, and also makes more sense so that multiple users on my machine could develop with no attempt to overlap.
To get your environment setup please get it setup according to MokoMakefile however if you do have the build environment setup manually and you're sure you know what you're doing then feel free to go forward with this.
Setting Up a Local Overlay
If you're at the point for setting up a local overlay this means a couple things. First: You've had a brilliant idea for an application that you just need to have on the OpenMoko platform. Second: You realize that this killer app of yours needs to be done properly and you're not going to do anything silly like include it in the actual tree for the OpenMoko distro because it would probably end up just getting overwritten eventually, or you just realize taht it's bad practice!
Thank you to User:CesarB for this part of the wiki.
To create a local overlay:
- Create a "local" directory and its subdirectories
mkdir local local/conf local/classes local/packages
- Copy
site.conf
from the openmoko tree tolocal/conf
cp oe/conf/site.conf local/conf/site.conf
- Edit the site.conf you copied to add the new tree as a source for bitbake recipes.
Change the current BBFILES
to look like this:
BBFILES := "${OMDIR}/openembedded/packages/*/*.bb ${OMDIR}/oe/packages/*/*.bb ${OMDIR}/local/packages/*/*.bb"
Change your BBFILE_COLLECTIONS
line to look like this:
BBFILE_COLLECTIONS = "upstream local overlay"
Add this line:
BBFILE_PATTERN_overlay = "^${OMDIR}/local/"
Add this line:
BBFILE_PRIORITY_overlay = "20"
The BBFILE_PRIORITY
should be greater than all the other BBFILE_PRIORITY
variables on the same file.
- Change your
BBPATH
environment variable to add the new tree before the two others for MokoMakefile, the variable is on thesetup-env
file.
export BBPATH="${OMDIR}/build:${OMDIR}/local:${OMDIR}/oe:${OMDIR}/openembedded"
Using Your New Local Overlay
Changing files in conf/
To change a file in conf/, just copy the file to the overlay tree (preserving the directory structure) and edit it.
Changing files in classes/
To change a file in classes/, just copy the file to the overlay tree and edit it.
Changing packages
Changing a package's recipe is a bit more complex. You have to copy over (or symlink) not only the .bb file for the package, but also all the files it includes with require
, and the FILESDIR
directories (all directories referred to by FILESDIR
, usually named either package-version or files
). If you forget one of them, the build will give an error (either when parsing the recipe in the case of require
, or when trying to build in the case of the FILESDIR
directories).
Adding a new package
You can add a new package (or a recipe for a new version of a package) to the overlay tree simply by creating it on the overlay tree.
Your First Application
I know that I said I'd have a GDK application in here, however, I'd really like to get this whole course done first and have you guys starting to code instead of just looking at what I've written!
This will be a very simple CLI hello world.
Before We Code
Like a good coder you want to make sure that you're not just doing things, but that you're doing them the right way!
Now change directories into your local/packages
directory.The following commands expect you'll be in that directory so don't change unless you know what you're doing!
You'll want to make a directory with the name of your application, and a subdirectory called files.
mkdir myhelloworld myhelloworld/files
Now you'll want to create two files in the files
directory
touch myhelloworld/files/READEME.txt myhelloworld/files/myhelloworld.c
And finally you'll want to create a bitbake file.
touch myhelloworld/myhelloworld.bb
Alrighty now all your necessary files are created so lets go over this real quick.
$HOME +- $OMDIR (contains the official openmoko tree) | +- local/ | +- packages/ | +- myhelloworld/ | +- myhelloworld.bb | +- files/ | +- myhelloworld.c | +- README.txt
That should be your structure, if it's not you should go and fix it up.
Filling the Files
So you've got your sample files all laid out now it's time to make them actually do something.
myhelloworld.c
#include <stdio.h> int main(int argc, char** argv) { printf("Ello Poppet!\n"); return 0; }
README.txt
This is a command line application. It prints a simple Hello World! To stdout.
myhelloworld.bb
DESCRIPTION = "A killer hello world applicaiton" AUTHOR = "Bryce Leo" HOMEPAGE = "" SECTION = "console/applications" PRIORITY = "optional" LICENSE = "MIT" #DEPENDS = "" #RDEPENDS = "" #RRECOMMENDS = "" #RCONFLICTS = "" #SRCDATE = "20070729" #PV = "0.1" #PR = "r0" SRC_URI = "file://myhelloworld.c \ file://README.txt " S = "${WORKDIR}/myhelloworld/" do_compile() { ${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/myhelloworld.c -o myhelloworld } do_install() { install -m 0755 -d ${D}${bindir} ${D}${docdir}/myhelloworld install -m 0755 ${S}/myhelloworld ${D}${bindir} install -m 0644 ${WORKDIR}/README.txt ${D}${docdir}/myhelloworld }
Your First Compilation
This is where the MokoMakefile comes in very very handy. Change to your ${OMDIR} directory, You'll now it by the fact that it is where Makefile
resides.
make build-package-myhelloworld
This should all come back and not return any error messages, The output should end in something similar to
NOTE: package myhelloworld-1.0: completed NOTE: build 200707291926: completed Build statistics: Attempted builds: 1 <pre> Now that no errors were thrown we are happily done! == Adding Your App to the Image ==