mini2440移植uboot 2014.04(三)


我修改的代碼已經上傳到github上,地址:https://github.com/qiaoyuguo/u-boot-2014.04-mini2440.git

參考文檔: s3c2440手冊(下載地址) mini2440電路圖(下載地址) K9F1G08數據手冊(下載地址

參考文章:《mini2440移植uboot 2011.03(下)

前兩篇博文: 《mini2440移植uboot 2014.04(一)

                      《mini2440移植uboot 2014.04(二)

(五)添加nand flash支持

主要是基於參考mini2440 自帶的uboot源代碼進行修改。

用官方uboot啟動時,得到的輸出信息是128MiB的nand flash。查看芯片電路圖可以知道是K9F系列芯片,而128MiB的芯片只能是K9F1G08(128Mx8bits)。

在上一節執行uboot時,關於nand flash的顯示信息如下:

NAND:  board_nand_init()
end of nand_init
hwcontrol(): 0xff 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
0 MiB

明顯沒有檢測到nand flash.
整個調用入口是nand_init->nand_init_chip->board_nand_init,而board_nand_init函數位於drivers/mtd/nand/s3c2410_nand.c中 。

首先需要考慮的就是幾個變量的值:tacls、twrph0、twrph1。

參考文章《uboot中nand flash控制器參數TACLS、TWRPH0和TWRPH1的確定(基於K9F2G08U0B)》,這三個值是根據時序來計算出來的。

根據K9F1G08手冊第17頁和第10頁以及s3c2440手冊587頁,可以知道tacls=tCLS>12ns,twrph0=tWP>12ns,twrph1=tCLH>5ns。

而nand flash是根據HCLK時鍾來計算,根據1:4:8的分頻,HCLK=100MHZ,每個時鍾=10ns.

可以將這三個值分別設置成2、2、1即可,但是為了保持和官方版本一致,我仍將其值設置成4、2、0.

根據2440手冊第226頁,其NFCONT寄存器中每一位的含義與s3c2410中的大部分都不相同,需要進行相應的修改。


我只是將mini2440中的uboot和當前代碼合並,修改代碼如下:

#ifdef CONFIG_S3C2410
#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_ADDR_NALE 4
#define S3C2410_ADDR_NCLE 8
#endif

#ifdef CONFIG_S3C2440
#define S3C2410_NFCONT_EN          (1<<0)
#define S3C2410_NFCONT_INITECC     (1<<4)
#define S3C2410_NFCONT_nFCE        (1<<1)
#define S3C2410_NFCONT_MAINECCLOCK (1<<5)
#define S3C2410_NFCONF_TACLS(x)    ((x)<<12)  
#define S3C2410_NFCONF_TWRPH0(x)   ((x)<<8)  
#define S3C2410_NFCONF_TWRPH1(x)   ((x)<<4)  

#define S3C2410_ADDR_NALE 0x08
#define S3C2410_ADDR_NCLE 0x0c
#endif

#if defined(CONFIG_S3C2410)
                if (ctrl & NAND_NCE)
                        writel(readl(&nand->nfconf) & ~S3C2410_NFCONF_nFCE,
                               &nand->nfconf);
                else
                        writel(readl(&nand->nfconf) | S3C2410_NFCONF_nFCE,
                               &nand->nfconf);
        }
#endif
#if defined(CONFIG_S3C2440)
                if (ctrl & NAND_NCE)
                        writel(readl(&nand->nfconf) & ~S3C2410_NFCONT_nFCE,
                               &nand->nfconf);
                else
                        writel(readl(&nand->nfconf) | S3C2410_NFCONT_nFCE,
                               &nand->nfconf);
        }
#endif
#if defined(CONFIG_S3C2410)
        writel(readl(&nand->nfconf) | S3C2410_NFCONF_INITECC, &nand->nfconf);
#endif

