您的位置:首页 > 博客中心 > 网络系统 >

linux内核调试指南

时间:2022-04-03 08:59

改成:
"xim" "X Input Method" "gtk20" "/usr/share/locale" "en:ko:ja:th:zh"
注意,一定要重启一下机器。
pdf乱码的解决
$sudo apt-get install xpdf-chinese-simplified xpdf-chinese-traditional poppler-data

参考:

http://wiki.ubuntu.org.cn/PDF%E6%96%87%E6%A1%A3%E7%9A%84%E4%B9%B1%E7%A0%81%E9%97%AE%E9%A2%98

建立编译环境

$ sudo apt-get install build-essential autoconf automake1.9 cvs subversion libncurses5-dev git rar unrar p7zip-full cabextract

其余的根据出错的提示,利用“立新得”搜索,然后进行安装。没有“立新得”界面程序的可以在终端下利用以下命令来搜索和安装。

$ sudo apt-get update
$ apt-cache search XXX
$ sudo apt-get install XXX

双硬盘系统切换设置, 私人备忘用

title           Microsoft Windows XP Professional
root (hd1,0)
savedefault
makeactive
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1

安装交叉编译工具

交叉编译工具下载网址

下面是几个交叉编译工具下载网址,需要手动安装时,对比一下编译器的名称可以找到合适的下载地址。debian维护有自己的已经打包成.deb形式安装包,在debian软件库中。

http://www.codesourcery.com/gnu_toolchains/arm/download.html
(据说是arm公司推荐的)

Download Sourcery G++ Lite Edition for ARM

Target OS Download
EABI Sourcery G++ Lite 2008q1-126
All versions...
uClinux Sourcery G++ Lite 2008q1-152
All versions...
GNU/Linux Sourcery G++ Lite 2008q1-126
All versions...
SymbianOS Sourcery G++ Lite 2008q1-126
All versions...

到底是选EABI还是GNU/LINUX呢?应该是后者....

点GNU/LINUX的连接进去,可看到

Download MD5 Checksum
IA32 GNU/Linux Installer 93eee13a08dd739811cd9b9b3e2b3212
IA32 Windows Installer fac5b0cee1d9639c9f15e018e6d272ad

Documentation

Title Format
Assembler (PDF) PDF
Binary Utilities (PDF) PDF
C Library (GLIBC) (PDF) PDF
Compiler (PDF) PDF
Debugger (PDF) PDF
Getting Started Guide (PDF) PDF
Linker (PDF) PDF
Preprocessor (PDF) PDF
Profiler (PDF) PDF

Advanced Packages

Expert users may prefer packages in these formats.

Download MD5 Checksum
IA32 GNU/Linux TAR 4f11b0fa881864f220ab1bd84666108b
IA32 Windows TAR ed6d25fd68301e728a1fba4cd5cb913f
Source TAR 2db28fb2aa80134e7d34d42b7039d866

名字标识不是很明显,进去看才知道。比如,IA32 GNU/Linux Installer对应的安装包
名字叫arm-2008q1-126-arm-none-linux-gnueabi.bin
为什么有个none?迷茫中..
---------------------------------
http://ftp.snapgear.org:9981/pub/snapgear/tools/arm-linux/
[DIR] Parent Directory 30-Sep-2003 15:44 -
[ ] arm-linux-tools-20031127.tar.gz 26-Nov-2007 16:56 141M
[ ] arm-linux-tools-20051123.tar.gz 24-Nov-2005 00:50 228M
[ ] arm-linux-tools-20061213.tar.gz 13-Dec-2006 13:31 230M
[ ] arm-linux-tools-20070808.tar.gz 30-Nov-2007 03:21 271M
[ ] binutils-2.16.tar.gz 16-Nov-2005 15:44 15.6M
[ ] binutils-2.17.tar.gz 06-Dec-2007 10:24 17.4M
[ ] build-arm-linux-3.4.4 02-Aug-2006 14:32 6k
[ ] build-arm-linux-4.2.1 30-Jul-2008 10:13 7k
[ ] elf2flt-20060707.tar.gz 17-Jan-2008 22:23 101k
[ ] elf2flt-20060708.tar.gz 30-Jul-2008 10:14 110k
[ ] gcc-3.4.4.tar.bz2 16-Nov-2005 15:39 26.3M
[ ] gcc-4.2.1.tar.bz2 06-Dec-2007 10:11 42.0M
[ ] genext2fs-1.3.tar.gz 03-Sep-2003 10:23 19k
[ ] glibc-2.3.3.tar.gz 16-Nov-2005 15:49 16.7M
[ ] glibc-2.3.6.tar.gz 06-Dec-2007 10:39 17.9M
[ ] glibc-linuxthreads-2.3.3.tar.gz 16-Nov-2005 15:49 303k
[ ] glibc-linuxthreads-2.3.6.tar.gz 06-Dec-2007 10:39 320k
--------------------------
http://www.handhelds.org/download/projects/toolchain/
[DIR] Parent Directory -
[ ] README 28-Jul-2004 17:37 788
[DIR] archive/ 28-Jul-2004 17:34 -
[ ] arm-linux-gcc-3.3.2.tar.bz2 03-Nov-2003 10:23 71M
[ ] arm-linux-gcc-3.4.1.tar.bz2 29-Jul-2004 14:01 41M
[DIR] beta/ 28-Jul-2004 17:36 -
[ ] crosstool-0.27-gcc3.4.1.tar.gz 28-Jul-2004 17:21 2.0M
[ ] gcc-build-cross-3.3 31-Oct-2003 15:43 5.1K
[DIR] jacques/ 24-Jul-2001 18:45 -
[ ] kernel-headers-sa-2.4.19-rmk6-pxa1-hh5.tar.gz 12-Mar-2003 17:42 4.7M
[DIR] monmotha/ 13-Aug-2002 17:54 -
[DIR] osx/ 14-Dec-2003 11:45 -
[DIR] pb/ 22-Nov-2002 20:10 -
[DIR] source/ 18-Mar-2004 16:12 -
------------------------------------
http://ftp.arm.linux.org.uk/pub/armlinux/toolchain/
[DIR] Parent Directory -
[ ] Oerlikon-DevKit-XScalev2.tar.gz 07-Feb-2003 22:30 3.7K
[ ] cross-2.95.3.tar.bz2 20-Jul-2001 21:12 35M
[ ] cross-3.0.tar.bz2 20-Jul-2001 22:27 39M
[ ] cross-3.2.tar.bz2 23-Aug-2002 11:04 81M
[ ] cross-3.2.tar.gz 23-Aug-2002 10:01 93M
[DIR] src-2.95.3/ 14-Jan-2002 17:52 -
[DIR] src-3.2/ 23-Aug-2002 10:53 -
--------------------------------------------
http://linux.omap.com/pub/toolchain/
[DIR] Parent Directory -
[ ] obsolete-gcc-3.3.2.t..> 15-May-2004 12:18 76M
---------------------------
http://www.uclinux.org/pub/uClinux/arm-elf-tools/
To install the Linux binaries, login as root and run "sh ./XXX-elf-tools-20030314.sh".

