码迷,mamicode.com
首页 > 其他好文 > 详细

mini2440移植uboot 2011.03(下)

时间:2014-06-06 08:31:32      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

参考博文:

       u-boot-2011.03在mini2440/micro2440上的移植

 

移植(五)添加nand支持:

bubuko.com,布布扣
host@debian:~/soft/mini2440/u-boot-2011.03$  touch drivers/mtd/nand/s3c2440_nand.c 
host@debian:~/soft/mini2440/u-boot-2011.03$ vim drivers/mtd/nand/s3c2440_nand.c 
添加下面内容:
#include <common.h>

#if 0
#define DEBUGN    printf
#else
#define DEBUGN(x, args ...) {}
#endif

#include <nand.h>
#include <asm/arch/s3c24x0_cpu.h>
#include <asm/io.h>

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

#define NF_BASE  0x4e000000             //Nand配置寄存器基地址
#define NFCONF   __REGi(NF_BASE + 0x0)  //偏移后还是得到配置寄存器基地址
#define NFCONT   __REGi(NF_BASE + 0x4)  //偏移后得到Nand控制寄存器基地址
#define NFCMD    __REGb(NF_BASE + 0x8)  //偏移后得到Nand指令寄存器基地址
#define NFADDR   __REGb(NF_BASE + 0xc)  //偏移后得到Nand地址寄存器基地址
#define NFDATA   __REGb(NF_BASE + 0x10) //偏移后得到Nand数据寄存器基地址
#define NFMECCD0 __REGi(NF_BASE + 0x14) //偏移后得到Nand主数据区域ECC0寄存器基地址
#define NFMECCD1 __REGi(NF_BASE + 0x18) //偏移后得到Nand主数据区域ECC1寄存器基地址
#define NFSECCD  __REGi(NF_BASE + 0x1C) //偏移后得到Nand空闲区域ECC寄存器基地址
#define NFSTAT   __REGb(NF_BASE + 0x20) //偏移后得到Nand状态寄存器基地址
#define NFSTAT0  __REGi(NF_BASE + 0x24) //偏移后得到Nand ECC0状态寄存器基地址
#define NFSTAT1  __REGi(NF_BASE + 0x28) //偏移后得到Nand ECC1状态寄存器基地址
#define NFMECC0  __REGi(NF_BASE + 0x2C) //偏移后得到Nand主数据区域ECC0状态寄存器基地址
#define NFMECC1  __REGi(NF_BASE + 0x30) //偏移后得到Nand主数据区域ECC1状态寄存器基地址
#define NFSECC   __REGi(NF_BASE + 0x34) //偏移后得到Nand空闲区域ECC状态寄存器基地址
#define NFSBLK   __REGi(NF_BASE + 0x38) //偏移后得到Nand块开始地址
#define NFEBLK   __REGi(NF_BASE + 0x3c) //偏移后得到Nand块结束地址

#define S3C2440_NFCONT_nCE  (1<<1)
#define S3C2440_ADDR_NALE   0x0c
#define S3C2440_ADDR_NCLE   0x08

ulong IO_ADDR_W = NF_BASE;

static void s3c2440_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
{
 struct nand_chip *chip = mtd->priv;

 DEBUGN("hwcontrol(): 0x%02x 0x%02x/n", cmd, ctrl);

 if (ctrl & NAND_CTRL_CHANGE)
 {
  IO_ADDR_W = NF_BASE;

  if (!(ctrl & NAND_CLE))                //要写的是地址
   IO_ADDR_W |= S3C2440_ADDR_NALE;
  if (!(ctrl & NAND_ALE))                //要写的是命令
   IO_ADDR_W |= S3C2440_ADDR_NCLE;

  if (ctrl & NAND_NCE)
   NFCONT &= ~S3C2440_NFCONT_nCE;    //使能nand flash
  else
   NFCONT |= S3C2440_NFCONT_nCE;     //禁止nand flash
 }

 if (cmd != NAND_CMD_NONE)
  writeb(cmd,(void *)IO_ADDR_W);
}

static int s3c2440_dev_ready(struct mtd_info *mtd)
{
 DEBUGN("dev_ready/n");
 return (NFSTAT & 0x01);
}

int board_nand_init(struct nand_chip *nand)
{
 u_int32_t cfg;
 u_int8_t tacls, twrph0, twrph1;
 struct s3c24x0_clock_power * const clk_power = s3c24x0_get_base_clock_power();

 DEBUGN("board_nand_init()/n");

 tacls = 1;

 twrph0 = 2; 

 twrph1 = 1; 

 cfg = (tacls<<12)|(twrph0<<8)|(twrph1<<4);
 NFCONF = cfg;

 cfg = (1<<6)|(1<<4)|(0<<1)|(1<<0);
 NFCONT = cfg;

 /* initialize nand_chip data structure */
 nand->IO_ADDR_R = nand->IO_ADDR_W = (void *)0x4e000010;

 /* read_buf and write_buf are default */
 /* read_byte and write_byte are default */

 /* hwcontrol always must be implemented */
 nand->cmd_ctrl = s3c2440_hwcontrol;

 nand->dev_ready = s3c2440_dev_ready;

 return 0;
}
host@debian:~/soft/mini2440/u-boot-2011.03$ vim drivers/mtd/nand/Makefile 
添加一行:
COBJS-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o
host@debian:~/soft/mini2440/u-boot-2011.03$ vim include/configs/mini2440.h
添加下面内容:

#define CONFIG_MTD_DEVICE
#define CONFIG_NAND_S3C2440
#define CONFIG_CMD_NAND
#if defined(CONFIG_CMD_NAND)
#define CONFIG_SYS_NAND_BASE            0x4E000000 //Nand配置寄存器基地址
#define CONFIG_SYS_MAX_NAND_DEVICE      1
#define CONFIG_MTD_NAND_VERIFY_WRITE    1

