The helloworld-image.bb recipe that comes with OE will build an image with a statically linked “Hello, World!” app which will replace ‘init’ on boot, print “Hello, World!” and loop endlessly. This is useful to show how to get your own app running in place of ‘init’. But I was looking to add a “Hello, World!” app to the console image so I can carry forward all the functionality of the console image as well.
These steps are done after work done in previous posts, here and here.
I started by duplicating an existing image recipe, altboot-console-image.bb:
$ cd ${OETREE}/openembedded/recipes/images
$ cat altboot-console-image.bb | sed 's/altboot/helloworld/g' - > helloworld-console-image.bb
$ cat helloworld-console-image.bb
require console-image.bb
ANGSTROM_EXTRA_INSTALL += " helloworld "
export IMAGE_BASENAME = "helloworld-console-image"
What this recipes does different than the included helloworld-image.bb recipe is that it builds upon the standard console image (require console-image.bb) and adds the helloworld package to those being installed in the image (ANGSTROM_EXTRA_INSTALL += ” helloworld “).
I then built the image:
$ cd ${OETREE}
$ source source-me.txt
$ bitbake helloworld-console-image
Once the image was built, I followed the steps for setting up the SD card, with the only real difference being the use of /dev/sdb vs. /dev/sdc (since that’s where the card auto-mounted) and I wound up formatting and labeling (as root) like this:
$ /sbin/mkfs.msdos -F 32 /dev/sdb1 -n LABEL1
$ /sbin/mkfs.ext3 -L LABEL2 /dev/sdb2
(Unplug and replug SD card reader.)
After verifying everything the existence of the images in ‘${OETREE}/angstrom-dev/deploy/glibc/images/’ I populated the SD card as follows:
$ cd ${OETREE}/angstrom-dev/deploy/glibc/images/
$ cp MLO-beagleboard /media/LABEL1/MLO
$ cp u-boot-beagleboard.bin /media/LABEL1/u-boot.bin
$ cp uImage-beagleboard.bin /media/LABEL1/uImage
$ cp Angstrom-helloworld-console-image-glibc-ipk-2009.X-test-20090501-beagleboard.rootfs.tar.bz2 /media/LABEL2
$ cd /media/LABEL2
$ tar -jxvf Angstrom-helloworld-console-image-glibc-ipk-2009.X-test-20090501-beagleboard.rootfs.tar.bz2
$ rm Angstrom-helloworld-console-image-glibc-ipk-2009.X-test-20090501-beagleboard.rootfs.tar.bz2
$ sync
$ cd
$ umount /media/LABEL*
This sequence was based on the steps found here for populating the SD card but I’ve used full file names as found in the images folder not generic names like ‘MLO’ and ‘uImage’.
When booting the BeagleBoard off this card Angstrom comes up to the login prompt:
.-------.
| | .-.
| | |-----.-----.-----.| | .----..-----.-----.
| | | __ | ---'| '--.| .-'| | |
| | | | | |--- || --'| | | ' | | | |
'---'---'--'--'--. |-----''----''--' '-----'-'-'-'
-' |
'---'
The Angstrom Distribution beagleboard ttyS2
Angstrom 2009.X-test-20090428 beagleboard ttyS2
beagleboard login: [root]
root@beagleboard:~# helloworld
Hello world![Ctrl-C]
.
root@beagleboard:~# ls -al /usr/bin/helloworld
-rwxr-xr-x 1 root root 445632 May 1 2009 /usr/bin/helloworld
root@beagleboard:~#
We still haven’t connected all the dots. This doesn’t include the ‘myhelloworld’ app we build in a previous post in new console image build, but the ‘helloworld’ app as distributed with OE, which is rather simplistic as the source file is generated via a ‘printf’ in ‘do_fetch()’ function of the recipe file, helloworld/helloworld_1.0.0.bb:
$ cd ${OETREE}/openembedded/recipes
$ cat helloworld/helloworld_1.0.0.bb
DESCRIPTION = "Minimal statically compiled Hello world!"
LICENSE = "GPL"
PR = "r0"
S = "${WORKDIR}/${P}"
do_fetch () {
mkdir -p ${WORKDIR}/${P}
cd ${WORKDIR}/${P}
printf "#include nint main(void)n{ntprintf("Hello world!\n");twhile(1);ntreturn 0;n}n" >helloworld.c
}
do_compile () {
${CC} -o helloworld helloworld.c -static
}
do_install () {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}/
# /bin/init is on purpose, it is tried after /sbin/init and /etc/init
# so if a sysvinit is installed, it will be used instead of helloworld
install -d ${D}${base_bindir}
ln -sf ${bindir}/helloworld ${D}${base_bindir}/init
}
$
The last step to be accomplished is to create a local overlay structure for building our own image so we do not have to mess with the base install. Instructions for doing that can be found here. I’ll keep you posted on my progress.