ppcboot添加nandflash支持

来源:互联网 发布:mac怎么设置wifi热点 编辑:程序博客网 时间:2024/05/20 05:57

从uboot中 copy -rf 以下目录或文件至ppcboot相应目录
drivers/nand
include/linux/mtd
include/nand.h
include/asm-arm/io.h
在 include/cmd_confdefs.h 中添加
#define min(X, Y)    /
 ({ typeof (X) __x = (X), __y = (Y); /
  (__x < __y) ? __x : __y; })

#define max(X, Y)    /
 ({ typeof (X) __x = (X), __y = (Y); /
  (__x > __y) ? __x : __y; })
#define CFG_CMD_NAND 0x0000100000000000 /* NAND support*/
在 include/comfigs/smdk2410.h 中添加
#define CFG_NAND_BASE 0x4e00000C
#define CFG_MAX_NAND_DEVICE 1

还有一些修改就等着编译出错了再修改就是了

主要的工作就是添加命令和对驱动的修改
暂时添加一个简单的命令,nandinit来初始化nandflash
在 include 下添加 cmd_nand.h
#ifndef _CMD_NAND_H
#define _CMD_NAND_H

#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#define CMD_TBL_NANDINIT MK_CMD_TBL_ENTRY(     /
 "nandinit", 5, 1, 1, do_nandinit,   /
 "nandinit  - init nand flash/n",    /
 "/n  nandinit  - init nand flash/n"  /
),
int do_nandinit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
#else
#define CMD_TBL_NANDINIT
#endif /* CFG_CMD_NAND */
#endif /* _CMD_NAND_H */

然后再 common 中添加相应的 cmd_nand.c文件,来实现这个命令

#include <common.h>
#include <command.h>
 
extern void nand_init(void);

#if (CONFIG_COMMANDS & CFG_CMD_NAND)

int do_nandinit ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
 ulong bank;
 nand_init();
 return 0;
}

#endif /* CFG_CMD_FLASH */

修改下Makefile,并在 common/command.c 中添加
#include <cmd_nand.h>
在 cmd_tbl 命令宏数组中加入 CMD_TBL_NANDINIT,使得run_command能找到命令

来自uboot的Nandflash的驱动基本就是2.6内核中的驱动
我们只需要实现几个更底层的接口函数,而且ppcboot中没有用到
MMU,这样直接对nandflash控制器的寄存器进行操作.
原本需要把这些函数放在 board/smdk2410 目录中,不过为了方便一点就直接修改驱动
的nand.c文件,以下是代码.
#include <common.h>
#include <asm/io.h>

#if (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CFG_NAND_LEGACY)

#include <nand.h>

#ifndef CFG_NAND_BASE_LIST
#define CFG_NAND_BASE_LIST { CFG_NAND_BASE }
#endif

#define S3C2410_NFREG(x) (x+0x4e000000)

#define S3C2410_NFCONF  S3C2410_NFREG(0x00)
#define S3C2410_NFCMD   S3C2410_NFREG(0x04)
#define S3C2410_NFADDR  S3C2410_NFREG(0x08)
#define S3C2410_NFDATA  S3C2410_NFREG(0x0C)
#define S3C2410_NFSTAT  S3C2410_NFREG(0x10)
#define S3C2410_NFECC   S3C2410_NFREG(0x14)

#define S3C2410_NFCONF_EN          (1<<15)
#define S3C2410_NFCONF_512BYTE     (1<<14)
#define S3C2410_NFCONF_4STEP       (1<<13)
#define S3C2410_NFCONF_INITECC     (1<<12)
#define S3C2410_NFCONF_nFCE        (1<<11)
#define S3C2410_NFCONF_TACLS(x)    ((x)<<8)
#define S3C2410_NFCONF_TWRPH0(x)   ((x)<<4)
#define S3C2410_NFCONF_TWRPH1(x)   ((x)<<0)

#define S3C2410_NFSTAT_BUSY        (1<<0)

