(转载)移植最新内核linux-3.14.6到mini2440开发板

 
1、建立目标平台
1.1 添加机器码--LINGD2440
在arch/arm/tools/mach-types 下,添加以下一行
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/tools/mach-types 
lingd2440 MACH_LINGD2440 LINGD2440 1998
1.2 添加平台文件--mach-lingd2440.c
复制arch/arm/mach-s3c24xx目录下的 mach-smdk2440.c,命名为mach-lingd2440.c。并找到 MACHINE_START(S3C2440,  "SMDK2440") , 修改为MACHINE_START(LINGD2440, 


"lingd mini2440 development board")。 并把mach-lingd2440.c文件中所有的smdk2440改为lingd2440,所有的SMDK2440改为LINGD2440。
lingd@ubuntu14:~/arm/linux-3.14.6$ cp arch/arm/mach-s3c24xx/mach-smdk2440.c arch/arm/mach-s3c24xx/mach-lingd2440.c
1.3 修改时钟源频率--mini2440晶振是12mhz
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/mach-lingd2440.c
在arch/arm/mach-s3c24xx/mach-lingd2440.c第162行static void __init smdk2440_map_io(void)函数中,将s3c24xx_init_clocks(16934400);改为s3c24xx_init_clocks


(12000000);
1.4 添加内核配置选项
在arch/arm/mach-s3c24xx/Kconfig 中,第551行(也就是mini2440的配置后面)添加以下内容
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/Kconfig 
config MACH_LINGD2440
bool "LINGD mini2440 development board"
select S3C_DEV_USB_HOST
select S3C_DEV_NAND
help
 Say Y here to select support for the LINGD-MINI2440. 
 Is a 10cm x 10cm board available via various sources. 
 It can come with a 3.5" or 7" touch LCD.
1.5 添加内核编译选项
在arch/arm/mach-s3c24xx/Makefile 中,第87行(也就是mini2440的配置后面)添加以下内容
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/Makefile
obj-$(CONFIG_MACH_LINGD2440) += mach-lingd2440.o
1.6 添加配置文件
复制arch/arm/configs目录下的mini2440_defconfig,命名为lingd2440_config。并把第21行中的CONFIG_MACH_MINI2440=y,修改为CONFIG_MACH_LINGD2440=y。再将


lingd2440_config复制到内核源码根目录下,命名为.config。
lingd@ubuntu14:~/arm/linux-3.14.6$ cp arch/arm/configs/mini2440_defconfig arch/arm/configs/lingd2440_config
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/configs/lingd2440_config
lingd@ubuntu14:~/arm/linux-3.14.6$ cp arch/arm/configs/lingd2440_config .config
1.7 修改Makefile
lingd@ubuntu14:~/arm/linux-3.14.6$ vim Makefile 
将198、199行修改为以下内容:
ARCH   ?= arm
CROSS_COMPILE ?= arm-linux-
1.8 配置内核
lingd@ubuntu14:~/arm/linux-3.14.6$ make menuconfig
1)设置内核默认启动参数
内核默认启动参数必须设置。当bootloader无法将启动参数传递给内核时,内核会按默认参数来启动。如果没有设置的话,就可能会出现内核解压后没有串口打印了(内核将启动


输出到lcd而不是串口),甚至内核无法启动。
Boot options  --->
() Default kernel command string  --->
填入以下内核启动参数:
noinitrd root=/dev/mtdblock3 rw init=/linuxrc console=ttySAC0,115200
如果改为以下启动参数,可同时将内核启动信息打印到串口和LCD显示屏
noinitrd root=/dev/mtdblock3 rw init=/linuxrc console=ttySAC0,115200 console=tty0
启动参数中rw不可忽略,否则可能造成根文件系统挂载完成后无法进入系统。我遇到过不填写rw时,yaffs2根文件系统被挂载为ro(只读),导致无法进入系统
其他配置可先不修改,直接退出保存
1.9 编译内核
lingd@ubuntu14:~/arm/linux-3.14.6$ make clean
lingd@ubuntu14:~/arm/linux-3.14.6$ make
lingd@ubuntu14:~/arm/linux-3.14.6$ ls arch/arm/boot/
bootp  compressed  dts  Image  install.sh  Makefile  zImage




