bootelf命令:启动vmlinux
bootm命令:启动uImage
go命令:启动zImage
Linux几种内核镜像及其关系
前言:链接脚本
用户态程序不用关心section的具体位置;在用户态,内核会解析elf可执行文件的各个section、然后把它映射到虚拟地址空间。
然而,uboot和linux内核的启动都是从零开始的;所以,需要在编译时指定链接地址、而链接地址一般在lds文件中确定(链接器通过读取lds配置文件来决定)。
vmlinux(这个vmlinux属于未压缩,带调试信息、符号表的最初的内核)的入口地址:
kernel/arch/arm/kernel/vmlinux.lds
OUTPUT_ARCH(arm) ENTRY(stext) SECTIONS { . = 0xC0008000;
kernel/arch/arm/kernel/head.S
ENTRY(stext)
zImage(由压缩后的vmlinux和自解压缩程序组成)的入口地址:
kernel/arch/arm/boot/compressed/vmlinux.lds
OUTPUT_ARCH(arm) ENTRY(_start) SECTIONS { . = 0;
kernel/arch/arm/boot/compressed/head.S
start:
说明:将zImage添加64Bytes的相关信息后就为uImage
=================================================================================================================================
以下附上skyeye1.2.6的下载地址(之前的skyeye1.2.8在uboot启动内核时有些问题):
http://pan.baidu.com/share/link?shareid=1673022906&uk=185233171&fid=1631621989
一、下载linux-2.6.14
http://download.csdn.net/download/bill_xiang/5240450
二、编译linux-交叉编译器arm-linux-gcc-3.4.1
交叉编译器下载地址:
http://ishare.iask.sina.com.cn/f/10838407.html1.基本配置
修改顶层Makefile:
ARCH ?= arm CROSS_COMPILE ?= /home/lianxi/skyeye/usr/local/arm/3.4.1/bin/arm-linux-
生成内核配置文件:
make smdk2410_defconfig2.添加网卡驱动
cs8900.c cs8900.h //具体可以在网上查找,这里不罗列
将上述文件拷贝至drivers/net/arm/
drivers/net/arm/Kconfig添加如下:
config ARM_CS8900 tristate "CS8900 support" depends on NET_ETHERNET && ARM && ARCH_SMDK2410 help Support for CS8900A chipset based Ethernet cards. If you have a network (Ethernet) card of this type, say Y and read the Ethernet-HOWTO, available from as well as .To compile this driver as a module, choose M here and read. The module will be called cs8900.o.
drivers/net/arm/Makefile添加如下:
obj-$(CONFIG_ARM_CS8900) += cs8900.o修改arch/arm/mach-s3c2410/mach-smdk2410.c
//add by tankai #include <asm-arm/arch-s3c2410/smdk2410.h> //end tankai static struct map_desc smdk2410_iodesc[] __initdata = { /* nothing here yet */ //add by tankai /* Map the ethernet controller CS8900A */ {vSMDK2410_ETH_IO,pSMDK2410_ETH_IO, SZ_1M, MT_DEVICE} //end tankai };
添加include/asm-arm/arch-s3c2410/smdk2410.h
#ifndef _INCLUDE_SMDK2410_H_ #define _INCLUDE_SMDK2410_H_ #include <linux/config.h> #define pSMDK2410_ETH_IO 0x19000000 #define vSMDK2410_ETH_IO 0xE0000000 #define SMDK2410_ETH_IRQ IRQ_EINT9 #endif
3.其他重要修改
修改include/asm-arm/arch-s3c2410/map.h include/asm-arm/arch/map.h include/asm/arch/map.h include/asm/arch/arch-s3c2410/map.h
//#define S3C2410_CS6 (0x30000000) #define S3C2410_CS6 (0xC0000000)修改include/asm-arm/arch-s3c2410/memory.h include/asm-arm/arch/memory.h include/asm/arch/memory.h include/asm/arch/arch-s3c2410/memory.h
//#define PHYS_OFFSET (0x30000000UL) #define PHYS_OFFSET (0xC0000000UL)修改arch/arm/kernel/head.S
ENTRY(stext) //add by tankai mov r0, #0 mov r1, #0xc1 ldr r2, =0x30000100 //end tankai msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | MODE_SVC @ ensure svc mode4.配置内核
内核启动参数(这个是我们内存盘根文件系统的加载路径,要跟配置文件s3c2410.conf中一样):
Boot options->Default kernel command string
mem=32M console=ttySAC0 root=/dev/ram initrd=0xc1000000,0x00600000 ramdisk_size=8192 rw
添加网卡驱动:
Device Drivers->Network device support->Ethernet (10 or 100Mbit)->CS8900 support
支持RamDisk内存盘(因为initrd需要):
Device Drivers->Block devices->RAM disk support
(4096) Default RAM disk size (kbytes)改成(8192) Default RAM disk size (kbytes)
Device Drivers->Block devices->Initial RAM disk (initrd) support
NFS文件系统支持:
File systems->Network File Systems->NFS file system support
File systems->Network File Systems->Provide NFSv3 client support
ROM文件系统支持:
File systems->ROM file system support
ext2文件系统支持:
File systems->Second extended fs support
5.编译
make -j2
生成vmlinux
三、制作根文件系统-交叉编译器arm-linux-gcc-3.4.1
1.下载busybox-1.9.2
http://download.csdn.net/download/eqwewr/31541082.编译
修改顶层Makefile:
ARCH ?= arm CROSS_COMPILE ?= /home/lianxi/skyeye/usr/local/arm/3.4.1/bin/arm-linux-
设置静态编译:
make menuconfigBusybox Settings->Build Options->Build BusyBox as a static binary (no shared libs)
编译错误:applets/applets.c:15:2: warning: #warning Static linking against glibc produces buggy executables applets/applets.c:16:2: warning: #warning (glibc does not cope well with ld --gc-sections). applets/applets.c:17:2: warning: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400 applets/applets.c:18:2: warning: #warning Note that glibc is unsuitable for static linking anyway. applets/applets.c:19:2: warning: #warning If you still want to do it, remove -Wl,--gc-sections applets/applets.c:20:2: warning: #warning from scripts/trylink and remove this warning. applets/applets.c:21:2: #error Aborting compilation. make[1]: *** [applets/applets.o] 错误 1 make: *** [applets] 错误 2
解决:
applets/applets.c
//#error Aborting compilation.scripts/trylink
去掉-Wl,--gc-sections
3.安装
make install
错误:
modutils/lib.a(insmod.o)(.text.insmod_main+0x4f0): In function `insmod_main': : undefined reference to `query_module' modutils/lib.a(insmod.o)(.text.insmod_main+0x52c): In function `insmod_main': : undefined reference to `query_module' modutils/lib.a(insmod.o)(.text.insmod_main+0x5d8): In function `insmod_main': : undefined reference to `query_module' modutils/lib.a(insmod.o)(.text.insmod_main+0x628): In function `insmod_main': : undefined reference to `query_module' modutils/lib.a(insmod.o)(.text.insmod_main+0x6f4): In function `insmod_main': : undefined reference to `query_module' modutils/lib.a(insmod.o)(.text.insmod_main+0x1118): In function `$a': : undefined reference to `create_module' collect2: ld returned 1 exit status make: *** [busybox_unstripped] 错误 1
解决:make menuconfig
去掉Linux Module Utilities->Support version 2.2.x to 2.4.x Linux Kernels4.制作initrd格式的文件系统
创建镜像并挂载到initrd目录:
mkdir initrd dd if=/dev/zero of=initrd.img bs=1k count=4096 mke2fs -F -v initrd.img mount -o loop initrd.img initrd
添加命令到该镜像:
cd initrd cp -r ../busybox-1.9.2/_install/* .
创建必要目录:
mkdir proc lib etc dev root home var tmp chmod 777 tmp
创建设备节点:
cd dev mknod -m 644 console c 5 1 mknod -m 644 null c 1 3 mknod -m 640 ram b 1 1 mknod -m 644 mem c 1 1 cd ..
创建脚本文件etc/inittab,内容如下:
::sysinit:/etc/init.d/rcS ::askfirst:-/bin/sh ::restart:/sbin/init ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a
chmod 644 etc/inittab
创建脚本文件etc/init.d/rcS, 内容如下:#!/bin/sh /bin/mount -t proc none /proc /sbin/ifconfig lo 127.0.0.1 up /sbin/ifconfig eth0 10.0.0.2 netmask 255.0.0.0 up hostname skyeye mkdir /var/tmp mkdir /var/log mkdir /var/run mkdir /var/lock /bin/ashchmod 755 etc/init.d/rcS
执行实际的写入操作,生成initrd.img
cd .. umount initrd
四、uboot部分修改u-boot-2011.12
1.交叉编译器——arm-linux-gcc-4.4.3
uboot/arch/arm/config.mk
CROSS_COMPILE ?= /home/lianxi/skyeye/opt/FriendlyARM/toolschain/4.4.3/bin/arm-linux-
2.dcache问题
uboot/arch/arm/lib/cache-cp15.cvoid dcache_enable(void) { //cache_enable(CR_C); } void dcache_disable(void) { //cache_disable(CR_C); }
uboot/arch/arm/cpu/arm920t/start.S
#define CONFIG_SKIP_LOWLEVEL_INIT //add by tankai
五、实际运行
1.硬件配置文件s3c2410.conf
#skyeye config file sample cpu: arm920t mach: s3c2410x ########################################################################### mem_bank: map=M, type=RW, addr=0x00000000, size=0x01000000, file=./u-boot.bin, boot=yes mem_bank: map=M, type=RW, addr=0x30000000, size=0x04000000 mem_bank: map=M, type=RW, addr=0xc0000000, size=0x01000000, file=./vmlinux mem_bank: map=M, type=RW, addr=0xc1000000, size=0x00600000, file=initrd.img mem_bank: map=M, type=RW, addr=0xc1600000, size=0x00a00000 ########################################################################## mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000 #mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020 #net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=0:4:3:2:1:f, ethmod=tuntap, hostip=10.0.0.1 #lcd:type=s3c2410x,mod=gtk dbct:state=on
2.运行
skyeye -c s3c2410.conf
结果:**************************** WARNING ********************************** If you want to run ELF image, you should use -e option to indicate your elf-format image filename. Or you only want to run binary image, you need to set the filename of the image and its entry in skyeye.conf. *********************************************************************** Your elf file is little endian. arch: arm cpu info: armv4, arm920t, 41009200, ff00fff0, 2 mach info: name s3c2410x, mach_init addr 0x427070 dbct info: turn on dbct! uart_mod:0, desc_in:, desc_out:, converter: SKYEYE: use arm920t mmu ops Loaded RAM ./u-boot.bin Loaded RAM ./vmlinux Loaded RAM initrd.img TK-------uboot/arch/arm/lib/board.c>>>board_init_f ERROR: s3c2410x_io_write_word(0x4c000000) = 0x00ffffff ERROR: s3c2410x_io_write_word(0x4c000008) = 0x00048032 U-Boot 2011.12 (Nov 08 2013 - 09:03:37) DRAM: 64 MiB TK--------uboot/arch/arm/lib/board.c>>>board_init_r TK--------uboot/arch/arm/lib/board.c>>>board_init_r>>call>>enable_caches() WARNING: Caches not enabled TK-------uboot/arch/arm/lib/cache-cp15.c>>>>cache_enable TK--------uboot/arch/arm/lib/cache-cp15.c>>>dcache_enable TK--------uboot/arch/arm/lib/cache-cp15.c>>>>>dcache_enable>>>11111 Flash: 1 MiB NAND: ERROR: s3c2410x_io_write_word(0x4e000000) = 0x00008377 ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff ERROR: s3c2410x_io_write_word(0x4e000004) = 0x000000ff ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff raise: Signal # 8 caught raise: Signal # 8 caught ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff ERROR: s3c2410x_io_write_word(0x4e000004) = 0x00000090 ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff ERROR: s3c2410x_io_write_word(0x4e000008) = 0x00000000 ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff raise: Signal # 8 caught raise: Signal # 8 caught ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff ERROR: s3c2410x_io_write_word(0x4e000004) = 0x00000090 ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff ERROR: s3c2410x_io_write_word(0x4e000008) = 0x00000000 ERROR: s3c2410x_io_write_word(0x4e000000) = 0xfffff7ff raise: Signal # 8 caught raise: Signal # 8 caught No NAND device found!!! ERROR: s3c2410x_io_write_word(0x4e000000) = 0xffffffff 0 MiB *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial Net: CS8900-0 Warning: failed to set MAC address SMDK2410 #
在uboot启动后,输入:bootelf 0xc0000000启动内核:
SMDK2410 # bootelf 0xc0000000 TK---------uboot/common/cmd_elf.c>>>>>do_bootelf TK---------uboot/common/cmd_elf.c>>>>>do_bootelf>>>>addr is 0xc0000000 ## Starting application at 0xc0008000 ... TK----->>>kernel/init/main.c>>>>>>start_kernel Linux version 2.6.14 (root@tankai-G41T-R3) (gcc version 3.4.1) #32 Fri Nov 8 11:00:06 CST 2013 CPU: ARM920Tid(wb) [41009200] revision 0 (ARMvundefined/unknown) Machine: SMDK2410 Warning: bad configuration page, trying to continue Memory policy: ECC disabled, Data cache writeback CPU S3C2410 (id 0x32410000) S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz S3C2410 Clocks, (c) 2004 Simtec Electronics CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on CPU0: D VIVT write-back cache CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets Built 1 zonelists Kernel command line: mem=32M console=ttySAC0 root=/dev/ram initrd=0xc1000000,0x00600000 ramdisk_size=8192 rw irq: clearing pending status 00004000 irq: clearing pending status 00008000 irq: clearing pending status 00800000 irq: clearing pending status 10000000 irq: clearing subpending status 00000093 PID hash table entries: 256 (order: 8, 4096 bytes) timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c Console: colour dummy device 80x30 Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) Memory: 32MB = 32MB total Memory: 24332KB available (1505K code, 277K data, 92K init) Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok TK-----kernel/init/initramfs.c>>>>__initramfs_start is 0xc001c560 TK-----kernel/init/initramfs.c>>>>__initramfs_end is 0xc001c5e6 TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs>>>>>11111,len is 134 TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs>>>>>2222 TK-----kernel/init/initramfs.c>>>>>err is 0x0 checking if image is initramfs...TK----kernel/init/initramfs.c>>>>>initrd_start is 0xc1000000 initrd_end is 0xc1600000 TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs>>>>>11111,len is 6291456 TK-------kernel/init/initramfs.c>>>>>unpack_to_rootfs>>>>>2222 it isn't (bad gzip magic numbers); looks like an initrd softlockup thread 0 started up. Freeing initrd memory: 6144K NET: Registered protocol family 16 S3C2410: Initialising architecture Console: switching to colour frame buffer device 80x25 fb0: Virtual frame buffer device, using 1024K of video memory s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2410 s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2410 s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2410 io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410) eth0: incorrect signature 0x0000 mice: PS/2 mouse device common for all mice NET: Registered protocol family 2 IP route cache hash table entries: 512 (order: -1, 2048 bytes) TCP established hash table entries: 2048 (order: 1, 8192 bytes) TCP bind hash table entries: 2048 (order: 1, 8192 bytes) TCP: Hash tables configured (established 2048 bind 2048) TCP reno registered TCP bic registered NET: Registered protocol family 1 RAMDISK: ext2 filesystem found at block 0 RAMDISK: Loading 4096KiB [1 disk] into ram disk... done. VFS: Mounted root (ext2 filesystem). Freeing init memory: 92K init started: BusyBox v1.9.2 (2013-11-05 10:11:12 CST) starting pid 15, tty '': '/etc/init.d/rcS' ifconfig: SIOCSIFADDR: No such device /bin/ash: can't access tty; job control turned off #