• 嵌入式系统移植三步曲 贾文龙


    嵌入式系统移植三步曲

    Bootloader的移植————>Linux的移植----->根文件系统的移植

    班机:09应用技术二班 姓名:贾文龙 学号:0906042030

    一、Bootloader的移植

    1.编辑u-boot根目录中的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

    2.复制必要的文件,编辑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

    OBJS       := smdk2410.o flash.o

    改为

    OBJS       := ok2410.o flash.o

    3.配置、编译u-boot

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

    修改cpu/arm920t/config.mk文件

    PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)

    改成:

    PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,$(call cc-option,-mabi=apcs-gnu,))

    修改examples目录下的Makefile文件

    将原文件的第58行开始的内容:

    SREC           = hello_world.srec

    BIN           = hello_world.bin hello_world

    改为

    SREC           = hello_world.o

    BIN           = hello_world.o hello_world

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

    make[1]: Leaving directory `/root/Desktop/u-boot-1.1.4/common'

    UNDEF_SYM=`/usr/local/arm/2.95.3/bin/arm-linux-objdump -x lib_generic/libgeneric.a board/ok2410/libok2410.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a |sed  -n -e 's/.*(__u_boot_cmd_.*)/-u1/p'|sort|uniq`;

                    /usr/local/arm/2.95.3/bin/arm-linux-ld -Bstatic -T /root/Desktop/u-boot-1.1.4/board/ok2410/u-boot.lds -Ttext 0x33F80000  $UNDEF_SYM cpu/arm920t/start.o

                            --start-group lib_generic/libgeneric.a board/ok2410/libok2410.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a --end-group -L /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3 -lgcc

                            -Map u-boot.map -o u-boot

    /usr/local/arm/2.95.3/bin/arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec

    /usr/local/arm/2.95.3/bin/arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin

    4.编辑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

    5.开始移植nand

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

    将从NOR Flash启动改成从NAND Flash启动。

    6.修改board/ok2410/Makefile

    OBJS           := ok2410.o flash.o

    改为

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

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

    #include

    #define __REGb(x) (*(volatile unsigned char *)(x))

    #define __REGi(x) (*(volatile unsigned int *)(x))

    #define NF_BASE  0x4e000000

    #define NFCONF  __REGi(NF_BASE + 0x0)

    #define NFCMD  __REGb(NF_BASE + 0x4)

    #define NFADDR  __REGb(NF_BASE + 0x8)

    #define NFDATA  __REGb(NF_BASE + 0xc)

    #define NFSTAT  __REGb(NF_BASE + 0x10)

    #define BUSY 1

    #ifndef NAND_SECTOR_SIZE

    #define NAND_SECTOR_SIZE 512

    #endif

    #ifndef NAND_BLOCK_MASK

     

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

    在文件的后部添加

    /****************** me add begin *******************/

    /*

    * Nandflash Boot

    */

    #define CONFIG_S3C2410_NAND_BOOT 1

    #define STACK_BASE    0x33f00000

    #define STACK_SIZE    0x8000

    //#define UBOOT_RAM_BASE    0x33f80000

    /* NAND Flash Controller */

    #define NAND_CTL_BASE            0x4E000000

    #define bINT_CTL(Nb)        __REG(INT_CTL_BASE + (Nb))

    /* Offset */

    #define oNFCONF               0x00

    #define oNFCMD                0x04

    #define oNFADDR               0x08

    #define oNFDATA               0x0c

    #define oNFSTAT               0x10

    #define oNFECC                0x14

    /****************** me add end *******************/

    9编译u-boot,然后测试u-boot是否可以从nand启动

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

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

    ……

    Loaded RAM   ./u-boot.bin        

    到此停止不动,需要执行如下命令:

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

    Bash:mknandflashdump:command not found

    解决:
    [root@localhost u-boot-1.1.4]# gcc -g mknandflashdump.c

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

    offset: 0x0 = 0

    1  pos: 0x0 = 0
    2  pos: 0x0 = 0
    finish

    [root@localhost u-boot-1.1.4]# ll nand.dump

    -rw-r--r-- 1 root root 118272 05-10 22:29 nand.dump

    [root@localhost u-boot-1.1.4]# chmod 666 nand.dump

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

    #define CONFIG_BAUDRATE                115200

    后面添加

    /*********************** me add begin *************************************/

    /* enable passing of ATAGs   */

    #define CONFIG_CMDLINE_TAG      1

    #define CONFIG_SETUP_MEMORY_TAGS  1

    #define CONFIG_INITRD_TAG   1

    /*********************** me add end *************************************/

                            /*CFG_CMD_NAND        |*/

    改为

                            CFG_CMD_NAND        |

    /*#define CONFIG_BOOTARGS            "root=ramfs devfs=mount console=ttySA0,9600" */

    改为

    #define CONFIG_BOOTARGS        "noinitrd root=/dev/nfs rw nfsroot=10.0.0.1:/tmp/nfs ip=10.0.0.110:10.0.0.1:10.0.0.1:255.255.255.0 init=linuxrc console=ttySAC0,115200  mem=64M"

    /*#define CONFIG_BOOTCOMMAND        "tftp; bootm" */

    改为

    #define CONFIG_BOOTCOMMAND        "tftp 0x31000000 uImage;bootm 0x31000000"

     

    /****************** me add begin *******************/

    //  #define         CFG_ENV_IS_IN_FLASH         1         /*将该行注释,添加下面一行*/

    #define CFG_ENV_IS_IN_NAND  1                  /*该行很重要,没有该行,saveenv命令将失效*/

    #define CFG_ENV_SIZE         0x10000                  /* Total Size of Environment Sector */

    #define CFG_NAND_LEGACY 1

    #define CFG_ENV_OFFSET  0X20000                  /*环境变量在Nand Flash0x20000*/

    #if (CONFIG_COMMANDS & CFG_CMD_NAND)

    #define CFG_NAND_BASE 0x4E000000         /* physical address to access nand at CS0*/

                                                                   /* Nand Flash控制器在SFR区起始寄存器地址 */

    #define CFG_MAX_NAND_DEVICE 1                  /*支持Nand Flash设备的最大个数*/

    #define SECTORSIZE 512

    #define NAND_SECTOR_SIZE SECTORSIZE

    #define NAND_BLOCK_MASK 511

    #define ADDR_COLUMN 1

    #define ADDR_PAGE 3

    #define ADDR_COLUMN_PAGE 4

    #define NAND_ChipID_UNKNOWN 0x00         /* 未知芯片的ID*/

    #define NAND_MAX_FLOORS 1

    #define NAND_MAX_CHIPS 1                           /* 板子上NAND Flash芯片的最大个数 */

    /*下面7行是Nand Flash命令层底层的接口函数 */

    #define WRITE_NAND_COMMAND(d, adr) {rNFCMD = d;}

    #define WRITE_NAND_ADDRESS(d, adr) {rNFADDR = d;}

    #define WRITE_NAND(d, adr) {rNFDATA = d;}

    #define READ_NAND(adr) (rNFDATA)

    #define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}

    #define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}

    #define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}

    /* the following functions are NOP's because S3C24X0 handles this in hardware */

    #define NAND_CTL_CLRALE(nandptr)

    #define NAND_CTL_SETALE(nandptr)

    #define NAND_CTL_CLRCLE(nandptr)

    #define NAND_CTL_SETCLE(nandptr)

    #define CONFIG_MTD_NAND_VERIFY_WRITE 1         /* 允许Nand Flash写校验 */

    /*

    * Nandflash Boot

    */

    #define CONFIG_S3C2410_NAND_BOOT 1

    #define STACK_BASE    0x33f00000

    #define STACK_SIZE    0x8000

    //#define UBOOT_RAM_BASE    0x33f80000

    /* NAND Flash Controller */

    #define NAND_CTL_BASE            0x4E000000

    #define bINT_CTL(Nb)        __REG(INT_CTL_BASE + (Nb))

    /* Offset */

    #define oNFCONF               0x00

    #define oNFCMD                0x04

    #define oNFADDR               0x08

    #define oNFDATA               0x0c

    #define oNFSTAT               0x10

    #define oNFECC                0x14

    #define rNFCONF (*(volatile unsigned int *)0x4e000000)

    #define rNFCMD (*(volatile unsigned char *)0x4e000004)

    #define rNFADDR (*(volatile unsigned char *)0x4e000008)

    #define rNFDATA (*(volatile unsigned char *)0x4e00000c)

    #define rNFSTAT (*(volatile unsigned int *)0x4e000010)

    #define rNFECC (*(volatile unsigned int *)0x4e000014)

    #define rNFECC0 (*(volatile unsigned char *)0x4e000014)

    #define rNFECC1 (*(volatile unsigned char *)0x4e000015)

    #define rNFECC2 (*(volatile unsigned char *)0x4e000016)

    #endif /* CONFIG_COMMANDS & CFG_CMD_NAND*/

    /****************** me add end *******************/

     

    11.编辑board/ok2410/ok2410.c文件

    在文件的尾部添加如下内容:

    /****************** me add begin *******************/

    #if (CONFIG_COMMANDS & CFG_CMD_NAND)

    typedef enum {

            NFCE_LOW,

            NFCE_HIGH

    } NFCE_STATE;

     

    static inline void NF_Conf(u16 conf)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            nand->NFCONF = conf;

    }

     

    static inline void NF_Cmd(u8 cmd)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            nand->NFCMD = cmd;

    }

     

    static inline void NF_CmdW(u8 cmd)

    {

            NF_Cmd(cmd);

            udelay(1);

    }

     

    static inline void NF_Addr(u8 addr)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            nand->NFADDR = addr;

    }

     

    static inline void NF_SetCE(NFCE_STATE s)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            switch (s) {

                    case NFCE_LOW:

                            nand->NFCONF &= ~(1<<11);

                            break;

                    case NFCE_HIGH:

                            nand->NFCONF |= (1<<11);

                            break;

            }

    }

     

    static inline void NF_WaitRB(void)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            while (!(nand->NFSTAT & (1<<0)));

    }

     

    static inline void NF_Write(u8 data)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            nand->NFDATA = data;

    }

     

    static inline u8 NF_Read(void)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            return(nand->NFDATA);

    }

     

    static inline void NF_Init_ECC(void)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            nand->NFCONF |= (1<<12);

    }

     

    static inline u32 NF_Read_ECC(void)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            return(nand->NFECC);

    }

     

    #endif

    /*

    * NAND flash initialization.

    */

    #if (CONFIG_COMMANDS & CFG_CMD_NAND)

    extern ulong nand_probe(ulong physadr);

     

    static inline void NF_Reset(void)

    {

            int i;

            NF_SetCE(NFCE_LOW);

            NF_Cmd(0xFF); /* reset command */

            for(i = 0; i < 10; i++); /* tWB = 100ns. */

            NF_WaitRB(); /* wait 200~500us; */

            NF_SetCE(NFCE_HIGH);

    }

     

    static inline void NF_Init(void)

    {

    #if 0 /* a little bit too optimistic */

    #define TACLS 0

    #define TWRPH0 3

    #define TWRPH1 0

    #else

    #define TACLS 0

    #define TWRPH0 4

    #define TWRPH1 2

    #endif

     

            NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));

    /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */

    /* 1 1 1 1, 1 xxx, r xxx, r xxx */

    /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */

            NF_Reset();

    }

     

    void nand_init(void)

    {

            S3C2410_NAND * const nand = S3C2410_GetBase_NAND();

            NF_Init();

    #ifdef DEBUG

            printf("NAND flash probing at 0x%.8lX ", (ulong)nand);

    #endif

            printf ("%4lu MB ", nand_probe((ulong)nand) >> 20);

    }

    #endif

    /****************** me add end *******************/

    12修改 common/cmd_nand.c文件

    NanD_ReadBuf函数中的

            NanD_Command (nand, NAND_CMD_READ0);

    注释

    13.编译、测试

    [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
    In:    serial
    Out:   serial
    Err:   serial
    Hit any key to stop autoboot:  0
    TFTP from server 10.0.0.1; our IP address is 10.0.0.110
    Filename 'uImage'.
    Load address: 0x31000000
    Loading: checksum bad
    T T T T T T T T

    解决:建立tftp服务器并修改权限
    #chmod-R 755 /tftpboot;

    二、Linux的移植

    1.解压linux-2.6.14.7.tar.bz2

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

    2.编辑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

    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/

    cp: 无法 stat “../cs8900/cs8900.c”: 没有那个文件或目录

    解决:在../下建立cs8900目录

    4.修改drivers/net/arm/目录下的Kconfig文件

    在最后添加如下内容:

    config ARM_CS8900

           tristate "CS8900 support"

           depends on NET_ETHERNET && ARM && ARCH_SMDK2410

           help

           Support for CS8900A chipset based Ethernet cards. If you have a network

              (Ethernet) card of this type, say Y and read the Ethernet-HOWTO, available

               from as well as .To compile this driver as a module, choose M here and read.

       The module will be called cs8900.o.

    5.修改drivers/net/arm/目录下的Makefile文件

           在文件最后添加如下内容:

            obj-$(CONFIG_ARM_CS8900)        += cs8900.o

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

    添加一个头文件

    #include 410/smdk2410.h>

     

    static struct map_desc smdk2410_iodesc[] __initdata = {

      /* nothing here yet */

    };

    改为

    static struct map_desc smdk2410_iodesc[] __initdata = {

            /* nothing here yet */

            /* Map the ethernet controller CS8900A */

            { vSMDK2410_ETH_IO, pSMDK2410_ETH_IO, SZ_1M, MT_DEVICE }

    };

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

    文件的内容如下

                    #ifndef _INCLUDE_SMDK2410_H_

                    #define _INCLUDE_SMDK2410_H_

                    #include

                    #define pSMDK2410_ETH_IO 0x19000000

                    #define vSMDK2410_ETH_IO 0xE0000000

                    #define SMDK2410_ETH_IRQ IRQ_EINT9

            #endif // _INCLUDE_SMDK2410_H_

    8.设置Flash分区

    在此要编辑3个文件:devs.cmach-smdk2410.cs3c2410.c

    1)编辑devs.c文件,指明分区信息

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

    添加内容并修改该文件中s3c_device_nand结构体变量,添加对dev成员的赋值。

    struct platform_device s3c_device_nand = {

               .name                        = "s3c2410-nand",                      /* device name */

               .id                        = -1,                                                       /* device id */

               .num_resources             = ARRAY_SIZE(s3c_nand_resource),

               .resource             = s3c_nand_resource,                      /* Nand Flash Controller Registers */

               .dev =                                                  /* Add the Nand Flash device */

               {

                          .platform_data = &superlpplatform

               }

    };

         (2)编辑mach-smdk2410.c文件,指定启动时初始化

    kernel启动时依据对分区的设置进行初始化。

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

    修改smdk2410_devices[],指明初始化时,包括前面设置的Flash分区信息。

    /* 添加如下语句 */

               &s3c_device_nand,

    3)编辑s3c2410.c文件,禁止Flash ECC校验

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

    s3c2410_nand_init_chip()函数中。

              

                          chip->eccmode               = NAND_ECC_SOFT;

               改为

               chip->eccmode               = NAND_ECC_NONE;

    9.配置内核

             (1)支持启动时挂载devfs

    为了让内核支持devfs,以及在启动时/sbin/init运行之前,能够自动挂载/devdevfs文件系统,需要编辑fs/Kconfig文件。

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

    找到menu "Pseudo filesystems"

    添加如下语句:

    config DEVFS_FS

               bool "/dev file system support (OBSOLETE)"

               default y

    config DEVFS_MOUNT

               bool "Automatically mount at boot"

               default y

               depends on DEVFS_FS

    2)配置内核,产生.config文件

    [root@localhost linux-2.6.14.7]# make smdk2410_defconfig

    [root@localhost linux-2.6.14.7]# make menuconfig        

    弹出的TUI界面中,进行配置

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

    [root@localhost linux-2.6.14.7]# make

     CHK     include/linux/version.h

     

    make[1]: “include/asm-arm/mach-types.h”是最新的。

     

      CHK     include/linux/compile.h

     

      CHK     usr/initramfs_list

     

      CC      arch/arm/mach-s3c2410/devs.o

     

    arch/arm/mach-s3c2410/devs.c:138: error: `superlpplatform' undeclared here (not in a function)

     

    arch/arm/mach-s3c2410/devs.c:138: error: initializer element is not constant

     

    arch/arm/mach-s3c2410/devs.c:138: error: (near initialization for `s3c_device_nand.dev.platform_data')

     

    arch/arm/mach-s3c2410/devs.c:138: error: initializer element is not constant

     

    arch/arm/mach-s3c2410/devs.c:138: error: (near initialization for `s3c_device_nand.dev')

     

    make[1]: *** [arch/arm/mach-s3c2410/devs.o] 错误 1

     

    make: *** [arch/arm/mach-s3c2410] 错误 2

     

    解决:将添加的内容添加到源文件的头文件下面就行了!

    然后[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  ../

    cp: 无法 stat “initrd.img”: 没有那个文件或目录

    解决:cp ../../initrd.img

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

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

    cp: 无法 stat “initrd.img”: 没有那个文件或目录

    解决:cp ../initrd.img

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

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

    [root@localhost tools]# iptables -F

    三、根文件系统的移植

     

    1、解压busybox-1.13.4.tar.bz2

     

    2.编辑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

    在弹出的TUI界面中进行配置

    5.编译

    [root@localhost busybox-1.13.4]# make

    编译出错,此时需要编辑networking/interface.c文件

    [root@localhost busybox-1.13.4]# gedit networking/interface.c

    networking/interface.c文件的818行修改为“.type = -1”,然后再次编译。

    [root@localhost busybox-1.13.4]# make install

    如果成功,会出现如下信息:

     

    --------------------------------------------------

    You will probably need to make your busybox binary

    setuid root to ensure all configured applets will

    work properly.

    --------------------------------------------------

    修改_install/bin/busybox文件的属性

    [root@localhost busybox-1.13.4]# chmod 4755 ./_install/bin/busybox       

    6、对配置信息进行修改 注意此处是在/tmp/nfs

    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

    [root@localhost nfs]# chmod 1777 tmp

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

    [root@localhost nfs]# cd dev/

    [root@localhost dev]# mknod -m 600 console c 5 1   注意此处是在/tmp/nfs/dev

    [root@localhost dev]# mknod -m 666 null c 1 3      注意此处是在/tmp/nfs/dev

    2)复制文件到/tmp/nfs

    /root/Desktop/busybox-1.13.4/_install中的内容复制到/tmp/nfs

    注意此处转换目录进入/busybox-1.13.4/_install

    [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文件、修改其权限

    文件内容如下:

    ::sysinit:/etc/init.d/rcS           #指定系统初始化脚本文件

    ::respawn:-/bin/login            #加上-语句会在登陆终端之后调用/etc/目录下的profile文件

    ::restart:/sbin/init                                 #指定系统重启时执行的初始化程序

     

    tty0::respawn:-/bin/login

     

    ::shutdown:/bin/umount -a -r           #指定关机时执行的操

    ::shutdown:/sbin/swapoff -a

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

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

    文件内容如下:

    #!/bin/sh

    # mount all filesystem defined in "fstab"

    echo "#mount all......."

    /bin/mount -a

     

    /bin/mknod -m 600 /dev/console c 5 1

    /bin/mknod -m 666 /dev/null c 1 3

    /bin/mknod -m 666 /dev/tty0 c 4 0

    /bin/mknod -m 666 /dev/mtdblock0 b 31 0

    /bin/mknod -m 666 /dev/mtdblock1 b 31 1

    /bin/mknod -m 666 /dev/mtdblock2 b 31 2

    /bin/mknod -m 666 /dev/mtdblock3 b 31 3

    #/bin/mount -t ext2 /dev/mtdblock3 /mnt/temp/

     

    echo "******************************************************************"

    echo "                   OK 2410 Rootfs made by JWL, 2011.06"

    echo "******************************************************************"

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

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

    文件内容如下:

    proc           /proc           proc           defaults           0           0

    sysfs           /sys           sysfs           defaults           0           0

    none           /tmp           ramfs           defaults           0           0

    mdev           /dev           ramfs           defaults           0           0

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

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

            文件内容如下:

    # /etc/profile: system-wide .profile file for the Bourne shells

    echo

    echo -n "Processing /etc/profile... "

    # no-op

    # Set search library path

    echo "Set search library path in /etc/profile"

    export LD_LIBRARY_PATH=/lib:/usr/lib

    # Set user path

    echo "Set user path in /etc/profile"

    export PATH=/bin:/sbin:/usr/bin:/usr/sbin           #设置命令搜索路径

    export HISTSIZE=100

    export PS1='[u@JWL W]$ '

    alias ll='ls -l'

    #/sbin/ifconfig eth0 192.168.1.22 netmask 255.255.255.0

    /sbin/ifconfig lo 127.0.0.1

    echo "Configure net done"

    echo "All Done"

    echo

    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::0:0:root:/root:/bin/sh

    [root@localhost nfs]# gedit etc/shadow

    内容是:root:$1$zs2zr2N4$15U99ll5tUm3DwOvKnCVV1:14335:0:99999:7:::

    [root@localhost nfs]# gedit etc/group

    内容是:root:x:0:root

    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

    #!/bin/bash

    #You should put this file cp.sh in /usr/local/arm/3.4.1/arm-linux/lib/

    ROOTFS_LIB=/tmp/nfs/lib/

    for file in libc libcrypt libdl libm libpthread libresolv libutil

    do

    cp $file-*.so ${ROOTFS_LIB}

    cp -d $file.so.[*0-9] ${ROOTFS_LIB}

    done

    cp -d ld*.so* ${ROOTFS_LIB}

    [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

    9.完整的启动过程(u-boot、内核、文件系统)

    注意:在嵌入式系统开发的过程中,一般的做法是通过tftp将操作系统内核下载到开发板,内核引导时通过NFS挂载根文件系统,下面的操作过程既是如此。

    (1)编辑/etc/xinetd.d/tftp文件

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

    (2)重启tftp服务器

    (3)编辑/etc/exports文件

    文件内容如下:

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

    4)重启NFS服务器     

    5)完整的启动过程(u-boot、内核、文件系统、用户程序(注意:通过uboot引导内核要在 u-boot-1.1.4文件夹里)),使用NFS文件系统

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

    10.0.0.110 login: root

    Password:

    login[25]: root login on 'console'

    login: cannot run /bin/bash: Exec format error

    解决:[root@localhost nfs]gedit etc/passwd

    将:root:x:0:0:root:/root:/bin/bash

    改为:root:x:0:0:root:/root:/bin/sh

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

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

                       OK 2410 Rootfs made by JWL, 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@JWL /root]#

    [root@JWL /root]# ls /

    bin           dev           lib           root          tmp

    boot          etc           linuxrc       sbin          usr

    copy_lib.sh   home          mnt           sys           var

    copy_lib.sh~  initrd.img    proc          temp

     


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




  • 相关阅读:
    python学习之集合
    fastjson SerializerFeature详细使用教程(特别注意:重复引用和循环引用问题)
    Elasticsearch 常见问题汇总及解决姿势(后续会持续更新)
    Elasticsearch常用操作命令——增删改查、集群维护
    Python 常用包、模块定义详解
    Elasticsearch Python脚本查询常用操作
    右键菜单中新建EXCEL丢失解决办法
    解决Spring Boot 使用RedisTemplate 存储键值出现乱码
    深入理解xhr responseType blob arrayBuffer document text json使用
    Android内存溢出解决方案总结
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647521.html
Copyright © 2020-2023  润新知