linux2.6.32.2移植到ARM平臺(tái)(mini2440)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
1、指定交叉編譯變量
即修改頂層Makefile文件,vim打開,修改如下:
原
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
改為
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm//指定目標(biāo)平臺(tái)為ARM
CROSS_COMPILE ?= arm-linux-//指定交叉編譯器,此處是系統(tǒng)默認(rèn)的,若指定其他的需要把路徑完整列出
修改完畢之后,先編譯一下,看是否能通過(guò),
#make s3c2410_defconfig
# make
2、編譯通過(guò)了,繼續(xù)。
mini2440的機(jī)器碼是1999,在內(nèi)核arch/arm/tools/mach-types查看,u-boot的在/include/asm-arm/mach-types.h查看
# cd /linux2.6.32.2/arch/arm/mach-s3c2440
有一個(gè)mini2440.c,這是國(guó)外的linux愛好者添加的對(duì)mini2440支持的源碼內(nèi)容,刪除,rm掉
# cp mach-smdk2440.c mach-mini2440.c
vim之,修改
MACHINE_START(S3C2440, "SMDK2440")
為
MACHINE_START(MINI2440, "FriendlyARM Mini2440 development board")//這里,MINI2440必須為大寫,不能小寫,原因應(yīng)該是編譯程序的識(shí)別問(wèn)題吧
這是什么意思呢?當(dāng)系統(tǒng)在開發(fā)板跑起來(lái)的時(shí)候,cat /proc/cpuinfo可以看到上面FriendlyARM Mini2440 developmentboard的字符串,即修改了開發(fā)板的信息。
3、修改時(shí)鐘頻率
還在2步的c文件,160行,16934400這串?dāng)?shù)字改為12000000,因?yàn)閟mdk開發(fā)板的晶振頻率是16.9344MHz,而mini2440是12MHz,不修改的話,暫時(shí)不知道會(huì)有什么問(wèn)題,不過(guò)就單片機(jī)而言,晶振不對(duì),各種驅(qū)動(dòng)也不可能成功驅(qū)動(dòng)。
4、還是2步的c文件,在vim編輯器里:%s/smdk2440/mini2440/g,這表示把文件中字符串“smdk2440”都匹配替換成“mini2440”,g=global,
把mini2440_machine_init(void)函數(shù)里面的smdk_machine_init()注釋掉,這是一個(gè)初始化函數(shù),需要自己寫
到這里,就可以make來(lái)測(cè)試一下了
----------------------------------------------------------------------------------------------------------------------------------------------------------------
5、移植nand驅(qū)動(dòng)及更改分區(qū)信息
在arch/arm/mach-s3c2440/mach-mini2440.c中,有一個(gè)nand分區(qū)信息結(jié)構(gòu)體,更改好分區(qū)信息,0區(qū)256KB,1區(qū)128KB,2區(qū)5MB,3區(qū)剩下的,4區(qū)留空備用,分區(qū)表完成
另外,還要把nand注冊(cè)到系統(tǒng)中去,具體是arch/arm/mach-s3c2440/mini2440.c的static struct platform_device*mini2440_devices[] __initdata結(jié)構(gòu)體,在末尾加上&s3c_device_nand,這樣,nand的驅(qū)動(dòng)算是移植完成了
在這里,有一個(gè)小問(wèn)題,在內(nèi)核添加了yaffs2的支持后,再make zImage有了無(wú)數(shù)個(gè)error和warning,原因:不是結(jié)構(gòu)體沒(méi)寫好,二是沒(méi)有頭文件的支持
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
接下來(lái),還得在static void __init mini2440_map_io(void)函數(shù)中添加:
s3c_device_nand.dev.platform_data=&mini2440_nand_info;
這才make成功,without errors and warnings
6、DM9000網(wǎng)卡驅(qū)動(dòng)的移植
在drivers/net/dm9000.c中添加頭文件
#include
定義網(wǎng)卡的物理地址
#define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
設(shè)置網(wǎng)卡
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函數(shù)中添加
&mini2440_device_eth,
以上是設(shè)備接口的填充,接著要調(diào)整DM9000的位寬寄存器,在dm9000.c文件中添加
#if defined(CONFIG_ARCH_S3C2410)
#include
#endif
在static int __initdm9000_init(void) 函數(shù)中添加以下代碼:
#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) 函數(shù)中添加紅色的代碼
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的配置