m68k-elf-20030314/arm-elf-20030314
Get the m68k binaries or the ARM binaries. The source is here.

m68k-elf-20020410/arm-elf-20011219
Get the m68k binaries or the ARM binaries. The source is here.

m68k-elf-20020218/arm-elf-20011219
Get the m68k binaries or the ARM binaries. The source is here.

m68k/arm-elf-20011219
Get the m68k binaries or the ARM binaries. The source is here.

You can also get Bernhard Kuhn‘s RPMs here.

m68k-elf-20010716
Get the binaries here and the source from here.

m68k-elf-20010712
Get the binaries here and the source from here.

m68k-elf-20010610
Get the binaries here and the source from here.

m68k-elf-20010228
The binaries are in two files, the compilers and the g++ headers. The source is here.

安装arm-linux-gnueabi-XXX 工具集

debian有自己维护的一套交叉编译工具集

[参考]http://www.emdebian.org/tools/crosstools.html

工具库: http://www.emdebian.org/debian/pool/main/

步骤:

1. 往/etc/apt/sources.list文件加入下面软件源

deb http://buildd.emdebian.org/debian/ unstable main
deb-src http://buildd.emdebian.org/debian/ unstable main
deb http://buildd.emdebian.org/debian/ testing main
deb-src http://buildd.emdebian.org/debian/ testing main

然后:

安装 emdebian-archive-keyring package 
$ sudo apt-get install emdebian-archive-keyring
更新
$ sudo apt-get update

2. 安装交叉编译器

$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi gcc-4.3-arm-linux-gnueabi g++-4.3-arm-linux-gnueabi

注意,在ubuntu8.04下,只能安装4.2版。把上面文字中的4.3全部换为4.2即可。

3. 安装交叉调试器

$sudo apt-get install gdb-arm-linux-gnueabi

注意:

a. 安装时使用名称:gdb-arm-linux-gnueabi,调用时使用命令名是:arm-linux-gnueabi-gdb

b. ubuntu下,arm-linux-gnueabi-gdb和gdb有冲突。

解决方法:

需要使用arm-linux-gnueabi-gdb时先卸载gdb,记下卸载gdb时与gdb一起被卸载的软件名,然后安装arm-linux- gnueabi-gdb。 想换回gdb时,在反操作。

apt-install remove arm-linux-gnueabi-gdb 然后apt-get install gdb以及之前和gdb一起被卸载包。可以写个脚本自动完成这些操作。本人环境下的脚本是:

脚本1. install-armgdb.sh

#! /bin/sh
sudo apt-get remove gdb
sudo apt-get install gdb-arm-linux-gnueabi

脚本2. install-gdb.sh

#! /bin/sh
sudo apt-get remove gdb-arm-linux-gnueabi
sudo apt-get install apport apport-gtk apport-qt bug-buddy cgdb gdb python-apport xxgdb

什么是EABI

答: 来自AAPCS

ABI: Application Binary Interface:

1). The specifications to which an executable must conform in order to execute in a specific execution environment. For example, the Linux ABI for the ARM Architecture.

2). A particular aspect of the specifications to which independently produced relocatable files must conform in order to be statically linkable and executable.

For example, the C++ ABI for the ARM Architecture, the Run-time ABI for the ARM Architecture, the C Library ABI for the ARM Architecture.

ARM-based … based on the ARM architecture …

EABI: An ABI suited to the needs of embedded (sometimes called free standing) applications.

参考:

ABI/EABI/OABI http://blog.csdn.net/hongjiujing/archive/2008/07/21/2686556.aspx

Re: 关于kernel ARM_EABI http://zh-kernel.org/pipermail/linux-kernel/2008-January/002793.html

Why ARM’s EABI matters http://www.linuxdevices.com/articles/AT5920399313.html

Why switch to EABI? http://www.applieddata.net/forums/topic.asp?TOPIC_ID=2305

ArmEabiPort http://wiki.debian.org/ArmEabiPort

安装arm-elf-XXX 工具集

注:arm-elf-XXX 工具集是用于uclinux的

1. 依据要求搜索下载相应的arm-elf-tools安装包。比如arm-elf-tools-20030315.sh

2. 安装: $ ./arm-elf-tools-20030315.sh

3. 如果,该安装包年代过老,比如arm-elf-tools-20030315.sh,会出现下面的错误提示 “tail: 无法打开“ 43” 读取数据: 没有那个文件或目录。”。 这时需要修改安装包源码。

方法:vi arm-elf-tools-20030315.sh,

搜索tail,在它后面加 -n .比如 把tail ${SKIP} ${SCRIPT} | gunzip | tar xvf -改成如下:tail -n ${SKIP} ${SCRIPT} | gunzip | tar xvf -

4.如何卸载已安装的arm-elf-tools? 答,重新安装一次,注意看终端提示。或直接vi arm-elf-tools-20030315.sh,看脚本的内容,

bin工具集的使用

[该怎么称呼这类工具?待详述]

arm-elf-addr2line   arm-elf-elf2flt     arm-elf-gdb         arm-elf-objdump     arm-elf-size
arm-elf-ar arm-elf-flthdr arm-elf-ld arm-elf-protoize arm-elf-strings
arm-elf-as arm-elf-g++ arm-elf-ld.real arm-elf-ranlib arm-elf-strip
arm-elf-c++ arm-elf-gasp arm-elf-nm arm-elf-readelf arm-elf-unprotoize
arm-elf-c++filt arm-elf-gcc arm-elf-objcopy arm-elf-run

arm-linux-gnueabi-addr2line arm-linux-gnueabi-g++ arm-linux-gnueabi-gprof arm-linux-gnueabi-readelf
arm-linux-gnueabi-ar arm-linux-gnueabi-g++-4.2 arm-linux-gnueabi-ld arm-linux-gnueabi-size
arm-linux-gnueabi-as arm-linux-gnueabi-gcc arm-linux-gnueabi-nm arm-linux-gnueabi-strings
arm-linux-gnueabi-c++filt arm-linux-gnueabi-gcc-4.2 arm-linux-gnueabi-objcopy arm-linux-gnueabi-strip
arm-linux-gnueabi-cpp arm-linux-gnueabi-gdb arm-linux-gnueabi-objdump
arm-linux-gnueabi-cpp-4.2 arm-linux-gnueabi-gdbtui arm-linux-gnueabi-ranlib