2、移植Nand驱动并修改分区信息
2.1 内核支持的nand flash类型
drivers/mtd/nand/nand_ids.c 定义了内核所支持的所有nand flash类型
2.2 修改nand flash分区表
在arch/arm/mach-s3c24xx/mach-lingd2440.c 中,添加以下内容
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/mach-lingd2440.c 
//nand flash相关头文件
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>
#include <linux/platform_data/mtd-nand-s3c2410.h>


//nand flash分区表
static struct mtd_partition lingd2440_default_nand_part[] = {
[0] = {
.name = "bootloader",
.size = SZ_256K,
.offset = 0,
},
[1] = {
.name = "param",
.offset = SZ_256K,
.size = SZ_128K,
},
[2] = {
.name = "kernel",
.offset = SZ_128K * 3,
.size = SZ_1M * 5,
},
[3] = {
.name = "root",
.offset = SZ_1M * 5 + SZ_128K * 3,
.size = MTDPART_SIZ_FULL,
},
[4] = {
.name = "nand",
.offset = 0,
.size = MTDPART_SIZ_FULL,
}
};
//开发板nand flash芯片集,mini2440只有一片nand flash
static struct s3c2410_nand_set lingd2440_nand_sets[] = {
[0] = {
.name = "NAND",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(lingd2440_default_nand_part),
.partitions = lingd2440_default_nand_part,
},
};
//开发板nand flash芯片信息
static struct s3c2410_platform_nand lingd2440_nand_info = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(lingd2440_nand_sets),
.sets = lingd2440_nand_sets,
.ignore_unset_ecc = 1,
};


//将nand flash添加到平台设备中
static struct platform_device *lingd2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, //添加nand flash平台设备
};


//调用s3c_nand_set_platdata将nand flash芯片信息添加到nand flash平台设备中
static void __init lingd2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&lingd2440_fb_info);
s3c_i2c0_set_platdata(NULL);


s3c_nand_set_platdata(&lingd2440_nand_info); //将nand flash芯片信息添加到nand flash平台设备中
platform_add_devices(lingd2440_devices, ARRAY_SIZE(lingd2440_devices));
// smdk_machine_init();
}


2.3 内核配置选项
ftl_cs: FTL header not found.问题解决方法:取消以下内核配置选项
lingd@ubuntu14:~/arm/linux-3.14.6$ make menuconfig
Device Drivers  ---> 
<*> Memory Technology Device (MTD) support  --->
< >   FTL (Flash Translation Layer) support  
< >   NFTL (NAND Flash Translation Layer) support
< >   INFTL (Inverse NAND Flash Translation Layer) support


