Archive for January, 2006

How to use Berkeley DB on blackfin

1. Download Berkeley DB 4.4.20 from http://dev.sleepycat.com/downloads/releasehistorybdb.html,
untar it into DBDIR/.

2. In DBDIR/build_unix/

$../dist/configure –host=bfin-uclinux –disable-tcl

(modify db_config.h here if you want to do customize features)

$make

We’ll get all the necessary header files and libdb.a in this same folder after make.
3. Test example
In DBDIR/examples_c/getting_started/, run

$ bfin-uclinux-gcc gettingstarted_common.c\
example_database_read.c \
-o example_database_read -L../../build_unix\
-ldb -I../../build_unix -lpthread \
-Wl,-elf2flt

$ bfin-uclinux-gcc gettingstarted_common.c\
example_database_load.c \
-o example_database_load -L../../build_unix\
-ldb -I../../build_unix -lpthread \
-Wl,-elf2flt

Note that DB needs a set of atomic mutex control functions, but Blackfin doesn’t have a simple atomic asm instruction, now we use the mutex functions in uclibc/libpthread. That is the reason for “-lpthread”.

Copy the generated “example_database_read”, “example_database_load” and “inventory.txt”, “vendors.txt” to Blackfin target. Run following to see the result.
$./example_database_load; ./example_database_read

Comments (1)

How is “ctrl-c” handled in kernel…

This picture shows how “control-c” gets into /dev/ttyS0 (that is, /dev/console).
The serial driver simply sends char stream to n_tty driver. And n_tty search for all the control characters.

When a ctrl-c pushed:
n_tty.c:n_tty_receive_break() –> isig(SIGINT,tty) –> kill_pg(SIGINT, tty->pgrp)
signal.c:kill_pg() calls signal(SIGINT,task) to interrupt every task has group number of tty->pgrp.

So, if a process has the same group id with the tty, it can be kill by “ctrl-c” from that tty, no matter it is in background or foreground. In some old shells without job control feature (such as msh in busybox 1.00), if you start a process in background (with an “&”) then list processes with “ps -j”, you’ll find that the “bg” process has the same PGID with tty. In this situation, ctrl-c can kill both you fg and bg processes.

Job control is a feature that most of shells have, such bash, ash, or lash in busybox. It assigns a new group id to a background process. Most implemented in this way:
setpgid(child->pid, newjob->progs[0].pid);
That means set the new background process’s pgid identical to its pid, which make the process leader of a new process group, and will not be kill by ctrl-c. To these shells, “&” means fork/setpgid.

And this topic leads to another interesting topic: How to write a “standard” daemon?
1. Parent must exit after fork().
2. call setsid. Which makes the child leader of a new process group and a new session,
and detached from the TTY.
3. fork() and exit again, so the new “grandson” process is not a session leader and will never
get TTY control again. This step may be unnecessary.
4. chdir(“/”); optional. To avoid possible umount problem.
4. Redirect handle 0,1,2. That is, close and reopen them to /dev/null or some safe files.

Comments (2)

Tiny-Gentoo with Qemu howto

http://gentoo-wiki.com/TinyGentoo
http://www.wplug.org/top/wplug-top018.txt

1. prepare

#mkdir tiny-gentoo
#cd tiny-gentoo
#wget http://gentoo.osuosl.org/experimental/x86/embedded/stages/
stage3-x86-uclibc-2005.0.tar.bz2
#wget http://gentoo.osuosl.org/snapshots/portage-20060102.tar.bz2
#tar xjpf stage*.tar.bz2
#cp -L /etc/resolv.conf etc/resolv.conf
#mkdir -p usr/portage
#tar xjf portage-20060102.tar.bz2 -C usr2. chroot to tiny-gentoo#chroot . /bin/bash
#env-update && source /etc/profile

3. Make a minimal gentoo

