1

在我的板上,我有一个存储配置信息的 I2C EEPROM。UBoot 使用如下所示的 read_eeprom 函数读取它。我还想从 Linux 内核内部访问这些信息,以便我的 /proc/cpuinfo 输出正确显示。但是我在 Linux 内核中找不到 i2c_probe 和 i2c_read 的等效功能。如何从内核内部执行以下功能?我正在使用 Linux 3.2。

static int read_eeprom(void)
{
        /* Check if baseboard eeprom is available */
        if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
                puts("Could not probe the EEPROM; something fundamentally "
                        "wrong on the I2C bus.\n");
                return -ENODEV;
        }

        /* read the eeprom using i2c */
        if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
                                                        sizeof(header))) {
                puts("Could not read the EEPROM; something fundamentally"
                        " wrong on the I2C bus.\n");
                return -EIO;
        }

        if (header.magic != 0xEE3355AA) {
                /*
                 * read the eeprom using i2c again,
                 * but use only a 1 byte address
                 */
                if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
                                        (uchar *)&header, sizeof(header))) {
                        puts("Could not read the EEPROM; something "
                                "fundamentally wrong on the I2C bus.\n");
                        return -EIO;
                }

                if (header.magic != 0xEE3355AA) {
                        printf("Incorrect magic number (0x%x) in EEPROM\n",
                                        header.magic);
                        return -EINVAL;
                }
        }

        return 0;
}
4

2 回答 2

1

为了解决您的问题,需要考虑一些问题:

  • 您自己构建内核吗?你的板子是定制的吗?

  • 你真的需要在内核中吗?

  • 你真的需要把你的信息放在procfs中吗?特别是在 cpuinfo 或自定义 procfs 文件中就足够了(procfs 接口procfs 指南)?

  • 使用 i2c-tools 或检查 sysfs (/sys/class/i2c*) 获取有关您的 EEPROM 的信息

  • 您的 EEPROM I2C 设备是如何注册的(多种方式)?

  • 确定您将在哪里引入您的代码,并确保它在设备注册后运行。您会创建自己的内核模块,例如在 staging 中吗?你会修补你的 EEPROM 驱动程序吗?

  • 查看如何访问和更新 procfs 的 cpuinfo

根据您的实际需求和配置,解决问题的方式可能会发生变化。

于 2014-05-13T20:41:11.407 回答
1

您是否尝试过使用 eeprog 实用程序,我过去曾使用它来读取 eeprom 的内容。它的源代码可在线获得,您可以将其移植到您的应用程序中。

http://www.codesink.org/eeprog.html

于 2014-06-07T05:46:23.730 回答