OK6410开发板linux内核移植

时间:2021-06-27 12:22:55
 

一、环境介绍:

1、环境配置

Ø  开发板:ok6410-A

Ø  宿主机:XP-sp3下用Vmware搭建的CENTOS6.0系统

注:1)、外网网卡用的NAT方式连接,用来在window客户端用putty连接虚拟机和更新工具连上网用;

2)、第二块儿网卡用的桥接方式,用来连接开发板;

3)、串口用来在虚拟机里使用minicom连接开发板。

Ø  交叉工具:arm-linux-4.4.1.tar.gz

2、环境搭建结果

Minicom连接开发板:

Putty连接好虚拟机:

结束后内核能正常启动并挂载NFS系统:

二、移植过程

1、源代码准备

接下来开始。。哈哈 ,此过程痛并快乐着。。。准备好了么?gogogo。。。。

更新最新源代码,并创建新实验分支:

[root@localhost linux-2.6]# git fetch

remote: Counting objects: 270, done.

remote: Compressing objects: 100% (117/117), done.

remote: Total 120 (delta 87), reused 0 (delta 0)

Receiving objects: 100% (120/120), 26.10 KiB, done.

Resolving deltas: 100% (87/87), completed with 54 local objects.

From git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6

   371de6e..89307ba  master     -> origin/master

[root@localhost linux-2.6]# git status

# On branch zkf

nothing to commit (working directory clean)

[root@localhost linux-2.6]# git checkout -b test

Switched to a new branch 'test'

[root@localhost linux-2.6]# ls

arch     Documentation  init     lib          README          sound

block    drivers        ipc      MAINTAINERS  REPORTING-BUGS  tools

COPYING  firmware       Kbuild   Makefile     samples         usr

CREDITS  fs             Kconfig  mm           scripts         virt

crypto   include        kernel   net          security

[root@localhost linux-2.6]#

新添加一个说明文件,说明一下修改源代码遵循GPL版权

[root@localhost linux-2.6]# vi ok6410_readme.txt

[root@localhost linux-2.6]# git add ok6410_readme.txt

[root@localhost linux-2.6]# git commit –a

[test 97a3a32] add note

 1 files changed, 3 insertions(+), 0 deletions(-)

 create mode 100644 ok6410_readme.txt

[root@localhost linux-2.6]#

2、移植过程

(1)、修改顶层makefile文件

注释掉默认的并新添加:

export KBUILD_BUILDHOST := $(SUBARCH)

#ARCH           ?= $(SUBARCH)

ARCH            ?= arm

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

CROSS_COMPILE   ?= arm-linux

# Architecture as present in compile.h

(2)、新增并修改板级文件

(复制现有最相近的板子的)

[root@localhost mach-s3c64xx]# ls

clock.c      Kconfig                 mach-smartq.c     setup-i2c0.c

cpu.c        mach-anw6410.c          mach-smartq.h     setup-i2c1.c

dev-audio.c  mach-crag6410.c         mach-smdk6400.c   setup-ide.c

dev-spi.c    mach-crag6410-module.c  mach-smdk6410.c   setup-keypad.c

dev-uart.c   mach-hmt.c              Makefile          setup-sdhci.c

dma.c        mach-mini6410.c         Makefile.boot     setup-sdhci-gpio.c

include      mach-ncp.c              pm.c              sleep.S

irq.c        mach-real6410.c         s3c6400.c

irq-eint.c   mach-smartq5.c          s3c6410.c

irq-pm.c     mach-smartq7.c          setup-fb-24bpp.c

[root@localhost mach-s3c64xx]# pwd

/home/linux-2.6/arch/arm/mach-s3c64xx

其中的mach-mini6410.c 板子的配置与ok6410比较相似

[root@localhost mach-s3c64xx]# cp mach-mini6410.c mach-ok6410.c

修改mach-ok6410.c

