MACHINE_START-内核板级初始化(board-xxx-reference.c)实现机制(linux3.10.31)

linux3.10 内核带设备树。

板级信息初始化文件最后有如下代码:(分析如何被调用的)

DT_MACHINE_START(XXX, "xxx")
    .smp        = smp_ops(xxx_smp_ops),
    .init_early    = xxx_init_delay,
    .init_time    = xxx_timer_init,
    .init_machine    = xxx_add_standard_devices,
    .init_late    = xxx_init_late,
    .reserve    = xxx_reserve,
    .restart    = xxx_restart,
    .dt_compat    = xxx_boards_compat_dt,
MACHINE_END

 

内核启动的时候跳转的C语言入口在main.c/start_kernel(void),start_kernel(void)会调用setup_arch()

void __init setup_arch(char **cmdline_p)
{
    struct machine_desc *mdesc;

    setup_processor();
    mdesc = setup_machine_fdt(__atags_pointer);
    if (!mdesc)
        mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
    machine_desc = mdesc;
    machine_name = mdesc->name;

    setup_dma_zone(mdesc);

    if (mdesc->restart_mode)
        reboot_setup(&mdesc->restart_mode);


....

 

解析设备树文件

/**
 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
 * @dt_phys: physical address of dt blob
 *
 * If a dtb was passed to the kernel in r2, then use it to choose the
 * correct machine_desc and to setup the system.
 */
struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
{
    struct boot_param_header *devtree;
    struct machine_desc *mdesc, *mdesc_best = NULL;
    unsigned int score, mdesc_score = ~1;
    unsigned long dt_root;
    const char *model;

#ifdef CONFIG_ARCH_MULTIPLATFORM
    DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
    MACHINE_END

    mdesc_best = (struct machine_desc *)&__mach_desc_GENERIC_DT;
#endif

    if (!dt_phys)
        return NULL;

    devtree = phys_to_virt(dt_phys);

    /* check device tree validity */
    if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
        return NULL;

    /* Search the mdescs for the 'best' compatible value match */
    initial_boot_params = devtree;
    dt_root = of_get_flat_dt_root();
    for_each_machine_desc(mdesc) {
        score = of_flat_dt_match(dt_root, mdesc->dt_compat);
        if (score > 0 && score < mdesc_score) {
            mdesc_best = mdesc;
            mdesc_score = score;
        }
    }
    if (!mdesc_best) {
        const char *prop;
        long size;

        early_print("\nError: unrecognized/unsupported "
                "device tree compatible list:\n[ ");

        prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
        while (size > 0) {
            early_print("'%s' ", prop);
            size -= strlen(prop) + 1;
            prop += strlen(prop) + 1;
        }
        early_print("]\n\n");

        dump_machine_table(); /* does not return */
    }

    model = of_get_flat_dt_prop(dt_root, "model", NULL);
    if (!model)
        model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
    if (!model)
        model = "<unknown>";
    pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);

    /* Retrieve various information from the /chosen node */
    of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
    /* Initialize {size,address}-cells info */
    of_scan_flat_dt(early_init_dt_scan_root, NULL);
    /* Setup memory, calling early_init_dt_add_memory_arch */
    of_scan_flat_dt(early_init_dt_scan_memory, NULL);

    /* Change machine number to match the mdesc we're using */
    __machine_arch_type = mdesc_best->nr;

    return mdesc_best;

 

设备树文件头数据:

/ {
    model = "xxx";
    compatible = "xxx,xxx", "xxx,xxx";

    aliases {

 

使用哪个设备树文件,就对应使用哪个板级信息初始化文件。

比如使用的设备树文件为:aaa.dtb;那么使用的板级信息初始化文件为:board-aaa-reference.c

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值