内核移植之Part1

 

 一知识要点:

1. 内核打补丁,编译,UBOOT烧写实验

2. 内核功能,目录结构内核菜单,驱动直接编译进内核和模块概念,结合Makefile,Kconfig分析

3. 内核的启动过程分析

   3.1 内核生成过程解析

   3.2 内核解压缩、 vmlinux启动流程(难,大致了解流程)

   3.3 机器ID的比较

   3.4 UBOOT参数传递的启动参数解析

   3.5 start_kernel()的典型过程

           setup_arch()

           rest_init()

           驱动加载过程

           根文件系统挂载,第一个应用程序init的执行 

.内核的编译过程

编译:

1. make distclean (彻底清除所有编译过程中产生的依赖和目标问题,不是每次都做)

2.准备内核配置.config

make fs2410_defconfig

   实际效果arch/arm/configs/fs2410_defconfig ====> .config

3. 编辑内核根目录下的Makefile,添加体系结构和交叉工具链定义

  ARCH            ?=arm

  CROSS_COMPILE   ?=arm-linux-gnu-

 也可以临时指定的方式: make ARCH=arm CROSS_COMPILE=arm-linux-gnu- fs2410_defconfig

4.配置内核

  linux-2.6.22.6$ make menuconfig

    System Type  --->  ARM system type (Samsung S3C2410)  ---> 

    菜单中: * :直接编译进内核   M: 不直接编译进内核, XXX.ko, 目标板上: insmod xxxx.ko

    exit &save  (写入.config)

make menuconfig的深入分析:

make menuconfig实际执行:

scripts/kconfig/mconf arch/arm/Kconfig

#

# using defaults found in .config

#

kernelMakefileKconfig的规则: kbuild

#

# Ethernet (10 or 100Mbit)

#

CONFIG_NET_ETHERNET=y

CONFIG_MII=y

CONFIG_CIRRUS=y

CONFIG_DM9000=y

# CONFIG_SMC91X is not set

Kconfig的语法规则

 参考 Documentation\kbuild

drivers/media/video/Kconfig 是一个好的例子

 

.config的作用

1.控制内核中某个文件或者目录是否编译进内核

2.编译过程中生成include/linux/autoconf.h, 通过这个autoconf.h控制我们内核中的.c文件某一块代码是否编译进内核

5.内核的编译:

make uImage

make uImage V=1 (显示详细信息)

make uImage V=1 2>&1 |tee compile_log.txt (显示详细信息并记录编译过程到compile_log.txt

三、内核的生成过程

arm-linux-gnu-ld -EL  -p --no-undefined -X -o vmlinux -T arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o arch/arm/kernel/init_task.o  init/built-in.o --start-group  usr/built-in.o  arch/arm/kernel/built-in.o  arch/arm/mm/built-in.o  arch/arm/common/built-in.o  arch/arm/mach-s3c2410/built-in.o  arch/arm/nwfpe/built-in.o  kernel/built-in.o  mm/built-in.o  fs/built-in.o  ipc/built-in.o  security/built-in.o  crypto/built-in.o  lib/lib.a  arch/arm/lib/lib.a  lib/built-in.o  arch/arm/lib/built-in.o  drivers/built-in.o  sound/built-in.o  net/built-in.o --end-group .tmp_kallsyms3.o
===>在内核的根目录下生成vmlinux(~24M,ELF )
echo 'cmd_vmlinux := arm-linux-gnu-ld -EL  -p --no-undefined -X -o vmlinux -T arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o arch/arm/kernel/init_task.o  init/built-in.o --start-group  usr/built-in.o  arch/arm/kernel/built-in.o  arch/arm/mm/built-in.o  arch/arm/common/built-in.o  arch/arm/mach-s3c2410/built-in.o  arch/arm/nwfpe/built-in.o  kernel/built-in.o  mm/built-in.o  fs/built-in.o  ipc/built-in.o  security/built-in.o  crypto/built-in.o  lib/lib.a  arch/arm/lib/lib.a  lib/built-in.o  arch/arm/lib/built-in.o  drivers/built-in.o  sound/built-in.o  net/built-in.o --end-group .tmp_kallsyms3.o' > ./.vmlinux.cmd
echo '  /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap System.map' && /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap vmlinux System.map; if [ $? -ne 0 ]; then rm -f vmlinux; /bin/false; fi;
  /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap System.map
echo '  /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap .tmp_System.map' && /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap .tmp_vmlinux3 .tmp_System.map
  /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/mksysmap .tmp_System.map
cmp -s System.map .tmp_System.map || (echo Inconsistent kallsyms data; echo Try setting CONFIG_KALLSYMS_EXTRA_PASS; rm .tmp_kallsyms* ; /bin/false )
rm -f .old_version
make -f scripts/Makefile.build obj=arch/arm/boot MACHINE=arch/arm/mach-s3c2410/ arch/arm/boot/uImage
  arm-linux-gnu-objcopy -O binary -R .note -R .comment -S  vmlinux arch/arm/boot/Image
  Kernel: arch/arm/boot/Image is ready
make -f scripts/Makefile.build obj=arch/arm/boot/compressed arch/arm/boot/compressed/vmlinux
  gzip -f -9 < arch/arm/boot/compressed/../Image > arch/arm/boot/compressed/piggy.gz
  arm-linux-gnu-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.o.d  -nostdinc -isystem /opt/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/lib/gcc/arm-linux-gnu/3.4.5/include -D__KERNEL__ -Iinclude  -mlittle-endian -D__ASSEMBLY__ -Wa,-L -gdwarf-2 -mapcs-32 -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4 -mtune=arm9tdmi -msoft-float    -c -o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/piggy.S
  arm-linux-gnu-ld -EL   --defsym zreladdr=0x30008000 --defsym params_phys=0x30000100 -p --no-undefined -X /opt/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/lib/gcc/arm-linux-gnu/3.4.5/libgcc.a -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/misc.o -o arch/arm/boot/compressed/vmlinux
  arm-linux-gnu- objcopy -O binary -R .note -R .comment -S  arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
  /bin/sh /home/shyi/s3c2410/fs2410/kernel/linux-2.6.14/scripts/ mkuboot.sh -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -n 'Linux-2.6.14' -d arch/arm/boot/zImage arch/arm/boot/uImage
Image Name:   Linux-2.6.14
Created:      Wed Aug 31 15:08:47 2011
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    1568348 Bytes = 1531.59 kB = 1.50 MB
Load Address: 30008000
Entry Point:  30008000
  Image arch/arm/boot/uImage is ready
注意: 要正确生成uImage, 必须先把u-boot编译后的tools/mkimage 放到系统路径下,比如/usr/bin目录下

待续……

你可能感兴趣的:(c,linux,image,assembly,documentation,makefile)