/* linux/arch/arm/mach-s3c64xx/mach-ok6410.c

将文件中所有mini6410替换为ok6410

:%s/mini6410/ok6410/g

注意需要将大写的MINI6410也要替换掉(其中大部分都是输出信息,有一处与机器码有关的要更改)

 

MACHINE_START(MINI6410, "MINI6410")

        /* Maintainer: Darius Augulis <augulis.darius@gmail.com> */

        .atag_offset    = 0x100,

        .init_irq       = s3c6410_init_irq,

        .map_io         = ok6410_map_io,

        .init_machine   = ok6410_machine_init,

        .timer          = &s3c24xx_timer,

 

此文件中包含NAND的分区信息可以根据自己的需求修改:

/*modify by zkf

//static struct mtd_partition ok6410_nand_part[] = {

//      [0] = {

//              .name   = "uboot",

//              .size   = SZ_1M,

//              .offset = 0,

//      },

//      [1] = {

//              .name   = "kernel",

//              .size   = SZ_2M,

//              .offset = SZ_1M,

//      },

//      [2] = {

//              .name   = "rootfs",

//              .size   = MTDPART_SIZ_FULL,

//              .offset = SZ_1M + SZ_2M,

//      },

//};

*/

struct mtd_partition ok6410_nand_part[] = {

 {

  .name  = "Bootloader",

  .offset  = 0,

  .size  = (1 * SZ_1M),

  .mask_flags = MTD_CAP_NANDFLASH,

 },

 {

  .name  = "Kernel",

  .offset  = (1 * SZ_1M),

  .size  = (5*SZ_1M) ,

  .mask_flags = MTD_CAP_NANDFLASH,

 },

 {

  .name  = "User",

  .offset  = (6 * SZ_1M),

  .size  = (120*SZ_1M) ,

 },

{

  .name  = "File System",

  .offset  = MTDPART_OFS_APPEND,

  .size  = MTDPART_SIZ_FULL,

 }

};

/*modify by zkf end*/

修改此目录下的Makefile 文件,使之在编译的时候编译我们刚才新建的“mach-ok6410”文件:

# Machine support

obj-$(CONFIG_MACH_ANW6410)      += mach-anw6410.o

obj-$(CONFIG_MACH_SMDK6400)     += mach-smdk6400.o

obj-$(CONFIG_MACH_SMDK6410)     += mach-smdk6410.o

obj-$(CONFIG_MACH_REAL6410)     += mach-real6410.o

obj-$(CONFIG_MACH_OK6410)       += mach-ok6410.o

obj-$(CONFIG_MACH_MINI6410)     += mach-mini6410.o

obj-$(CONFIG_MACH_NCP)          += mach-ncp.o

obj-$(CONFIG_MACH_HMT)          += mach-hmt.o

obj-$(CONFIG_MACH_SMARTQ)       += mach-smartq.o

obj-$(CONFIG_MACH_SMARTQ5)      += mach-smartq5.o

obj-$(CONFIG_MACH_SMARTQ7)      += mach-smartq7.o

obj-$(CONFIG_MACH_WLF_CRAGG_6410) += mach-crag6410.o mach-crag6410-module.o

修改此目录下的Kconfig文件:(比照其他开发板增加)

config MACH_OK6410

        bool "OK6410"

        select CPU_S3C6410

        select S3C_DEV_HSMMC

        select S3C_DEV_HSMMC1

        select S3C64XX_SETUP_SDHCI

        select S3C_DEV_USB_HOST

        select S3C_DEV_NAND

        select S3C_DEV_FB

        select S3C64XX_SETUP_FB_24BPP

        select SAMSUNG_DEV_ADC

        select SAMSUNG_DEV_TS

        help

          Machine support for the FriendlyARM MINI6410

 

(3)、机器码修改

修改/home/linux-2.6/arch/arm/tools目录下mach-types文件,增加新添加开发板的机器码

# machine_is_xxx        CONFIG_xxxx             MACH_TYPE_xxx           number

smdk4212                MACH_SMDK4212           SMDK4212                3638

smdk4412                MACH_SMDK4412           SMDK4412                3765

ok6410                  MACH_OK6410             OK6410                  1216

(4)、配置内核

接下来配置内核:(如果有现成的配置文件更好啦,哈哈)

