Linux i2c eeprom / sys / bus / i2c / ... / eeprom文件是只读的

问题描述 投票:1回答:2
  1. 我有一个带有自定义I2C Master Harware的X86 CPU。我的Linux是Ubuntu 14.04,内核3.13。
  2. 我为自定义I2C主硬件编写了一个I2c驱动程序。
  3. 当我加载驱动程序时,会创建设备/ sys / bus / i2c / devices / i2c-11。
  4. 连接到我的I2C总线的是一个I2C eeprom存储器。
  5. 当我加载linux eeprom驱动程序时,ephrom驱动程序会自动创建sys文件/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom。
  6. 问题:这个文件/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom只读。
  7. 从eeprom文件中读取WORKS OK,例如:$ sudo cat / sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom | hexdump -C。
  8. 但我不能写入/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom,因为它是只读的。为什么这个文件只读创建?

谢谢。

佩伊奥

P.D:我尝试将eeprom文件chmod到rwx,但无论如何我收到错误,试图写入eeprom:“bash:eeprom:Permission denied”。

linux linux-kernel kernel-module i2c eeprom
2个回答
0
投票

看来eeprom Linux驱动只能实现drivers / misc / eeprom / eeprom.c读取sysfs属性:

https://github.com/torvalds/linux/blob/master/drivers/misc/eeprom/eeprom.c#L117

static const struct bin_attribute eeprom_attr = {
    .attr = {
        .name = "eeprom",
        .mode = S_IRUGO,
    },
    .size = EEPROM_SIZE,
    .read = eeprom_read,
};

0
投票

一个问题是您使用的eeprom.c驱动程序不支持编写eeprom,因为它没有写入功能。

考虑在24.c使用驱动程序。它具有写入功能,例如at24_eeprom_write()

实际上,此驱动程序的probe()函数将决定该部分是否可写,然后在可写时根据需要设置函数调用。当器件为只读时,写功能不可用。它会自动处理这个问题。

以下是linux内核v3.3的at24.c驱动程序的代码,如下所示:https://elixir.bootlin.com/linux/v3.3/source/drivers/misc/eeprom/at24.c

© www.soinside.com 2019 - 2024. All rights reserved.