I want to be a complete engineer - technical genius and sensitive humanist all in one!

Wednesday, December 10, 2008

Debugging linux kernel on DaVinci DM6446 using kgdb

monta vista 已经在davinci运行的kernel里面打上了他们修改过的kgdb补丁,按照如下步骤可以使用这个补丁对内核进行调试:

Rebuilding Kernel with kgdb support

Launch kernel configuration menu using the following command

#make ARCH=arm CROSS_COMPILE=arm_v5t_le- gconfig

Enable the following options in kernel configuration menu

a) CONFIG_NETCONSOLE (Networking support -> Network console logging support)

b) CONFIG_DEBUG_KERNEL (Kernel hacking -> Kernel Debugging)

c) CONFIG_KGDB (Kernel hacking -> KGDB)

d) CONFIG_KGDB_ETH (Kernel hacking -> KGDB -> Method of KGDB communication -> Ethernet)

After enabling the options in gconfig rebuild the kernel.

Target configuration

Target is configured by additional Linux kernel arguments passed e.g. via U-Boot. Add kgdboe option in bootargs environment variable on U-Boot prompt.

#kgdboe=[target-port]@/[dev][target-macaddr],[host-port]@/[dev]
  • target-port (optional): GDB port (default 6443)
  • target-ip: target ip address (i.e DVEVM ip address)
  • dev (optional): network interface (default eth0)
  • host-port (optional): Host port use to send/recieve UDP packets (default 6442)
  • host-ip: Host IP address

Example for U-Boot configuration:

DVEVM# setenv bootargs ... kgdboe=@192.168.1.4/,@192.168.1.3/

Note that in this example host IP address is 192.168.1.3 and DVEVM IP address is 192.168.1.4 (same as you normally set in U-Boot parameters serverip and ipaddr).

Host configuration

Go to Linux kernel main directory (where you executed make uImage and where the main Linux kernel executable vmlinux is located) and there create a file .gdbinit:

#touch .gdbinit

Edit this with your preferred editor and add

#target remote udp:192.168.2.4:6443

(with IP address of the target the host should connect to, same as used above in target configuration).

Connecting from Host

1. Boot DVEVM with the kgdb kernel. In boot messages you should get anything like

...
TI DaVinci EMAC: MAC address is deadbeaf
TI DaVinci EMAC Linux version updated 4.0
TI DaVinci EMAC: Installed 1 instances.
netconsole: not configured, aborting
kgdboe: local port 6443
kgdboe: local IP 192.168.1.4
kgdboe: interface eth0
kgdboe: remote port 6442
kgdboe: remote IP 192.168.1.3
kgdboe: remote ethernet address ff:ff:ff:ff:ff:ff
kgdboe: device eth0 not up yet, forcing it
kgdboe: debugging over ethernet enabled
...

2. Start cross debugging on Host machine

  $ arm_v5t_le-gdb vmlinux
GNU gdb 6.3 (MontaVista 6.3-20.0.22.0501131 2005-07-23)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=armv5tl-montavista-linuxeabi".
warning: The remote protocol may be unreliable over UDP
warning: some events may be lost, rendering further debugging impossible
0xc00533dc in breakpoint () at kernel/kgdb.c:1620
1620 atomic_set(&kgdb_setting_breakpoint,1);
(gdb)

Further reading

Included in the kgdb kernel patch is documentation. To get this, in Linux main directory on host (where you executed make uImage) e.g. call

#make htmldocs

After some time, redirect your web browser to file index.html in Linux kernel documentation subdirectory

Documentation/DocBook/index.html

There you should find now an entry kgdb with further infos.

No comments:

Labels

Followers