[root@localhost linux-2.6]# make menuconfig

  HOSTCC  scripts/basic/fixdep

  HOSTCC  scripts/kconfig/conf.o

 *** Unable to find the ncurses libraries or the

 *** required header files.

 *** 'make menuconfig' requires the ncurses libraries.

 ***

 *** Install ncurses (ncurses-devel) and try again.

 ***

make[1]: *** [scripts/kconfig/dochecklxdialog] 错误 1

make: *** [menuconfig] 错误 2

 

提示错误没有安装ncurses

[root@localhost linux-2.6]# yum –y install ncurses  ncurses-devel 安装后进入配置界面:

有耐心可以每项都看看。。。。这里附上一个配置好的文件(cp ok6410_config .config 即可)

此时文件的修改已经结束了, 。

(5)修改文件概览

看一下修改的文件有哪些:

[root@localhost linux-2.6]# git status

# On branch test

# Changed but not updated:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#       modified:   Makefile

#       modified:   arch/arm/mach-s3c64xx/Makefile

#       modified:   arch/arm/tools/mach-types

#

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#       arch/arm/mach-s3c64xx/mach-ok6410.c

#       ok6410_config

no changes added to commit (use "git add" and/or "git commit -a")

[root@localhost linux-2.6]# git add arch/arm/mach-s3c64xx/mach-ok6410.c

[root@localhost linux-2.6]# git add ok6410_config

Commit一下做一下记录:

commit c07db86a1c7f6658958678eccb418f08bf665c6b

Author: zkaifa@VM <zkaifa@163.com>

Date:   Fri Dec 30 16:22:59 2011 +0800

 

    config is done

 

    lala...Prepare to "make"

 

commit a26c6397a3446766ed6744012b4e570e185a698e

Author: zkaifa@VM zkaifa@163.com

(6)、编译内核

make  zImage

 

三、烧写内核

由于linux下DNW不太好用所以暂时把串口切换到windows下,使用DNW工具下载调试(大家谁有好的办法记得通知我哦, )

1、将编译好的zImage拷贝到windows下

2、用DNW下载内核

选择好内核下载到板子内存中

下载完成

3、擦除NAND内核分区

4、写入NAND

Reset一下,重启板子。

四、后期DEBUG

1、机器码问题

下载好内核,运行后提示机器码不对

将9d8 转换为十进制:2520,这是飞凌UBOOT支持的机器码,所以需要将以上源代码中arch/arm/tools目录下mach-types文件里的机器码改为2520.

phy3250                 MACH_PHY3250            PHY3250                 2511

ok6410          MACH_OK6410             OK6410          2520

#mini6410               MACH_MINI6410           MINI6410                2520

这里只是暂时修改一下,为了调试通过,没有破坏源代码的意思。

2、NAND的oobsize问题

接着报错,应该是NAND驱动的问题oobsize没有与218对应的:

 

Debug信息:

------------[ cut here ]------------

kernel BUG at drivers/mtd/nand/nand_base.c:3268!

