现在的位置: 首页 > 综合 > 正文

Linux-2.6.32.2内核在mini2440上的移植—-克隆建立自己的目标平台

2013年05月14日 ⁄ 综合 ⁄ 共 8568字 ⁄ 字号 评论关闭

注:主要参考网上的移植,结合自己的操作,再次对参考的作者的博文表示感谢!

1、下载linux-2.6.32.2.tar.gz将其拷贝到

clx@think:/work/armlinux$ ls
linux-2.6.32.2.tar.gz

将其解压到此目录下

clx@think:/work/armlinux$ tar -zxvf  linux-2.6.32.2.tar.gz

clx@think:/work/armlinux$ ls
linux-2.6.32.2  linux-2.6.32.2.tar.gz

2、指定交叉编译变量

我们移植目的是让Linux-2.6.32.2 可以在mini2440上运行。首先,我们要使得Linux-2.6.32.2 的缺省目标平台成为ARM 的平台,修改总目录下的Makefile。

用gedit打开/Makefile,定位到183行,修改如下:

#Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH  ?= arm
CROSS_COMPILE ?= arm-linux-

#Architecture as present in compile.h

其中,ARCH 是指定目标平台为arm,CROSS_COMPILE 是指定交叉编译器,这里指定的是系统默认的交叉编译器,如要使用其它的,则要把编译器的全路径在这里写出。注意,在arm和arm-linux-后不要留空格,否则在编译时会出现错误。

3、建立自己的目标平台

(1)、关于机器码

内核在启动时,是通过bootloader传入的机器码(MACH_TYPE)确定应启动哪种目标平台的,友善之臂已经为mini2440 申请了自己的机器码为1999,它位于linux-2.6.32.2/arch/arm/tools/mach_types文件中。如果内核的机器码和bootloader传入的不匹配,就不能正确引导内核。

linux-2.6.32.2/arch/arm/mach-s3c2440 目录下有个mach-mini2440.c 文件,它其实就是国外爱好者为mini2440 移植添加的主要内容了,但我们不用它,把它直接删除。将linux-2.6.32.2/arch/arm/mach-s3c2440/目录下的mach-smdk2440.c 复制一份。命名为mach-mini2440.c 

clx@think:/work/armlinux/linux-2.6.32.2/arch/arm/mach-s3c2440$ cp -p mach-smdk2440.c mach-mini2440.c

并打开文件定位到末尾处,找到

MACHINE_START(S3C2440, "SMDK2440") , 将其修改为
MACHINE_START(MINI2440,"Mini2440 development board")
提示:开发板运行后,在命令行终端输入:cat /proc/cpuinfo 可以看到我们添加的开发板信息,当然这个信息可以定制成我们需要的信息。

(2)、修改时钟源频率

在上面我们刚刚复制并修改过的mach-mini2440.c文件中,定位到163行附近,把其中的16934400(代表原SMDK2440 目标板的晶振是16.9344MHz)改为mini2440 开发板上实际使用的12000000(代表mini2440 开发板上的晶振12MHz,元器件标号为X2),如下所示:

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));
}

(3)、从SMDK2440 到MINI2440

因为我们要制作自己的mini2440平台体系,因此把mach-mini2440.c 中所有的smdk2440字样改为mini2440,在gedit里用查找替换,比较方便,操作如下:
gedit->搜索->替换,在打开的对话框中,在搜索一栏输入“smdk2440”,在替换为一栏输入“mini2440”然后点击全部替换按钮,即可完成。

除此之外,还有一个地方需要改动,在mini2440_machine_init(void)函数中,把smdk_machine_init()函数调用注释掉,因为我们后面会编写自己的初始化函数,不需要调用smdk2440 原来的,定位到173行,修改如下:

static void__init mini2440_machine_init(void)
{
 s3c24xx_fb_set_platdata(&mini2440_fb_info);
 s3c_i2c0_set_platdata(NULL);

 platform_add_devices(mini2440_devices,ARRAY_SIZE(mini2440_devices));
 //smdk_machine_init();
}

(4)、编译测试

在 Linux 源代码根目录下执行

clx@think:/work/armlinux/linux-2.6.32.2$ make mini2440_defconfig

使用Linux 官方自带的mini2440 配置

clx@think:/work/armlinux/linux-2.6.32.2$ make zImage

编译了20多分钟

clx@think:/work/armlinux/linux-2.6.32.2/arch/arm/boot$ ls
bootp  compressed  Image  install.sh  Makefile  zImage

把生成的内核文件zImage下载到板子的内存中运行。

##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[a] Absolute User Application
[n] Download Nboot for WinCE 
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin 
[d] Download & Run 
[z] Download zImage into RAM 
[g] Boot linux from RAM 
[f] Format the nand flash 
[b] Boot the system 
[s] Set the boot parameters 
[u] Backup NAND Flash to HOST through USB(upload) 
[r] Restore NAND Flash from HOST through USB 
[q] Goto shell of vivi 
[i] Version: 1026-2K
Enter your selection: k
USB host is connected. Waiting a download.

Now, Downloading [ADDRESS:30000000h,TOTAL:2067306]
RECEIVED FILE SIZE: 2067306 (672KB/S, 3S)
Downloaded file at 0x30000000, size = 2067296 bytes
Found block size = 0x00200000
Erasing...    ... done
Writing...    ... done
Written 2067296 bytes

##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[a] Absolute User Application
[n] Download Nboot for WinCE 
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin 
[d] Download & Run 
[z] Download zImage into RAM 
[g] Boot linux from RAM 
[f] Format the nand flash 
[b] Boot the system 
[s] Set the boot parameters 
[u] Backup NAND Flash to HOST through USB(upload) 
[r] Restore NAND Flash from HOST through USB 
[q] Goto shell of vivi 
[i] Version: 1026-2K
Enter your selection: b
Copy linux kernel from 0x00060000 to 0x30008000, size = 0x00500000 ... done
zImage magic = 0x016f2818
Setup linux parameters at 0x30000100
linux command line is: "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0"
MACH_TYPE = 1999
NOW, Booting Linux......
Uncompressing Linux................................................................................................................................ done, booting the kernel.
Linux version 2.6.32.2 (clx@think) (gcc version 4.4.3 (ctng-1.6.1) ) #1 Sun May 12 22:46:33 CST 2013
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: Mini2440 development board
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 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: noinitrd root=/dev/mtdblock3 init=/linuxrc 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: 60608KB available (3596K code, 417K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
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
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 98 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.
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
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
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
Root-NFS: No NFS server available, giving up.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "mtdblock3" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[<c002e9c0>] (unwind_backtrace+0x0/0xd8) from [<c02d4798>] (panic+0x40/0x118)
[<c02d4798>] (panic+0x40/0x118) from [<c0008e68>] (mount_block_root+0x1c8/0x208)
[<c0008e68>] (mount_block_root+0x1c8/0x208) from [<c00090fc>] (prepare_namespace+0x160/0x1b8)
[<c00090fc>] (prepare_namespace+0x160/0x1b8) from [<c0008434>] (kernel_init+0xd8/0x10c)
[<c0008434>] (kernel_init+0xd8/0x10c) from [<c002a868>] (kernel_thread_exit+0x0/0x8)

可以看到内核已经可以正常启动了,但此时大部分硬件驱动还没加,并且也没有文件系统,因此还无法登陆。

抱歉!评论已关闭.