Archive for September, 2004

Writing a Linux Kernel Module under 2.6

Wednesday, September 8th, 2004

Everytime I want to try something inside the kernel, I patch it’s code and recompile it whole, but this is not the nicest way when implementing new functionalities. The best way to do so is to implement it as a kernel module (LKM). The usual skeleton for a 2.6 kernel module is as follows:

hello.c:

#include <linux/module.h> // Needed by all modules
#include <linux/kernel.h> // Needed for KERN_ALERT
#include <linux/init.h> // Needed for the macros

static int hello_init(void)
{
        printk(KERN_ALERT “Hello, world \n”);
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT “Goodbye, world\n”);
}

module_init(hello_init);
module_exit(hello_exit);

Makefile:

ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
            $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif

References:
Questions about loading modules.
Writing your own (2.6 kernel) device driver 101.
The Linux Kernel Module Programming Guide (for 2.4 Kernels).

New Layout

Saturday, September 4th, 2004

I’ve just changed a little bit the layout of the Blog, If anyone experiences any difficulties while browsing, please leave a comment

Thanks!

PowerMac G4 12″ Backlight

Saturday, September 4th, 2004

The default linux 2.6 kernel does not support the backlight control of my notebook. The problem is that NVidia has not released any ppc drivers for this card and I have to use the Open Firmware video framebuffer (offb) from the kernel, which is like VESA extensions in a PC.

So the way to have support for it is to patch the offb with the NVidia specific code for the backlight control, this is not a nice way to do it, as the offb is meant to be a general driver for all OF devices, but this was the only way I found.

The patch can be obtained from any of these sources. To use it just do like normal, in the kernel tree do a patch -p1 < 02_nv_backlight.patch

The place from where I obtained the patch
Backup of the previous link

Laptop Mode

Friday, September 3rd, 2004

Since version 2.6.6 of the linux kernel there has been the Laptop mode support, however, to use it some userland tools need to be installed. Laptop mode delays write opperations, this way the HD can sleep.

I’ve just installed it on my new laptop ( mac Powerbook G4 12″ ) and seems to work great, to install it I’ve just made a crapy ebuild, I won’t submit it to gentoo bugs because it is not neat and onlys work on PPC, to make it work under any other architecture the script on_ac_power should be replaced by a generic one, I’ve been to lazy to do it, this scripts returns 0 on AC and 1 on Battery.

The ebuild I made
Bulma Article About Laptop Mode
Laptop Mode Tools Homepage

Me

Thursday, September 2nd, 2004

I’ll do my posts with this user, this is just a test post…