u-boot-2012.04.01移植到TQ2440(五):支持NAND FLASH读写

一、    支持NAND FLASH读写

修改配置文件include\configs\tq2440.h打开之前注释掉的NAND相关的宏

#defineCONFIG_CMD_NAND

#define CONFIG_ENV_IS_IN_NAND
#define CONFIG_ENV_OFFSET0x40000
#define CONFIG_ENV_SIZE 0x20000

编译出错

iteral-Wno-format-security      -os3c2410_nand.o s3c2410_nand.c -c

s3c2410_nand.c: In function's3c2410_hwcontrol':

s3c2410_nand.c:57: warning:implicit declaration of function 's3c2410_get_base_nand'

s3c2410_nand.c:57: warning:initialization makes pointer from integer without a cast

s3c2410_nand.c:72: error:dereferencing pointer to incomplete type

s3c2410_nand.c:72: error:dereferencing pointer to incomplete type

s3c2410_nand.c:75: error:dereferencing pointer to incomplete type

s3c2410_nand.c:75: error:dereferencing pointer to incomplete type

s3c2410_nand.c: In function's3c2410_dev_ready':

s3c2410_nand.c:85: warning:initialization makes pointer from integer without a cast

s3c2410_nand.c:87: error:dereferencing pointer to incomplete type

s3c2410_nand.c: In function'board_nand_init':

s3c2410_nand.c:129: warning:initialization makes pointer from integer without a cast

s3c2410_nand.c:150: error:dereferencing pointer to incomplete type

s3c2410_nand.c:153: error:dereferencing pointer to incomplete type

s3c2410_nand.c:154: error:dereferencing pointer to incomplete type

make[1]: ***[s3c2410_nand.o] Error 1

make[1]: Leaving directory`/home/work/u-boot-2012.04.01/drivers/mtd/nand'

make: ***[drivers/mtd/nand/libnand.o] Error 2

将drivers/mtd/nand/s3c2410_nand.c拷贝为drivers/mtd/nand/s3c2440_nand.c

root@zjh:/home/work/u-boot-2012.04.01#cp drivers/mtd/nand/s3c2410_nand.c drivers/mtd/nand/s3c2440_nand.c

在drivers/mtd/nand/Makefile文件中增加一行

COBJS-$(CONFIG_NAND_S3C2440)+= s3c2440_nand.o

将s3c2440_nand.c中所有的2410替换为2440

修改配置文件include\configs\tq2440.h

#define CONFIG_NAND_S3C2440

#define CONFIG_SYS_S3C2440_NAND_HWECC

修改drivers\mtd\nand\s3c2440_nand.c中的board_nand_init()函数

#ifdefined(CONFIG_S3C24XX_CUSTOM_NAND_TIMING)

  tacls  =CONFIG_S3C24XX_TACLS;

  twrph0 = CONFIG_S3C24XX_TWRPH0;

  twrph1 = CONFIG_S3C24XX_TWRPH1;

#else

  tacls = 0;

  twrph0 = 1;

  twrph1 = 0;

#endif

 

#if 0

  cfg = S3C2440_NFCONF_EN;

  cfg |= S3C2440_NFCONF_TACLS(tacls - 1);

  cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);

  cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);

#endif

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

  writel(cfg, &nand_reg->nfconf);

/*初始化ECC、禁止片选、使能NANDFLASH控制器*/

  writel((1 << 4)|(1 << 1)|(1<< 0), &nand_reg->nfcont);

nand->select_chip = s3c2440_nand_select;

添加函数s3c2440_nand_select

static voids3c2440_nand_select(struct mtd_info *mtd, int chipnr)

{

         structs3c2440_nand *nand = s3c2440_get_base_nand();

         switch(chipnr) {

         case-1: /* 取消选中 */

                nand->nfcont |= (1<<1);

                break;

         case0:  /* 选中 */

                nand->nfcont&= ~(1<<1);

                break;

         default:

                BUG();

         }

}

修改s3c2440_hwcontrol()函数

/*

** ctrl:表示做什么(选中芯片/取消选中,发命令还是发地址)

** cmd:命令值或地址值

*/

static voids3c2440_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)

{

         struct s3c2440_nand*nand = s3c2440_get_base_nand();

         if(ctrl & NAND_CLE) {

                /*发命令 */

                writeb(cmd,&nand->nfcmd);

         }else if (ctrl & NAND_ALE) {

                /* 发地址 */

                writeb(cmd,&nand->nfaddr);            

         }

}

重新编译烧到NOR FLASh执行

TQ2440 # tftp 32000000u-boot.bin

dm9000 i/o: 0x20000000, id:0x90000a46

DM9000: running in 16 bitmode

MAC: 00:0c:29:4d:e4:f4

Using dm9000 device

TFTP from server172.28.12.60; our IP address is 172.28.12.10

Filename 'u-boot.bin'.

Load address: 0x32000000

Loading: T ################

done

Bytes transferred = 226588(3751c hex)

TQ2440 # pro off all

Un-Protect Flash Bank # 1

TQ2440 # erase 0 +40000

 

....... done

Erased 7 sectors

TQ2440 # cp.b 32000000 040000

Copy to Flash...9....8....7....6....5....4....3....2....1....done

TQ2440 # res

resetting ...

 

 

U-Boot 2012.04.01 (Dec 292012 - 21:53:59)

 

CPUID: 32440001

FCLK:      400 MHz

HCLK:      100 MHz

PCLK:       50 MHz

DRAM:  64 MiB

WARNING: Caches not enabled

Flash: 2 MiB

NAND:  256 MiB

*** Warning - bad CRC, usingdefault environment

 

In:    serial

Out:   serial

Err:   serial

Net:   dm9000

TQ2440 #

测试

将SDRAM的0x32000000地址的0xff字节数据写到NAND FLASH的0地址

TQ2440 # nand write 320000000 ff  

NAND write: device 0 offset0x0, size 0xff

 255 bytes written: OK

从NAND FLASH的0地址读0xff字节数据到SDRAM的0x31000000地址

TQ2440 # nand read 310000000 ff

NAND read: device 0 offset0x0, size 0xff

 255 bytes read: OK

比较

TQ2440 # cmp.b 3100000032000000 ff

Total of 255 byteswere the same

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奋斗-永无止境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值