【轉】 linux核心移植和網卡驅動(二)

來源:互聯網
上載者:User

標籤:

原文網址:http://blog.chinaunix.net/uid-29589379-id-4708911.html

一,核心移植步驟:

1, 修改頂層目錄下的Makefile

ARCH            ?= $(SUBARCH)

CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%)

修改為:

ARCH :=arm

CROSS_COMPILE :=/usr/local/arm/4.4.3/bin/arm-linux-

2, 拷貝設定檔

這裡用的是FS2410開發板,拷貝相應的板檔案到頂層目錄下

cp arch/arm/configs/s3c2410_defconfig ./

編譯設定檔,產生.config檔案:

Make s3c2410_defconfig

核心配置的目的:

.config檔案記錄了哪些部分會被編譯進核心,哪些部分會被編譯成核心模組,核心在編譯前,尋找.config檔案,作為他編譯的準則。即.config檔案是給Makefile來讀

3,1)選擇板子

在arch/arm/mach-s3c2410/Kconfig中,修改相應的配置

[email protected]#  vim Kconfig 

[email protected]#  pwd

/change/linux-3.1.4/arch/arm/mach-s3c2410

 

config ARCH_SMDK2410

          bool "SMDK2410/A9M2410"

          select CPU_S3C2410

          select MACH_SMDK

          help

                  Say Y here if you are using the SMDK2410 or the derived module A9M2410

                  http://www.fsforth.de

改成:

config ARCH_SMDK2410

         bool "SMDK2410"

         select CPU_S3C2410

         select MACH_SMDK

         select S3C_DEV_USB_HOST

         select S3C_DEV_NAND

         select S3C2410_SETUP_TS

         help

               Say Y here if you are using the SMDK2410 or the derived module A9M2410

                http://www.fsforth.de

2)選配資源,這裡用的是fs2410開發板,可以在/arch/arm/kconfig中選配

if ARCH_S3C2410

#source "arch/arm/mach-s3c2400/Kconfig"

 

s3c2410目標板:

source "arch/arm/mach-s3c2410/Kconfig"

#A8目標板:

#source "arch/arm/mach-s5pc100/Kconfig"

#source "arch/arm/mach-s3c2412/Kconfig"

#source "arch/arm/mach-s3c2416/Kconfig"

#source "arch/arm/mach-s3c2440/Kconfig"

#source "arch/arm/mach-s3c2443/Kconfig"

endif

4, 核心配置

1) General setup  --->  

[*] Prompt for development and/or incomplete code/drivers(可選)

[*] Automatically append version information to the version string│

Kernel compression mode (Gzip)  --->    

2)[*] Enable loadable module support  --->

[*]   Forced module loading  

[*]   Module unloading

[*]     Forced module unloading

[*]   Module versioning support

3)System Type  --->(選板子)

S3C2410 Machines  --->

[*] SMDK2410/A9M2410(只選擇此項)

[ ] IPAQ H1940(選擇後會在31008000)

4)Kernel Features  --->

[*] Use the ARM EABI to compile the kernel

[*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL

[*] Provide old way to pass kernel parameters

5)Userspace binary formats  --->

[*] Kernel support for ELF binaries

[*] Write ELF core dumps with partial segments

< > Kernel support for a.out and ECOFF binaries(此項不選,選擇後會報某些錯)

6)Networking support

Networking options  --->  

[*] TCP/IP networking

……

7)Device Drivers  --->  (裝置驅動,根據需要添加修改,如網卡,led,lcd,beep等)

[*] Network device support  --->(網卡裝置支援)

Character devices  --->  (字元裝置支援,如:led,lcd)

<*> Multimedia support  --->(多媒體支援,如:V4L2)

[*] USB support  --->(USB支援)

8)File systems  --->(檔案系統,支援yaffs2,crmfs等)

[*] Network File Systems  --->(網路檔案系統)

<*>   NFS client support

[*]   Root file system on NFS

 

5, 核心編譯並拷貝到tftpboot下

make zImage

cp arch/arm/boot/zImage /tftpboot

6, 查看記憶體映射表:

[email protected]#  vim System.map

從記憶體映射表中可以知道

說明:以上的相關配置是針對arm平台的基本配置。如果想實現檔案分享權限設定,led,lcd驅動等,則可以在此基礎上修改和添加。

 

 

二,Nand flash驅動的添加

目的:nand flash 是預設配置的,只是他的分區可以根據我們的實際情況來配置

1, 修改分區資訊表

在arch/arm/plat-s3c24xx/common-smdk.c中有nand flash的分區資訊,根據我們實際生產中的需要,進行一些修改:

static struct mtd_partition smdk_default_nand_part[] = {

        [0] = {

                .name   = "uBoot",

                .size   = 0x40000,

                .offset = 0,

        },

        [1] = {

                .name   = "kernel",

                .offset = 0x40000,

                .size   = 0x400000,

        },

        [2] = {

                .name   = "fs",

                .offset = 0x440000,

                .size   = 0x800000,

        },

        [3] = {

                .name   = "extern fs",

                .offset = 0xc40000,

                .size   = 0x33c0000,

         },

}

name: 代表分區名字

size: 代表flash分區大小(單位:位元組)

offset: 代表flash分區的起始地址(相對於0x0的位移)

2,在此前的基礎上配置核心:

Device Drivers  --->

<*> Memory Technology Device (MTD) support  --->  

<*>   NAND Device Support  --->

<*>   NAND Flash support for Samsung S3C SoCs

 

3,編譯好,移植到開發板後可以看見這樣的列印資訊:

Creating 4 MTD partitions on "NAND":

0x000000000000-0x000000040000 : "uB00t"

0x000000040000-0x000000440000 : "kernel"

0x000000440000-0x000000c40000 : "fs"

0x000000c40000-0x000004000000 : "extern fs"

 

三,網卡驅動的添加:

目的:將網卡驅動移植到linux-3.1.4核心上,使其可以通過網路nfs的方式掛載主機環境上的檔案系統,從而實現linux系統的啟動

在此前的核心移植的步驟上面進行以下的修改和配置:

1, 我們這裡用到的網卡是cs8900。將已經下載好的網路卡驅動程式cs8900.c和cs8900.h兩個檔案拷貝到驅動下

[email protected]#  cp ……/cs8900.* drivers/net/arm

2, 修改drivers/net/arm/Kconfig 添加cs8900的配置項:

[email protected]#  cd drivers/net/arm/

[email protected]#  vim Kconfig

進行以下的配置(添加):

config ARM_CS8900

  tristate "cs8900 support"

  depends on ARM

  help

  support cs8900

3, 修改drivers/net/arm/Makefile 添加核心編譯配置:

[email protected]#  vim Makefile

添加一下的內容:

obj-$(CONFIG_ARM_CS8900) +=cs8900.o

4, 添加地址映射:

在arch/arm/plat-s3c24xx/include/plat/map.h添加宏定義:  

[email protected]#  vim arch/arm/mach-s3c2410/include/mach/map.h

 #define S3C24XX_VA_CS8900 0xE0000000

 #define S3C24XX_PA_CS8900 0x19000000

  #define S3C24XX_SZ_CS8900 SZ_1M

 

5, 添加平台代碼

在arch/arm/mach-s3c2410/mach-smdk2410.c中添加:

[email protected]#  vim arch/arm/mach-s3c2410/mach-smdk2410.c

static struct map_desc smdk2410_iodesc[] __initdata = {

   IODESC_ENT(CS8900)}

 

6, 虛擬位址到物理地址的轉換:

查看arch/arm/plat-samsang/include/plat/cpu.h

[email protected]#  vim arch/arm/plat-samsung/include/plat/cpu.h

#define IODESC_ENT(x) { (unsigned long)S3C24XX_VA_##x,

  __phys_to_pfn(S3C24XX_PA_##x), S3C24XX_SZ_##x, MT_DEVICE }

7, 一點說明:在linux-3.1.4核心的網卡驅動裡面加入了中斷處理機制

添加:

#include <linux/interrupt.h>

將set_irq_type(dev->irq, (1<<1)||(1<<0));修改為:

irq_set_irq_type(dev->irq, (1<<1)||(1<<0));

8, 核心配置,使之支援cs8900網卡:

Device Drivers  --->

[*] Network device support  --->  

[*]   Ethernet (10 or 100Mbit)  --->

<*>   cs8900 support

9, 重新編譯核心

make zImage

10,網卡移植好了可以再板子上面看見以下資訊:

Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)

eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0

 

 

 

 

說明:上一篇文章,直接粘貼了圖片,但是基本上不能看清楚,因而此篇文章就直接寫的哈。

【轉】 linux核心移植和網卡驅動(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.