u boot移植(六)新增nandflash支援

2021-06-02 16:37:41 字數 4020 閱讀 7272

1、   新增nand flash 移植

mtd為linux下的儲存架構,mtd封裝了對儲存器操作的統一介面函式,方便linux呼叫

檢視lib_arm/boart.c檔案,可以看到nand_init()函式在drivers/mtd/nand/nand.c中定義

#if defined(config_cmd_nand)

puts ("nand:  ");

nand_init();                  /* go init the nand */

#endif

用sourceinsight檢視,發現

a)         在include/s3c24x0.h中新增

typedef struct s3c2440_nand;

在include/s3c2410.h中新增

#define s3c2440_nand_base               0x4e000000

static inline s3c2440_nand * s3c2440_getbase_nand(void)

return (s3c2440_nand * const)s3c2440_nand_base;

b)         include/configs/mini2440.h

修改1:新增對nand的支援,新增

#define config_cmd_nand

#define config_max_nand_device  1

#define config_sys_nand_base    0x4e000000

#define config_mtd_device選項可以不加,只是對nand info命令有影響

c)          drivers/mtd/nand/s3c2410_nand.c

修改1:注釋掉原始檔開始的所有暫存器定義,新增

#define nfconf          __regi(nf_base + 0x0)

#define nfcont          __regi(nf_base + 0x4)

#define nfcmd           __regb(nf_base + 0x8)

#define nfaddr          __regb(nf_base + 0xc)

#define nfdata          __regb(nf_base + 0x10)

#define nfstat          __regb(nf_base + 0x20)

#define nfecc0          __regb(nf_base + 0x14)

#define nfecc1          __regb(nf_base + 0x18)

#define nfsecc          __regb(nf_base + 0x1c)

#define s3c2440_nfcont_en          (1<<0)

#define s3c2440_nfcont_nfce        (0<<1)

#define s3c2440_nfcont_initecc     (1<<4)

#define s3c2440_nfconf_tacls(x)    ((x)<<12)

#define s3c2440_nfconf_twrph0(x)   ((x)<<8)

#define s3c2440_nfconf_twrph1(x)   ((x)<<4)

#define s3c2440_nfcont_nce         (1<<1)

#define s3c2440_addr_nale 0x0c

#define s3c2440_addr_ncle 0x08

修改2:修改函式s3c2410_hwcontrol如下

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

struct nand_chip *chip = mtd->priv;//可加可不加

ulong io_addr_w = nf_base;

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;

else

nfcont |= s3c2440_nfcont_nce;

if (cmd != nand_cmd_none)

writeb(cmd, (void *)io_addr_w);

個人認為全域性變數io_addr_w可以換成其他變數名

修改3:board_nand_init函式,首先設定nfconf,nfcont暫存器的值,並確定nand讀寫的nfdata暫存器,

twrph0 =5; twrph1 = 3; tacls = 0;

cfg = s3c2440_nfconf_tacls(tacls - 1);

cfg |= s3c2440_nfconf_twrph0(twrph0 - 1);

cfg |= s3c2440_nfconf_twrph1(twrph1 - 1);

nfconf = cfg;

cfg = s3c2440_nfcont_en;

cfg |= s3c2440_nfcont_nfce;

cfg |= s3c2440_nfcont_initecc;

nfcont = cfg;

設定mtd_info中io_addr_w和io_addr_r值,

nand->io_addr_r = nand->io_addr_w = (void *)0x4e000010;

並設定命令解析函式和等待空閒函式,正常結束返回0值。

nand->cmd_ctrl = s3c2410_hwcontrol;

nand->dev_ready = s3c2410_dev_ready;

修改4 :進入頂層目錄編譯工程,出現undefined reference to `board_nand_init',檢視drivers/mtd/nand/makefile檔案,看到

cobjs-$(config_nand_ndfc) += ndfc.o

cobjs-$(config_nand_nomadik) += nomadik.o

cobjs-$(config_nand_s3c2410) += s3c2410_nand.o

cobjs-$(config_nand_s3c64xx) += s3c64xx.o

修改5:修改nandflash讀寫時序,drivers/mtd/nand/s3c2410_nand.c

ulong nand_addr = nf_base;

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

if (ctrl & nand_ctrl_change) {

nand_addr = nf_base;

if (!(ctrl & nand_cle))

nand_addr |= s3c2440_addr_nale;

if (!(ctrl & nand_ale))

nand_addr |= s3c2440_addr_ncle;

if (ctrl & nand_nce)

nfcont &=~s3c2440_nfcont_nce;

else

nfcont |=s3c2440_nfcont_nce;

if (cmd != nand_cmd_none)

writeb(cmd, (void *)nand_addr);

uboot移植新增單板支援

cp configs mx6qarm2 defconfig fet mx6q defconfig四 修改 fet mx6q defconfig vi fet mx6q defconfig config arm y config arch mx6 y mx6 config target fet mx6...

U Boot移植日誌(3) 新增命令

u boot在定義指令時按模組化設計,指令的結構設計在 common command.c中定義,而各條指令的相關函式在單獨的檔案中 common cmd commandname.c,其中commandname為各指令名。要新增自己的指令可以按以下步驟 1 建立一函式do mycommandname,...

uboot移植 uboot啟動回顧

一 uboot啟動的第一階段start.s 路徑uboot cpu s5pc11x start.s 1 include 標頭檔案包含,config.件原始碼中不存 在,配置後自動生成 路徑 include linux config.h 2 include 標頭檔案包含,version.件原始碼中不存...