Internal error: Oops - undefined instruction: 0 [#1]

Modules linked in:

CPU: 0    Not tainted  (3.2.0-rc7-00021-g6fdd858-dirty #2)

PC is at nand_scan_tail+0xbc/0x5d8

LR is at nand_scan_tail+0xbc/0x5d8

pc : [<c01c3094>]    lr : [<c01c3094>]    psr: 60000013

sp : cf82fee8  ip : 00003f00  fp : 00000001

r10: 00000000  r9 : 00000001  r8 : c03ba950

r7 : 00000000  r6 : cf84a540  r5 : cf907800  r4 : cf907a00

r3 : 00000000  r2 : cf82fedc  r1 : c0347669  r0 : 0000002c

Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel

Control: 00c5387d  Table: 50004008  DAC: 00000017

Process swapper (pid: 1, stack limit = 0xcf82e268)

Stack: (0xcf82fee8 to 0xcf830000)

fee0:                   cf907800 cf9f6e40 cf84a540 c01c8fec 00000000 00000000

ff00: 0000001c c03ba958 c03ba958 c03d6510 c03d6510 00000000 00000000 00000000

ff20: 00000000 c01b0738 c01b0720 c01af568 00000000 c03ba958 c03ba98c c03d6510

ff40: 00000000 c01af678 c03d6510 c01af618 00000000 c01aede4 cf803c48 cf8262e0

ff60: c03d6510 cf9f6de0 c03d3038 c01ae748 c03483a9 c03483a9 00000001 c03d6510

ff80: c03a44c4 c000e8b4 00000000 00000000 00000000 c01afc60 c03b18b0 c03a44c4

ffa0: c000e8b4 00000000 00000000 c00085e0 00000064 0000000c c03b1618 00303031

ffc0: 00000000 c03b18b0 c03b1618 c000e8b4 00000013 00000000 00000000 00000000

ffe0: 00000000 c0393208 00000000 00000000 c0393198 c000e8b4 ffffdfbf bf5fff5f

[<c01c3094>] (nand_scan_tail+0xbc/0x5d8) from [<c01c8fec>] (s3c24xx_nand_probe+0x380/0x43c)

[<c01c8fec>] (s3c24xx_nand_probe+0x380/0x43c) from [<c01b0738>] (platform_drv_probe+0x18/0x1c)

[<c01b0738>] (platform_drv_probe+0x18/0x1c) from [<c01af568>] (driver_probe_device+0xa8/0x158)

[<c01af568>] (driver_probe_device+0xa8/0x158) from [<c01af678>] (__driver_attach+0x60/0x84)

[<c01af678>] (__driver_attach+0x60/0x84) from [<c01aede4>] (bus_for_each_dev+0x44/0x74)

[<c01aede4>] (bus_for_each_dev+0x44/0x74) from [<c01ae748>] (bus_add_driver+0xa8/0x21c)

[<c01ae748>] (bus_add_driver+0xa8/0x21c) from [<c01afc60>] (driver_register+0xa4/0x130)

[<c01afc60>] (driver_register+0xa4/0x130) from [<c00085e0>] (do_one_initcall+0x94/0x164)

[<c00085e0>] (do_one_initcall+0x94/0x164) from [<c0393208>] (kernel_init+0x70/0x118)

[<c0393208>] (kernel_init+0x70/0x118) from [<c000e8b4>] (kernel_thread_exit+0x0/0x8)

Code: e58431c0 ea000003 e59f0488 eb037830 (e7f001f2)

---[ end trace 1ce9fea0dee9eda6 ]---

Kernel panic - not syncing: Attempted to kill init!

[<c001309c>] (unwind_backtrace+0x0/0xec) from [<c02a1028>] (panic+0x54/0x184)

[<c02a1028>] (panic+0x54/0x184) from [<c0024058>] (do_exit+0x98/0x628)

[<c0024058>] (do_exit+0x98/0x628) from [<c001135c>] (die+0x1a8/0x1d8)

[<c001135c>] (die+0x1a8/0x1d8) from [<c000838c>] (do_undefinstr+0x168/0x18c)

[<c000838c>] (do_undefinstr+0x168/0x18c) from [<c000d628>] (__und_svc+0x48/0x60)

Exception stack(0xcf82fea0 to 0xcf82fee8)

fea0: 0000002c c0347669 cf82fedc 00000000 cf907a00 cf907800 cf84a540 00000000

fec0: c03ba950 00000001 00000000 00000001 00003f00 cf82fee8 c01c3094 c01c3094

fee0: 60000013 ffffffff

[<c000d628>] (__und_svc+0x48/0x60) from [<c01c3094>] (nand_scan_tail+0xbc/0x5d8)

[<c01c3094>] (nand_scan_tail+0xbc/0x5d8) from [<c01c8fec>] (s3c24xx_nand_probe+0x380/0x43c)

[<c01c8fec>] (s3c24xx_nand_probe+0x380/0x43c) from [<c01b0738>] (platform_drv_probe+0x18/0x1c)

[<c01b0738>] (platform_drv_probe+0x18/0x1c) from [<c01af568>] (driver_probe_device+0xa8/0x158)

[<c01af568>] (driver_probe_device+0xa8/0x158) from [<c01af678>] (__driver_attach+0x60/0x84)

[<c01af678>] (__driver_attach+0x60/0x84) from [<c01aede4>] (bus_for_each_dev+0x44/0x74)

[<c01aede4>] (bus_for_each_dev+0x44/0x74) from [<c01ae748>] (bus_add_driver+0xa8/0x21c)

[<c01ae748>] (bus_add_driver+0xa8/0x21c) from [<c01afc60>] (driver_register+0xa4/0x130)

[<c01afc60>] (driver_register+0xa4/0x130) from [<c00085e0>] (do_one_initcall+0x94/0x164)

[<c00085e0>] (do_one_initcall+0x94/0x164) from [<c0393208>] (kernel_init+0x70/0x118)

[<c0393208>] (kernel_init+0x70/0x118) from [<c000e8b4>] (kernel_thread_exit+0x0/0x8)

 

从上面看出drivers/mtd/nand/nand_base.c此文件中报错

经仔细阅读此文件在3251行的一个if语句处发现了BUG():

3251         if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH))         {

   3252                 switch (mtd->oobsize) {

   3253                 case 8:

   3254                         chip->ecc.layout = &nand_oob_8;

   3255                         break;

   3256                 case 16:

   3257                         chip->ecc.layout = &nand_oob_16;

   3258                         break;

   3259                 case 64:

   3260                         chip->ecc.layout = &nand_oob_64;

   3261                         break;

   3262                 case 128:

   3263                         chip->ecc.layout = &nand_oob_128;

   3264                         break;

   3265                 default:

   3266                         pr_warn("No oob scheme defined for oobsize %d\n"        ,

   3267                                    mtd->oobsize);

   3268                         BUG();

   3269                 }

   3270         }