#if defined(CONFIG_S3C2440)
        writel(readl(&nand->nfconf) | S3C2410_NFCONT_INITECC, &nand->nfconf);
#endif

#if defined(CONFIG_S3C2410)
        /* initialize hardware */
#if defined(CONFIG_S3C24XX_CUSTOM_NAND_TIMING)
        tacls  = CONFIG_S3C24XX_TACLS;
        twrph0 = CONFIG_S3C24XX_TWRPH0;
        twrph1 =  CONFIG_S3C24XX_TWRPH1;
#else
        tacls = 4;
        twrph0 = 8;
        twrph1 = 8;
#endif
#endif

#if defined(CONFIG_S3C2440)
        tacls = 4;
        twrph0 = 2;
        twrph1 = 0;

        cfg = 0;
        cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
        cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
        cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
        writel(cfg, &nand_reg->nfconf);

        cfg = (1<<4)|(1<<0);
    writel(cfg, &nand_reg->nfcont);
#else
        cfg = S3C2410_NFCONF_EN;
        cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
        cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
        cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
        writel(cfg, &nand_reg->nfconf);
        writel(cfg, &nand_reg->nfcont);
#endif

重新編譯加載到mini2440,得到輸出信息如下:

NAND:  board_nand_init()
end of nand_init
hwcontrol(): 0xff 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
128 MiB

執行一些命令,得到的輸出信息:

SMDK2410 # nand info

Device 0: nand0, sector size 128 KiB
  Page size      2048 b
  OOB size         64 b
  Erase size   131072 b
Initial value for argc=3
Final value for argc=3
Initial value for argc=3
Final value for argc=3
Initial value for argc=3
Final value for argc=3

貌似nand flash基本支持已經完成了,后面使用有問題了再修改代碼。

 

執行了幾個nand命令,重新加載uboot到mini2440,卻出現下面的錯誤:

U-Boot 2014.04-g9541fe9-dirty (Jun 05 2014 - 15:45:56)

U-Boot code: 33E80000 -> 33EF9ED0  BSS: -> 33F488D0
CPUID: 32440001
FCLK:      405 MHz
HCLK:  101.250 MHz
PCLK:   50.625 MHz
monitor len: 000C88D0
ramsize: 04000000
TLB table from 33ff0000 to 33ff4000
Top of RAM usable for U-Boot at: 33ff0000
Reserving 802k for U-Boot at: 33f27000
Reserving 4160k for malloc() at: 33b17000
Reserving 32 Bytes for Board Info at: 33b16fe0
Reserving 160 Bytes for Global Data at: 33b16f40
New Stack Pointer is: 33b16f30
RAM Configuration:
Bank #0: 30000000 64 MiB
addr=33f27000,_start=33e80000
relocation Offset is: 000a7000
WARNING: Caches not enabled
monitor flash len: 000846C0
dram_bank_mmu_setup: bank: 0
Now running in RAM - U-Boot at: 33f27000
Flash: fwc addr 00000000 cmd f0 00f0 16bit x 16 bit
fwc addr 0000aaaa cmd aa 00aa 16bit x 16 bit
fwc addr 00005554 cmd 55 0055 16bit x 16 bit
fwc addr 0000aaaa cmd 90 0090 16bit x 16 bit
fwc addr 00000000 cmd f0 00f0 16bit x 16 bit
JEDEC PROBE: ID f0 ffff 0
fwc addr 00000000 cmd ff 00ff 16bit x 16 bit
fwc addr 00000000 cmd 90 0090 16bit x 16 bit
fwc addr 00000000 cmd ff 00ff 16bit x 16 bit
JEDEC PROBE: ID 90 ffff 0
*** failed ***
### ERROR ### Please RESET the board ###

居然又無法檢測到nor flash了。我折騰了好一會兒,將nand flash全部擦除,然后將官方的uboot重新加載進來,

之后再加載自己的uboot,能正常進入到uboot命令行了。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM