kernel machine_desc表信息在哪里?

发布于 2025-02-02 04:01:45 字数 2060 浏览 4 评论 0原文

我试图了解Devicetrees的工作方式。

根据内核文档,它们以以下方式在手臂架构中使用:

在大多数情况下,机器身份无关紧要,而内核将基于机器的Core CPU或SOC选择设置代码。例如,在ARCH/ARM/ARM/kernel/setup.c中的setup_arch()将在Arch/arm/arm/kernel/devtree.c中调用setup_machine_fdt(),该搜索通过Machine_desc表搜索并选择机器_DESC,并与设备树数据最匹配的Machine_desc 。它通过查看root设备树节点中的“兼容”属性来确定最佳匹配,并将其与struct machine_desc中的DT_COMPAT列表进行比较(如果您在Arch/Arm/Indram/incruph/asm/Mach/Arch.h中定义的dt_compat列表'很好奇)。

“兼容”属性包含以机器确切名称开头的字符串列表,然后是可选的板列表,它与最兼容至最少的分类兼容。

我找到了与DTS文件中的Machine_desc与兼容参数集的比较有关的源代码:

const struct machine_desc * __init setup_machine_fdt(void *dt_virt)
{
    const struct machine_desc *mdesc, *mdesc_best = NULL;

#if defined(CONFIG_ARCH_MULTIPLATFORM) || defined(CONFIG_ARM_SINGLE_ARMV7M)
    DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
        .l2c_aux_val = 0x0,
        .l2c_aux_mask = ~0x0,
    MACHINE_END

    mdesc_best = &__mach_desc_GENERIC_DT;
#endif

    if (!dt_virt || !early_init_dt_verify(dt_virt))
        return NULL;

    mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach);

    if (!mdesc) {
        const char *prop;
        int size;
        unsigned long dt_root;

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

        dt_root = of_get_flat_dt_root();
        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 */
    }

    /* We really don't want to do this, but sometimes firmware provides buggy data */
    if (mdesc->dt_fixup)
        mdesc->dt_fixup();

    early_init_dt_scan_nodes();

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

    return mdesc;
}

但是,我没有找到Machine_desc表定义。

如果我想阅读所有Machine_desc,我在哪里可以找到它?

I'm trying to understand how devicetrees work.

According to the kernel documentation, they are used, in arm architecture, in the following manner:

In the majority of cases, the machine identity is irrelevant, and the kernel will instead select setup code based on the machine’s core CPU or SoC. On ARM for example, setup_arch() in arch/arm/kernel/setup.c will call setup_machine_fdt() in arch/arm/kernel/devtree.c which searches through the machine_desc table and selects the machine_desc which best matches the device tree data. It determines the best match by looking at the ‘compatible’ property in the root device tree node, and comparing it with the dt_compat list in struct machine_desc (which is defined in arch/arm/include/asm/mach/arch.h if you’re curious).

The ‘compatible’ property contains a sorted list of strings starting with the exact name of the machine, followed by an optional list of boards it is compatible with sorted from most compatible to least.

I found the source code related to the comparison of machine_desc to the compatible parameter set in the dts file:

const struct machine_desc * __init setup_machine_fdt(void *dt_virt)
{
    const struct machine_desc *mdesc, *mdesc_best = NULL;

#if defined(CONFIG_ARCH_MULTIPLATFORM) || defined(CONFIG_ARM_SINGLE_ARMV7M)
    DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
        .l2c_aux_val = 0x0,
        .l2c_aux_mask = ~0x0,
    MACHINE_END

    mdesc_best = &__mach_desc_GENERIC_DT;
#endif

    if (!dt_virt || !early_init_dt_verify(dt_virt))
        return NULL;

    mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach);

    if (!mdesc) {
        const char *prop;
        int size;
        unsigned long dt_root;

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

        dt_root = of_get_flat_dt_root();
        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 */
    }

    /* We really don't want to do this, but sometimes firmware provides buggy data */
    if (mdesc->dt_fixup)
        mdesc->dt_fixup();

    early_init_dt_scan_nodes();

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

    return mdesc;
}

However, I didn't find machine_desc table definition.

If I'd like to read all machine_desc, Where can I find it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2025-02-09 04:01:45

TL; DR-机器描述是通过将不同的源文件链接到内核来构建的。因此,每个机器源文件都会在表中添加一个条目。


该表基于 Arch/arm/kernel/vmlinux.lds.s (或相关的架构链接器文件)。它是用宏Machine_startMachine_end构建的。这在对象文件的“ arch.info.init”部分中放置了一个结构。所有这些对象都会被链接器聚集在一起。这形成了表。因此,它是通过将不同的源文件与machine_startMachine_end宏链接起来来构建的。因此,它不存在于一个地方。

但是,您可以使用git grep -a10 machine_start获取相当不错的列表。此命令运行良好,通常是文件中的最后一件事,因此只能打印五个或六行。或者,您可以通过打印Machine_desc条目来编写初始代码来丢弃表。

也就是说,桌子并不有趣,因为它只是在不同时间打电话的功能指针。大多数将是无效的,因为它使用了指定的初始化器。

相关:控制'dt_machine_start'在Android上

TL;DR - The machine description is built by building and linking different source files into the kernel. So each machine source file adds an entry into the table.


The table is based in arch/arm/kernel/vmlinux.lds.S (or relevant architecture linker file). It is built with the macros MACHINE_START and MACHINE_END. This places a structure in the 'arch.info.init' sections of the object file. All of these objects get globbed together by the linker. This forms the table. So, it is constructed by linking different source files with the MACHINE_START and MACHINE_END macros. Therefore, it doesn't exist in one place.

However, you can use git grep -A10 MACHINE_START to get a fairly good list. This command works well, as typically, it is the last thing in the file so only five or six lines may print. Or you could write init code to dump the table by printing the machine_desc entries.

That said, the table is not too interesting as it is just function pointers to call at different times. The majority will be NULL as it used designated initializers.

Related: Control to 'dt_machine_start' on Android

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文