zoukankan      html  css  js  c++  java
  • 嵌入式系统移植三部曲 李敏敏

    院系:计算机与信息工程学院

    班级:09级计算机应用2班

    姓名:李敏敏

    学号:0906042023

     

    嵌入式系统移植三步曲

    Bootloader的移植

    Linux内核的移植

    Linux根文件系统的移植

     

     

     

     

    一、Bootloader的移植

    准备工作:

    1. 创建交叉编译环境

    解压arm-linux-gcc-2.95.3.tar.bz2到/usr/local/arm/中

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

    修改/etc/profile 文件,在文件的末尾添加如下内容:

    PATH=$PATH:/usr/local/arm/2.95.3/bin/arm-linux-

    运行:

    [root@localhost 嵌入式实验]# source /etc/profile

    检查所使用的交叉编译环境:

    [root@localhost 嵌入式实验]# arm-linux-gcc -v

    Reading specs from /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/specs

    gcc version 2.95.3 20010315 (release)

    2.安装SkyEye

    解压源码包

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

    编译skyeye-1.2.6

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

    [root@localhost skyeye-1.2.6_rc1]# ls

    aclocal.m4      ChangeLog     configure     depcomp     LICENSE      misc     REPORTING-BUGS

    arch            config.guess  configure.in  device      MAINTAINERS  missing  TODO

    AUTHORS         config.h.in   COPYING       INSTALL     Makefile.am  NEWS     utils

    autom4te.cache  config.sub    dbct          install-sh  Makefile.in  README

    [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                     //将skyeye安装到/usr/local/bin/

    [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

    下面一条命令将/usr/local/bin/skyeye改名为/usr/local/bin/skyeye1.2.6。

    [root@localhost skyeye-1.2.6_rc1]# mv /usr/local/bin/skyeye /usr/local/bin/skyeye1.2.6

      Bootloader的移植 

       本试验用的是u-boot-1.1.4.tar.bz2编辑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

    接着复制必要的文件,编辑ok2410.h头文件:

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

    改为

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

    编辑board/limin2410/Makefile文件:

    OBJS       := smdk2410.o flash.o

    改为

    OBJS       := ok2410.o flash.o

    配置、编译u-boot:

    出现如下错误:

    ......

    make -C examples all

    make[1]: Entering directory `/root/Desktop/u-boot-1.1.4/examples'

    /usr/local/arm/2.95.3/bin/arm-linux-gcc -g  -Os   -fno-strict-aliasing  -fno-common -ffixed-r8 -msoft-float  -D__KERNEL__ -DTEXT_BASE=0x33F80000 -I/root/Desktop/u-boot-1.1.4/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/include -pipe  -DCONFIG_ARM -D__ARM__ -march=armv4 -mabi=apcs-gnu -Wall -Wstrict-prototypes -c -o hello_world.o hello_world.c

    cc1: Invalid option `abi=apcs-gnu'

    make[1]: *** [hello_world.o] 错误 1

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

    make: *** [examples] 错误 2

    修改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,))

    编译接着出现了如下的错误

    ......

    /usr/local/arm/2.95.3/bin/arm-linux-ar crv libstubs.a  stubs.o

    a - stubs.o

    make[1]: *** 没有规则可以创建“all”需要的目标“hello_world.srec”。 停止。

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

    make: *** [examples] 错误 2

    修改examples目录下的Makefile文件:

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

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

    SREC       = hello_world.srec

    BIN       = hello_world.bin hello_world

    改为

    SREC       = hello_world.o

    BIN       = hello_world.o hello_world

    即可重新编译。

    出现如下错误:

    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

     

    [root@localhost u-boot-1.1.4]# ll u-boot*

    再添加skyeye.conf文件

    -rwxr-xr-x 1 root root 396429 05-03 18:32 u-boot

    -rwxr-xr-x 1 root root 100156 05-03 18:32 u-boot.bin

    -rw-r--r-- 1 root root  48690 05-03 18:32 u-boot.map

    -rwxr-xr-x 1 root root 300538 05-03 18:32 u-boot.srec

    [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

    cpu info: armv4, arm920t, 41009200, ff00fff0, 2

    mach info: name s3c2410x, mach_init addr 0x806bae0

    ethmod num=1, mac addr=8:0:3e:26:a:5b, hostip=10.0.0.1

    nandflash: dump ./nand.dump

    file size:69206016

    dbct info: turn on dbct!

    uart_mod:0, desc_in:, desc_out:, converter:

    SKYEYE: use arm920t mmu ops

    Loaded RAM   ./u-boot.bin

    ERROR: s3c2410x_io_write_word(0x4c000000) = 0x00ffffff

    ERROR: s3c2410x_io_write_word(0x4c000008) = 0x00048032

     

    U-Boot 1.1.4 (May  3 2009 - 18:31:55)

     

    U-Boot code: 33F80000 -> 33F9873C  BSS: -> 33F9C814

    RAM Configuration:

    Bank #0: 30000000 64 MB

    Flash: 512 kB

    *** Warning - bad CRC, using default environment

     

    In:    serial

    Out:   serial

    Err:   serial

     

    开始移植nand:

    修改cpu/arm920t/start.S文件:

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

    将以下U-Boot的重定向语句段:

    #ifndef CONFIG_SKIP_RELOCATE_UBOOT

    relocate:                            /* relocate U-Boot to RAM           */

           adr       r0, _start              /* r0 <- current position of code   */

           ldr       r1, _TEXT_BASE              /* test if we run from flash or RAM */

           cmp     r0, r1                  /* don't reloc during debug         */

           beq     stack_setup

     

           ldr       r2, _armboot_start

           ldr       r3, _bss_start

           sub       r2, r3, r2              /* r2 <- size of armboot            */

           add       r2, r0, r2              /* r2 <- source end address         */

     

    copy_loop:

           ldmia       r0!, {r3-r10}              /* copy from source address [r0]    */

           stmia       r1!, {r3-r10}              /* copy to   target address [r1]    */

           cmp       r0, r2                     /* until source end addreee [r2]    */

           ble       copy_loop

    #endif       /* CONFIG_SKIP_RELOCATE_UBOOT */

     

    替换成:

    //#ifndef CONFIG_SKIP_RELOCATE_UBOOT

    //relocate:                            /* relocate U-Boot to RAM           */

    //       adr       r0, _start              /* r0 <- current position of code   */

    //       ldr       r1, _TEXT_BASE              /* test if we run from flash or RAM */

    //       cmp     r0, r1                  /* don't reloc during debug         */

    //       beq     stack_setup

     

    //       ldr       r2, _armboot_start

    //       ldr       r3, _bss_start

    //       sub       r2, r3, r2              /* r2 <- size of armboot            */

    //       add       r2, r0, r2              /* r2 <- source end address         */

     

    //copy_loop:

    //       ldmia       r0!, {r3-r10}              /* copy from source address [r0]    */

    //       stmia       r1!, {r3-r10}              /* copy to   target address [r1]    */

    //       cmp       r0, r2                     /* until source end addreee [r2]    */

    //       ble       copy_loop

    //#endif       /* CONFIG_SKIP_RELOCATE_UBOOT */

    #ifdef CONFIG_S3C2410_NAND_BOOT

    @ reset NAND

           mov r1, #NAND_CTL_BASE

           ldr   r2, =0xf830           @ initial value

           str   r2, [r1, #oNFCONF]

           ldr   r2, [r1, #oNFCONF]

           bic  r2, r2, #0x800              @ enable chip

           str   r2, [r1, #oNFCONF]

           mov r2, #0xff         @ RESET command

           strb r2, [r1, #oNFCMD]

     

     

           mov r3, #0                   @ wait

    nand1:

           add  r3, r3, #0x1

           cmp r3, #0xa

           blt   nand1

     

    nand2:

           ldr   r2, [r1, #oNFSTAT]      @ wait ready

           tst    r2, #0x1

           beq  nand2

     

           ldr   r2, [r1, #oNFCONF]

           orr  r2, r2, #0x800              @ disable chip

           str   r2, [r1, #oNFCONF]

     

    @ get read to call C functions (for nand_read())

           ldr   sp, DW_STACK_START       @ setup stack pointer

           mov fp, #0                    @ no previous frame, so fp=0

     

    @ copy U-Boot to RAM

           ldr   r0, =TEXT_BASE

           mov     r1, #0x0

           mov r2, #0x20000

           bl    nand_read_ll

           tst    r0, #0x0

           beq  ok_nand_read

     

    bad_nand_read:

    loop2:    b     loop2          @ infinite loop

     

    ok_nand_read:

    @ verify

           mov r0, #0

           ldr   r1, =TEXT_BASE

           mov r2, #0x400     @ 4 bytes * 1024 = 4K-bytes

    go_next:

           ldr   r3, [r0], #4

           ldr   r4, [r1], #4

           teq   r3, r4

           bne  notmatch

           subs r2, r2, #4

           beq  stack_setup

           bne  go_next

     

    notmatch:

    loop3:     b     loop3         @ infinite loop

     

    #endif /* CONFIG_S3C2410_NAND_BOOT */

     

    _start_armboot:       .word start_armboot

    后面加入

           .align       2

    DW_STACK_START:  .word  STACK_BASE+STACK_SIZE-4

    修改board/ok2410/Makefile文件:

    OBJS       := ok2410.o flash.o

    改为

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

    创建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

    #define NAND_BLOCK_MASK 511

    #endif

     

    inline void wait_idle(void) {

           int i;

           while(!(NFSTAT & BUSY))

           for(i=0; i<10; i++);

    }

     

    /* low level nand read function */

    int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)

    {

           int i, j;

           if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

                  return -1; /* invalid alignment */

           }

           /* chip Enable */

           NFCONF &= ~0x800;

           for(i=0; i<10; i++);

           for(i=start_addr; i < (start_addr + size);) {

                  /* READ0 */

                  NFCMD = 0;

                  /* Write Address */

                  NFADDR = i & 0xff;

                  NFADDR = (i >> 9) & 0xff;

                  NFADDR = (i >> 17) & 0xff;

                  NFADDR = (i >> 25) & 0xff;

                  wait_idle();

                  for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

                         *buf = (NFDATA & 0xff);

                         buf++;

                  }

           }

           /* chip Disable */

           NFCONF |= 0x800; /* chip disable */

           return 0;

    }

    编辑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 *******************/

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

    多次执行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

    cpu info: armv4, arm920t, 41009200, ff00fff0, 2

    mach info: name s3c2410x, mach_init addr 0x806bae0

    ethmod num=1, mac addr=8:0:3e:26:a:5b, hostip=10.0.0.1

    nandflash: dump ./nand.dump

     

    Init nandflash dump file.

    file size:69206016

    finish init nandflash dump

    dbct info: turn on dbct!

    uart_mod:0, desc_in:, desc_out:, converter:

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

    [root@localhost u-boot-1.1.4]# mknandflashdump u-boot.bin nand.dump 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

    注意:使用mknandflashdump命令生成nand.dump文件,同时向该文件所模拟的NAND Flash的起始地址(0x0)处烧写u-boot.bin。

    再次执行skyeye1.2.6

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

    以下是u-boot添加nand指令的支持。               

    编辑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 *************************************/

    说明:为了能使U-BOOT正确引导Linux内核,必须传递合适的参数给内核。引导内核时可以将bootargs传递给内核。bootargs是指ok2410.h文件中的CONFIG_BOOTARGS宏。

                         /*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"

    进一步编辑include/configs/ok2410.h文件:

    /****************** 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 Flash的0x20000处*/

    #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 *******************/

    编辑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 *******************/

    修改 common/cmd_nand.c文件:

    将NanD_ReadBuf函数中的

           NanD_Command (nand, NAND_CMD_READ0);

    改为

           //NanD_Command (nand, NAND_CMD_READ0);

    如果没有将该行注释掉,启动skyeye1.2.6后,将会出现如下错误:

    Hit any key to stop autoboot:  0

    OK2410 # nand read 0x31000000 0x0 0x1BFC8

    NAND read: device 0 offset 0, size 114632 ... warning when RE  falling,do nothing

      0 bytes read: ERROR

    OK2410 #

    编译、测试:

    [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

    cpu info: armv4, arm920t, 41009200, ff00fff0, 2

    mach info: name s3c2410x, mach_init addr 0x806bae0

    ethmod num=1, mac addr=8:0:3e:26:a:5b, hostip=10.0.0.1

    nandflash: dump ./nand.dump

    file size:69206016

    dbct info: turn on dbct!

    uart_mod:0, desc_in:, desc_out:, converter:

    SKYEYE: use arm920t mmu ops

    Loaded RAM   ./u-boot.bin

    ERROR: s3c2410x_io_write_word(0x4c000000) = 0x00ffffff

    ERROR: s3c2410x_io_write_word(0x4c000008) = 0x00048032

     

     

    U-Boot 1.1.4 (Jun 14 2011 - 18:45:47)

     

    U-Boot code: 33F80000 -> 33F9C304  BSS: -> 33FA03E0

    RAM Configuration:

    Bank #0: 30000000 64 MB

    Flash: 512 kB

    NAND:  64 MB

    *** Warning - bad CRC or NAND, using default environment

     

    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

    checksum bad

           T       T       T       T       T       .................

    出现

    Flash: 512 kB

    NAND:  64 MB

    表示实验成功,T代表try尝试去连接服务器,因为没有建立服务器所以不能连接成功。将NAND Flash(/dev/mtdblock2)作为根文件系统:

    **************************** 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

    cpu info: armv4, arm920t, 41009200, ff00fff0, 2

    mach info: name s3c2410x, mach_init addr 0x806bae0

    ethmod num=1, mac addr=8:0:3e:26:a:5b, hostip=10.0.0.1

    nandflash: dump ./nand.dump

    file size:69206016

    dbct info: turn on dbct!

    uart_mod:0, desc_in:, desc_out:, converter:

    SKYEYE: use arm920t mmu ops

    Loaded RAM   ./u-boot.bin

    ERROR: s3c2410x_io_write_word(0x4c000000) = 0x00ffffff

    ERROR: s3c2410x_io_write_word(0x4c000008) = 0x00048032

     

    U-Boot 1.1.4 (May 11 2009 - 11:46:42)

     

    U-Boot code: 33F80000 -> 33F9C20C  BSS: -> 33FA02E8

    RAM Configuration:

    Bank #0: 30000000 64 MB

    Flash: 512 kB

    NAND:  64 MB

    *** Warning - bad CRC, using default environment

     

    In:    serial

    Out:   serial

    Err:   serial

    Hit any key to stop autoboot:  0

    OK2410 # printenv

    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

    bootcmd=tftp 0x31000000 uImage;bootm 0x31000000        //要记住该环境变量,后面的实例中会用到

    bootdelay=3

    baudrate=115200

    ipaddr=10.0.0.110

    serverip=10.0.0.1

    netmask=255.255.255.0

    stdin=serial

    stdout=serial

    stderr=serial

    ethaddr=08:00:3E:26:0A:5B

     

    Environment size: 341/65532 bytes

    OK2410 #

    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 ...

       Image Name:   linux-2.6.14.7

       Created:      2009-05-10  14:48:03 UTC

       Image Type:   ARM Linux Kernel Image (uncompressed)

       Data Size:    1009504 Bytes = 985.8 kB

       Load Address: 30008000

       Entry Point:  30008000

       Verifying Checksum ... OK

    OK

     

    Starting kernel ...

    Uncompressing Linux................................................................ done, booting the kernel.

    Linux version 2.6.14.7 (root@localhost.localdomain) (gcc version 3.4.1) #1 Sun May 10 15:13:57 CST 2009

    CPU: ARM920Tid(wb) [41009200] revision 0 (ARMvundefined/unknown)

    Machine: SMDK2410

    Warning: bad configuration page, trying to continue

    Memory policy: ECC disabled, Data cache writeback

    CPU S3C2410 (id 0x32410000)

    S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz

    S3C2410 Clocks, (c) 2004 Simtec Electronics

    CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

    CPU0: D VIVT write-back cache

    CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

    CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

    Built 1 zonelists

    Kernel command line: noinitrd mem=64M root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200

    irq: clearing pending status 00004000

    irq: clearing pending status 00008000

    irq: clearing pending status 00800000

    irq: clearing pending status 10000000

    irq: clearing subpending status 00000093

    PID hash table entries: 512 (order: 9, 8192 bytes)

    timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c

    Console: colour dummy device 80x30

    Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)

    Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)

    Memory: 64MB = 64MB total

    Memory: 62720KB available (1635K code, 321K data, 92K init)

    Mount-cache hash table entries: 512

    CPU: Testing write buffer coherency: ok

    softlockup thread 0 started up.

    NET: Registered protocol family 16

    S3C2410: Initialising architecture

    NetWinder Floating Point Emulator V0.97 (double precision)

    devfs: 2004-01-31 Richard Gooch (rgooch@atnf.csiro.au)

    devfs: boot_options: 0x1

    Console: switching to colour frame buffer device 80x25

    fb0: Virtual frame buffer device, using 1024K of video memory

    S3C2410 RTC, (c) 2004 Simtec Electronics

    s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2410

    s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2410

    s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2410

    io scheduler noop registered

    io scheduler anticipatory registered

    io scheduler deadline registered

    io scheduler cfq registered

    RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

    Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)

    eth0: CS8900A rev D at 0xe0000300 irq=53, no eeprom , addr: 08: 0:3E:26:0A:5B

    S3C24XX NAND Driver, (c) 2004 Simtec Electronics

    s3c2410-nand: mapped registers at c4980000

    s3c2410-nand: timing: Tacls 10ns, Twrph0 30ns, Twrph1 10ns

    NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)

    NAND_ECC_NONE selected by board driver. This is not recommended !!

    Scanning device for bad blocks

    Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":

    0x00000000-0x00100000 : "bootloader"

    0x00100000-0x00400000 : "kernel"

    0x00400000-0x02c00000 : "root"

    0x02d00000-0x03c00000 : "user"

    mice: PS/2 mouse device common for all mice

    NET: Registered protocol family 2

    IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

    TCP established hash table entries: 4096 (order: 2, 16384 bytes)

    TCP bind hash table entries: 4096 (order: 2, 16384 bytes)

    TCP: Hash tables configured (established 4096 bind 4096)

    TCP reno registered

    TCP bic registered

    NET: Registered protocol family 1

    Reading data from NAND FLASH without ECC is not recommended

    Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)

     

    //错误,因为mtdblock2中还没有文件系统,该问题将在下一小节中解决

     

    通过NFS访问文件系统:

    **************************** 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 # tftp 0x31000000 uImage

    TFTP from server 10.0.0.1; our IP address is 10.0.0.110

    Filename 'uImage'.

    Load address: 0x31000000

    Loading:

    ……                     //部分信息省略

    done

    Bytes transferred = 1009568 (f67a0 hex)

    OK2410 # bootm 31000000

    ……                     //部分信息省略

    OK

    Starting kernel ...

    Uncompressing Linux................................................................ done, booting the kernel.

    Linux version 2.6.14.7 (root@localhost.localdomain) (gcc version 3.4.1) #1 Sun May 10 15:13:57 CST 2009

    CPU: ARM920Tid(wb) [41009200] revision 0 (ARMvundefined/unknown)

    Machine: SMDK2410

    ……                     //部分信息省略

    Kernel command line: 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

    ……                     //部分信息省略

    Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":

    0x00000000-0x00100000 : "bootloader"

    0x00100000-0x00400000 : "kernel"

    0x00400000-0x02c00000 : "root"

    0x02d00000-0x03c00000 : "user"

    ……                     //部分信息省略

    NET: Registered protocol family 1

    IP-Config: Complete:

          device=eth0, addr=10.0.0.110, mask=255.255.255.0, gw=10.0.0.1,

         host=10.0.0.110, domain=, nis-domain=(none),

         bootserver=10.0.0.1, rootserver=10.0.0.1, rootpath=

    Looking up port of RPC 100003/2 on 10.0.0.1

    Looking up port of RPC 100005/1 on 10.0.0.1

    VFS: Mounted root (nfs filesystem).

    Mounted devfs on /dev

    Freeing init memory: 92K

    Failed to execute linuxrc.  Attempting defaults...

    Kernel panic - not syncing: No init found.  Try passing init= option to kernel.

     

    //错误,原因可能是NFS文件系统没有准备好,或者是防火墙,该问题将在下一小节中解决

     

    三、根文件系统的移植

    解压busybox-1.13.4.tar.bz2到桌面

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

    [root@localhost Desktop]# cd busybox-1.13.4

    [root@localhost busybox-1.13.4]#

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

    进行默认配置

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

    对配置信息进行修改

    [root@localhost busybox-1.13.4]# make menuconfig

    HOSTLD  scripts/kconfig/mconf

      HOSTCC  scripts/kconfig/lxdialog/checklist.o

      HOSTCC  scripts/kconfig/lxdialog/inputbox.o

      HOSTCC  scripts/kconfig/lxdialog/lxdialog.o

      HOSTCC  scripts/kconfig/lxdialog/menubox.o

      HOSTCC  scripts/kconfig/lxdialog/msgbox.o

      HOSTCC  scripts/kconfig/lxdialog/textbox.o

      HOSTCC  scripts/kconfig/lxdialog/util.o

      HOSTCC  scripts/kconfig/lxdialog/yesno.o

      HOSTLD  scripts/kconfig/lxdialog/lxdialog

    scripts/kconfig/mconf Config.in

    在检查Miscellaneous Utilities--->

        taskset 是否去除

    同时设置如下:

    Busybox Settings --->

            Build Options --->

                [*]Build BusyBox as a static binry (no shared libs)              //选用静态连接

                [*]Build with Large File Support (for accessing files > 2 GB)

                (/usr/local/arm/3.4.1/bin/arm-linux-) Cross Compiler prefix

            Installation Options --->

                [*] Don't use /usr

                (./_install) BusyBox installation prefix                           //安装路径

            Busybox Library Tuning  --->

                (6) Minimum password length

                (2) MD5: Trade Bytes for Speed

                [*] Faster /proc scanning code (+100 bytes)

                [ ] Support for /etc/networks

                [*] Command line editing

                (1024) Maximum length of input

                [*]   vi-style line editing commands

                (15)  History size

                [*]   History saving

                [*]   Tab completion

                [*]     Username completion

                [*]   Fancy shell prompts              //Setting this option allows for prompts to use things like w and

                                                     //  $ and escape codes.

                [ ] Give more precise messages when copy fails (cp, mv etc)

                (4) Copy buffer size, in kilobytes

                [ ] Use clock_gettime(CLOCK_MONOTONIC) syscall

                [*] Use ioctl names rather than hex values in error messages

                [*] Support infiniband HW弹出的TUI界面中进行如下配置:

     

    设置完毕后,保存、退出

    编译

    [root@localhost busybox-1.13.4]# make

    ......

      CC      networking/inetd.o

      CC      networking/interface.o

    networking/interface.c:818: error: `ARPHRD_INFINIBAND' undeclared here (not in a function)

    networking/interface.c:818: error: initializer element is not constant

    networking/interface.c:818: error: (near initialization for `ib_hwtype.type')

    make[1]: *** [networking/interface.o] 错误 1

    make: *** [networking] 错误 2

    编译出错,此时需要编辑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

    ......

      CC      util-linux/volume_id/volume_id.o

      CC      util-linux/volume_id/xfs.o

      AR      util-linux/volume_id/lib.a

      LINK    busybox_unstripped

    Trying libraries: crypt m

     Library crypt is not needed, excluding it

     Library m is needed, can't exclude it (yet)

    Final link with: m

      DOC     busybox.pod

      DOC     BusyBox.txt

      DOC     BusyBox.1

      DOC     BusyBox.html

    [root@localhost busybox-1.13.4]# ll busybox*

    [root@localhost busybox-1.13.4]# make install

    -rwxr-xr-x 1 root root 1701216 05-11 17:26 busybox

    -rwxr-xr-x 1 root root 2045185 05-11 17:26 busybox_unstripped

    -rw-r--r-- 1 root root  889321 05-11 17:26 busybox_unstripped.map

    -rw-r--r-- 1 root root   83503 05-11 17:26 busybox_unstripped.out

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

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

    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]# ll _install/bin/busybox

    -rwxr-xr-x 1 root root 1701216 05-11 17:41 _install/bin/busybox

    [root@localhost busybox-1.13.4]# chmod 4755 ./_install/bin/busybox         //修改busybox属性

    [root@localhost busybox-1.13.4]# ll _install/bin/busybox

    -rwsr-xr-x 1 root root 1701216 05-11 17:41 _install/bin/busybox

    [root@localhost busybox-1.13.4]# ll _install/

    总计 20

    drwxr-xr-x 2 root root 4096 05-11 17:41 bin

    lrwxrwxrwx 1 root root   11 05-11 17:41 linuxrc -> bin/busybox

    drwxr-xr-x 2 root root 4096 05-11 17:41 sbin

    [root@localhost busybox-1.13.4]# cd _install/

    [root@localhost _install]# pwd

    /root/Desktop/busybox-1.13.4/_install

    在/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]# pwd

    /tmp/nfs/dev

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

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

    复制文件到/tmp/nfs中

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

    [root@localhost _install]# pwd

    /root/Desktop/busybox-1.13.4/_install

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

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

    [root@localhost _install]# ll linuxrc

    lrwxrwxrwx 1 root root 11 05-11 17:41 linuxrc -> bin/busybox

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

    [root@localhost _install]# ll /tmp/nfs/linuxrc

    lrwxrwxrwx 1 root root 11 05-11 17:43 /tmp/nfs/linuxrc -> bin/busybox

    [root@localhost _install]# cd ..

    [root@localhost busybox-1.13.4]# pwd

    /root/Desktop/busybox-1.13.4

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

    [root@localhost busybox-1.13.4]# ls /tmp/nfs/etc/

    fstab  init.d  inittab  profile

    [root@localhost busybox-1.13.4]#

    创建配置文件

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

    [root@localhost nfs]# gedit 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]# ll etc/inittab

    -rw-r--r-- 1 root root 309 05-11 18:28 etc/inittab

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

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

    [root@localhost nfs]# gedit 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 liminmin, 2010.06"

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

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

    -rw-r--r-- 1 root root 92 05-11 18:27 etc/init.d/rcS

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

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

    [root@localhost nfs]# gedit 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]# ll etc/fstab

    -rw-r--r-- 1 root root 59 05-11 18:30 etc/fstab

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

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

    [root@localhost nfs]# gedit 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@h 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

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

    下面3个文件可以从宿主机中复制,只留下root帐号。

    [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:x: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

    为mdev创建配置文件

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

    内容是:空

    [root@localhost nfs]# ll etc/

    总计 60

    -rwxr-xr-x 1 root root  117 05-11 19:28 fstab

    -rw-r--r-- 1 root root   14 05-11 20:09 group

    drwxr-xr-x 2 root root 4096 05-11 20:04 init.d

    -rwxr-xr-x 1 root root  184 05-11 19:33 inittab

    -rw-r--r-- 1 root root    0 05-11 20:09 mdev.conf

    -rw-r--r-- 1 root root   30 05-11 20:07 passwd

    -rwxr-xr-x 1 root root  801 05-11 19:42 proflie

    -rw-r--r-- 1 root root   59 05-11 20:08 shadow

    删除备份文件

    [root@localhost nfs]# rm

    复制常用的库文件

    编写脚本文件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]# ll copy_lib.sh

    -rw-r--r-- 1 root root 303 05-11 20:18 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 -

    /tmp/nfs

    [root@localhost nfs]# ll lib

    总计 2516

    -rwxr-xr-x 1 root root  131480 05-11 20:19 ld-2.3.2.so

    lrwxrwxrwx 1 root root      11 05-11 20:19 ld-linux.so.2 -> ld-2.3.2.so

    -rwxr-xr-x 1 root root 1560352 05-11 20:19 libc-2.3.2.so

    -rwxr-xr-x 1 root root   30155 05-11 20:19 libcrypt-2.3.2.so

    lrwxrwxrwx 1 root root      17 05-11 20:19 libcrypt.so.1 -> libcrypt-2.3.2.so

    lrwxrwxrwx 1 root root      13 05-11 20:19 libc.so.6 -> libc-2.3.2.so

    -rwxr-xr-x 1 root root   15736 05-11 20:19 libdl-2.3.2.so

    lrwxrwxrwx 1 root root      14 05-11 20:19 libdl.so.2 -> libdl-2.3.2.so

    -rwxr-xr-x 1 root root  546854 05-11 20:19 libm-2.3.2.so

    lrwxrwxrwx 1 root root      13 05-11 20:19 libm.so.6 -> libm-2.3.2.so

    -rwxr-xr-x 1 root root   97975 05-11 20:19 libpthread-0.10.so

    lrwxrwxrwx 1 root root      18 05-11 20:19 libpthread.so.0 -> libpthread-0.10.so

    -rwxr-xr-x 1 root root   81495 05-11 20:19 libresolv-2.3.2.so

    lrwxrwxrwx 1 root root      18 05-11 20:19 libresolv.so.2 -> libresolv-2.3.2.so

    -rwxr-xr-x 1 root root   13689 05-11 20:19 libutil-2.3.2.so

    lrwxrwxrwx 1 root root      16 05-11 20:19 libutil.so.1 -> libutil-2.3.2.so

    drwxr-xr-x 2 root root    4096 05-11 11:23 modules

    [root@localhost nfs]#

    至此,一个基本的根文件系统(通过NFS挂载)构建完成。

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

    编辑/etc/xinetd.d/tftp文件

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

    tftp文件内容如下

    1       # default: off

     2       # description: The tftp server serves files using the trivial file transfer

     3       #       protocol.  The tftp protocol is often used to boot diskless

     4       #       workstations, download configuration files to network-aware printers,

     5       #       and to start the installation process for some operating systems.

     6       service tftp

     7       {

     8              socket_type              = dgram

     9              protocol              = udp

    10              wait                     = yes

    11              user                     = root

    12              server                     = /usr/sbin/in.tftpd

    13              server_args              = -s /tftpboot

    14              disable              = no

    15              per_source              = 11

    16              cps                     = 100 2

    17              flags                     = IPv4

    18       }

    重启tftp服务器

    [root@localhost opt]# service xinetd restart

    停止 xinetd:                                              [确定]

    启动 xinetd:                                              [确定]

    编辑/etc/exports文件

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

    exports文件内容如下

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

    重启NFS服务器

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

    关闭 NFS mountd:                                          [确定]

    关闭 NFS 守护进程:                                        [确定]

    关闭 NFS quotas:                                           [确定]

    关闭 NFS 服务:                                            [确定]

    启动 NFS 服务:                                            [确定]

    关掉 NFS 配额:                                            [确定]

    启动 NFS 守护进程:                                        [确定]

    启动 NFS mountd:                                          [确定]

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

    /tmp/nfs       

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

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

    **************************** 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

    Filename 'uImage'.

    Load address: 0x31000000

    Loading: checksum bad

    checksum bad

    #################################################################

             #################################################################

             #################################################################

             ################################

    done

    Bytes transferred = 1161416 (11b8c8 hex)

    ## Booting image at 31000000 ...

       Image Name:   linux-2.6.14.7

       Created:      2009-05-24  11:22:39 UTC

       Image Type:   ARM Linux Kernel Image (uncompressed)

       Data Size:    1161352 Bytes =  1.1 MB

       Load Address: 30008000

       Entry Point:  30008000

       Verifying Checksum ... OK

    OK

     

    Starting kernel ...

     

    Uncompressing Linux.......................................................................... done, booting the kernel.

    Linux version 2.6.14.7 (root@localhost.localdomain) (gcc version 3.4.1) #6 Sun May 24 19:22:08 CST 2009

    CPU: ARM920Tid(wb) [41009200] revision 0 (ARMvundefined/unknown)

    Machine: SMDK2410

    Memory policy: ECC disabled, Data cache writeback

    CPU S3C2410 (id 0x32410000)

    S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz

    S3C2410 Clocks, (c) 2004 Simtec Electronics

    CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

    CPU0: D VIVT write-back cache

    CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

    CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

    Built 1 zonelists

    Kernel command line: 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

    ……                     //部分启动信息省略

    Memory: 64MB = 64MB total

    Memory: 62464KB available (1888K code, 393K data, 92K init)

    ……                     //部分启动信息省略

    JFFS version 1.0, (C) 1999, 2000  Axis Communications AB

    JFFS2 version 2.2. (NAND) (C) 2001-2003 Red Hat, Inc.

    yaffs May 24 2009 19:21:42 Installing.

    Console: switching to colour frame buffer device 80x25

    fb0: Virtual frame buffer device, using 1024K of video memory

    ……                     //部分启动信息省略

    RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

    Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)

    eth0: CS8900A rev D at 0xe0000300 irq=53, no eeprom , addr: 08: 0:3E:26:0A:5B

    S3C24XX NAND Driver, (c) 2004 Simtec Electronics

    s3c2410-nand: mapped registers at c4980000

    s3c2410-nand: timing: Tacls 10ns, Twrph0 30ns, Twrph1 10ns

    NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)

    NAND_ECC_NONE selected by board driver. This is not recommended !!

    Scanning device for bad blocks

    Bad eraseblock 7 at 0x0001c000

    Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":

    0x00000000-0x00100000 : "bootloader"

    0x00100000-0x00400000 : "kernel"

    0x00400000-0x02c00000 : "root"

    0x02d00000-0x03c00000 : "user"

    mice: PS/2 mouse device common for all mice

    NET: Registered protocol family 2

    ……                     //部分启动信息省略

    IP-Config: Complete:

          device=eth0, addr=10.0.0.110, mask=255.255.255.0, gw=10.0.0.1,

         host=10.0.0.110, domain=, nis-domain=(none),

         bootserver=10.0.0.1, rootserver=10.0.0.1, rootpath=

    Looking up port of RPC 100003/2 on 10.0.0.1

    Looking up port of RPC 100005/1 on 10.0.0.1

    VFS: Mounted root (nfs filesystem).

    Mounted devfs on /dev

    Freeing init memory: 92K

    #mount all.......

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

                       OK 2410 Rootfs made by liminmin, 2011.5.16

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

    liminmin 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@liminmin /root]# printenv

    USER=root

    LD_LIBRARY_PATH=/lib:/usr/lib

    HOME=/root

    PS1=[u@h W]$

    LOGNAME=root

    TERM=vt102

    PATH=/bin:/sbin:/usr/bin:/usr/sbin

    HISTSIZE=100

    SHELL=/bin/sh

    PWD=/root

    [root@liminmin /root]# ifconfig

    eth0      Link encap:Ethernet  HWaddr 08:00:3E:26:0A:5B 

              inet addr:10.0.0.110  Bcast:10.0.0.255  Mask:255.255.255.0

              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

              RX packets:1826 errors:0 dropped:0 overruns:0 frame:0

              TX packets:730 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:1000

              RX bytes:2386884 (2.2 MiB)  TX bytes:116644 (113.9 KiB)

              Interrupt:53 Base address:0x300

     

    lo        Link encap:Local Loopback 

              inet addr:127.0.0.1  Mask:255.0.0.0

              UP LOOPBACK RUNNING  MTU:16436  Metric:1

              RX packets:0 errors:0 dropped:0 overruns:0 frame:0

              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:0

              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

     

    [root@liminmin /root]# ping -c 2 10.0.0.1

    PING 10.0.0.1 (10.0.0.1): 56 data bytes

    64 bytes from 10.0.0.1: seq=0 ttl=64 time=0.034 ms

    64 bytes from 10.0.0.1: seq=1 ttl=64 time=0.021 ms

     

    --- 10.0.0.1 ping statistics ---

    2 packets transmitted, 2 packets received, 0% packet loss

    round-trip min/avg/max = 0.021/0.027/0.034 ms

    [root@liminmin /root]# ll

    -rwxr-xr-x    1 root     root         8044 May 14  2009 test    //该文件在宿主机通过交叉编译器编译

    -rw-r--r--    1 root     root          284 May 14  2009 test.c    //该文件在宿主机编辑

    [root@liminmin /root]# ./test

    ===== main =====

    Hello world!

    argv[0]=./test

    ==== exit main ====

    [root@liminmin /root]# ./test as sdfasdf asdfasf

    ===== main =====

    Hello world!

    argv[0]=./test

    argv[1]=as

    argv[2]=sdfasdf

    argv[3]=asdfasf

    ==== exit main ====

    [root@liminmin /root]# less test.c                       //查看文件内容

    #include

    #include

     

    int main (int argc,char* argv[])

    {

        int i;

        printf("===== main ===== ");

        printf ("Hello world! ");

        for(i=0;i

        {

            printf("argv[%d]=%s ",i,argv[i]);

        }

        printf("==== exit main ==== ");

        return 0;

    }

    [root@liminmin /root]#

    完整的启动过程(u-boot、内核、文件系统),使用/dev/mtdblock2中的文件系统创建cramfs文件系统

    [root@localhost tmp]# pwd

    /tmp

    [root@localhost tmp]# mkfs.cramfs nfs ok2410.cramfs

    [root@localhost tmp]# ll ok2410.cramfs

    -rw-r--r-- 1 root root 2199552 05-13 08:18 ok2410.cramfs

    复制ok2410.cramfs到tftp服务器根目录

    [root@localhost tmp]# cp ok2410.cramfs /tftpboot/

    执行skyeye1.2.6,启动系统

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

    /root/Desktop/u-boot-1.1.4

    [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 # tftp 0x31000000 ok2410.cramfs

    TFTP from server 10.0.0.1; our IP address is 10.0.0.110

    Filename 'ok2410.cramfs'.

    Load address: 0x31000000

    Loading: checksum bad

    ############checksum bad

    #####################################################

             #################################################################

             #################################################################

             #################################################################

             #################################################################

             #################################################################

             #######################################

    done

    Bytes transferred = 2195456 (218000 hex)

    OK2410 # nand erase 400000 300000

     

    NAND erase: device 0 offset 4194304, size 3145728 ... OK

    OK2410 # nand write 31000000 400000 0x218000

     

    NAND write: device 0 offset 4194304, size 2195456 ...  2195456 bytes written: OK

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

    OK2410 # run bootcmd

    ……                     //启动信息省略

     

     

    错误:按照书上说的去做,基本上不会出错,如果出错,一定是因为自己粗心大意。多做几遍,熟能生巧!

     

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



  • 相关阅读:
    RVM Ruby 版本管理器的删除 Gatling
    JWT 构建Rails API 授权登录
    Linux grep根据关键字匹配前后几行
    bootstrap-table 常用总结-树形结构
    linux 下jq的使用
    SHELL脚本获取域名对应的IP地址
    golang将切片或数组进行分组
    linux的统计实现
    Linux:“awk”命令的妙用
    rails 上传文件
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647536.html
Copyright © 2011-2022 走看看