Embedded Freaks..

February 3, 2009

Hello World Module for TS-7260

Filed under: ARM9, linux-device-driver — Tags: , — kunilkuda @ 12:14 pm

Actually this post is based on Linux Device Driver 3rd book (you can buy its hardcopy here, or view its softcopy here).  I only port it into TS-7260 platform.

The hello module consist of hello.c and the Makefile. Here’s the hello.c file:

 * The hello module from Ch#2 of Linux Device Driver 3rd Ed

static int __init hello_init(void) {
  printk(KERN_ALERT "Hello world\n");
  return 0;

static void __exit hello_exit(void) {
  printk(KERN_ALERT "Goodbye\n");


MODULE_DESCRIPTION("Hello world module from LDD3 book Ch2");

The Makefile is a bit complex, but the explanation is within the book.


# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
  obj-m := $(MODULE_NAME).o

# Otherwise we were called directly from the command
# line; invoke the kernel build system.

  KERNELDIR ?= /lib/modules/$(shell uname -r)/build
  PWD := $(shell pwd)

# kunil: The whitespace in front of '$(MAKE)' line should be tab
# (not spaces). Otherwise, the GNU make will not be able to run
# this Makefile
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

	rm -rf *.o *.ko *.mod.c .*.cmd .tmp_versions Module.markers modules.order Module.symvers

To cross compile the module, the command is:


Just replace the $KERNEL_HEADER_DIR with your kernel header’s directory, and $PREFIX with cross compiler’s prefix.

And now it’s time for testing. To install the module, just copy “hello.ko” file into your board’s root fs. To run it, issue:

root@ts7800:ts_hello_modules# insmod hello.ko

To unload it, issue:

root@ts7800:ts_hello_modules# rmmod hello

Have fun !

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: