Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> S3C6410下移植NAND驅動

S3C6410下移植NAND驅動

編輯:初級開發

在之前的一文中提到了一些NAND的信息。下面具體說說NAND的驅動移植。 由於我在android官網GIT下來的2.6.29內核與海泰克6410開發版中提供的2.6.24內核的出入比較大,因此我在29的內核的/include/asm中添加了一些頭文件,在此先做個提醒。 下載的NAND驅動放在/drivers/mtd/nand/該文件夾中。
在該文件夾下的KCONFIG文件中添加下面信息:
config MTD_NAND_S3C
tristate "NAND Flash support for S3C SoC"
depends on ARCH_S3C64XX && MTD_NAND
help
This enables the NAND Flash controller on the S3C. No board specfic support is done by this driver, each board
must advertise a platform_device for the driver to attach. config MTD_NAND_S3C_DEBUG
bool "S3C NAND driver debug"
depends on MTD_NAND_S3C
help
Enable debugging of the S3C NAND driver config MTD_NO_ECC_WARNING
bool "S3C MTD NO ECC warning"
depends on MTD_NAND_S3C
default y
help
Disable warnings when reading or writing on NO ECC Mode. config MTD_NAND_S3C_HWECC
bool "S3C NAND Hardware ECC"
depends on MTD_NAND_S3C
help
Enable the use of the S3C's internal ECC generator when
using NAND. Early versions of the chip have had problems with
incorrect ECC generation, and if using these, the default of
software ECC is preferable. If you lay down a device with the hardware ECC, then you will
currently not be able to switch to software, as there is no
implementation for ECC method used by the S3C config S3C_LARGEPAGE_NAND
bool "Large (2K) page nand Support Enable"
depends on MTD_NAND_S3C
default n
help
S3C Large Page nand support. 在makefile文件中添加:
obj-$(CONFIG_MTD_NAND_S3C)        += s3c_nand.o s3c_nand.c中,s3c_nand_probe函數裡面做一些修改:
        //nand->ecc.mode = NAND_ECC_SOFT;       //- chachi
        nand->ecc.mode = NAND_ECC_NONE;        //+ chachi 為什麼這麼改,網上是這麼說的:
    假設你把NAND_ECC_SOFT改成NAND_ECC_NONE,那[*] Lets Yaffs do its own ECC 這一步是必需的。
最後,如果你把NAND_ECC_SOFT改成NAND_ECC_NONE的話,那你下載yaffs文件系統的時候就不應該加上-e的參數了。
這個東西我可是經歷了無數次的"mount_devfs_fs(): unable to mount devfs, err: -2"才悟出來的,本來想不講出來的,但實在太多人問這個問題了,實在不忍^_^
最後給點建議:先讓內核掛載cramfs試試看(記得把NAND_ECC_SOFT改成NAND_ECC_NONE哦),因為這個文件系統只要用下載內核的命令下載就行,成功掛載cramfs的話將會是你最大的鼓舞 先這麼理解,開發版不支持硬件的ECC校驗,menuconfig中不配置硬件ECC校驗,驅動中也會執行軟件的ECC校驗,而且貌似ECC校驗會占用大量的系統資源,因此將參數設置為NAND_ECC_NONE附:如何編寫Linux下nand Flash驅動-2


NAND Flash ECC校驗的原理

http://blog.ednchina.com/lIEal/17736/message.ASPx 驅動設置好以後,進行參數配置。
比較了一下2.6.24和2.6.29內核以後,發現2.6.29內核中6410(其他類似)中的所有platform_device都定義在了 /arch/arm/mach-s3c6410/mach-smdk6410.c 以及 /arch/arm/plat-s3c64xx/dev-xxx.c(比如:dev-fb.c)中。 因此,在Mach-smdk6410.c中添加注冊信息: * NAND分區
* 一共分為4個區,其中第3個分區存放android的文件系統

* 第4個分區存放android文件系統data文件夾的內容
* 因此在UBOOT的參數設置為root=/dev/mtdblock2 struct mtd_partition s3c_partition_info[] = { .name        = "Bootloader",
.offset        = 0,
.size        = (256*SZ_1K),
.mask_flags    = MTD_CAP_NANDFlash, {
.name        = "Kernel",
.offset        = (256*SZ_1K),    /* Block number is 0x10 */
.size        = (5*SZ_1M) - (256*SZ_1K),
// .mask_flags    = MTD_CAP_NANDFlash,        //- chachi {
.name        = "File System",
.offset        = (5*SZ_1M),    /* Block number is 0x10 */
.size        = (90*SZ_1M),            //gzy
// .mask_flags    = MTD_CAP_NANDFlash,    //- chachi {
.name        = "Data",
.offset        = MTDPART_OFS_APPEND,
.size        = MTDPART_SIZ_FULL, }; struct s3c_nand_mtd_info s3c_nand_mtd_part_info = {
.chip_nr = 1,
.mtd_part_nr = ARRAY_SIZE(s3c_partition_info),
.partition = s3c_partition_info,
}; static struct resource s3c_nand_resource[] = {
[0] = {
.start = S3C24XX_PA_NAND,
.end   = S3C24XX_PA_NAND + S3C24XX_SZ_NAND - 1,
.flags = IORESOURCE_MEM, }; struct platform_device s3c_device_nand = {
.name        = "s3c-nand",
.id        = -1,
.num_resources    = ARRAY_SIZE(s3c_nand_resource),
.resource    = s3c_nand_resource,
.dev = {
.platform_data = &s3c_nand_mtd_part_info };
/* end change by chachi */ static struct platform_device *smdk6410_devices[] __initdata = { &s3c_device_nand, //+ chachi };NAND的PHY地址定義為:
#define S3C24XX_PA_NAND (0x70200000)
#define S3C24XX_SZ_NAND SZ_1M 最後配置menuconfig(我更喜歡用xconfig ^_^):
<*> Memory Technology Device (MTD) support ---> 
[*]   MTD partitioning support
<*>   RedBoot partition table parsing                            │ │ 
│ │    (-1)    Location of RedBoot partition table                      │ │ 
│ │    [*]     Include unallocated Flash regions                        │ │ 
│ │    [ ]     Force read-only for RedBoot system images                │ │ 
│ │    [*]   Command line partition table parsing                       │ 
<*>   Direct char device Access to MTD devices                   │ │ 
│ │    -*-   Common interface to block layer for MTD 'translation layers│ │ 
│ │    <*>   Caching block device Access to MTD devices   │ │          RAM/ROM/Flash chip drivers ---> 
<*> Detect flash chips by Common Flash Interface (CFI) probe     │ │ 
│ │    <*> Detect non-CFI AMD/JEDEC-compatible Flash chips              │ │ 
│ │    [ ] Flash chip driver advanced configuration options             │ │ 
│ │    <*> Support for Intel/Sharp Flash chips                          │ │ 
│ │    <*> Support for AMD/Fujitsu/Spansion Flash chips                 │ │ 
│ │    < > Support for ST (Advanced Architecture) Flash chips           │ │ 
│ │    < > Support for RAM chips in bus mapping                         │ │ 
│ │    <*> Support for ROM chips in bus mapping                         │ │ 
│ │    < > Support for absent chips in bus mapping                      │ │ │ └────────────────────────────────────────────────── <*>   NAND Device Support ---> 
--- NAND Device Support                                          │ │ 
│ │    [*]   Verify NAND page writes                                    │ │ 
│ │    [ ]   NAND ECC Smart Media byte order                            │ │ 
│ │    [ ]   Enable chip ids for obsolete ancIEnt NAND devices          │ │ 
│ │    < >   GPIO NAND Flash driver                                     │ │ 
│ │    <*>   NAND Flash support for S3C SoC                             │ │ 
│ │    [ ]     S3C NAND driver debug                                    │ │ 
│ │    [*]     S3C MTD NO ECC warning                                   │ │ 
│ │    [ ]     S3C NAND Hardware ECC                                    │ │ 
│ │    [*]     Large (2K) page nand Support Enable                      │ │ │ │    < >   Support for generic platform NAND driver                   │ │ 
│ └───────────────────────────────────────────────────────────────

在uboot中配置bootargs參數:

root=/dev/mtdblock2 rootfstype=jffs2

啟動內核後顯示:

S3C NAND Driver, (c) 2007 Samsung Electronics

<6>NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)

<4>NAND_ECC_NONE selected by board driver. This is not recommended !!

<5>Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":

<5>0x000000000000-0x000000040000 : "Bootloader"

<5>0x000000040000-0x000000500000 : "Kernel"

<5>0x000000500000-0x000005f00000 : "File System"

<5>0x000005f00000-0x000008000000 : "data"

install NAND DRIVE = 0

......

VFS: Mounted root (jffs2 filesystem) on device 31:2.

<6>Freeing init memory: 88K

<4>Warning: unable to open an initial console.

<0>Kernel panic - not syncing: Attempted to kill init!

表示NAND驅動移植成功

JFFS2文件系統等,在之後的文章中寫

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved