Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2150588
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2016-10-28 14:36:14

1. 编译工具
现在版本的ubuntu上的gcc编linux-2.4的内核错误太多,想了一个折中的方法:
把redhat9上的gcc-3.34拿出来编译linux-2.4.18就可以了
b. 刚开始下载的内核版本是linux-2.4.12了,后来发现《深入理解linux内核 第二版》指定的内核版本是2.4.18,
所以就换成2.4.18了,反正编译花不了多长是间,轻车熟路。

2. 修改如下
2.1顶层Makefile
ARCH := $(shell uname -m | sed -e s/x86_64/i386/  -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
添加 sed -e s/x86_64/i386/

2.2 指定交叉编译工具链
CROSS_COMPILE = /work/os/bak/gcc/gcc-3.34/bin/

CFLAGS := -g $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O0 \
 -fomit-frame-pointer -fno-strict-aliasing -fno-common

-O2 改为 O0   并添加了 -g
GENKSYMS = /sbin/genksyms
DEPMOD = /sbin/depmod
修改为-->
GENKSYMS = $(CROSS_COMPILE)/sbin/genksyms
DEPMOD = $(CROSS_COMPILE)/sbin/depmod

2.3 
  1. /work/os/linux-2.4.18/include/asm/checksum.h:72:30: missing terminating " character
  2. In file included from ksyms.c:50:
  3. /work/os/linux-2.4.18/include/asm/checksum.h: In function `ip_fast_csum':
  4. /work/os/linux-2.4.18/include/asm/checksum.h:73: error: parse error before "movl"
  5. /work/os/linux-2.4.18/include/asm/checksum.h:75:17: invalid suffix "f" on integer constant
  6. /work/os/linux-2.4.18/include/asm/checksum.h:82:17: invalid suffix "b" on integer constant
  7. /work/os/linux-2.4.18/include/asm/checksum.h:90:13: missing terminating " character
  8. /work/os/linux-2.4.18/include/asm/checksum.h:105:17: missing terminating " character
  9. /work/os/linux-2.4.18/include/asm/checksum.h: In function `csum_fold':
  10. /work/os/linux-2.4.18/include/asm/checksum.h:106: error: parse error before "addl"
  11. /work/os/linux-2.4.18/include/asm/checksum.h:108:17: missing terminating " character
  12. /work/os/linux-2.4.18/include/asm/checksum.h:121:13: missing terminating " character
  13. /work/os/linux-2.4.18/include/asm/checksum.h: In function `csum_tcpudp_nofold':
  14. /work/os/linux-2.4.18/include/asm/checksum.h:122: error: parse error before "addl"
  15. /work/os/linux-2.4.18/include/asm/checksum.h:126:9: missing terminating " character
  16. /work/os/linux-2.4.18/include/asm/checksum.h:161:17: missing terminating " character
  17. /work/os/linux-2.4.18/include/asm/checksum.h: In function `csum_ipv6_magic':
  18. /work/os/linux-2.4.18/include/asm/checksum.h:162: error: parse error before "addl"
  19. /work/os/linux-2.4.18/include/asm/checksum.h:173:17: missing terminating " character
改正:   /work/os/linux-2.4.18/include/asm-i386/checksum.h

2.4
ide-cd.h:438: error: long, short, signed or unsigned used invalidly for `slot_tablelen'
__u8 short slot_tablelen; 
--> unsigned short slot_tablelen; 

2.5
  1. /work/os/bak/gcc/gcc-3.34/bin/gcc -g -D__KERNEL__ -I/work/os/linux-2.4.18/include -Wall -Wstrict-prototypes -Wno-trigraphs -O0 -fomit-frame-pointer -fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2 -march=i686 -DKBUILD_BASENAME=eepro100 -c -o eepro100.o eepro100.c
  2. eepro100.c:87:2: warning: #warning You must compile this file with the correct
  3. eepro100.c:88:2: warning: #warning See the last lines of the source file.
  4. eepro100.c:89:2: #error You must compile this driver with "-O".
改正:
  89 #error You must compile this driver with "-O".
--> 89 #warning You must compile this driver with "-O".


2.6
  1. /work/os/bak/gcc/gcc-3.34/bin/gcc -g -D__KERNEL__ -I/work/os/linux-2.4.18/include -Wall -Wstrict-prototypes -Wno-trigraphs -O0 -fomit-frame-pointer -fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2 -march=i686 -DKBUILD_BASENAME=semaphore -c -o semaphore.o semaphore.c
  2. semaphore.c:241:1: missing terminating " character
  3. semaphore.c:242: error: request for member `align' in something not a structure or union
  4. semaphore.c:242: error: parse error before numeric constant
  5. semaphore.c:248:17: invalid suffix "b" on integer constant
  6. semaphore.c:258: error: parse error before '%' token
  7. semaphore.c:260: warning: type defaults to `int' in declaration of `$1'
  8. semaphore.c:260: error: parse error before '%' token
  9. semaphore.c:261:17: invalid suffix "b" on integer constant
  10. semaphore.c:263: error: parse error before '%' token
  11. semaphore.c:266:1: missing terminating " character
  12. make[1]: *** [semaphore.o] Error 1
将linux-2.4.18/arch/i386/kernel/semaphore.c的最后改成如下形式
  1. #if defined(CONFIG_SMP)
  2. asm(
  3. "\n\t"
  4. ".align    4\n\t"
  5. ".globl    __write_lock_failed\n\t"
  6. "__write_lock_failed:\n\t"
  7. "    " LOCK "addl    $" RW_LOCK_BIAS_STR ",(%eax)\n\t"
  8. "1:    rep; nop\n\t"
  9. " cmpl    $" RW_LOCK_BIAS_STR ",(%eax)\n\t"
  10. "    jne    1b\n\t"
  11. "\n\t"
  12. "    " LOCK "subl    $" RW_LOCK_BIAS_STR ",(%eax)\n\t"
  13. "    jnz    __write_lock_failed\n\t"
  14. "    ret\n\t"

  15. "\n\t"
  16. ".align    4\n\t"
  17. ".globl    __read_lock_failed\n\t"
  18. "__read_lock_failed:\n\t"
  19. "    lock ; incl    (%eax)\n\t"
  20. "1:    rep; nop\n\t"
  21. " cmpl    $1,(%eax)\n\t"
  22. "    js    1b\n\t"
  23. "\n\t"
  24. "    lock ; decl    (%eax)\n\t"
  25. "    js    __read_lock_failed\n\t"
  26. "    ret\n\t"
  27. );
  28. #endif

2.7 
/work/os/bak/gcc/gcc-3.34/bin/ld -m elf_i386  -r -o kernel.o process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o pci-dma.o i386_ksyms.o i387.o bluesmoke.o dmi_scan.o pci-i386.o pci-pc.o pci-irq.o smp.o smpboot.o trampoline.o mpparse.o apic.o nmi.o io_apic.o acpitable.o
trampoline.o: file not recognized: File format not recognized
这是因为我的交叉编译工具链没有完全弄好,对于*.S的文件,它会用原系统中的as工具
  1. /work/os/bak/gcc/gcc-3.34/bin/gcc -D__ASSEMBLY__ -D__KERNEL__ -I/work/os/linux-2.4.18/include -traditional -c arch/i386/kernel/entry.-o entry.--verbose
  2. as --Qy -o entry.o /tmp/cckGi4Jo.s
  3. GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24
所以只好手动编译了:
手动编译 --> arch/i386/kernel/entry.S
手动编译 --> arch/i386/kernel/trampoline.S
手动编译--> arch/i386/kernel/head.S 
手动编译--> arch/i386/lib/checksum.S

2.8
/work/os/linux-2.4.18/arch/i386/lib/usercopy.c:47: undefined reference to `prefetch'
/work/os/linux-2.4.18/include/asm-i386/processor.h
extern inline void prefetch(const void *x) --->
static inline void prefetch(const void *x)


2.9
/work/os/linux-2.4.18/net/sunrpc/xdr.c:95: undefined reference to `ntohl'
/work/os/linux-2.4.18/include/linux/byteorder/generic.h

#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
--> 
//modify by wangcong
//#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
#if defined(__GNUC__) && (__GNUC__ >= 2) 

2.10
/work/os/linux-2.4.18/net/sunrpc/xprt.c:241: undefined reference to `xprt_move_iov'

/work/os/linux-2.4.18/net/sunrpc/xprt.c
extern inline void
xprt_move_iov(struct msghdr *msg, struct iovec *niv, unsigned amount)
-->static inline void
xprt_move_iov(struct msghdr *msg, struct iovec *niv, unsigned amount)

2.11
net/network.o(.text+0x652f5):/work/os/linux-2.4.18/net/unix/garbage.c:268: undefined reference to `maybe_unmark_and_push'
unix_release_addr -->net/packet/af_packet.c
fn_flush_list --> net/ipv4/fib_hash.c
before --> include/net/tcp.h
after --> include/net/tcp.h
tcp_replace_ts_recent --> net/ipv4/tcp_input.c
sockfd_put --> net/socket.c
socki_lookup -->net/socket.c
ipc_lock -->ipc/util.h
SBI --> fs/devpts/devpts_i.h 
tcpdiag_rcv_skb -->net/ipv4/tcp_diag.c
rotate_left -->drivers/char/random.c
rtnetlink_rcv_skb -->net/core/rtnetlink.c
tcp_need_reset -->net/ipv4/tcp.c
还有一些没有添加的

2.12. /work/os/linux-2.4.18/include/linux/brlock.h:87: undefined reference to `__br_lock_usage_bug'

/work/os/linux-2.4.18/include/linux/brlock.h
extern void __br_lock_usage_bug (void);
-->//modify by wangcong
static inline void __br_lock_usage_bug (void)
{
printk("cong: __BRLOCK_USE_ATOMICS\n");
return ;
}


include/asm/fixmap.h
extern void __this_fixmap_does_not_exist(void);
-->//modify by wangcong
static inline void __this_fixmap_does_not_exist(void)
{
printk("cong: __this_fixmap_does_not_exist\n");
}

2.13.
/work/os/linux-2.4.18/net/ipv4/af_inet.c:839: undefined reference to `__get_user_4'
arch/i386/lib/getuser.S 手动编译
arch/i386/boot/compressed/head.S 手动编译


2.14
tools/build -b bbootsect bsetup compressed/bvmlinux.out CURRENT > bzImage
Root device is (8, 8)
./Makefile 
export ROOT_DEV = CURRENT -->
export ROOT_DEV = 
arch/i386/boot/tools/build.c 
 42 #define DEFAULT_MAJOR_ROOT 0
 43 #define DEFAULT_MINOR_ROOT 0
-->
 42 #define DEFAULT_MAJOR_ROOT 0x03
 43 #define DEFAULT_MINOR_ROOT 0x01


2.15 现在编译成功了,运行时出现Kernel panic: I have no root and I want to scream
/work/os/linux-2.4.18/fs/super.c --> mount_root 的开始添加 ROOT_DEV = 0x301;

2.16 用qemu运行完美
a. qemu 进行内核调试

b. 启动运行busybox ls 正常


2.17 用bochs调试
如果在编译的最扣出现 kernel is too big for standalone boot, 说明内核太大了不支持从软盘单独启动,解决方法有两个
a. 制作grub引导的硬盘镜像,将bzImage放在硬盘分区中
b. 裁减内核到小于 960K就可以了

附录1. 编译流程
  1. cong@msi:/work/os/linux-2.4.18$ make config
  2. cong@msi:/work/os/linux-2.4.18$ ./mycompile.sh      -->先手动编译一下
  3. cong@msi:/work/os/linux-2.4.18$ make -j8 bzImage    -->会出现entry.S编译不正确
  4. cong@msi:/work/os/linux-2.4.18$ ./mycompile.sh      -->没关系再执行一下手动编译
  5. cong@msi:/work/os/linux-2.4.18$ make -j8 bzImage    -->这次就正常了

附2:手动编译脚本
  1. cong@msi:/work/os/linux-2.4.18$ cat mycompile.sh
  2. #!/bin/sh
  3. GCC_PATH=/work/os/bak/gcc/gcc-3.34
  4. CC=$GCC_PATH/bin/gcc
  5. CC1=$GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/cc1
  6. AS=$GCC_PATH/bin/as
  7. SRC=`pwd`
  8. make_module()
  9. {
  10. echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/work/os/bak/gcc/gcc-3.34/lib/"
  11. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/work/os/bak/gcc/gcc-3.34/lib/
  12. #$CC -D__ASSEMBLY__ -D__KERNEL__ -I$SRC/include -traditional -c arch/i386/kernel/entry.S -o entry.o --verbose
  13. echo "make----> arch/i386/kernel/entry.o"
  14. $CC1 -E -traditional-cpp -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ arch/i386/kernel/entry.S -o /tmp/entry.s
  15. $AS -V -Qy -o entry.o /tmp/entry.s
  16. cp ./entry.o ./arch/i386/kernel/entry.o
  17. rm /tmp/entry.s

  18. echo "make ----> arch/i386/kernel/trampoline.o"
  19. $CC1 -E -traditional-cpp -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ ./arch/i386/kernel/trampoline.S -o /tmp/trampoline.s
  20. $AS -V -Qy -o trampoline.o /tmp/trampoline.s
  21. cp ./trampoline.o ./arch/i386/kernel/trampoline.o
  22. rm /tmp/trampoline.s

  23. echo "make ----> arch/i386/kernel/head.o"
  24. $CC1 -E -traditional-cpp -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ ./arch/i386/kernel/head.S -o /tmp/head.s
  25. $AS -V -Qy -o head.o /tmp/head.s
  26. cp ./head.o ./arch/i386/kernel/head.o
  27. rm /tmp/head.s

  28. echo "make ----> arch/i386/lib/checksum.o"
  29. $CC1 -E -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ ./arch/i386/lib/checksum.S -o /tmp/checksum.s
  30. $AS -V -Qy -o checksum.o /tmp/checksum.s
  31. cp ./checksum.o ./arch/i386/lib/checksum.o
  32. rm /tmp/checksum.s

  33. echo "make ----> arch/i386/lib/getuser.o"
  34. $CC1 -E -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ arch/i386/lib/getuser.S -o /tmp/getuser.s
  35. $AS -V -Qy -o getuser.o /tmp/getuser.s
  36. cp ./getuser.o ./arch/i386/lib/getuser.o
  37. rm /tmp/getuser.s

  38. echo "make ----> arch/i386/boot/compressed/head.o"
  39. $CC1 -E -traditional-cpp -lang-asm -quiet -v -I$SRC/include -iprefix $GCC_PATH/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D__ASSEMBLY__ -D__KERNEL__ arch/i386/boot/compressed/head.S -o /tmp/head.s
  40. $AS -V -Qy -o head.o /tmp/head.s
  41. cp ./head.o ./arch/i386/boot/compressed/head.o
  42. rm /tmp/head.s
  43. }

  44. make_sched()
  45. {
  46.     #02-->ok O0-->bad
  47.     #change the CFLAGS at kernle/Makefile
  48.     echo "make --> kernel/sched.c "
  49.     $CC -g -D__KERNEL__ -I$SRC/include -Wall -Wstrict-prototypes -Wno-trigraphs -O1 -fomit-frame-pointer -fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2 -march=i686 -c -o kernel/sched.o kernel/sched.c
  50. }

  51. case "$1" in
  52.     *)
  53.         make_module
  54.         ;;
  55. esac

附录2. 下面将生成的patch打包
diff -Nur linux-2.4.18 linux-2.4.18_grep > linux-2.4.18-patch.txt
tar czf linux-2.4.18-patch.rar ./linux-2.4.18-patch.txt
 linux-2.rar (下载后改名为linux-2.4.18.patch.tar.gz)


阅读(2038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~