十八、flash 适配(二)

18.5 流程总结

同时我们也知道我们可能需要配置的配置宏:

  • CONFIG_CMD_NAND
  • CONFIG_SYS_MAX_NAND_DEVICE
  • CONFIG_SYS_NAND_BASE
  • CONFIG_S3C24XX_CUSTOM_NAND_TIMING
  • CONFIG_S3C2440_NAND_HWECC
  • CONFIG_S3C2440_NAND_BBT

18.6 代码移植

18.6.1 Kconfig 中添加配置

需要修改的 kconfig 文件 driversmtd andKconfig,添加如下代码:

 1 config NAND_S3C24X0
 2     bool "Support S3c24x0 NAND Controller"
 3     default n
 4     help
 5       Support s3c2410 s3c2440.
 6 
 7 config SYS_MAX_NAND_DEVICE
 8     int "Number of nand device"
 9     default 0
10     help
11       There may be more than one nandflash on a board.
12       Enter the number of nandflash on your board.
13       default 0
14 
15 config SYS_NAND_BASE
16     hex "Basic address of NAND controller"
17     default 0x4e000000 if S3C2440
18     default 0x4e000000 if S3C2410
19     help
20       Base address of NAND controller of SOC.
21 
22 config S3C24XX_CUSTOM_NAND_TIMING
23     bool "Support s3c24xx Custom NAND Timing"
24     default n
25     depends on NAND_S3C24X0
26     help
27       Support s3c24xx custom nand timing
28 
29 config S3C24XX_TACLS
30     int "Tacls of NAND controller of S3C24XX"
31     depends on S3C24XX_CUSTOM_NAND_TIMING
32     help
33       Tacls of NAND controller of S3C24XX.
34       This is the parameter of the NAND controller's register nfconf.
35       For S3C2440, tacls = S3C24XX_TACLS - 1
36 
37 config S3C24XX_TWRPH0
38     int "Twrph0 of NAND controller of S3C24XX"
39     depends on S3C24XX_CUSTOM_NAND_TIMING
40     help
41       Twrph0 of NAND controller of S3C24XX.
42       This is the parameter of the NAND controller's register nfconf.
43       For S3C2440, twrph0 = S3C24XX_TWRPH0 - 1
44 
45 config S3C24XX_TWRPH1
46     int "Twrph1 of NAND controller of S3C24XX"
47     depends on S3C24XX_CUSTOM_NAND_TIMING
48     help
49       Twrph1 of NAND controller of S3C24XX.
50       This is the parameter of the NAND controller's register nfconf.
51       For S3C2440, Twrph1 = S3C24XX_TWRPH1 - 1
52 
53 choice
54     prompt "s3c24x0 nand ecc"
55     default n
56     depends on NAND_S3C24X0
57     help
58       Support s3c24x0 nand hwecc
59 
60 config S3C2410_NAND_HWECC
61     bool "s3c2410 nand hwecc"
62 
63 config S3C2440_NAND_HWECC
64     bool "s3c2440 nand hwecc"
65 
66 endchoice
67 
68 choice
69     prompt "s3c24x0 nand BBT"
70     default n
71     depends on NAND_S3C24X0
72     help
73       Support s3c24x0 nand BBT
74 
75 config S3C2410_NAND_BBT
76     bool "s3c2410 nand BBT"
77 
78 config S3C2440_NAND_BBT
79     bool "s3c2440 nand BBT"
80 
81 endchoice

修改完成后,执行 make menuconfig 将配置打开。

18.6.2 文件名修改

mv s3c2410_nand.c s3c24x0_and.c 

在文件使用特性宏隔开 2410 和 2440 不同的配置

18.6.3 时钟、NFCONF、NFCONT 修改

 s3c24x0_get_base_clock_power 和 s3c24x0_get_base_nand 都有对应的芯片头文件对应,不用管。

需要注意的是 s3c24x0_clock_power 和 s3c24x0_nand 这两个结构体,这两个结构体是用来描述时钟电源寄存器和 nand 控制器寄存器的。对照 datasheet 确认是否修改。

继续流程向下:时钟设置、NFCONF寄存器设置和 nand 结构体中的 IO_ADDR_R 和 IO_ADDR_W 设置

带 S3C2410 的字样的宏需要进行修改,这是与 2440 的差异。修改如下:

board_nand_init() 中修改:

 

18.6.4 片选函数修改

继续向下查看源码,开始初始化 nand_chip 的数据结构了,但是 nand->select_chip 这个回调函数没有写。

 写一个 select_chip 的回调函数:

board_nand_init 修改:

18.6.5 hwcontrol 修改

 继续向下查看修改,nand_read_buf 与我们当前无关,没有看 SPL,不用管,后面两个函数需要做适配 S3C2440。

 s3c24x0_hwcontrol 修改如下:

 注意:在后面的编译测试中发现一个问题,NAND_CLE 和 NAND_ALE 的定义反了,ALE 应该是地址总线的,但是却成了命令,CLE 是命令的,却成了地址,为了不改变 u-boot 的总体架构,这里的两个宏也定义成反的:

 当然也可以做源码修改。

修改后的代码如下

18.6.6 dev_ready 修改

此函数的作用是,读取 nfstat 寄存器, 获取 nandflash 的状态,不需要修改。

原文地址:https://www.cnblogs.com/kele-dad/p/13154024.html