#endif

#define CONFIG_ENV_IS_IN_NAND  1
#define CONFIG_ENV_OFFSET      0x40000 //将环境变量保存到nand中的0x40000位置
#define CONFIG_ENV_SIZE        0x10000 /* Total Size of Environment Sector */

bubuko.com,布布扣

修改后,进行编译,却得到好几个编译错误:

bubuko.com,布布扣
env_nand.o: In function `env_get_char_spec:
/home/host/soft/mini2440/u-boot-2011.03/common/env_nand.c:77: multiple definition of `env_get_char_specenv_flash.o:/home/host/soft/mini2440/u-boot-2011.03/common/env_flash.c:82: first defined here
env_nand.o: In function `env_init:
/home/host/soft/mini2440/u-boot-2011.03/common/env_nand.c:144: multiple definition of `env_initenv_flash.o:/home/host/soft/mini2440/u-boot-2011.03/common/env_flash.c:244: first defined here
env_nand.o: In function `env_relocate_spec:
/home/host/soft/mini2440/u-boot-2011.03/common/env_nand.c:420: multiple definition of `env_relocate_specenv_flash.o:/home/host/soft/mini2440/u-boot-2011.03/common/env_flash.c:379: first defined here
env_nand.o: In function `saveenv:
/home/host/soft/mini2440/u-boot-2011.03/common/env_nand.c:245: multiple definition of `saveenvenv_flash.o:/home/host/soft/mini2440/u-boot-2011.03/common/env_flash.c:259: first defined here
env_nand.o:(.data+0x0): multiple definition of `env_name_specenv_flash.o:(.data+0x4): first defined here
env_nand.o: In function `env_get_char_spec:
/home/host/soft/mini2440/u-boot-2011.03/common/env_nand.c:77: multiple definition of `env_ptrenv_flash.o:(.data+0x0): first defined here
make[1]: *** [libcommon.o] 错误 1
make[1]: Leaving directory `/home/host/soft/mini2440/u-boot-2011.03/common
bubuko.com,布布扣

这是因为include/configs/mini2440.h已经定义了CONFIG_ENV_IS_IN_FLASH,新加入的定义CONFIG_ENV_IS_IN_NAND与之冲突,可以将

CONFIG_ENV_IS_IN_FLASH宏定义屏蔽掉即可。

修改好后重新编译,按照《mini2440移植uboot 2011.03(上)》中的步骤将其加载到mini2440 内存,然后启动uboot,得到下面的输出信息:

bubuko.com,布布扣
U-Boot 2011.03-00000-g18dedc3-dirty (Jun 04 2014 - 10:25:38)

DRAM:  64 MiB
Flash: 512 KiB
NAND:  NAND_ECC_NONE selected by board driver. This is not recommended !!
128 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
MINI2440 # nand
nand - NAND sub-system

Usage:
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read - addr off|partition size
nand write - addr off|partition size
    read/write size bytes starting at offset off
    to/from memory address addr, skipping bad blocks.
nand erase[.spread] [clean] [off [size]] - erase size bytes from offset off
    With .spread, erase enough for given file size, otherwise,
    size includes skipped bad blocks.
nand erase.part [clean] partition - erase entire mtd partitionnand erase.chip [clean] - erase entire chipnand bad - show bad blocks
nand dump[.oob] off - dump page
nand scrub off size | scrub.part partition | scrub.chip
    really clean NAND erasing bad blocks (UNSAFE)
nand markbad off [...] - mark bad block(s) at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
bubuko.com,布布扣

移植(六):添加nfs,命令补全的支持.

bubuko.com,布布扣
host@debian:~/soft/mini2440/u-boot-2011.03$ vim include/configs/mini2440.h 
添加下面内容:
#define CONFIG_CMDLINE_EDITING
#ifdef CONFIG_CMDLINE_EDITING
#undef CONFIG_AUTO_COMPLETE
#else
#define CONFIG_AUTO_COMPLETE
#endif
#define CONFIG_CMD_NFS
bubuko.com,布布扣

修改完后,重新进行编译并加载到mini2440内存中执行,得到下面的输出:

bubuko.com,布布扣
U-Boot 2011.03-00000-g0e6506b-dirty (Jun 04 2014 - 10:49:01)

DRAM:  64 MiB
Flash: 512 KiB
NAND:  NAND_ECC_NONE selected by board driver. This is not recommended !!
128 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
MINI2440 # nfs 30007fc0 /home/host/nfs/mini2440/uImage
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at unknown: 0 mode
Using dm9000 device
File transfer via NFS from server 192.168.211.2; our IP address is 192.168.211.25
Filename /home/host/nfs/mini2440/uImage.
Load address: 0x30007fc0
Loading: *
Abort
MINI2440 # nfs 30007fc0 /home/host/nfs/mini2440/uImage
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at unknown: 0 mode
Using dm9000 device
File transfer via NFS from server 192.168.211.2; our IP address is 192.168.211.25
Filename /home/host/nfs/mini2440/uImage.
Load address: 0x30007fc0
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################################################
done
Bytes transferred = 2266684 (22963c hex)
bubuko.com,布布扣

第一次调用nfs有可能不成功(跟前面的ping命令执行情况类似)。

后续移植过程我没有再继续下去了,因为我对yaffs兴趣不大,我希望能让它支持ubifs并且自己重新移植一遍。

整个代码(包含git历史记录)下载地址:http://pan.baidu.com/s/1dDipCqt

mini2440移植uboot 2011.03(下),布布扣,bubuko.com

mini2440移植uboot 2011.03(下)

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/qiaoqiao2003/p/3767459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!