void s3c2410_nand_inithw(void)
{
 u16 tacls, twrph0, twrph1;
 u16 cfg = 0;
 tacls = 4;
 twrph0 = 8;
 twrph1 = 8;
 cfg  = S3C2410_NFCONF_EN;
 cfg |= S3C2410_NFCONF_TACLS(tacls-1);
 cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1);
 cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1);
 writew(cfg,S3C2410_NFCONF);
}


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

 switch (cmd) {
 case NAND_CTL_SETNCE:
  writew(readw(S3C2410_NFCONF) & ~S3C2410_NFCONF_nFCE , S3C2410_NFCONF);
  break;
 case NAND_CTL_CLRNCE:
  writew(readw(S3C2410_NFCONF) | S3C2410_NFCONF_nFCE , S3C2410_NFCONF);
  break;

 case NAND_CTL_SETCLE:
  chip->IO_ADDR_W = (void __iomem *)S3C2410_NFCMD;
  break;

 case NAND_CTL_SETALE:
  chip->IO_ADDR_W = (void __iomem *)S3C2410_NFADDR;
  break;

  /* NAND_CTL_CLRCLE: */
  /* NAND_CTL_CLRALE: */
 default:
  chip->IO_ADDR_W = (void __iomem *)S3C2410_NFDATA;
  break;
 }
}

static int s3c2410_nand_devready(struct mtd_info *mtd)
{
 return readb(S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
}


void board_nand_init(struct nand_chip *nand)
{
 s3c2410_nand_inithw();
 nand->hwcontrol    = s3c2410_nand_hwcontrol;
 nand->dev_ready    = s3c2410_nand_devready;
 nand->chip_delay   = 50;
 nand->options    = 0;
 nand->eccmode    = NAND_ECC_SOFT;
}


int nand_curr_device = -1;
nand_info_t nand_info[CFG_MAX_NAND_DEVICE];

static struct nand_chip nand_chip[CFG_MAX_NAND_DEVICE];
static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST;

static const char default_nand_name[] = "nand";


static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
      ulong base_addr)
{
 mtd->priv = nand;

 nand->IO_ADDR_R = nand->IO_ADDR_W = (void  __iomem *)base_addr;
 board_nand_init(nand);

 if (nand_scan(mtd, 1) == 0) {
  if (!mtd->name)
   mtd->name = (char *)default_nand_name;
 } else
  mtd->name = NULL;

}

void nand_init(void)
{
 int i;
 unsigned int size = 0;
 for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
  nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
  size += nand_info[i].size;
  if (nand_curr_device == -1)
   nand_curr_device = i;
 }
 printf("Nand flash %dM/n", size / (1024 * 1024));
}

#endif

很容易就能读懂了,以后就可以在这基础上再加入烧写nandflash的命令
还可以加入启动wince的命令,来实现linux和wince的双系统.
 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 别人电脑上c盘文件无权访问怎么办 网络已连接但上不了网怎么办 asp复选框选中的有重复值怎么办 邮件在邮递中出现损坏怎么办呢? 爱彩彩票资金密码忘记了怎么办 注册彩票网站忘了资金密码怎么办 电车电瓶加水后电压变低怎么办 电动车电瓶四块电池坏了一块怎么办 把小孩的玩具修坏了怎么办 电动车插头太紧了插不到底怎么办 宜家沙发不能更换布套怎么办 苹果官网买的无线充坏了怎么办 苹果官网上买的耳机坏了怎么办 led灯开关关掉了闪烁是怎么办 我朋友借的网贷光给我打电话怎么办 电脑上的文件变成了图片查看怎么办 外卖店打印机纸卡住打不开了怎么办 微信撤回图片留下一堆代码怎么办 拼多多砍价免费拿砍不到0元怎么办 一岁三个月宝宝老足拉肚子怎么办丶 想打好关系送礼发红包不敢收怎么办 我在相亲市场太受欢迎了怎么办小说 有人报警说我诈骗警察说立案怎么办 微信账号长时间未登录不想要怎么办 手机号注销了百度云登录不了怎么办 申请百度云账号的手机不用了怎么办 新注册的微信号显示账号异常怎么办 注册公众号说邮箱被占用了怎么办 向钱贷登录手机号换了怎么办 qq号绑定的手机号码换了怎么办 用手机号注册的支付宝换号了怎么办 支付宝转的账户手机号消号了怎么办 激活微信账号手机号写错了怎么办 大学试卷没有写名字和考号怎么办 公司被注销了公众号还想要怎么办 公司认证的公众号公司注销了怎么办 信而富注册手机号码不用了怎么办 信而富本时段额度已放完怎么办 知道qq号密码账号忘了怎么办 扣扣绑定的手机号被别人用了怎么办 我的手机号被别人绑定了快手怎么办