日期:2014-05-16  浏览次数:20854 次

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 => M