2009年4月28日星期二

使用gdbserver调试arm应用程序

1.下载gdbserver
   gdbserver的源代码在gdb的源代码包中
  ftp://sourceware.org/pub/gdb/releases/gdb-6.8.tar.bz2

2.准备toolchain
  使用codesoucery的toolchain
  http://www.codesourcery.com/sgpp/lite/arm/portal/package3696/public/arm-none-linux-gnueabi/arm-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

3.配置gdbserver
  在gdb文件下下,能找到gdbserver文件夹
  首先声明一个环境变量CC
  export CC=YOUR-PATH-OF-GCC/arm-none-linux-gnueabi-gcc
  配置
 ./configure --host=arm-none-linux --target=arm-none-linux
 意思是说编译在arm-none-linux上运行的,能执行arm-none-linux目标文件的gdbserver

4.make 编译
  就会生成一个gdbserver可执行文件

5.使用gdbserver远程调试应用程序
  以串口为例
 假设应用程序为hello

在arm板子上的命令行下运行
gdbserver  /dev/ttyS0 hello

在开发机上运行
gdb hello
在gdb的提示符下运行
target remote YOUR SERIAL


 

2009年4月26日星期日

编译busybox1.14.0

1.下载toolchain
    http://www.codesourcery.com/sgpp/lite/arm/portal/package3698/public/arm-none-linux-gnueabi/arm-2008q3-72-arm-none-linux-gnueabi.bin
2.在busybox目录下
  配置busybox
   make menuconfig
   配置成静态链接,并指定toolchain路径和前缀
3.make  编译
  如果提示dnsd.c lvalue error相关的错误,打下面的补丁给busybox
 http://www.busybox.net/downloads/fixes-1.14.0/busybox-1.14.0-unaligned.patch

编译成功后,会生成一个busybox可执行文件
 

使用qemu和kgdb调试内核

1.配置内核
        CONFIG_KGDB=y
        CONFIG_DEBUG_INFO=y
        CONFIG_DEBUG_BUGVERBOSE=y
        CONFIG_FRAME_POINTER=y
        CONFIG_KGDB_SERIAL_CONSOLE=y
2.运行qemu (以versatilepb机器为例)
qemu-system-arm -M versatilepb -kernel arch/arm/boot/zImage -append "kgdboc=ttyAMA0 kgdbwait root=/dev/nfs \
nfsroot=192.168.1.24:/mnt/arm-fs rw ip=dhcp" -net nic,vlan=0 -net tap,vlan=0,script=./qemu-ifup -serial tcp::4444,server

kgdboc选项指定了通过串口用kgdb来调试内核,kgdbwait,等待gdb链接
-serial 选项指定了串口和tcp端口的映射

3.运行gdb
 
 arm-eabi-gdb vmlinux
 target remote 主机ip:4444 

可以开始调试了。
 

用qemu通过nfs启动linux

假设开发机安装的是Fedora 9

1.设置网络-使qemu能使用开发机的网络
  首先确认下开发机的内核时候配置了TUN
   grep CONFIG_TUN= /boot/config-`uname -r`
  正常的情况下是CONFIG_TUN=m或者=y

2.安装网络配置工具
   yum install bridge-utils

3.配置网络
  /usr/sbin/brctl addbr br0
  /sbin/ifconfig eth0 0.0.0.0 promisc up
  /usr/sbin/brctl addif br0 eth0
  /sbin/dhclient br0
  /sbin/iptables -F FORWARD

4. Fedora 9 配置网络文件系统
  假设网络文件系统的目录是/mnt/arm-nfs
  在/etc/export内添加如下一条:
   /mnt/arm-nfs/   *(rw,sync,no_root_squash)
  启动网络文件系统服务
   /sbin/service nfs restart

5.准备qemu启动用的脚本,将下面代码保存为qemu-ifup,设置执行模式chmod +x qemu-ifup
  #!/bin/sh
  /sbin/ifconfig $1 0.0.0.0 promisc up
  /usr/sbin/brctl addif br0 $1

6.内核配置
CONFIG_IP_PNP_DHCP=y
CONFIG_TUN=y
CONFIG_AEABI=y
CONFIG_TMPFS=y

7.启动qemu 
qemu-system-arm -M YourMachine -kernel zImage root="/dev/nfs nfsroot=<host-ip>:/mnt/YourNFS rw ip=dhcp" \
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup




2009年4月5日星期日

git 恢复所有被修改的文件到初始状态

命令行下执行下面的命令,就能取消所有文件的修改
git checkout -f