单独编译内核: make V=s target/linux/install
相调函数调用流程:
init/main.c : start_kernel() -> setup_arch(&command_line)
arch/mips/kernel/setup.c:
setup_arch()-> cpu_probe()-> prom_init()-> arch_mem_init() -> plat_mem_setup() -> detect_memory_region()
prom_init()
arch/mips/ralink/prom.c 读寄存器收集CPU信息
void __init prom_init(void)
{int argc;char **argv;prom_soc_init(&soc_info);pr_info("SoC Type: %s\n", get_system_type());prom_init_cmdline(argc, argv);
}
prom_soc_init(&soc_info) 在 arch/mips/ralink/mt7620.c
其中从寄存器读得系统信息,填充到sock_info中。
prom.c 中定义了 struct ralink_soc sock_info结构体:
struct ralink_soc_info {unsigned char sys_type[RAMIPS_SYS_TYPE_LEN];unsigned char *compatible;unsigned long mem_base;unsigned long mem_size;unsigned long mem_size_min;unsigned long mem_size_max;
};
开机内核打印信息中有如下打印:
[ 0.000000] Board has DDR2
[ 0.000000] Analog PMU set to hw control
[ 0.000000] Digital PMU set to hw control
[ 0.000000] SoC Type: Ralink MT7620A ver:2 eco:3
sock_info 填充的值为:
soc_info->compatible = "ralink,mt7620a-soc";
sock->sys_type = "Ralink MT7620A ver:2 eco:3";
soc_info->mem_base = MT7620_DRAM_BASE; // 0x0
soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN; // 32
soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX; // 256
最后到detect_memory_region()中检测内存大小:
void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
{void *dm = &detect_magic;phys_t size;for (size = sz_min; size < sz_max; size <<= 1) {pr_info("%s: dm %p, size 0x%x, sizeof 0x%x\n", __func__,dm, (uint32_t)size, sizeof(detect_magic));if (!memcmp(dm, dm + size, sizeof(detect_magic)))break;}pr_info("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",((unsigned long long) size) / SZ_1M,(unsigned long long) start,((unsigned long long) sz_min) / SZ_1M,((unsigned long long) sz_max) / SZ_1M);add_memory_region(start, size, BOOT_MEM_RAM);
}
打印值如下:
[ 0.000000] detect_memory_region: dm 8030e9cc, size 0x2000000, sizeof 0x4
[ 0.000000] detect_memory_region: dm 8030e9cc, size 0x4000000, sizeof 0x4
[ 0.000000] detect_memory_region: dm 8030e9cc, size 0x8000000, sizeof 0x4
[ 0.000000] Memory: 128MB of RAM detected at 0x0 (min: 32MB, max: 256MB)