如何获取这些工具的命令选项? 看章节“知识从哪里来” 一般是用命 xxxxxx –help就能得到简单的命令选项列表

下载arm-linux-gnueabi- 手册地址 http://www.codesourcery.com/gnu_toolchains/arm/portal/release324

然后搜索”arm”,便能找到处理器相关的特殊命令选项

arm-linux-gnueabi-gcc

查看arm处理器相关的编译选项

$ vi arch/arm/Makefile

阅读Makefile文件,并联系源码根目录下的.config文件,便能知道arm-linux-gnueabi-gcc用了哪些编译选项。再到 手册中查找,便能知道这些选项是干什么用的,

但手册中说的不是很详细。另外查找有用解释的方法的是,

利用make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig,找到与命令选项有关联的CONFIG_XXX的菜单项,看它的帮助说明.比如

$ vi arch/arm/Makefile
....
ifeq ($(CONFIG_AEABI),y)
CFLAGS_ABI :=-mabi=aapcs-linux -mno-thumb-interwork
else
CFLAGS_ABI :=$(call cc-option,-mapcs-32,-mabi=apcs-gnu) $(call cc-option,-mno-thumb-interwork,)
endif
..

再查看CONFIG_AEABI的帮助文档 $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig 找到CONFIG_AEABI相关的菜单,看它的帮助文档,

便能知道选项-mabi=aapcs-linux -mno-thumb-interwork的整体效果怎样的。

  ┌───────────────────── Use the ARM EABI to compile the kernel ──────────────────────┐
│ CONFIG_AEABI: │
│ │
│ This option allows for the kernel to be compiled using the latest │
│ ARM ABI (aka EABI). This is only useful if you are using a user │
│ space environment that is also compiled with EABI. │
│ │
│ Since there are major incompatibilities between the legacy ABI and │
│ EABI, especially with regard to structure member alignment, this │
│ option also changes the kernel syscall calling convention to │
│ disambiguate both ABIs and allow for backward compatibility support │
│ (selected with CONFIG_OABI_COMPAT). │
│ │
│ To use this you need GCC version 4.0.0 or later. │
│ │
│ Symbol: AEABI [=n] │
│ Prompt: Use the ARM EABI to compile the kernel │
│ Defined at arch/arm/Kconfig:554 │
│ Location: │
│ -> Kernel Features

arm-linux-gnueabi-gcc的主要编译选项有如下几个。但是在编译内核时,这些选项是不需要手工去写的,而是通过make menuconfig生成包含了编译选项配置信息的.config文件。在make编译内核时,

再利用Makefile文件中的规则结合.config文 件提取出那些选项。

太多了,手册吧

arm-linux-gnueabi-gdb

注意它的默认选项设置

$ arm-linux-gnueabi-gdb
(gdb) show arm
abi: The current ARM ABI is "auto" (currently "APCS").
apcs32: Usage of ARM 32-bit mode is on.
disassembler: The disassembly style is "std".
fpu: The current ARM floating point model is "auto" (currently "fpa").
(gdb)

但是,如果如果在命令后有参数vmlinux的话,它会自动识别出内核的abi,从而自动设置了gdb的abi。比如,在编译内核时,如果选了CONFIG_AEABI,则gdb的提示如下

$ arm-linux-gnueabi-gdb vmlinux 
...
(gdb) show arm
abi: The current ARM ABI is "auto" (currently "AAPCS"). <--注意
apcs32: Usage of ARM 32-bit mode is on.
disassembler: The disassembly style is "std".
fpu: The current ARM floating point model is "auto" (currently "softvfp").

qemu的使用

参考手册

http://bellard.org/qemu/user-doc.html

http://wiki.debian.org.tw/index.php/QEMU

http://www.h7.dion.ne.jp/~qemu-win/

http://bellard.org/qemu/

邮件列表

http://lists.gnu.org/archive/html/qemu-devel/

参考文章

“QEMU安装使用全攻略” http://forum.ubuntu.org.cn/viewtopic.php?p=248267&sid=f4e95025bdaf6a24a218315d03ad9933

[补充命令]引用自http://bbs.chinaunix.net/viewthread.php?tid=779540

安装过程中,要求换盘:
在qemu中按ctrl+alt+2切换到qemu monitor模式 输入?或help可以查看可用命令及使用说明。
(在其他版本的qemu中,运行qemu加载OS后,这个shell就会自动变成qemu monitor模式)
change device filename -- change a removable media
看来它就是用来换盘的了 : change cdrom /rhel4/EL_disc2.iso

切换回安装界面ctrl+alt+1

monitor下还有几个常用的命令:
savevm filename 将整个虚拟机当前状态保存起来
loadvm filename 恢复 (最初我没用change换盘时,就是先savevm->重新运行qemu->loadvm )
sendkey keys 向VM中发送按键,例如你想在虚拟机里切换到另一个终端,按下了ctrl-alt-F2
不幸的是,切换的却是你的主系统,所以就需要用 sendkey了 sendkey ctrl-alt-f2
还有其他几个命令,自己看看啦。

经过N久终于装好了,现在可以启动试试:
[root@LFS distro]#qemu redhat.img -enable-audio -user-net -m 64
-user-net 相当于VMware的nat,主系统可以上,虚拟机就可以
-m 64 使用64M内存,缺省下使用128M

ctrl-alt-f 全屏
ctrl-alt 主机/虚拟机鼠标切换
qemu还有一些其他参数,输入qemu可以查看其相关说明

initrd.img的原理与制作

[扩展,原理,相关命令。下面的skyeye可能需要这部分知识]

“Linux2.6 内核的 Initrd 机制解析” http://www.ibm.com/developerworks/cn/linux/l-k26initrd/

“Introducing initramfs, a new model for initial RAM disks” http://www.linuxdevices.com/articles/AT4017834659.html

””深入理解 Linux 2.6 的 initramfs 機制 (上)“ http://blog.linux.org.tw/~jserv/archives/001954.html

MKINITRAMFS http://www.manpage.org/cgi-bin/man/man2html?8+mkinitramfs

安装与使用

$ sudo apt-get install initramfs-tools 
$ mkinitramfs /lib/modules/2.6.26/ -o initrd.img-2.6.26

