--by FeCen
这里我们来看XLOADER_ENTRY中调用的第二个标号ddr_init处的代码,这部分代码的作用是对外部内存SDRAM进行初始化,在我spearplus开发板中,使用的是DDR SDRAM。在调用ddr_init之前,外部内存是不能用的,因为外部内存的时钟以及控制寄存器都还没有初始化,因此此时只有芯片内部的SRAM以及在sys_init的时候已经初始化了的Serial Flash、UART以及gmac是可用的。
而ddr_init的作用就是根据板子使用的外部SDRAM来对外部内存进行初始化,针对不同的板子使用不同的SDRAM的,需要根据特定的SDRAM来定制这个初始化过程,这也是为什么要把ddr_init单独放在一个文件中的原因,便于在不同的外部内存之间的代码移植。
在这里,我还有很多不明白的地方,我想是因为我对硬件不过熟悉的缘故。所以很多代码只能够看到它的表面,真正代码想要完成的功能需要结合各个寄存器本身的作用以及对SDRAM初始化的整个过程的定义才能够看清楚。但是,这需要阅读大量的芯片手册,这对于我来说,至少目前还不具备这种能力和条件,因此暂时先放一放,等到以后真正需要用到的时候再回过头来仔细研究。在这里,我们只需要明白,这一段代码,是在对特定的外部内存进行初始化,初始化完成之后,外部内存就可以使用了,将来uboot以及linux kernel的代码都需要转移到外部内存之后才可以运行的。
对于我的代码来说,ddr_init位于Xloader根目录下面的ddr/splus_mt47h128m8_3.266_c15_map_async.S中,完整的代码以及对代码的粗略分析如下:
1 #define MPMCBase 0xfc600000
2 #define NUM_OF_MPMC_REGS 100
3
4
5 /*****************************************************************************/
6
7 #define MPMCRegsBase 0xfca80000
8 #define DDR_PLL_REG MPMCRegsBase + 0x0020
9 #define PER1_CLKEN MPMCRegsBase + 0x002C
10 #define DDR_PAD_REG MPMCRegsBase + 0x00f0
11 #define DDR_1V8_REG MPMCRegsBase + 0x00e4
12 #define DDR_2V5_REG MPMCRegsBase + 0x00e8
13 #define DDR_3V3_REG MPMCRegsBase + 0x00ec
14
15 #define MPMCBase 0xfc600000
16
17 #define DENALI_CTL_00 MPMCBase + 0x000
18 #define DENALI_CTL_01 MPMCBase + 0x004
19 #define DENALI_CTL_02 MPMCBase + 0x008
20 #define DENALI_CTL_03 MPMCBase + 0x00c
21 #define DENALI_CTL_04 MPMCBase + 0x010
22 #define DENALI_CTL_05 MPMCBase + 0x014
23 #define DENALI_CTL_06 MPMCBase + 0x018
24 #define DENALI_CTL_07 MPMCBase + 0x01c
25 #define DENALI_CTL_08 MPMCBase + 0x020
26 #define DENALI_CTL_09 MPMCBase + 0x024
27 #define DENALI_CTL_10 MPMCBase + 0x028
28 #define DENALI_CTL_11 MPMCBase + 0x02c
29 #define DENALI_CTL_12 MPMCBase + 0x030
30 #define DENALI_CTL_13 MPMCBase + 0x034
31 #define DENALI_CTL_14 MPMCBase + 0x038
32 #define DENALI_CTL_15 MPMCBase + 0x03c
33 #define DENALI_CTL_16 MPMCBase + 0x040
34 #define DENALI_CTL_17 MPMCBase + 0x044
35 #define DENALI_CTL_18 MPMCBase + 0x048
36 #define DENALI_CTL_19 MPMCBase + 0x04c
37 #define DENALI_CTL_20 MPMCBase + 0x050
38 #define DENALI_CTL_21 MPMCBase + 0x054
39 #define DENALI_CTL_22 MPMCBase + 0x058
40 #define DENALI_CTL_23 MPMCBase + 0x05c
41 #define DENALI_CTL_24 MPMCBase + 0x060
42 #define DENALI_CTL_25 MPMCBase + 0x064
43 #define DENALI_CTL_26 MPMCBase + 0x068
44 #define DENALI_CTL_27 MPMCBase + 0x06c
45 #define DENALI_CTL_28 MPMCBase + 0x070
46 #define DENALI_CTL_29 MPMCBase + 0x074
47 #define DENALI_CTL_30 MPMCBase + 0x078
48
49 /*;-----------------------------------------------------------------------------------*/
50 #define DENALI_CTL_31 MPMCBase + 0x07c
51 #define DENALI_CTL_32 MPMCBase + 0x080
52 #define DENALI_CTL_33 MPMCBase + 0x084
53 #define DENALI_CTL_34 MPMCBase + 0x088
54 #define DENALI_CTL_35 MPMCBase + 0x08c
55 #define DENALI_CTL_36 MPMCBase + 0x090
56 #define DENALI_CTL_37 MPMCBase + 0x094
57 #define DENALI_CTL_38 MPMCBase + 0x098
58 #define DENALI_CTL_39 MPMCBase + 0x09c
59 #define DENALI_CTL_40 MPMCBase + 0x0a0
60 #define DENALI_CTL_41 MPMCBase + 0x0a4
61 #define DENALI_CTL_42 MPMCBase + 0x0a8
62 #define DENALI_CTL_43 MPMCBase + 0x0ac
63 #define DENALI_CTL_44 MPMCBase + 0x0b0
64 #define DENALI_CTL_45 MPMCBase + 0x0b4
65 #define DENALI_CTL_46 MPMCBase + 0x0b8
66 #define DENALI_CTL_47 MPMCBase + 0x0bc
67 #define DENALI_CTL_48 MPMCBase + 0x0c0
68 #define DENALI_CTL_49 MPMCBase + 0x0c4
69 #define DENALI_CTL_50 MPMCBase + 0x0c8
70 #define DENALI_CTL_51 MPMCBase + 0x0cc
71 #define DENALI_CTL_52 MPMCBase + 0x0d0
72 #define DENALI_CTL_53 MPMCBase + 0x0d4
73 #define DENALI_CTL_54 MPMCBase + 0x0d8
74 #define DENALI_CTL_55 MPMCBase + 0x0dc
75 #define DENALI_CTL_56 MPMCBase + 0x0e0
76 #define DENALI_CTL_57 MPMCBase + 0x0e4
77 #define DENALI_CTL_58 MPMCBase + 0x0e8
78 #define DENALI_CTL_59 MPMCBase + 0x0ec
79 #define DENALI_CTL_60 MPMCBase + 0x0f0
80 #define DENALI_CTL_61 MPMCBase + 0x0f4
81 #define DENALI_CTL_62 MPMCBase + 0x0f8
82 #define DENALI_CTL_63 MPMCBase + 0x0fc
83 #define DENALI_CTL_64 MPMCBase + 0x100
84 #define DENALI_CTL_65 MPMCBase + 0x104
85 #define DENALI_CTL_66 MPMCBase + 0x108
86 #define DENALI_CTL_67 MPMCBase + 0x10c
87 #define DENALI_CTL_68 MPMCBase + 0x110
88 #define DENALI_CTL_69 MPMCBase + 0x114
89 #define DENALI_CTL_70 MPMCBase + 0x118
90 #define DENALI_CTL_71 MPMCBase + 0x11c
91 #define DENALI_CTL_72 MPMCBase + 0x120
92 #define DENALI_CTL_73 MPMCBase &