3、添加yaffs2支持
3.1 获取yaffs源码
lingd@ubuntu14:~/arm$ git clone git://www.aleph1.co.uk/yaffs2 
3.2 为内核打yaffs2补丁
lingd@ubuntu14:~/arm$ cd yaffs2/
lingd@ubuntu14:~/arm/yaffs2$ ./patch-ker.sh l m /home/lingd/arm/linux-3.14.6
Updating /home/lingd/arm/linux-3.14.6/fs/Kconfig
Updating /home/lingd/arm/linux-3.14.6/fs/Makefile
3.3 内核配置选项
lingd@ubuntu14:~/arm/yaffs2$ cd ../linux-3.14.6/
lingd@ubuntu14:~/arm/linux-3.14.6$ make menuconfig
File systems  --->
[*] Miscellaneous filesystems  --->
<*>   yaffs2 file system support
-*-     512 byte / page devices
[ ]       Use older-style on-NAND data format with pageStatus byte
[ ]         Lets yaffs do its own ECC
-*-     2048 byte (or larger) / page devices
[*]       Autoselect yaffs2 format
[ ]       Disable yaffs from doing ECC on tags by default
[ ]     Force chunk erase check
[ ]     Empty lost and found on boot
[ ]     Disable yaffs2 block refreshing
[ ]     Disable yaffs2 background processing
[ ]     Disable yaffs2 bad block marking
[ ]     Enable yaffs2 xattr support
3.4 yaffs2补丁
最新yaffs2源码无法通过编译,需要修改,待续
4、移植网卡dm9000驱动
内核自带网卡dm9000驱动drivers/net/ethernet/davicom/dm9000.c。它也是一个平台设备,因此在目标平台初始化代码中,只要填写好相应的结构表即可,具体步骤如下:
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/mach-lingd2440.c 
4.1 添加驱动所需的头文件 dm9000.h
//dm9000相关头文件
#include <linux/dm9000.h> 
//内存控制器相关头文件
#include "regs-mem.h"
4.2 添加dm9000网卡物理基地址定义
//dm9000网卡物理基地址
#define MACH_LINGD2440_DM9000_BASE (S3C2410_CS4 + 0x300) 
4.3 添加dm9000网卡资源定义
//dm9000网卡资源
static struct resource lingd2440_dm9000_resources[] = {
[0] = DEFINE_RES_MEM(MACH_LINGD2440_DM9000_BASE, 4),
[1] = DEFINE_RES_MEM(MACH_LINGD2440_DM9000_BASE + 4, 4),
[2] = DEFINE_RES_NAMED(IRQ_EINT7, 1, NULL, IORESOURCE_IRQ \
| IORESOURCE_IRQ_HIGHEDGE),
};
4.4 添加dm9000平台数据定义
//dm9000平台数据
static struct dm9000_plat_data lingd2440_dm9000_platdata = {
.flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
.dev_addr = { 0x88, 0x00, 0xC0, 0xA8, 0x00, 0x88 }, //MAC地址
};
4.5 添加dm9000平台设备定义
//dm9000平台设备
struct platform_device lingd2440_dm9000 = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(lingd2440_dm9000_resources),
.resource = lingd2440_dm9000_resources,
.dev = {
.platform_data = &lingd2440_dm9000_platdata,
},
};
4.6 添加dm9000初始化函数
//dm9000初始化函数
static void lingd2440_dm9000_init(void)
{
/* bank 4 configurations */
#define S3C2410_BWSCON_DW4_8 (0<<16)
#define S3C2410_BWSCON_DW4_16 (1<<16)
#define S3C2410_BWSCON_DW4_32 (2<<16)
#define S3C2410_BWSCON_WS4 (1<<18)
writel((readl(S3C2410_BWSCON) & 0xFFF0FFFF) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4, S3C2410_BWSCON);
writel(0x1F7C, S3C2410_BANKCON4);
}
4.7 将dm9000平台设备添加到开发板平台设备定义中
static struct platform_device *lingd2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, //添加nand flash平台设备
&lingd2440_dm9000, //添加dm9000平台设备
};
4.8 在开发板初始化函数中,调用dm9000初始化函数lingd2440_dm9000_init
static void __init lingd2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&lingd2440_fb_info);
s3c_i2c0_set_platdata(NULL);


lingd2440_dm9000_init(); //初始化dm9000
s3c_nand_set_platdata(&lingd2440_nand_info); //将nand flash芯片信息添加到nand flash平台设备中
platform_add_devices(lingd2440_devices, ARRAY_SIZE(lingd2440_devices));
// smdk_machine_init();
}
4.9 添加dm9000支持
lingd@ubuntu14:~/arm/linux-3.14.6$ make menuconfig
Device Drivers  --->
[*] Network device support  --->
[*] Ethernet driver support  --->
<*> DM9000 support
5、添加RTC支持
内核自带s3c2440 RTC驱动drivers/rtc/rtc-s3c.c。
5.1 将RTC平台设备添加到开发板平台设备定义中
lingd@ubuntu14:~/arm/linux-3.14.6$ vim arch/arm/mach-s3c24xx/mach-lingd2440.c 
static struct platform_device *lingd2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc, //添加RTC平台设备
&s3c_device_nand, //添加nand flash平台设备
&lingd2440_dm9000, //添加dm9000平台设备
};
5.2 添加RTC支持
Device Drivers  --->
[*] Real Time Clock  --->
<*> Samsung S3C series SoC RTC
5.3 测试
root@lingd2440:/# date
Sat Jan  1 00:00:10 UTC 2000
root@lingd2440:/# date -s 201406081948
Sun Jun  8 19:48:00 UTC 2014
root@lingd2440:/# date
Sun Jun  8 19:48:04 UTC 2014
root@lingd2440:/# hwclock 
Sat Jan  1 00:00:32 2000  0.000000 seconds
root@lingd2440:/# hwclock -w
root@lingd2440:/# hwclock 
Sun Jun  8 19:48:16 2014  0.000000 seconds


6、添加telnet支持
Device Drivers  --->
Character devices  --->  
-*- Unix98 PTY support
[ ]   Support multiple instances of devpts  
[*] Legacy (BSD) PTY support
(128) Maximum number of legacy PTY in use  