x86虚拟调试环境的建立

参考

“debugging-linux-kernel-without-kgdb” http://memyselfandtaco.blogspot.com/2008/06/debugging-linux-kernel-without-kgdb.html

“使用 KGDB 调试 Linux 内核” http://blog.chinaunix.net/u/8057/showart_1087126.html

“透過虛擬化技術體驗 kgdb (1)” http://blog.linux.org.tw/~jserv/archives/002045.html

基于qemu和内核内置kgdb

缺点:相对于下节的“基于qemu和qemu内置gdbstub”,这个方法配置麻烦。

优点:真机远程调试时只能使用内置kgdb这个方法。

[等待扩展,,,,]

终极参考

“Using kgdb and the kgdb Internals” http://www.kernel.org/pub/linux/kernel/people/jwessel/kgdb/index.html

参考文章

“使用 KGDB 调试 Linux 内核” http://blog.chinaunix.net/u/8057/showart_1087126.html

基于qemu和qemu内置gdbstub

  • 参考文章

“Debugging Linux Kernel Without KGDB Patch (Qemu + GDB)” http://memyselfandtaco.blogspot.com/2008/06/debugging-linux-kernel-without-kgdb.html

  • 优缺点

优点:相对上节,优点是操作简单,几乎不需要什么配置

缺点:真机的远程调试,就只能利用内核的内置kgdb了

说明:

如果长时间调试固定版本的内核,采取下面的把调试用内核安装的虚拟机内部就可以了。但是如果是要频繁地更换新内核或修改被调试内核,就需要采取把内 核挂在虚拟机外部的形式。

也就是用 -kernel在虚拟机外面挂个内核, 再利用-append 传递起内核启动参数等。[待研究]

[太概过了,待扩展...]

  • 调试用内核的安装过程:

1. 利用qemu安装一个系统.

2. 在真机中配置并编译一个用于安装到虚拟系统中的新内核,注意配置时的选择

* 配置和启动
1. 内核选项
同时,为了能在系统运行时中断系统并出发远程 gdb,必须打开内核 Magic Sys-Rq 键选项 :[后记,没实验去掉会怎样,估计没影响]
CONFIG_MAGIC_SYSRQ=y
打开内核符号调试:
CONFIG_DEBUG_INFO=y

3. 在真机下编译好虚拟机新内核的源码

4. 结束qemu,用以下命令在真机上挂载虚拟硬盘。然后把编译好的整个源码目录都拷贝到挂载好的虚拟硬盘上(真机上保留一份源码)。

$ sudo mount -o loop,offset=32256 debian.img /mnt

拷贝完后,在真机上卸载虚拟硬盘

$ sudo umount /mnt

5.启动虚拟机,进入旧系统,在新内核源码根目录下用以下命令给qemu的虚拟系统安装一个新的内核

拷贝模块
$ make modules_install
安装内核

$ make install
制作initrd.img
$ cd /boot
$ mkinitramfs /lib/modules/2.6.26/ -o initrd.img-2.6.26
检查/boot/grub/menu.lst 文件内容是否妥当

6.用以下命令重启虚拟系统,并选择进入新系统,确认新系统是否安装成功。

$ shutdown -r now
  • 调试:

1. 在真机新内核源码目录下建立一个文件 .gdbinit 内容是

target remote localhost:1234
b start_kernel
#c

注意我把c注释掉是因为ddd和gdb有切换的需要。见”gdb技巧”

2. 用以下命令启动虚拟机

qemu -hda debian.img -cdrom ../debian-testing-i386-CD-1.iso -m 500 -S -s

3. 在真机新内核源码目录下运行

gdb ./vmlinux

[实验记录]

实验过了,.config中不选择kgdb,利用qemu照样能调试。也不能调试start_kernel以前的代码。比如head_32.S中的代码。

CONFIG_HAVE_ARCH_KGDB=y
# CONFIG_KGDB is not set

但是不知CONFIG_HAVE_ARCH_KGDB是在menuconfig菜单的哪里。想试试把这项去了qemu还能不能调试。

经测试,取消CONFIG_HAVE_ARCH_KGDB后,qemu也能进行调试。情况不变。看来qemu能完全脱离内核中的kgdb就能调试内核。

  • 调试截图
步骤2:
XXX@ubuntu:/new/myqemu/debian-x86$ qemu -hda debian.img -cdrom ../debian-testing-i386-CD-1.iso -m 500 -S -s

步骤3:
由下图我们注意到:“基于qemu和qemu内置gdbstub”这个方法的调试,最早只能从函数 start_kernel () 开始进行。
内核在start_kernel ()之前的初始化过程就无法观察了。这就是这个方法的最大缺点。但下节利用skyeye调试arm-linux的
方法就可以从第一个机器指令开始进行。

XXX@ubuntu:/storage/myqemu/new/linux-2.6.26$ gdb ./vmlinux
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
0x0000fff0 in ?? ()
Breakpoint 1 at 0xc037f5ca: file init/main.c, line 535.
(gdb) c
Continuing.

