Tux
Communication
Mailing lists
Documentation
User Manual
Target board info.
Target chip info.
Support
Linux support
Bugzilla
Downloads
STLinux
Updates
Search
Google


The web
stlinux.com
Using STWorkbench with STLinux
Building and debugging a kernel module
ST Logo
Previous   Contents   Next

Overview

This describes how to use STWorkbench to build and debug an ST40 Linux kernel module. It reuses the launch configuration set up in Debugging the kernel and can be used on ST200 systems when some values are appropriately substituted.

Creating and building the project

  1. Click File > New > Project.... The New Project window appears.

  2. Select C > C Project from the Wizards tree/list and click Next. The C Project dialog appears.

  3. Enter 'HelloModule' into the Project name text box

  4. Select Makefile project from the Project types list

  5. Select ST40 Linux GCC from the Toolchain list.

  6. Click Finish. If a confirmation appears, click Yes.

  7. From the STWorkbench C/C++ Projects view, select HelloModule.

  8. Click File > New > File. The New File window appears.

  9. In the File name text box, enter 'hello.c' and click Finish.

  10. Copy the following into the editor.

  11. #include <linux/module.h>
    
    static int hello_init(void)
    {
        printk(KERN_ALERT "Starting module hello\n");
        return 0;
    }
    
    static void hello_exit(void)
    {
        printk(KERN_ALERT "Unloading module hello\n");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);
    MODULE_LICENSE("GPL");
    

  12. Save the file.

  13. Click File > New > File. The New File window appears.

  14. In the File name text box, enter 'Makefile' and click Finish.

  15. Copy the following into the editor.

  16. ifneq ($(KERNELRELEASE),) 
    # we ARE using the standard kernel make system, good.
    
    # define the module to build
    obj-m := hello.o
    
    else 
    
    # we are NOT using the standard kernel make system
    # so invoke the standard kernel top Makefile.
    
    # KDIR is the top-level Kernel build directory itself
    KDIR := /scratch/smithc/2.6.23/linux-sh4
    
    PWD := $(shell pwd) 
    
    all:
    	$(MAKE) ARCH=sh CROSS_COMPILE=sh4-linux- -C $(KDIR) SUBDIRS=$(PWD) modules 
    endif

  17. Change the value of KDIR to the path to your kernel tree.

  18. Save the makefile.

  19. Select Project > Build Project. The kernel module is built.

Debugging the module

This describes how to debug kernel modules on Linux.

Note: The root user must be able to log in to the target using SSH without a password. This the default, provided the root user has remotely logged in at least once previously.

  1. Select Run > Debug.... The Create, manage and run configurations window appears.

  2. Select the Boot STb7100ref configuration set up in Debugging the kernel and click the Debugger tab.

  3. In the Kernel modules sub-tab, click Add. Navigate to the directory containing the kernel module and click OK. The path is added to the list.

  4. In the Source tab,

    click Add. The Add Source dialog appears.

  5. Select Project and click Next.

  6. Check the kernel module project and click OK.

  7. Click Debug. The kernel boots and a debugger is attached.

  8. Set a breakpoint on the printf in hello_init by double-clicking in the left border of the line.

  9. Select Window > Show View > Other.... The Show View dialog opens.

  10. Select STLinux > Remote Filesystem and click OK. The Remote Filesystem view appears.

  11. In the Target field, enter the name or IP address of your target. The filesystem of your target system is displayed.

  12. Expand /root, right-click it and select Upload files to target.... The Upload dialog appears.

  13. In the Upload field, enter the full path to HelloModule.ko and click OK. HelloModule.ko is copied to that directory on the target.

  14. In Remote Filesystem view, right-click the module and select Insert module. The module is inserted and the breakpoint is hit.

From this point on, the module can be debugged like any other C/C++ application. For more information, see the generic C/C++ Development Guide.

Previous   Contents   Next
Valid HTML 4.01! Last updated: 18th December 2007
© Copyright STMicroelectronics Limited, 2005
Printer