linux2.6.32.2移植到ARM平台(mini2440)
扫描二维码
随时随地手机看文章
1、指定交叉编译变量
即修改顶层Makefile文件,vim打开,修改如下:
原
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
改为
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm//指定目标平台为ARM
CROSS_COMPILE ?= arm-linux-//指定交叉编译器,此处是系统默认的,若指定其他的需要把路径完整列出
修改完毕之后,先编译一下,看是否能通过,
#make s3c2410_defconfig
# make
2、编译通过了,继续。
mini2440的机器码是1999,在内核arch/arm/tools/mach-types查看,u-boot的在/include/asm-arm/mach-types.h查看
# cd /linux2.6.32.2/arch/arm/mach-s3c2440
有一个mini2440.c,这是国外的linux爱好者添加的对mini2440支持的源码内容,删除,rm掉
# cp mach-smdk2440.c mach-mini2440.c
vim之,修改
MACHINE_START(S3C2440, "SMDK2440")
为
MACHINE_START(MINI2440, "FriendlyARM Mini2440 development board")//这里,MINI2440必须为大写,不能小写,原因应该是编译程序的识别问题吧
这是什么意思呢?当系统在开发板跑起来的时候,cat /proc/cpuinfo可以看到上面FriendlyARM Mini2440 developmentboard的字符串,即修改了开发板的信息。
3、修改时钟频率
还在2步的c文件,160行,16934400这串数字改为12000000,因为smdk开发板的晶振频率是16.9344MHz,而mini2440是12MHz,不修改的话,暂时不知道会有什么问题,不过就单片机而言,晶振不对,各种驱动也不可能成功驱动。
4、还是2步的c文件,在vim编辑器里:%s/smdk2440/mini2440/g,这表示把文件中字符串“smdk2440”都匹配替换成“mini2440”,g=global,
把mini2440_machine_init(void)函数里面的smdk_machine_init()注释掉,这是一个初始化函数,需要自己写
到这里,就可以make来测试一下了
----------------------------------------------------------------------------------------------------------------------------------------------------------------
5、移植nand驱动及更改分区信息
在arch/arm/mach-s3c2440/mach-mini2440.c中,有一个nand分区信息结构体,更改好分区信息,0区256KB,1区128KB,2区5MB,3区剩下的,4区留空备用,分区表完成
另外,还要把nand注册到系统中去,具体是arch/arm/mach-s3c2440/mini2440.c的static struct platform_device*mini2440_devices[] __initdata结构体,在末尾加上&s3c_device_nand,这样,nand的驱动算是移植完成了
在这里,有一个小问题,在内核添加了yaffs2的支持后,再make zImage有了无数个error和warning,原因:不是结构体没写好,二是没有头文件的支持
static struct mtd_partition mini2440_default_nand_part[] = {
[0] = {
.name = "U-boot",
.size = 0x00040000,
.offset = 0,
},
[1] = {
.name = "UbootEnv",
.offset = 0x00040000,
.size = 0x00020000,
},
[2] = {
.name = "Kernel",
.offset = 0x00060000,
.size = 0x00500000,
},
[3] = {
.name = "Rootfs",
.offset = 0x00560000,
.size = 1024 * 1024 * 1024, //
},
[4] = {
.name = "nand",
.offset = 0x00000000,
.size = 1024 * 1024 * 1024, //
}
};
static struct s3c2410_nand_set mini2440_nand_sets[] = {
[0] = {
.name = "NAND",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
.partitions = mini2440_default_nand_part,
},
};
static struct s3c2410_platform_nand mini2440_nand_info = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(mini2440_nand_sets),
.sets = mini2440_nand_sets,
.ignore_unset_ecc = 1,
};
添加了以上代码后,在include一下头文件:
#include
#include
#include
#include
#include
接下来,还得在static void __init mini2440_map_io(void)函数中添加:
s3c_device_nand.dev.platform_data=&mini2440_nand_info;
这才make成功,without errors and warnings
6、DM9000网卡驱动的移植
在drivers/net/dm9000.c中添加头文件
#include
定义网卡的物理地址
#define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
设置网卡
static struct resource mini2440_dm9k_resource[] = {
[0] = {
.start = MACH_MINI2440_DM9K_BASE,
.end = MACH_MINI2440_DM9K_BASE + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = MACH_MINI2440_DM9K_BASE + 4,
.end = MACH_MINI2440_DM9K_BASE + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};static struct dm9000_plat_data mini2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};static struct platform_device mini2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
.resource = mini2440_dm9k_resource,
.dev = {
.platform_data = &mini2440_dm9k_pdata,
},
};
在mach-mini2440.c的static struct platform_device *mini2440_devices[] __initdata函数中添加
&mini2440_device_eth,
以上是设备接口的填充,接着要调整DM9000的位宽寄存器,在dm9000.c文件中添加
#if defined(CONFIG_ARCH_S3C2410)
#include
#endif
在static int __initdm9000_init(void) 函数中添加以下代码:
#if defined(CONFIG_ARCH_S3C2410)
unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;
*((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
*((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
#endif
使用“软”mac地址:
在static int __devinit dm9000_probe (struct platform_device *pdev) 函数中添加红色的代码
if (!is_valid_ether_addr(ndev->dev_addr))
{
/* try reading from mac */
mac_src = "chip";
for (i = 0; i < 6; i++)
ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
}
// 使用“软”MAC地址: 08:90:90:90:90:90
memcpy(ndev->dev_addr, "x08x90x90x90x90x90", 6);
然后在make menuconfig选上DM9K的配置