2013年9月29日 星期日

How to debug android linux kernel or driver by KGTP

Ref. http://code.google.com/p/kgtp/wiki/HOWTOCN

1. install pci serial port card (option install)

2. Vmware add hardware serial port (option install)

3. serial port assign com9 (option install)

4. minicom (option install)
install minicom and check /dev/ttyS1 work or not
root@ubuntu:~#  sudo apt-get install minicom
root@ubuntu:~#  minicom -s

serial port setting
A -    序 列  設 備 : /dev/ttyS1
or connect usb to serial port device on host PC
A -    序 列  設 備 : /dev/ttyUSB0

儲存設定為 dfl
離開 Minicom
root@ubuntu:~# minicom

5. minicom menu call :press Ctrl+A,release Ctrl+A,press Z

6. my file path
(a)Android linux

(b)kgtp

7. root@ubuntu:xxxxxx/android2.3_kernel_v1.01# make menuconfig
General setup  --->
    [*] Prompt for development and/or incomplete code/drivers
    [*] Kprobes
[*] Enable loadable module support

Kernel hacking  --->
    [*] Spinlock and rw-lock debugging: basic checks
    [*] Spinlock debugging: sleep-inside-spinlock checking
    [*] Debug preemptible kernel
[*] Debug Filesystem
[*] Compile the kernel with debug info
[*] Debug page memory allocations
[*] Enable stack utilization instrumentation

You can check flags of .config in ./android2.3_kernel_v1.01

8.download kgtp
git clone https://github.com/teawater/kgtp.git -b release
or
https://github.com/teawater/kgtp/archive/release.zip

9.build kgtp
modify parameter KERNELDIR , CROSS_COMPILE, ARCH, in makefile

Remove $(CROSS_COMPILE) in gtemod, getframe, putgtprsp

~# make P=1

10. install right GDB version match with KGTP
If GDB version earlier than 7.6, the function tracepoint have some bug can not use, if your GDB earlier than 7.6 please new GDB match with  KGTP

sudo apt-get install gcc texinfo m4 flex bison libncurses5-dev libexpat1-dev python-dev

git clone -b gdb_7_6-branch git://sourceware.org/git/gdb.git gdb-release

./configure --prefix=/usr/local/kgtp-gdb --target=arm-none-linux-gnueabi --program-prefix=kgtp-none-linux-gnueabi-

make
make install

11. Install Gui (option)
sudo apt-get install ddd

12. add path
gedit /etc/environment
add
/usr/local/kgtp-gdb/bin
~#reboot

13. install to Development board
sudo adb push gtp.ko /
adb shell insmod /gtp.ko

sudo adb shell mount -t sysfs none /sys/
Ignore  failed: Device or resource busy

sudo adb shell mount -t debugfs none /sys/kernel/debug/

14.trigger remote kgtp work
adb forward tcp:1234 tcp:1234
adb shell "nc -l -p 1234 </sys/kernel/debug/gtp >/sys/kernel/debug/gtp"

15. Open new console in android linux kernel
kgtp-none-linux-gnueabi-gdb ./vmlinux
or
ddd --debugger kgtp-none-linux-gnueabi-gdb ./vmlinux

(gdb) target remote :1234

16. test final
(gdb) p linux_banner
$1 = "Linux version 2.6.36 (root@ubuntu) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #703 PREEMPT Sat Feb 22 05:19:55 CST 2014\n"
(gdb) p jiffies_64
回應 $1 = 4295029698

17. trace a var
s3c6410_leds_ioctl of s3c6410_leds.c
static long s3c6410_leds_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
    switch(cmd) {
        unsigned tmp;
    case 0:
    case 1:
                 if (arg > 4)
                 {
             return -EINVAL;
         }
        tmp = readl(S3C64XX_GPMDAT);
           
        if(cmd==0) //close light
                  {
            tmp &= (~(1<<arg));
                  }
        else  //open light
                  {
            tmp |= (1<<arg);
                  }

                writel(tmp,S3C64XX_GPMDAT);

        printk (DEVICE_NAME": %d %d\n", arg, cmd);
        return 0;
    default:
        return -EINVAL;
    }
}

See cmd = 1, arg=3

17.other commands
Trace command
http://davis.lbl.gov/Manuals/GDB/gdb_10.html
trace skill -> 如何使用GDB控制KGTP跟蹤和調試Linux內核
http://code.google.com/p/kgtp/wiki/HOWTOCN
goto youtube find keyword KGTP

full document download
http://www.mediafire.com/download/iozho8i7pbv4z0d/kgtp.zip

沒有留言:

張貼留言