[okl4-developer] Using an iguana server from wombat HowTo

Remy Gottschalk rgottschalk at linagora.com
Tue Apr 1 03:31:41 EST 2008


Hi again

This howto directly follows the previous one (HelloWorld Iguana server
HowTo) and explain how interacting with the helloworld server from wombat.
The next will probably deal with more elaborate communication and shared
memory.


----------------------------
Using the server from Wombat
----------------------------

Now we have a functional hello server we will use it from the
para-virtualized Linux. We will do so using a new entry in /proc.

 1 Library
 ---------

The first thing to do is to link the kernel to our client library
libhello.a. To achieve this we simply add a -lhello flag to the kernel
Makefile.

$ cat linux/kernel-2.6.11-v2/arch/l4/Makefile
[...]
libs-y +=  -lvtimer -lvserial -ll4e -lll -liguana -ll4 -lgcc -lmutex
-lcircular_buffer -lnaming -lhello
[...]

 2 A new module
 --------------

We will now create a new kernel module to allow use interacting with the
server using a /proc entry.
We will work directly in a hello folder in the kernel root in order to
make things fast and easy.

$ mkdir linux/kernel-2.6.11-v2/hello
$ touch linux/kernel-2.6.11-v2/hello/Makefile
$ touch linux/kernel-2.6.11-v2/hello/my_l4_hello.c
$ ls  linux/kernel-2.6.11-v2/hello
Makefile  my_l4_hello.c

We need to modify the global Makefile :
$ cat linux/kernel-2.6.11-v2/Makefile
[...]
core-y		:= usr/ hello/
[...]
and create a new one for our source file.
$ cat linux/kernel-2.6.11-v2/hello/Makefile
obj-y += my_l4_hello.o

Now here is the code for our module :

$ cat linux/kernel-2.6.11-v2/hello/my_l4_hello.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h>

#include <hello/hello.h>

/* Defines the license for this LKM */
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("L4 Hello Wrapper");

static struct proc_dir_entry *proc_entry;

int hello_read( char *page, char **start, off_t off,
		  int count, int *eof, void *data )
{
  say_hello();
  return 0;
}

int my_module_init( void )
{
  int ret = 0;

  proc_entry = create_proc_entry( "hello", 0644, NULL );
  if (proc_entry == NULL)
    {
      ret = -ENOMEM;
      printk(KERN_INFO "fortune: Couldn't create proc entry\n");
    }
  else
    {
      proc_entry->read_proc = hello_read;
      proc_entry->write_proc = hello_write;
      proc_entry->owner = THIS_MODULE;
      printk(KERN_INFO "<===== Hello Module Started =====>\n");
    }
  hello_init();
  return ret;
}

void my_module_cleanup( void )
{
  remove_proc_entry("hello", &proc_root);
  printk(KERN_INFO "<===== Hello Module Unloaded =====>\n");
  return;
}

module_init( my_module_init );
module_exit( my_module_cleanup );

This module creates a new entry in /proc (/proc/hello) and calls say_hello
on each reading access.

We can see that using our server is pretty simple, three line are
concerned :
#include <hello/hello.h>
To include user library headers
hello_init();
In order to initiate the communication.
say_hello();
To interact with our server.

 3 Final test
 ------------

We compile and test :

$ ./tools/build.py machine=ia32_pc99 project=iguana wombat=True
toolprefix=i686-unknown-linux-gnu- simulate
[...]
<===== Hello Module Started =====>
[...]
<===== Hello Server Started =====>
[...]
Please press Enter to activate this console.

BusyBox v1.00 (2008.03.28-14:47+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

/ #  cat /proc/hello
I say hello
/ #






-- 
Remy Gottschalk - rgottschalk at linagora.com
Ingénieur informatique embarquée
Groupe LINAGORA - http://www.linagora.com
Tél.: +33(0)1 58 18 68 28 - Fax : +33(0)1 58 18 68 29





More information about the Developer mailing list