Breakpoint 1, start_kernel () at init/main.c:535
535 {
(gdb)

调试示意图:
给sys_read下断点
(gdb) b sys_read
Breakpoint 2 at 0xc017585e: file fs/read_write.c, line 360.
(gdb)

用快捷键 ctrl+x+2 打开tui,并按c继续运行,而后拦截到sys_read
┌──fs/read_write.c────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│354 { │
│355 struct file *file; │
│356 ssize_t ret = -EBADF; │
│357 int fput_needed; │
│358 │
│359 file = fget_light(fd, &fput_needed); │
B+>│360 if (file) { │
│361 loff_t pos = file_pos_read(file); │
│362 ret = vfs_read(file, buf, count, &pos); │
│363 file_pos_write(file, pos); │
│364 fput_light(file, fput_needed); │
│365 } │
│366 │
│367 return ret; │
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│0xc017585a <sys_read> push %ebp │
│0xc017585b <sys_read+1> mov %esp,%ebp │
│0xc017585d <sys_read+3> push %esi │
B+>│0xc017585e <sys_read+4> mov $0xfffffff7,%esi │
│0xc0175863 <sys_read+9> push %ebx │
│0xc0175864 <sys_read+10> sub $0xc,%esp │
│0xc0175867 <sys_read+13> mov 0x8(%ebp),%eax │
│0xc017586a <sys_read+16> lea -0xc(%ebp),%edx │
│0xc017586d <sys_read+19> call 0xc0175f65 <fget_light> │
│0xc0175872 <sys_read+24> test %eax,%eax │
│0xc0175874 <sys_read+26> mov %eax,%ebx │
│0xc0175876 <sys_read+28> je 0xc01758b1 <sys_read+87> │
│0xc0175878 <sys_read+30> mov 0x24(%ebx),%edx │
│0xc017587b <sys_read+33> mov 0x20(%eax),%eax │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
remote Thread 42000 In: sys_read Line: 360 PC: 0xc017585e
(gdb) c
Continuing.

Breakpoint 2, sys_read (fd=3, buf=0xbfc781a4 "", count=512) at fs/read_write.c:360
(gdb)

arm虚拟调试环境的建立

利用qemu

利用qemu安装debian linux

目标:

本节在qemu虚拟机上安装一个基于arm的“桌面“系统,可以有X桌面,该虚拟系统能利用apt-get从debian的软件库下载数不完的用交 叉编译已经编译好的arm下的程序和工具。除了虚拟处理器是arm外,

简直就是PC机。可以进行应用程序的本机(在虚拟机内进行)调试。但是,本人装的时 候,如果选了安装桌面环境,内核就启动失败,好像是提示文件系统出错。[成功的麻烦把过程贴出来]

过程是:

Debian on an emulated ARM machine http://www.aurel32.net/info/debian_arm_qemu.php

下面是过程的提炼步骤,方便查看。

1.创建虚拟硬盘

$ qemu-img create -f qcow hda.img 40G

2.下载必要文件

$ wget http://people.debian.org/~aurel32/arm-versatile/vmlinuz-2.6.18-6-versatile
$ wget http://people.debian.org/~aurel32/arm-versatile/initrd.img-2.6.18-6-versatile
$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-arm/current/images/rpc/netboot/initrd.gz

2.安装系统

qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.gz -hda hda.img -append "root=/dev/ram" 
在安装过程中,为了节省时间,在这步choose a mirror of the debian archive
选http 回车 ;
debian archive mirror country 选taiwan 回车;
debian archive mirror 选ftp.tw.debian.org

安装好基本系统后,不要选择安装Desktop environment

安装完成后,它提示你把光盘拿掉并重启系统时,终止掉qemu。并用下一步的命令启动qemu.不要回车,否则又重新安装。

3. 第一次启动系统

$ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.img-2.6.18-6-versatile -hda hda.img -append "root=/dev/sda1"

4. 把旧的内核,intrd.img制作工具安装到虚拟机的系统内(操作在虚拟机内)

$ apt-get install initramfs-tools
$ wget http://people.debian.org/~aurel32/arm-versatile/linux-image-2.6.18-6-versatile_2.6.18.dfsg.1-18etch1+versatile_arm.deb
$ su -c "dpkg -i linux-image-2.6.18-6-versatile_2.6.18.dfsg.1-18etch1+versatile_arm.deb"

5.其他更多的玩法请看原文http://www.aurel32.net/info/debian_arm_qemu.php

参考:

Debian ARM Linux on Qemu

http://909ers.apl.washington.edu/~dushaw/ARM/#SYSTEM

Running Linux for ARM processors under QEMU

http://iomem.com/index.php?archives/2-Running-Linux-for-ARM-processors-under-QEMU.html&serendipity[entrypage]=2

Debian on an emulated ARM machine

http://www.aurel32.net/info/debian_arm_qemu.php

利用qemu安装能进行内核调试的系统

[暂时没法子,期待扩展。下面这个例子可以,但没尝试。估计这个方法与下节的利用skyeye的方法相比,没有优势。因为这个方法可能也是不能进行全程调试。

但是下面网站的资料还是有一定参考价值的。]

使用qemu-jk2410做為學習環境:

http://wiki.jk2410.org/wiki/%E4%BD%BF%E7%94%A8qemu-jk2410%E5%81%9A%E7%82%BA%E5%AD%B8%E7%BF%92%E7%92%B0%E5%A2%83

另外:看看下面这个站点,

Firmware Linux: http://landley.net/code/firmware/

利用skyeye

skyeye虚拟机的内核调试

相对于利用qemu的方式,用skyeye虚拟机调试内核有个很重要的

优点是:

调试可以从第一条机器指令开始。这对研究系统启动过程提供了极大的便利。

skyeye的安装与使用

该文非常好,好像没啥要扩充的

SkyEye硬件模拟平台,第二部分: 安装与使用

http://www.ibm.com/developerworks/cn/linux/l-skyeye/part2/

SkyEye User Manual http://www.skyeye.org/wiki/UserManual

http://skyeye.wiki.sourceforge.net/

参考文档:

Linux-2.6.20 on XXX platform

http://skyeye.wiki.sourceforge.net/Linux

uClinux-dist-20070130 on XXX platform

http://skyeye.wiki.sourceforge.net/uClinux

http://www.linuxfans.org/bbs/thread-182101-1-1.html

安装:

1. 安装主程序

在ubuntu系统能进行在线安装,但版本是v1.2,不是最新的

$sudo apt-get install skyeye

2. 测试套件

测试套件下载后解压开即可

地址:http://sourceforge.net/project/showfiles.php?group_id=85554

快速试玩

目的:

尽可能快的成功运行一个arm linux虚拟机。如果您化了很长时间也无法编译出一个能运行的内核,或写不出一个恰当的skyeye.conf时,在你的热情受到打击之前,我想这节是你急需的。

操作步骤:

1.依照上节说明安装好主程序,下载并解压好测试套件

2.进入测试套件的目录 skyeye-testsuite-1.2.5/linux/s3c2410/s3c2410x-2.6.14

可以看到有三个文件initrd.img skyeye.conf vmlinux

3.运行虚拟机

$skyeye -e vmlinux

注意下面的提示,说明平时要注意在启动命令前加上sudo

NOTICE: you should be root at first !!!
NOTICE: you should inmod linux kernel net driver tun.o!!!
NOTICE: if you don‘t make device node, you should do commands:
NOTICE: mkdir /dev/net; mknod /dev/net/tun c 10 200
NOTICE: now the net simulation function can not support!!!
NOTICE: Please read SkyEye.README and try again!!!

4.可以看到,一个2.6.14 版本的linux跑起来了,还带有一个lcd.

快速配置能调试的环境

参考:

http://skyeye.wiki.sourceforge.net/linux_2_6_17_lubbock

环境条件:

1. ubuntu hardy 8.04

2. 安装了debian提供的交叉编译工具套件 arm-linux-gnueabi- (4.2版本)

目标:

这小节能得到基于pxa平台(类似s3c2410,也基于arm核心)的linux2.6.20内核的虚拟系统,具备调试功能。相比“基于qemu 和qemu内置gdbstub”该节,

利用skyeye的调试有那节所没有的优点:调试时可以从内核运行的第一条指令开始[这就是模拟硬件调试?]。

参考手册:

XScale PXA250开发手册 http://soft.laogu.com/download/intelpxa250.pdf

ARMv5 体系结构参考手册 http://www.arm.com/community/university/eulaarmarm.html

操作步骤:

1. 下载linux-2.6.20 (由于交叉编译器太新,如果利用linux-2.6.17则编译不过)

2. 修改文件include/asm-arm/arch-pxa/memory.h 第18行

#define PHYS_OFFSET UL(0xa0000000)

#define PHYS_OFFSET UL(0xc0000000)

3. 下载内核配置选项,放置于linux-2.6.20源码的根目录下 http://skyeye.wiki.sourceforge.net/space/showimage/skyeye_2.6.17_lubbock.config

这个下载好的配置文件已经帮我们做了的两件事

首先,在block device菜单下配置了ramdisk和initrd的支持

其次,把内核原来的启动参数改为

root=/dev/ram0 console=ttyS0 initrd=0xc0800000,0x00800000 rw mem=64M

4. 把下载到的skyeye_2.6.17_lubbock.config更名为.config

5. 编译内核

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

6. 创建文件 skyeye.conf,内容如下:

cpu: pxa25x
mach: pxa_lubbock
mem_bank: map=I, type=RW, addr=0x40000000, size=0x0c000000
mem_bank: map=M, type=RW, addr=0xc0000000, size=0x00800000
mem_bank: map=M, type=RW, addr=0xc0800000, size=0x00800000, file=./initrd.img
mem_bank: map=M, type=RW, addr=0xc1000000, size=0x00800000
mem_bank: map=M, type=RW, addr=0xc1800000, size=0x02800000

7. 从skyeye的测试套件中拷贝initrd.img到linux-2.6.20源码根目录下。该initrd.img的路径是:

skyeye-testsuite-1.2.5/linux/pxa/2.6.x/

8. 运行内核看看,在linux-2.6.20源码根目录下运行下面的命令。可以看到,内核成功运行

sudo skyeye -e vmlinux

调试:

1. 在linux-2.6.20源码根目录下运行命令:

sudo skyeye -d -e vmlinux  

2. 在源码根目录下新开一个终端,并运行:

arm-linux-gnueabi-gdb ./vmlinux

gdb界面出来后

(gdb) target remote:12345

之后可以看到,下断点,查看汇编等一切调试功能和x86下都一样。

3. ddd下如何调用arm-linux-gnueabi-gdb ? 答

$ ddd --debugger arm-linux-gnueabi-gdb ./vmlinux
为s3c2410配置2.6.26内核

[启动过程中有若干错误提示,但内核能启动成功并运行。有待研究]

目标:

得到一个基于s3c2410cpu的2.6.26最新稳定内核的虚拟系统,能进行全程的内核调试,即调试能从第一条机器指令开始进行。

参考:

http://skyeye.wiki.sourceforge.net/Linux

http://www.linuxfans.org/bbs/thread-182101-1-1.html

环境条件:

1. ubuntu hardy 8.04

2. 安装了debian提供的交叉编译工具套件 arm-linux-gnueabi- (4.2版本)

操作步骤:

1.依据“安装交叉编译工具”这节,安装好交叉编译工具

2.修改源码

将include/asm-arm/arch-s3c2410/map.h里的
#define S3C2410_CS6 (0x30000000)
改为
#define S3C2410_CS6 (0xc0000000)

将include/asm-arm/arch-s3c2410/memory.h里的
#define PHYS_OFFSET UL(0x30000000)
改为
#define PHYS_OFFSET UL(0xc0000000)

3.把默认.config替换为s3c2410版本

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- s3c2410_defconfig

3.修改配置文件

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
进入[Device Driver] ->[ Character Driver] -> [Serial Driver] 等菜单下 ,
取消8250/16550 and compatible serial support的选择

4.修改内核启动命令

在Boot option --> Default kernel command string 里输入
mem=32M console=ttySAC0 root=/dev/ram initrd=0xc0800000,0x00800000 ramdisk_size=2048 rw

5.编译

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

6.从skyeye的测试套件中拷贝相应的文件initrd.img和skyeye.conf到linux-2.6.26源码根目录下。这两个文件的位于

skyeye-testsuite-1.25/linux/s3c2410/s3c2410x-2.6.14/中

7.启动虚拟机

XXX@ubuntu:~/dt/linux-2.6.26$ sudo skyeye -e vmlinux

8.启动完成后那激动人心的logo如下

Welcome to
_ _____ __ __ _ _
/ \ / __ \ / \_/ \ | | |_|
/ _ \ | | | | / /\ /\ \ | | _ ____ _ _ _ _
/ /_\ \ | |__| | / / \_/ \ \| | | | _ \| | | |\ \/ /
/ /___\ \ | |__\ \ | | | || |___ | | |_| | |_| |/ \
/_/ \_\| | \_\|_| |_||_____||_|_| |_|\____|\_/\_/

ARMLinux for Skyeye
For further information please check:
http://www.skyeye.org/



BusyBox v1.4.1 (2007-02-10 01:19:06 CST) Built-in shell (ash)
Enter ‘help‘ for a list of built-in commands.

/bin/ash: can‘t access tty; job control turned off
/ $ uname -a
Linux skyeye 2.6.26 #2 Sun Oct 5 19:56:57 CST 2008 armv4tl unknown
/ $

调试:

1. 在linux-2.6.26源码根目录下新建文件”.gdbinit”,内容是:

(gdb) target remote:12345

2. 在linux-2.6.26源码根目录下命令:

sudo skyeye -d -e vmlinux  

3. 在源码根目录下新开一个终端,并运行:

arm-linux-gnueabi-gdb ./vmlinux

之后可以看到,下断点,查看汇编等一切调试功能和x86下都一样。

4. ddd下如何调用arm-linux-gnueabi-gdb ? 答

$ ddd --debugger arm-linux-gnueabi-gdb ./vmlinux

截图:

步骤2:
XXX@ubuntu:~/桌面/test/linux-2.6.26_s3c2410$ sudo skyeye -d -e vmlinux
big_endian is false.
arch: arm
cpu info: armv4, arm920t, 41009200, ff00fff0, 2
mach info: name s3c2410x, mach_init addr 0x805f030
lcd_mod:1
dbct info: Note: DBCT not compiled in. This option will be ignored
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm920t mmu ops
Loaded RAM ./initrd.img
start addr is set to 0xc0008000 by exec file.
debugmode= 1, filename = skyeye.conf, server TCP port is 12345
------------------------
步骤3:
fqh@ubuntu:~/桌面/test/linux-2.6.26_s3c2410$ arm-linux-gnueabi-gdb vmlinux
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i486-linux-gnu --target=arm-linux-gnueabi"...
stext () at arch/arm/kernel/head.S:80
80 msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE @ ensure svc mode
Current language: auto; currently asm
(gdb) source extendinstr //载入辅助的gdb宏
--------------
用快捷键 ctrl+x+2 打开tui模式后的图示,可看到调试是从第一条指令开始的。这对研究系统启动过程提供了极大的便利。
┌──arch/arm/kernel/head.S────────────────────────────────────────────────────────────────────────────┐
>│80 msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE @ ensure svc mode │
│81 @ and irqs disabled │
│82 mrc p15, 0, r9, c0, c0 @ get processor id │
│83 bl __lookup_processor_type @ r5=procinfo r9=cpuid │
│84 movs r10, r5 @ invalid processor (r5=0)? │
│85 beq __error_p @ yes, error ‘p‘ │
│86 bl __lookup_machine_type @ r5=machinfo │
│87 movs r8, r5 @ invalid machine (r5=0)? │
│88 beq __error_a @ yes, error ‘a‘ │
│89 bl __vet_atags │
│90 bl __create_page_tables │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘
>│0xc0008000 <stext> msr CPSR_c, #211 ; 0xd3 │
│0xc0008004 <stext+4> mrc 15, 0, r9, cr0, cr0, {0} │
│0xc0008008 <stext+8> bl 0xc00082f8 <__lookup_processor_type> │
│0xc000800c <stext+12> movs r10, r5 │
│0xc0008010 <stext+16> beq 0xc0008190 <__error_p> │
│0xc0008014 <stext+20> bl 0xc0008358 <__lookup_machine_type> │
│0xc0008018 <stext+24> movs r8, r5 │
│0xc000801c <stext+28> beq 0xc00081e8 <__error_a> │
│0xc0008020 <stext+32> bl 0xc00083a0 <__vet_atags> │
│0xc0008024 <stext+36> bl 0xc0008078 <__create_page_tables> │
│0xc0008028 <stext+40> ldr sp, [pc, #240] ; 0xc0008120 <__switch_data> │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘
remote Thread 42000 In: stext Line: 80 PC: 0xc0008000
(gdb) b sys_read //下断点
Breakpoint 1 at 0xc008cc4c: file fs/read_write.c, line 354.
(gdb) c

----------------
调试示意图
效果可能与你机器上看到的不一样。这个例子中,每个gdb单步指令都会自动显示backtrace。这是因为本人使用了章节“gdb宏”中的extendinstr宏。
┌──include/asm/thread_info.h──────────────────────────────────────────────────────────────────────────────────────────────┐
│91 */ │
│92 static inline struct thread_info *current_thread_info(void) __attribute_const__; │
│93 │
│94 static inline struct thread_info *current_thread_info(void) │
│95 { │
│96 register unsigned long sp asm ("sp"); │
>│97 return (struct thread_info *)(sp & ~(THREAD_SIZE - 1)); │
│98 } │
│99 │
│100 /* thread information allocation */ │
│101 #ifdef CONFIG_DEBUG_STACK_USAGE │
│102 #define alloc_thread_info(tsk) \ │
│103 ((struct thread_info *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, \ │
│104 THREAD_SIZE_ORDER)) │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
│0xc008d480 <fget_light> mov r12, sp │
│0xc008d484 <fget_light+4> push {r11, r12, lr, pc} │
│0xc008d488 <fget_light+8> sub r11, r12, #4 ; 0x4 │
│0xc008d48c <fget_light+12> bic r3, sp, #8128 ; 0x1fc0 │
>│0xc008d490 <fget_light+16> bic r3, r3, #63 ; 0x3f │
│0xc008d494 <fget_light+20> ldr r3, [r3, #12] │
│0xc008d498 <fget_light+24> mov r12, #0 ; 0x0 │
│0xc008d49c <fget_light+28> ldr r2, [r3, #560] │
│0xc008d4a0 <fget_light+32> str r12, [r1] │
│0xc008d4a4 <fget_light+36> ldr r3, [r2] │
│0xc008d4a8 <fget_light+40> cmp r3, #1 ; 0x1 │
│0xc008d4ac <fget_light+44> bne 0xc008d4d0 <fget_light+80> │
│0xc008d4b0 <fget_light+48> ldr r2, [r2, #4] │
│0xc008d4b4 <fget_light+52> ldr r3, [r2] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
remote Thread 42000 In: fget_light Line: 97 PC: 0xc008d490

Program received signal SIGHUP, Hangup.
0xc008d490 in fget_light (fd=1, fput_needed=0xc1c17ed4) at include/asm/thread_info.h:97
-------------------
#0 0xc008d490 in fget_light (fd=1, fput_needed=0xc1c17ed4) at include/asm/thread_info.h:97
#1 0xc008cc5c in sys_read (fd=1, buf=0xc1196800 "", count=512) at fs/read_write.c:359
#2 0xc000ac7c in rd_load_image (from=0xc02b43bc "/initrd.image") at init/do_mounts_rd.c:108
#3 0xc000bbe8 in initrd_load () at init/do_mounts_initrd.c:121
#4 0xc00094c0 in prepare_namespace () at init/do_mounts.c:384
#5 0xc0008a9c in kernel_init (unused=<value optimized out>) at init/main.c:878
#6 0xc0048484 in sys_waitid (which=<value optimized out>, upid=-1044283692, infop=0x0, options=0, ru=Cannot access memory at
address 0x4
) at kernel/exit.c:1689
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)
使用最新的skyeye

1. 新版本的改进

在ubuntu下利用在线安装命令所安装的skyeye是旧的版本,新版本修正了旧版本的一些小问题。比如,旧版本在调试时会出现下面一些烦人的小提示。

Can‘t send signals to this remote system.  SIGHUP not sent.

Program received signal SIGHUP, Hangup.

但是,两个版本并不是完全兼容的,主要是skyeye.conf的处理上。不过,幸好这些都是很容易解决的问题。

2. 新版本的安装

http://sourceforge.net/project/showfiles.php?group_id=85554

到上面的网站下载最新版本,目前是skyeye-1.2.6_rc1。解压后用下面命令编译就可以了

$./configure
$ make STATIC=1

然后把在源码根目录下生成的skyeye拷到内核目录下运行即可。这样系统中的老版本skyeye还照样可以使用。

sudo ./skyeye -d -e vmlinux

3. 新老版本的兼容问题

主要是skyeye.conf的格式识别上。老版本要求load_address,load_address_mask不能写在 skyeye.conf文件内部,只能用-l选项指定。如果运行老版本时提示skyeye.conf出错,

你就得去查查那里,并手动修改处理一下即可。

arm开发板调试环境的建立

基于串口

为qq2440平台移植2.6.26或更新内核,并建立kgdb调试环境

进行中...

[移植中的一些零碎的笔记]

1.内核版本

使用linus的git,但是已知2.6.25中arm已经支持kgdb了。

XXX@ubuntu:/storage/linus-git/linux-2.6$ git-describe 
v2.6.27-rc9-2-g85ba94b

2.

arm体系的默认配置文件在
arch/arm/configs

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- s3c2410_defconfig

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
选取以下选现
CONFIG_DEBUG_INFO=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

移植环境

windows:硬盘安装的真实系统(XP)
ubuntu: 运行在windows下的vmware虚拟机中
qq2440开发板:真实开发板,IP是192.168.1.230

第一天:(完成)
熟悉开发板,PC机,虚拟机的网络互连
理解内核启动过程

开发板与PC机(XP)PING不通的原因有

1. PC机开着防火
2. PC机上的VMWARE的网络设置有问题(先卸载确认)
3. 安全类软件造成,比如卡巴司机(先卸载,不行重装系统)


ubuntu的网络配置分两种情况,一种是平时上网用的,一种是和开发板通讯用的。


平时使用虚拟机ubuntu上网的配置:

连接方式选出NAT: used to share the host‘s IP address
虚拟系统启动后,桌面右上角的
wired connection->properties->configuration选automatic configuration(DHCP)



开发板挂载ubuntu虚拟系统中的nfs

1.虚拟机本身的网络设置不用动

2.虚拟系统如ubuntu的网卡设置改为桥接
edit virtual machine settings->virtual machine setting->hardware->ethernet
->bridged:connected directly to the physical network

3.虚拟系统启动后,桌面右上角的manual network configuration要改.
点左键->network settings->wired connection->properties:enable roaming mode不选,
connection settings
configuration:static IP address
IP address:192.168.1.111 与PC机IP,开发板IP同个网段
subnet mask:255.255.255.0
gateway address:空

PC机网络信息:

Ethernet adapter 本地连接:

Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.100
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

开发板的网络信息:

[root@(none) /]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:3E:26:0A:5B
inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1011 errors:0 dropped:0 overruns:0 frame:0
TX packets:610 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:111858 (109.2 KiB) TX bytes:57276 (55.9 KiB)
Interrupt:53 Base address:0x300

windows打开ubuntu中的samba共享目录的方法

\\192.168.1.111


ubuntu中nfs服务的安装和启用

$ sudo apt-get install nfs-common
$ sudo apt-get install nfs-kernel-server


$ sudo vi /etc/exports
/new/root_nfs *(rw,sync)

$ sudo /etc/init.d/nfs-kernel-server start

4. 檢查

$ showmount -e localhost
开发板挂载nfs成功后可看到显示结果是
All mount points on localhost:
192.168.1.230:/new/root_nfs


开发板挂载ubuntu中的nfs
(此时运行的文件系统还是在开发板上)

mount -t nfs -o nolock 192.168.1.111:/new/root_nfs /tmp/fuck

192.168.1.111:ubuntu的IP
/tmp/fuck:开发板中的挂载点


[root@(none) /]# mount -t nfs -o nolock 192.168.1.111:/new/root_nfs /tmp/fuck
[root@(none) /]# cd /tmp/fuck/
[root@(none) fuck]# ls
bin lib proc usr
dev linuxrc sbin var
etc mnt shanghaitan.mp3 www
home opt tmp
-----

通过nfs启动开发板
(挂载的文件系统是在ubuntu虚拟系统上)

下面文字来自于:Embedded Linux Primer: A Practical, Real-World Approach

ip=192.168.1.139:192.168.1.1:192.168.1.1:255.255.255.0:coyote1:eth0:off
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<PROTO>

Here, client-ip is the target‘s IP address; server-ip is the address of the NFS server; gw-ip is the gateway (router), in case the server-ip is on a different
subnet; and netmask defines the class of IP addressing. hostname is a string that is passed as the target hostname; device is the Linux device name, such as eth0;
and PROTO defines the protocol used to obtain initial IP parameters.

本人的实际操作的命令参数是:

param set linux_cmd_line
"console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.111:/new/root_nfs ip=192.168.1.130:192.168.1.111:192.168.1.111:255.255.255.0:sbc2440.arm9.net:eth0:off"

注意把编辑器的换行功能去掉后,再复制上面的命令。

192.168.1.130是开发板的IP,系统启动后,用ifconfig就会显示这个IP地址。可以随意设置,当然要满足和PC机,ubuntu的IP在同个网段,而且不能冲突的先前条件。

130:192.168.1.111:nfs的server,也就是ubuntu的IP
按住空格健重启开发板,出现:

+---------------------------------------------+
| S3C2440A USB Downloader ver R0.03 2004 Jan |
+---------------------------------------------+
USB: IN_ENDPOINT:1 OUT_ENDPOINT:3
FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>
NOTE: Power off/on or press the reset button for 1 sec
in order to get a valid USB device address.

NAND device: Manufacture ID: 0xec, Chip ID: 0x76 (Samsung K9D1208V0M)
Found saved vivi parameters.
Press Return to start the LINUX/Wince now, any other key for vivi
type "help" for help.
Supervivi> menu

##### FriendlyARM BIOS for 2440 #####
[x] bon part 0 320k 2368k
[v] Download vivi
[k] Download linux kernel
[y] Download root_yaffs image
[c] Download root_cramfs image
[n] Download Nboot
[e] Download Eboot
[i] Download WinCE NK.nb0
[w] Download WinCE NK.bin
[d] Download & Run
[f] Format the nand flash
[p] Partition for Linux
[b] Boot the system
[s] Set the boot parameters
[t] Print the TOC struct of wince
[q] Goto shell of vivi
Enter your selection: s //<--

##### Parameter Menu #####
[r] Reset parameter table to default table
[s] Set parameter
[v] View the parameter table
[w] Write the parameter table to flash memeory
[q] Quit
Enter your selection: s //<--

Enter the parameter‘s name(mach_type, media_type, linux_cmd_line, etc): linux_cmd_line

Enter the parameter‘s value(if

热门排行

今日推荐

热门手游