Gcc-2.95.3的编译安装及编译Linux-2.6.10
由于毕设的缘故,需要对Linux下的驱动开发有一定的了解,所以决定研究一下Linux设备驱动程序,这本经典的book。
首先建立试验的环境,我使用Fedora9的虚拟机,自带的gcc版本时4.3.0,内核版本是2.6.25。书中提到所基于的是2.6.10的内核,为了避免以后可能遇到的问题,打算在虚拟机编译一个2.6.10的内核,从kernel.org下载到了linux-2.6.10.tar.bz2,查看Documentation/Changes文件,发现需要的编译器版本是经典的gcc-2.95.3,所以首先安装这个版本的编译器。
cd /home/xdl2007;
tar xvf gcc-2.95.3
mkdir -v /home/xdl2007/gcc-build
从http://www.linuxfromscratch.org/patches/downloads/gcc这个地方下载所需要的补丁,共7个,放在gcc-patch中。
cd gcc-build
../gcc-2.95.3/configure --prefix=/usr/local/gcc-2.95.3 --enable-shared --with-gnu-as --with-gnu-ld --disable-threads --enable-languages=c,c++
cd gcc-2.95.3
make && make install
等装完之后,可以改一下gcc的名字,改为gcc-2.95.3,然后把路径加入到PATH中,重新登录即可。
--disable-threads:不用打补丁了
现在就可以用gcc-2.95.3来编译linux-2.6.10了,首先下载到源码包,然后解压,
make menuconfig
make
make modules
make modules_install
make install
编译中遇到的问题:
(1)首先由于binutils中的as版本不同,如果直接编译就会出现一大堆
{standard input}: Assembler messages:
{standard input}:3233: Error: suffix or operands invalid for `mov'
{standard input}:3238: Error: suffix or operands invalid for `mov'
{standard input}:3727: Error: suffix or operands invalid for `mov'
{standard input}:3732: Error: suffix or operands invalid for `mov'
{standard input}:3882: Error: suffix or operands invalid for `mov'
{standard input}:3883: Error: suffix or operands invalid for `mov'
{standard input}:4137: Error: suffix or operands invalid for `mov'
{standard input}:4142: Error: suffix or operands invalid for `mov'
{standard input}:4156: Error: suffix or operands invalid for `mov'
{standard input}:4172: Error: suffix or operands invalid for `mov'
make[2]: *** [arch/i386/kernel/process.o] 错误 1
之类的错误,可以下载http://www.kernel.org/pub/linux/devel/binutils/linux-2.6-seg-5.patch
补丁来解决
相关资料如下:
The new i386/x86_64 assemblers no longer accept instructions for moving
between a segment register and a 32bit memory location, i.e.,
movl (%eax),%ds
movl %ds,(%eax)
To generate instructions for moving between a segment register and a
16bit memory location without the 16bit operand size prefix, 0x66,
mov (%eax),%ds
mov %ds,(%eax)
should be used. It will work with both new and old assemblers. The
assembler starting from 2.16.90.0.1 will also support
movw (%eax),%ds
movw %ds,(%eax)
without the 0x66 prefix. Patches for 2.4 and 2.6 Linux kernels are
available at
http://www.kernel.org/pub/linux/devel/binutils/linux-2.4-seg-4.patch
http://www.kernel.org/pub/linux/devel/binutils/linux-2.6-seg-5.patch
(2)打过补丁就可以编译了,但是编译好之后重启遇到了这个错误。
Volume group "VolGroup00" not found
Unalbe to access resume device (/dev/VolGroup00/LogVol00)
mount: could not find filesystem '/dev/root'
setuproot:moving /dev failed: No such file or directory
setuproot:error mounting /proc: No such file or directory
setuproot:error mounting /sys: No such file or directory
switchroot: mount failed: No such file or directory
到这里就卡住了,无解,从网上找到这段话
//-------------------------------
前段时间也遇到和lz类似的问题,出现这种情况可能是有以下几个原因:
1.编译内核时未添加相应的硬件支持,比如对于SCSI或IDE硬盘的支持,这些硬件驱动都是以模块的形式编译进内核。
2.编译时的选项不正确对LVM,RAID的支持应该是以模块的形式编译进内核,而不是Built-in,否则可能就会出现lz所说的情况。
建议楼主用cpio解压你的initrd-2.6.31.4-*.img,检查一下解压后的lib目录里是否有相应的支持LVM的内核模块,如果没有,那就是编译时内核选项不正确,需要重新编译了。
//--------------------------------
我使用的是默认配置,重新编译时把make menuconfig => Device Drivers => Mutil-device support(RAID and LVM)
select <Y> lvm这个模块没有载入,这样重新进行编译
(3)在make install时发现有这些warnning
WARNING: No module ehci-hcd found for kernel 2.6.10, continuing anyway
WARNING: No module ohci-hcd found for kernel 2.6.10, continuing anyway
WARNING: No module uhci-hcd found for kernel 2.6.10, continuing anyway
先不管他。
(4)重启之后,发现依然进入去系统,不过这次的错误不是先前的了,出现了
kernel panic -not syncing: vfs :unable to mount root fs on unknown
//----------------------------
通常这种现像是由於内核在启动的时候,加载根文件系统但不成功而引起的,原因很多,如:
1. 文件系统不被内核支持
2. 需要 initrd 但不存在或路径不符
3. 在 menu.lst 指定的根文件系统不存在
4. 内核挂载根文件系统的时候,文件系统还未能被系统识别,这种情况最常见於移动硬盘上装 Linux
//----------------------------
block(0,0)怀疑内核编译是没有添加相应的硬件模块。
编译内核时要注意的问题:
1.首先拷贝arch/i386下的defconfig到编译目录重新命名为.config,cp arch/i386/defconfig ./.config
2.make menuconfig
这个时候要注意根据你的硬件选择对应的硬件驱动,主要是驱动的问题。
a.Loadable Module support->enable loadable module support (Y)
Module unloading(Y)
Automatic kernel module loading(Y)
b.Device Driver->Multi-device support(RAID and LVM)(Y)->Device mapper suport(Y)
DD->Block devices->Loopback device support(y)
DD->Graphics support-> Support for frame buffer devices(Y)
DD->USB support ->USB Mass Storage support(Y)
DD->Network device support ->AMD PCNet PCI support
DD->SCSI device support->legacy /proc/scsi/ support
SCSI disk support
SCSI generic support
->SCSI low-level drivers->Serial ATA (SATA) support(Y)
c.FileSystems->ext2/ext3全选
3.但是重新编译之后,还是那个问题,纠结,应该是内核配置的问题,但是我用Fedora9 boot文件夹下的config文件作为默认的.config编译仍然不能启动,最有我发现在LDD第一章节里面有这么一段话:
“如果想要学习驱动程序的编写,标准内核是最好的。不管内核来自哪里,要想为2.6.x内核构造模块,还必须在自己的系统中配置并构造好内核树。这一要求和先前版本的内核不同,先前的内核只需要一套内核头文件就够了。但因为2.6内核的模块要和内核源代码树中的目标文件连接,通过这种方式,可得到一个更加健壮的模块装载器,但也需要这些目标文件存在于内核目录树中。”
也就是说,我们可以在任何一个发行版中,构建一个和当前使用的内核相同版本的源码树,构造一个新的内核,然后安装到自己的系统中。(如果在构造内核时运行的恰好是目标内核,则开发工作就会非常轻松,当然,这并不是必须的)
所以我决定,在我的Ubuntu10.04主机中在做实验,放弃了虚拟机。
参考:http://hi.baidu.com/%B2%A4%B2%CB%B1%F9%B1%F9/blog/item/ae1619ec46fc36da2f2e215a.html
http://blog.csdn.net/subfate/archive/2011/03/25/6277967.aspx