1. 背景
通常一套代码会跑在不同档次的板子上,比如中档板子和低档板子的区别可能就是DDR大小不同,那么这个时候适配两个板子就只需要把DDR 初始化时的大小改一下就可以了,当然了,前提是使用同一类型的DDR,只是大小不一样而已。
2. 分析
在uboot 启动过程中会遍历执行 init_sequence_f[]数组中的函数指针来初始化硬件,其中就包括DDR的初始化函数指针dram_init。对uboot启动流程不清楚的兄弟可以看我的博客《uboot启动流程》。
static init_fnc_t init_sequence_f[] = {
#ifdef CONFIG_SANDBOX
setup_ram_buf,
#endif
setup_mon_len,
setup_fdt,
trace_early_init,
#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
/* TODO: can this go into arch_cpu_init()? */
probecpu,
#endif
arch_cpu_init, /* basic arch cpu dependent setup */
#ifdef CONFIG_X86
cpu_init_f, /* TODO(sjg@chromium.org): remove */
# ifdef CONFIG_OF_CONTROL
find_fdt, /* TODO(sjg@chromium.org): remove */
# endif
······ /* 此处省略500字··· */
------------------------------------------------------------------
#ifdef CONFIG_ARM
dram_init, /* configure available RAM banks */
#endif
------------------------------------------------------------------
#ifdef CONFIG_PPC
init_func_ram,
#endif
#ifdef CONFIG_POST
post_init_f,
#endif
NULL,
};
在dram_init()函数中会对dram的大小进行设置,因为该函数所在文件并未声明为GNU许可证下,所以源码就不贴了!!!