|
|
 |
Using STWorkbench with STLinux
Building and debugging a kernel module
|
|
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
Click File > New > Project.... The New Project window appears.
Select C > C Project from the Wizards tree/list and click Next.
The C Project dialog appears.
Enter 'HelloModule' into the Project name text box
Select Makefile project from the Project types list
Select ST40 Linux GCC from the Toolchain list.
Click Finish. If a confirmation appears, click Yes.
From the STWorkbench C/C++ Projects view, select HelloModule.
Click File > New > File. The New File window appears.
In the File name text box, enter 'hello.c' and
click Finish.
Copy the following into the editor.
#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");
|
|
|
Save the file.
Click File > New > File. The New File window appears.
In the File name text box, enter 'Makefile' and
click Finish.
Copy the following into the editor.
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
|
|
|
Change the value of KDIR to the path to your kernel tree.
Save the makefile.
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.
Select Run > Debug.... The Create, manage and run configurations window
appears.
Select the Boot STb7100ref configuration set up in
Debugging the kernel and click the Debugger tab.
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.
- In the Source tab,
click Add. The Add Source dialog appears.
Select Project and click Next.
Check the kernel module project and click OK.
Click Debug. The kernel boots and a debugger is attached.
Set a breakpoint on the printf in
hello_init by double-clicking in the left border of the line.
Select Window > Show View > Other.... The Show View dialog opens.
Select STLinux > Remote Filesystem and click OK. The Remote
Filesystem view appears.
In the Target field, enter the name or IP address of your target. The filesystem
of your target system is displayed.
Expand /root, right-click it and select
Upload files to target.... The Upload dialog appears.
In the Upload field, enter the full path to HelloModule.ko
and click OK. HelloModule.ko is copied to that directory on
the target.
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.
|