7、内核正常启动过程
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,115200"
MACH_TYPE = 1998
NOW, Booting Linux......
Booting Linux on physical CPU 0x0
Linux version 3.14.6 (lingd@ubuntu14) (gcc version 4.4.3 (ctng-1.6.1) ) #8 Sun Jun 8 19:44:34 CST 2014
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: lingd mini2440 development board
Warning: Neither atags nor dtb found
Memory policy: Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 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 off.  Total pages: 4064
Kernel command line: noinitrd root=/dev/mtdblock3 rw init=/linuxrc console=ttySAC0,115200
PID hash table entries: 64 (order: -4, 256 bytes)
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 10756K/16384K available (3797K kernel code, 185K rwdata, 1012K rodata, 144K init, 246K bss, 5628K reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    vmalloc : 0xc1800000 - 0xff000000   ( 984 MB)
    lowmem  : 0xc0000000 - 0xc1000000   (  16 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .text : 0xc0008000 - 0xc04ba840   (4811 kB)
      .init : 0xc04bb000 - 0xc04df22c   ( 145 kB)
      .data : 0xc04e0000 - 0xc050e4e0   ( 186 kB)
       .bss : 0xc050e4e0 - 0xc054bfd0   ( 247 kB)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:103
S3C2440: IRQ Support
irq: clearing pending status 00000003
irq: clearing pending status 00000002
sched_clock: 16 bits at 1012kHz, resolution 987ns, wraps every 64725925ns
Console: colour dummy device 80x30
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x303a0f78 - 0x303a0fd0
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
cpuidle: using governor menu
S3C2440: Initialising architecture
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.0: slave address 0x10
s3c-i2c s3c2440-i2c.0: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c.0: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Initialized.
Switched to clocksource samsung_clocksource_timer
NET: Registered protocol family 2
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
futex hash table entries: 256 (order: -1, 3072 bytes)
NFS: Registering the id_resolver key type
Key type id_resolver registered
Key type id_legacy registered
jffs2: version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 21
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
s3c2410-lcd s3c2410-lcd: fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 74, base_baud = 0) is a S3C2440
console [ttySAC0] enabled
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 77, base_baud = 0) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 80, base_baud = 0) is a S3C2440
brd: module loaded
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
nand: device found, Manufacturer ID: 0xec, Chip ID: 0xda
nand: Samsung NAND 256MiB 3,3V 8-bit
nand: 256MiB, SLC, page size: 2048, OOB size: 64
Scanning device for bad blocks
Bad eraseblock 1344 at 0x00000a800000
Bad eraseblock 1476 at 0x00000b880000
Creating 5 MTD partitions on "NAND":
0x000000000000-0x000000040000 : "bootloader"
0x000000040000-0x000000060000 : "param"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000010000000 : "root"
0x000000000000-0x000010000000 : "nand"
dm9000 dm9000: read wrong id 0x01010101
eth0: dm9000e at c18ca300,c18cc304 IRQ 55 MAC: 88:00:c0:a8:00:88 (platform data)
ohci_hcd: USB 1.1 ‘Open‘ Host Controller (OHCI) Driver
ohci-s3c2410: OHCI S3C2410 driver
s3c2410-ohci s3c2410-ohci: OHCI Host Controller
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
mousedev: PS/2 mouse device common for all mice
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
s3c-rtc s3c2410-rtc: warning: invalid RTC value so initializing it
i2c /dev entries driver
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq disabled
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
hidraw: raw HID events driver (C) Jiri Kosina
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
TCP: cubic registered
NET: Registered protocol family 17
Key type dns_resolver registered
s3c-rtc s3c2410-rtc: setting system clock to 2000-01-01 00:00:00 UTC (946684800)
ALSA device list:
  No soundcards found.
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing unused kernel memory: 144K (c04bb000 - c04df000)
Processing /etc/init.d/rcS
mount -a
Processing /etc/rc.local
Get hostname
Starting mdev
Starting telnetd
ifconfig eth0 192.168.1.100
dm9000 dm9000 eth0: link down
**************************************************
*                                                *
*                  lingd rootfs                  *
*                                                *
*          arm-linux-gcc version 4.4.3           *
*                                                *
*                   2014-05-11                   *
*                                                *
**************************************************

原文地址http://blog.chinaunix.net/uid-23089249-id-4293986.html

(转载)移植最新内核linux-3.14.6到mini2440开发板,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。