Linux-2.6.32.67内核裁剪与移植之内核启动与根文件系统制作
作者:赵凯
QQ: 1205958201
第一部分:内核启动与根文件系统制作
注:转载请注明出处哦!
1. 修改内核以支持s3c2440开发板
在顶层的makefile中,将
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
修改为:
ARCH ?= arm
CROSS_COMPILE?= arm-linux-
2. 修改内核中的时钟设置
进入/arch/arm/mach-s3c2440/mach-smdk2440.c中,将
static void __init smdk2440_map_io(void)
{
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
s3c24xx_init_clocks(xxx); //是多少搞忘了,改成12M
s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
}修改为
static void __init smdk2440_map_io(void)
{
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
s3c24xx_init_clocks(12000000);
s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
}
然后执行命令:[root@localhost linux-4.1.2]# make s3c2410_defconfig;使用arch/arm/configs/s3c2410_defconfig文件来配置内核,它生成.config配置文件,以后可以使用make menuconfig修改配置了。执行上述命令的运行结果如下:
[root@localhost linux-2.6.32.67]# make s3c2410_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/kxgettext.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#执行命令:make uImage生成uImage镜像;
这个时候出现错误:
"mkimage" command not found - U-Boot images will not be built
make[1]: *** [arch/arm/boot/uImage]错误 1
make: *** [uImage]错误 2
解决方法:
由于前几天移植uboot,在uboot源码目录下tools目录中已经生成了mkimage,只需要将其路径在环境变量中声明即可,在etc/bashrc文件的末尾添加如下语句:
export PATH:=$PATH:/Mydir/u-boot-2014.04/tools
然后更新一下bashrc脚本:source /etc/bashrc;
但是这样不保险,因为后面可能清除掉mkimage,保险的做法是将mkimage复制到/usr/bin目录下,可以用echo $PATH看下PATH的内容,可以看到包含/usr/bin路径,这时候不用进行修改。这里采用第二种方法。
然后继续执行命令:make uImage生成uImage镜像,输出的结果如下:
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: “include/generated/mach-types.h”是最新的。
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-4.1.2
Created: Thu Jul 16 22:59:31 2015
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2808992 Bytes = 2743.16 kB = 2.68 MB
Load Address: 30108000
Entry Point: 30108000
Image arch/arm/boot/uImage is ready
这个时候可以将生成的uImage拷贝到tftp目录,然后下载到开发板上:
[root@localhost linux-4.1.2]# cd arch/arm/boot
[root@localhost boot]# cp uImage /var/lib/tftpboot
启动开发板:
ZK2440 # tftp 0x32000000 uImage
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 0a:1b:2c:3d:4e:5f
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.8; our IP address is 192.168.1.6
Filename 'uImage'.
Load address: 0x32000000
Loading: T #################################################################
#################################################################
##############################################################
402.3 KiB/s
done
Bytes transferred = 2809056 (2adce0 hex)
提示下载成功,然后从0x32000000启动,可以看到内核的打印信息:
EmbedSky> tftp 0x32000000 uImage
dm9000 i/o: 0x20000300, id: 0x90000a46
MAC: 0a:1b:2c:3d:4e:5f
TFTP from server 192.168.1.8; our IP address is 192.168.1.6
Filename 'uImage'.
Load address: 0x32000000
Loading: checksum bad
checksum bad
checksum bad
checksum bad
checksum bad
T #################################################################
#################################################################
###############################################################
done
Bytes transferred = 2809000 (2adca8 hex)
EmbedSky> bootm 0x32000000
## Booting image at 32000000 ...
Image Name: Linux-4.1.2
Created: 2015-07-17 4:28:37 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2808936 Bytes = 2.7 MB
Load Address: 30108000
Entry Point: 30108000
Verifying Checksum ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Error: unrecognized/unsupported machine ID (r1 = 0x000000a8).
。。。。。。。。。
内核无法正常启动,因为Linux内核中的机器码一定要与bootloader的机器码一致,否则便会出现内核启动不了。在u-boot和kernel中都会有一个机器码(即:MACH_TYPE),只有这两个机器码一致时才能引导内核。
可以查看下我的uboot机器码,如下
ZK2440 # bdinfo
arch_number = 0x000000C1(对应十进制193)
boot_params = 0x30000100
DRAM bank = 0x00000000
-> start = 0x30000000
-> size = 0x04000000
eth0name = dm9000
ethaddr = 0a:1b:2c:3d:4e:5f
current eth = dm9000
ip_addr = 192.168.1.6
baudrate = 115200 bps
TLB addr = 0x33FF0000
relocaddr = 0x33FB4000
reloc off = 0x33FB4000
irq_sp = 0x33D93F40
sp start = 0x33D93F30
修改内核中的机器码,与uboot中的一致,打开arch/arm/tools/mach-types文件,修改第87行如下
s3c2440 ARCH_S3C2440 S3C2440 193
重新编译make uImage,然后下载到开发板中运行
ZK2440 # bootm 0x32000000
## Booting kernel from Legacy Image at 32000000 ...
Image Name: Linux-2.6.32.67
Created: 2015-07-17 17:16:30 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1996676 Bytes = 1.9 MiB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
Starting kernel ...
Uncompressing Linux............................................................................................................................... done, booting the kernel.
Linux version 2.6.32.67 (root@localhost.localdomain) (gcc version 4.4.4 (crosstool-NG-1.11.1) ) #2 Sat Jul 18 01:16:20 CST 2015
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: root=/dev/hda1 ro init=/bin/bash console=ttySAC0
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60712KB available (3684K code, 321K data, 132K init, 0K highmem)
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 97 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
JFFS2 version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
fb0: s3c2410fb frame buffer device
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
loop: module loaded
Uniform Multi-Platform E-IDE driver
ide-gd driver 1.18
ide-cd driver 5.00
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=2, 20ns Twrph0=6 60ns, Twrph1=2 20ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 1158 at 0x0000090c0000
Bad eraseblock 1590 at 0x00000c6c0000
Bad eraseblock 1975 at 0x00000f6e0000
Creating 8 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000004000 : "Boot Agent"
mtd: partition "Boot Agent" doe