zoukankan      html  css  js  c++  java
  • 嵌入式系统移植三部曲 于青林

    班级:09计应1班    姓名:于青林     学号:0906041017

     

    嵌入式系统移植三部曲

     

    一、           BootLoader的移植

    二、           Linux内核移植

    三、           根文件系统的移植

    准备工作:安装SkyEye

    SkyEye可以仿真出多种嵌入式开发板和外设,在安装SkyEye的过程中,就等于是在模拟出一个开发板。

    SkyEye的安装过程:

    1、下载skyeye-1.2.6_rc1,对其进行解压;

    [root@localhost Desktop]# tar -xjvf skyeye-1.2.6_rc1.tar.bz2 -C ./

    2、编译安装skyeye-1.2.6;

    [root@localhost Desktop]# cd skyeye-1.2.6_rc1

    [root@localhost skyeye-1.2.6_rc1]# gedit INSTALL       //编译安装信息

    [root@localhost skyeye-1.2.6_rc1]# ./configure               //配置

    [root@localhost skyeye-1.2.6_rc1]# make                            //编译

                                                                          [root@localhost skyeye-1.2.6_rc1]# make install      //安装

    [root@localhost skyeye-1.2.6_rc1]# ll /usr/local/bin/skyeye 

    出现 -rwxr-xr-x 1 root root 2544308 05-17 17:59 /usr/local/bin/skyeye

    则安装成功。

       

    一、BootLoader的移植

    BootLoader是加电后的第一个运行程序,它可以初始化开发板的硬件设备,将内核映像从硬盘上读到RAM中,从而跳转到linux的内核入口去执行程序,这样就可以启动操作系统了。由于BootLoader是第一个执行的程序,所以它和开发板的体系结构有很大的关系。

     

    BootLoader的移植过程:

    所需文件:交叉编译器:arm-linux-gcc2.95.3.tar.bz2,

    Bootloaderu-boot-1.1.4.tar.bz2

    1.解压u-boot-1.1.4.tar.bz2 和gcc2.95.3编译器

    [root@localhost Desktop]# tar -xjvf u-boot-1.1.4.tar.bz2  -C ./

    [root@localhost Desktop]# tar -xjvf arm-linux-gcc-2.95.3.tar.bz2 -C /usr/local/arm

     

    2.编辑u-boot目录中的Makefile文件

       [root@localhost u-boot-1.1.4]# gedit Makefile

      

    ifeq ($(ARCH),arm)

    CROSS_COMPILE = arm-linux-

    endif

    改为

    ifeq ($(ARCH),arm)

    CROSS_COMPILE=/usr/local/arm/2.95.3/bin/arm-linux-

    endif

     

    smdk2410_config       :       unconfig

                  @./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0

    后面添加

    ok2410_config       :       unconfig

                  @./mkconfig $(@:_config=) arm arm920t ok2410 NULL s3c24x0

    3复制必要的文件,编辑ok2410.h头文件

    [root@localhost u-boot-1.1.4]# mkdir board/ok2410

    [root@localhost u-boot-1.1.4]# cp board/smdk2410/* board/ok2410/

    [root@localhost u-boot-1.1.4]# mv board/ok2410/smdk2410.c board/ok2410/ok2410.c

    [root@localhost u-boot-1.1.4]# cp include/configs/smdk2410.h include/configs/ok2410.h

    [root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h

      

    #define       CFG_PROMPT              "SMDK2410 # "       /* Monitor Command Prompt       */

    改为

    #define       CFG_PROMPT              "OK2410 # "       /* Monitor Command Prompt       */

    4.编辑board/ok2410/Makefile文件

    [root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile

    OBJS       := smdk2410.o flash.o

    改为

    OBJS       := ok2410.o flash.o

    5.配置、编译u-boot

       [root@localhost u-boot-1.1.4]# make ok2410_config

       [root@localhost u-boot-1.1.4]# make

    6.编辑skyeye.conf文件

      [root@localhost u-boot-1.1.4]# gedit skyeye.conf

    # skyeye config file for S3C2410X

    cpu: arm920t

    mach: s3c2410x

    # physical memory

    mem_bank: map=M, type=RW, addr=0x00000000, size=0x00800000, file=./u-boot.bin ,boot=yes

    mem_bank: map=M, type=RW, addr=0x30000000, size=0x00800000

    mem_bank: map=M, type=RW, addr=0x30800000, size=0x00800000

    mem_bank: map=M, type=RW, addr=0x31000000, size=0x03000000

    # all peripherals I/O mapping area

    mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000

    mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020

     

    net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=08:00:3E:26:0A:5B, ethmod=tuntap, hostip=10.0.0.1

    nandflash: type=s3c2410x,name=K9F1208U0B,dump=./nand.dump

    #lcd:type=s3c2410x, mod=gtk

    dbct:state=on

    7.执行skyeye1.2.6

    [root@localhost u-boot-1.1.4]# skyeye1.2.6

    出现结果:

    ************************ WARNING ****************************

    If you want to run ELF image, you should use -e option to indicate

    your elf-format image filename. Or you only want to run binary image,

    you need to set the filename of the image and its entry in skyeye.conf.

    *************************************************************

    Your elf file is little endian.  //省略部分信息

    In:    serial

    Out:   serial

    Err:   serial

    OK2410 #

    8移植nand

    [root@localhost u-boot-1.1.4]# gedit cpu/arm920t/start.S

    9修改board/ok2410/Makefile

    [root@localhost u-boot-1.1.4]# gedit board/ok2410/Makefile

    OBJS       := ok2410.o flash.o

    改为

    OBJS       := ok2410.o flash.o nand_read.o

    10创建board/ok2410/nand_read.c文件

    [root@localhost u-boot-1.1.4]# gedit board/ok2410/nand_read.c

    11.编辑include/configs/ok2410.h文件

    [root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h

    12.编译u-boot测试u-boot是否可以从nand启动

     [root@localhost u-boot-1.1.4]# make

    [root@localhost u-boot-1.1.4]# skyeye1.2.6 //再次执行skyeye1.2.6

    13对u-boot添加nand指令的支持

    [root@localhost u-boot-1.1.4]# gedit include/configs/ok2410.h

    [root@localhost u-boot-1.1.4]# gedit board/ok2410/ok2410.c

    [root@localhost u-boot-1.1.4]# gedit common/cmd_nand.c

    14编译、测试

    [root@localhost u-boot-1.1.4]# make

    [root@localhost u-boot-1.1.4]# ./mknandflashdump u-boot.bin nand.dump 0

    [root@localhost u-boot-1.1.4]# skyeye1.2.6

      出现如第7步结果;

    到目前为止,BootLoader的移植完毕;

    二、Linux内核移植

       内核作为操作系统的核心,管理系统的进程、存储设备、文件系统等。内核移植是至关重要的一部分;

    linux内核移植的过程:

    需要文件:linux-2.6.14.7.tar.bz2  cs8900.ccs8900.h

            arm-linux-gcc3.4.1.tar.bz2

    在移植之前要搭建tftp服务器:

    查看tftp的配置文件:

    [root@localhost Desktop]# gedit /etc/xinetd.d/tftp

    [root@localhost Desktop]#chmod -R 755 /tftpboot

    [root@localhost Desktop]#service xinetd restart

    1.解压linux-2.6.14.7.tar.bz2

    [root@localhost Desktop]# tar -xjvf linux-2.6.14.7.tar.bz2 -C ./

    [root@localhost Desktop]#tar -xjvf arm-linux-gcc3.4.1.tar.bz2 -C ./

    2.编辑Makefile文件

    [root@localhost Desktop]# cd linux-2.6.14.7

    [root@localhost linux-2.6.14.7]# gedit Makefile

    ARCH              ?= $(SUBARCH)

    CROSS_COMPILE       ?=

    改为

    ARCH              ?= arm

    CROSS_COMPILE       ?= /usr/local/arm/3.4.1/bin/arm-linux-

    3、cs8900网卡的移植

    [root@localhost linux-2.6.14.7]# cp ../cs8900/cs8900.c drivers/net/arm/

    [root@localhost linux-2.6.14.7]# cp ../cs8900/cs8900.h drivers/net/arm/

    [root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Kconfig

    [root@localhost linux-2.6.14.7]# gedit drivers/net/arm/Makefile

    4.编辑arch/arm/mach-s3c2410/mach-smdk2410.c文件

    [root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/mach-smdk2410.c

    5在include/asm-arm/arch-s3c2410/目录下创建smdk2410.h文件

    [root@localhost linux-2.6.14.7]# gedit include/asm-arm/arch-s3c2410/smdk2410.h

    6设置Flash分区

    编辑3个文件devs.cmach-smdk2410.cs3c2410.c

    [root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/devs.c

    [root@localhost linux-2.6.14.7]# gedit arch/arm/mach-s3c2410/mach-smdk2410.c

    [root@localhost linux-2.6.14.7]# gedit drivers/mtd/nand/s3c2410.c

                  chip->eccmode           = NAND_ECC_SOFT;

    改为

                  chip->eccmode           = NAND_ECC_NONE;

    7配置内核

    [root@localhost linux-2.6.14.7]# gedit fs/Kconfig

    [root@localhost linux-2.6.14.7]# cp arch/arm/configs/smdk2410_defconfig .config

    [root@localhost linux-2.6.14.7]# make smdk2410_defconfig

    [root@localhost linux-2.6.14.7]# make menuconfig

    8编译内核,创建uImage,将uImage复制到tftp服务器的根目录(/tftpboot/)

    [root@localhost linux-2.6.14.7]# make

    [root@localhost linux-2.6.14.7]# cp arch/arm/boot/compressed/vmlinux ../u-boot-1.1.4/tools/

    [root@localhost linux-2.6.14.7]# cd ../u-boot-1.1.4/tools/

    [root@localhost tools]# ./mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008000 -n linux-2.6.14.7 -d vmlinux uImage

    [root@localhost tools]# cp uImage  ../

    [root@localhost tools]# cp initrd.img  ../

    [root@localhost tools]# cp uImage /tftpboot/

    [root@localhost tools]# cp initrd.img /tftpboot/

    [root@localhost tools]# cp ../u-boot.bin /tftpboot/

    [root@localhost tools]# cp initrd.img /tmp/nfs/

    [root@localhost tools]# iptables -F

    [root@localhost tools]# cd ..

    9.执行skyeye1.2.6,通过u-boot-1.1.4引导linux-2.6.14.7

    [root@localhost u-boot-1.1.4]# skyeye1.2.6

    **************************** WARNING ***************************

    If you want to run ELF image, you should use -e option to indicate

    your elf-format image filename. Or you only want to run binary image,

    you need to set the filename of the image and its entry in skyeye.conf.

    *****************************************************************

    Your elf file is little endian.

    arch: arm       //省略部分信息;

    *** Warning - bad CRC, using default environment

    In:    serial

    Out:   serial

    Err:   serial

    Hit any key to stop autoboot:  0

    OK2410 #setenv bootargs noinitrd mem=64M root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200

    OK2410 # tftp 0x31000000 uImage

    OK2410 # bootm 31000000

    ## Booting image at 31000000 ...

    //此时应该进行第三步,根文件系统的移植;

     

    三、根文件系统的移植

      linux启动后第一个必须挂载的是根文件系统,若不能挂载根文件系统,则系统会出错自动退出;

      根文件系统移植的过程:

    移植根文件系统所需文件:busybox-1.13.4.tar.bz2

    1.解压busybox-1.13.4.tar.bz2

    [root@localhost Desktop]# tar -xjvf busybox-1.13.4.tar.bz2 -C ./

    2.编辑Makefile文件

    [root@localhost busybox-1.13.4]# gedit Makefile

    CROSS_COMPILE ?=

    改为

    CROSS_COMPILE ?=/usr/local/arm/3.4.1/bin/arm-linux-

    ARCH ?= $(SUBARCH)

    改为

    ARCH ?= arm

    3进行默认配置

    [root@localhost busybox-1.13.4]# make defconfig       //恢复默认配置

    4对配置信息进行修改

    [root@localhost busybox-1.13.4]# make menuconfig

    5.编译

    [root@localhost busybox-1.13.4]# make

    6对配置信息进行修改

    1)在/tmp/nfs中创建所需的目录

    [root@localhost nfs]# mkdir -p bin sbin lib/modules etc/init.d dev usr/bin usr/sbin usr/lib proc sys  home root boot mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp var/lib var/lock var/log var/run var/tmp tmp

    注意:其中bindevetclibprocsbinsysusr必备的8个目录

    [root@localhost nfs]# chmod 1777 tmp

    [root@localhost nfs]# chmod 1777 var/tmp

    [root@localhost dev]# mknod -m 600 console c 5 1

    [root@localhost dev]# mknod -m 666 null c 1 3

    2)复制文件到/tmp/nfs中

    [root@localhost _install]# cp -a bin /tmp/nfs/

    [root@localhost _install]# cp -a sbin /tmp/nfs/

    [root@localhost _install]# cp -a linuxrc /tmp/nfs/

    [root@localhost _install]# cd ..

    [root@localhost busybox-1.13.4]# cp -a examples/bootfloppy/etc/* /tmp/nfs/etc/

    7创建配置文件

    1)编写etc/inittab文件、修改其权限

    [root@localhost nfs]# gedit etc/inittab

    [root@localhost nfs]# chmod 755 etc/inittab

    2)编写etc/init.d/rcS文件、修改其权限

    [root@localhost nfs]# gedit etc/init.d/rcS

    [root@localhost nfs]# chmod 755 etc/init.d/rcS

    3)编写etc/fstab文件、修改其权限

    [root@localhost nfs]# gedit etc/fstab

    [root@localhost nfs]# chmod 755 etc/fstab

    4)编写etc/proflie文件、修改其权限

    [root@localhost nfs]# gedit etc/proflie

    5)创建密码文件、修改其权限

    [root@localhost nfs]# cp /etc/passwd etc/ ;cp /etc/shadow etc/ ;cp /etc/group etc/

    [root@localhost nfs]# chmod 600 etc/shadow

    [root@localhost nfs]# gedit etc/passwd

    [root@localhost nfs]# gedit etc/shadow

    6)为mdev创建配置文件

    [root@localhost nfs]# gedit etc/mdev.conf

    7)删除备份文件

    [root@localhost nfs]# rm etc/*~ etc/init.d/*~

    8复制常用的文件

    编写脚本文件copy_lib.sh

    [root@localhost nfs]# gedit copy_lib.sh

    [root@localhost nfs]# chmod a+x copy_lib.sh

    [root@localhost nfs]# cp copy_lib.sh /usr/local/arm/3.4.1/arm-linux/lib/

    [root@localhost nfs]# cd /usr/local/arm/3.4.1/arm-linux/lib/

    [root@localhost lib]# ./copy_lib.sh

    [root@localhost lib]# cd -

     

    完整的启动过程

    通过tftp将操作系统内核下载到开发板,内核引导时通过NFS挂载根文件系统

    1)重启tftp服务器

    [root@localhost Desktop]# service xinetd restart

    2)编辑/etc/exports文件

    [root@localhost Desktop]# gedit /etc/exports

    /tmp/nfs *(rw,sync,no_root_squash)

    3)重启NFS服务器

    [root@localhost u-boot-1.1.4]# service nfs restart

    [root@localhost u-boot-1.1.4]# exportfs

    [root@localhost u-boot-1.1.4]# exportfs -ra       //重新扫描配置文件

    4)完整的启动过程(u-boot、内核、文件系统、用户程序),使用NFS文件系统

    [root@localhost u-boot-1.1.4]# skyeye1.2.6

    ************************** WARNING ***************************

    If you want to run ELF image, you should use -e option to indicate

    your elf-format image filename. Or you only want to run binary image,

    you need to set the filename of the image and its entry in skyeye.conf.

    *****************************************************************

    ……                     //省略部分信息;

    Hit any key to stop autoboot:  0

    OK2410 # run bootcmd

    TFTP from server 10.0.0.1; our IP address is 10.0.0.110

       //省略部分信息;

    Freeing init memory: 92K

    #mount all.......

    ******************************************************************

                       OK 2410 Rootfs made by yql, 2011,06

    ******************************************************************

    10.0.0.110 login: root

    login[25]: root login on 'console'

     Processing /etc/profile... Set search library path in /etc/profile

    Set user path in /etc/profile

    Configure net done

    All Done

    [root@10 root]#

    以上所述是通过tftp将操作系统内核下载到开发板,内核引导时通过NFS挂载根文件系统      另一种启动方式即将uImage烧写到nand flash上,烧写过程如下面所述的两种启动方式的第二种。

    四、错误分析

    BootLoader移植过程中:

    1、在第2步中:

       

    ifeq ($(ARCH),arm)

    CROSS_COMPILE = arm-linux-

    Endif

    改为

    ifeq ($(ARCH),arm)

    CROSS_COMPILE=/usr/local/arm/2.95.3/bin/arm-linux-

    Endif

       因为这里交叉编译器指定为

    CROSS_COMPILE=/usr/local/arm/2.95.3/bin/arm-linux- ,所以要安装arm-linux-gcc-2.95.3;

    因为没有事先安装,所以在配置、编译u-boot时出错;

    linux内核的移植:

    1、在第3步中:编辑Makefile文件

    [root@localhost linux-2.6.14.7]# gedit Makefile

    ARCH              ?= $(SUBARCH)

    CROSS_COMPILE       ?=

    改为

    ARCH              ?= arm

    CROSS_COMPILE       ?= /usr/local/arm/3.4.1/bin/arm-linux-       //linux2.6.14的交叉编译器为gcc-3.4.1

    在改写过程中CROSS_COMPILE       ?= /usr/local/arm/3.4.1/bin/arm-linux-

    注意交叉编译环境改写;

    2、第10步中:配置内核

       需要安装yaffs文件系统;

    3、tftp服务器搭建的过程中:

      [root@localhost Desktop]#chmod -R 755 /tftpbooot

    4、启动时注意防火墙的设置;

      

     五、启动的两种方式:

    1、通过nfs

       内核文件在宿主机上,开发板(skyeye)启动时,通过tftp将操作系统内核下载到开发板,内核引导时通过NFS挂载根文件系统      ,这种方法需要tftp和nfs服务器的支持,在开发的过程中这种方法是经常使用的。

        上面所述的过程即是通过这种方式启动的;

    2、通过nand flash,开发板自行启动

    这种方法需要将内核文件烧写到开发板上,当然这需要在开发板上建立文件系统,建立文件系统的过程如298页创建的Cramfs文件系统。(其他的文件系统也可)

    建立文件系统后,开始内核烧写:

    OK2410 # tftp 0x31000000 uImage

    OK2410 # nand erase 0x00100000 0x00300000

    OK2410 # nand write 0x31000000 0x00100000 0x00300000

    OK2410 # setenv bootcmd‘nand read 0x31000000 0x00100000 0x00300000;bootm 0x31000000’

    OK2410 # saveenv

    烧写到nand flash上后,再次启动skyeye时就会自行显示是在nand flash上启动,而不需要在从宿主机传送;

     

    http://blog.chinaunix.net/space.php?uid=14735472&do=blog&id=110947



    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
    阅读(401) | 评论(0) | 转发(1) |
    给主人留下些什么吧!~~
    评论热议
  • 相关阅读:
    怎样编写一个Photoshop滤镜(1)
    蜂窝状网格的定位方法
    【转载】[TC]飞船动画例子《C高级实用程序设计》
    【完全随笔】用户体验和设计
    在 WinCe 平台读写 ini 文件
    关于携带完整 alpha 通道图标的技术研究
    【转载】When should static_cast, dynamic_cast and reinterpret_cast be used?
    怎样编写一个Photoshop滤镜(3) Scripting Plugins
    配电网WebGIS研究与开发[5]
    配电网WebGIS研究与开发[4]
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647552.html
Copyright © 2011-2022 走看看