#ln -snf /usr/portage/profiles/uclibc/x86/2005.1/ /etc/make.profile
#nano /etc/make.conf
FEATURES=”ccache”
USE=”minimal”
#emerge ccache
#emerge -auDN world
#etc-update
(#emerge vanilla-sources)
#cp /etc/skel/.bash_profile /etc/skel/.bashrc /root/

4. Make the real tiny rootfs

#mkdir /rootfs
#mkdir -p /etc/portage
#echo “sys-apps/baselayout-lite -*” >> /etc/portage/package.keywords
#nano /etc/make.conf
#ROOT=/rootfs emerge -av baselayout-lite uclibc busybox

5. Chroot to the new /rootfs

#chroot /rootfs /bin/ash
#passwd
#addgroup -g 100 users foo
#adduser -h /home/foo -s /bin/ash -G users foo
#exit (–this exit to the last chroot box tiny-gentoo)

6. Modify the fstab file.

#echo “TinyGentoo” > /rootfs/etc/hostname
# echo “/dev/hda / ext3 defaults” >> rootfs/etc/fstab
#chmod 555 /rootfs/proc

7. Emerge the wanted packages into /rootfs

#ROOT=/rootfs emerge -av net-tools udhcp lynx scrollz dropbear screen

8. Now the /rootfs directory now contains your complete system. Clean it and make a tar ball.

# cd /rootfs
# tar -zcf ../rootfs.tgz .
# exit ( — exit to your host linux)

9. Build the disk img file. (write the rootfs to an img file.)

# qemu-img create gentoo.img 64M
# mkfs.ext3 -q gentoo.img
# mount -o loop gentoo.img /mnt/floppy
# tar -zxf rootfs.tgz -C /mnt/floppy
# umount /mnt/floppy

10. Build kernel for Qemu

The Qemu has following devices:

  • i440FX host PCI bridge and PIIX3 PCI to ISA bridge
  • Cirrus CLGD 5446 PCI VGA card or dummy VGA card with Bochs VESA extensions
  • PS/2 mouse and keyboard
  • 2 PCI IDE interfaces with hard disk and CD-ROM support
  • Floppy disk
  • NE2000 PCI network adapters
  • Serial ports
  • Soundblaster 16 card

Just remember to add all the device drivers into kernel, not as modules. And also add ext3 support into the kernel.
Finally we’ll get kernel/arch/i386/boot/bzImage.

11. Boot from Qemu!

# qemu -hda gentoo.img -kernel bzImage -append “root=/dev/hda”

Comments (6)

Kernel maintiain tools — Ketchup

1. http://www.selenic.com/ketchup/ download. As I tested, now only version 0.9.5 works.
http://www.selenic.com/ketchup/wiki/

2. ketchup -l : list all supported kernel trees. ( like 2.6, 2.6-mm, 2.6-rt, 2.6-git)
ketchup -s 2.6:  list the latest version of 2.6 stable tree.

ketchup -G 2.6.15.1 : update your kernel (in current directory) to 2.6.15.1, without pgp verify.

3. commands works in a existing kernel folder:
ketchup -m : show current kernel version (actually from the Makefile)
ketchup 2.6-rt : switch to another tree.
ketchup 2.6-tip : update to the latest release.
ketchup 2.6.11-rc3 : Downgrade to a particular release.
ketchup -s 2.6-mm : show latest version of a particular tree.
ketchup -u 2.6-mm : Find the URL for a given version. (find the bz2 package).

-n –dry-run
don’t download or apply patches
-p –show-previous
output version previous to <arg>

4. We can also use ~/.ketchuprc to maintain a localtree. TBD.
It can be used with quilt . TBD.

Leave a Comment

Quilt Howto

Make a patch fits quilt: 
Use unified diffs (diff -Nurd <old file> <new file>)

Leave a Comment

Get my palm m500 sync to ubuntu!

1. delete /dev/ttyUSB*
2. add one file “/etc/udev/rules.d/10-custom.rules”
BUS=”usb”, SYSFS{product}=”Handspring*”, KERNEL=”ttyUSB*”, NAME{ignore_remove}=”pilot”, MODE=”666″
After these 2 steps, any time I push “Hotsync” in crandle, /dev/ttyUSB0 and ttyUSB1 will be installed. (Remember to add your user to “root” gourp).

3. Set jpilot, gnome-pilot to sync with /dev/pilot.
Enable conduits in Evolution.
Add “pilot sync” applet into gnome panel.

4. The ubuntu kernel 2.6.12 USB driver just fails to install palm device from time to time. Use following instructions to reset the USB driver.

rmmod uhci-hcd
rmmod ehci-hcd
modprobe uhci-hcd
modprobe ehci-hcd

Leave a Comment

A little bit analysis of OE

  Architecture: 
1. $BBPATH variable used by bitbake to find conf/local.conf and conf/bitbake.conf files. (And also defines the $TOPDIR for bitbake? I am not sure). It contains two positions: build/ and openembedded/, both of them have a conf/ folder.

 2. conf/bitbake.conf: defines many variables used by bitbake and openembedded. Normally doesn’t need to be modified. It also includes some other conf files, such as
conf/local.conf,        ————actually it is build/conf/local.conf.  Needs to be modified.
conf/build/${BUILD_SYS}.conf     ————–doesn’t exists. Seems not important.
conf/target/${TARGET_SYS}.conf   ———– doesn’t exists. Seems not important?
conf/machine/${MACHINE}.conf   —– in openembedded/conf/machine, ${MACHINE} defined in local.conf.
conf/distro/${DISTRO}.conf   ——– in openembedded/conf/machine, ${DISTRO} defined in local.conf.

 3. Install:
  required software: 

apt-get install python python-dev python-psyco ccache patch m4 sed bison make \
wget bzip2 cvs gawk libc6-dev g++ subversion sharutils coreutils \
docbook openjade quilt libmpfr-dev libpcre3-dev unzip subversion

  svn(subversion) -> bitbake
svn co svn://svn.berlios.de/bitbake/trunk/bitbake
cd bitbake
$ ./setup.py install –prefix=/usr/local –install-data=/usr/local/share

Build bitbake documents:
$ cd /stuff/bitbake
$ make -C doc/manual # optional, takes some time
$ # make sure that you have configured sudo properly
$ sudo ./setup.py install
$ make -C doc/manual clean #optional
$ sudo mv /usr/doc/bitbake-1.0 /usr/local/share/doc # optional
$ sudo rmdir /usr/doc # optional. Might fail if there are other documents installed here

Install Monotone
apt-get install monotone

Monotone -> OpenEmbedded
monotone --db=/stuff/oe.db pull monotone.vanille.de "org.openembedded.{dev,dreambox}"

monotone –db=/stuff/oe.db checkout –branch=org.openembedded.dev

monotone --db=/stuff/oe.db pull monotone.vanille.de org.openembedded.{dev,dreambox} 
(cd /stuff/org.openembedded.dev; monotone update)
(cd /stuff/org.openembedded.dreambox; monotone update)

Comments (1)