经过考虑,暂时修改为如下进行实验,使其不至于因为判断oobsize为218报错:

   3251         if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) {

   3252                 switch (mtd->oobsize) {

   3253                 case 8:

   3254                         chip->ecc.layout = &nand_oob_8;

   3255                         break;

   3256                 case 16:

   3257                         chip->ecc.layout = &nand_oob_16;

   3258                         break;

   3259                 case 64:

   3260                         chip->ecc.layout = &nand_oob_64;

   3261                         break;

   3262                 case 128:

   3263                         chip->ecc.layout = &nand_oob_128;

   3264                         break;

   3265                 case 218:

   3266                         chip->ecc.layout = &nand_oob_128;

   3267                         break;

   3268                 default:

   3269                         pr_warn("No oob scheme defined for oobsize %d\n",

   3270                                    mtd->oobsize);

   3271                         BUG();

   3272                 }

   3273         }

修改完在进行编译、下载、运行,结果:

再次启动能根据uboot设置的NFS地址正常挂载NFS分区,至此内核简单的移植后在OK6410板子上暂时跑起来了,网卡驱动已经驱动起来。可以在进行一些实验,挂载NFS还是一个不错的办法哦。

至此编译好的:

保存一下现场,commit一下,lalalala。。。。。。

[root@localhost linux-2.6]# git status

# On branch test

# Changed but not updated:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#       modified:   arch/arm/mach-s3c64xx/mach-ok6410.c

#       modified:   arch/arm/tools/mach-types

#       modified:   drivers/mtd/nand/nand_base.c

#

no changes added to commit (use "git add" and/or "git commit -a")

[root@localhost linux-2.6]# git commit -a

[test d0c9386] Transplant the kernel ... done

 3 files changed, 11 insertions(+), 8 deletions(-)

[root@localhost linux-2.6]#

 

调试过程中其他问题欢迎探讨.

五、总结

     内核移植和调试是一个比较繁琐的过程,需要有细心、耐心。此文只是简单记录一下移植的流程,还需进行LCD、音频、USB、摄像头、蓝牙、红外、WIFI等驱动的编写和移植。相关的GIT patch文件可以发邮件。

 

图片粘贴贴不上去。需要的可以到下载里搜索本文标题