简体   繁体   English

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

[英]Linux i2c eeprom /sys/bus/i2c/…/eeprom file is read only

  1. I have a X86 CPU with custom I2C Master Harware. 我有一个带有自定义I2C主硬件的X86 CPU。 My Linux is Ubuntu 14.04, kernel 3.13. 我的Linux是Ubuntu 14.04,内核3.13。
  2. I wrote an I2c driver for my custom I2C Master Hardware. 我为自定义I2C主硬件编写了I2c驱动程序。
  3. When I load my driver the device /sys/bus/i2c/devices/i2c-11 is created. 当我加载驱动程序时,将创建设备/ sys / bus / i2c / devices / i2c-11。
  4. Attached to my I2C bus there is a I2C eeprom memory. I2C eeprom存储器连接到我的I2C总线。
  5. When I load the linux eeprom driver, the sys file /sys/bus/i2c/devices/i2c-11/11-0050/eeprom is created automatically by eeprom driver. 当我加载linux eeprom驱动程序时,eeprom驱动程序会自动创建sys文件/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom。
  6. PROBLEM: this file /sys/bus/i2c/devices/i2c-11/11-0050/eeprom is READ ONLY. 问题:这个文件/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom是只读的。
  7. Read from eeprom file WORKS OK, eg : $ sudo cat /sys/bus/i2c/devices/i2c-11/11-0050/eeprom | 从eeprom文件读取工作正常,例如:$ sudo cat / sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom | hexdump -C. 十六进制转储-C。
  8. But I can't write to /sys/bus/i2c/devices/i2c-11/11-0050/eeprom because is read only. 但是我无法写入/ sys / bus / i2c / devices / i2c-11 / 11-0050 / eeprom,因为它是只读的。 Why is this file created READ ONLY?. 为什么创建此文件为只读?

Thank you. 谢谢。

Peio io

PD: I tried chmod the eeprom file to rwx, but in anycase I receive an error trying to write to the eeprom: "bash: eeprom: Permission denied". PD:我尝试将eeprom文件chmod更改为rwx,但是无论如何,我都会收到尝试写入eeprom的错误消息:“ bash:eeprom:权限被拒绝”。

It appears eeprom Linux driver only implements drivers/misc/eeprom/eeprom.c read sysfs attribute: 看来eeprom Linux驱动程序仅实现driver / misc / eeprom / eeprom.c读取sysfs属性:

https://github.com/torvalds/linux/blob/master/drivers/misc/eeprom/eeprom.c#L117 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,
};

One problem is that the eeprom.c driver you are using does not support writing the eeprom, as it has no write function. 一个问题是您使用的eeprom.c驱动程序不支持编写eeprom,因为它没有写功能。

Consider using instead the driver at24.c. 考虑改用驱动程序at24.c。 It has functions for writing, for example at24_eeprom_write() 它具有写功能,例如at24_eeprom_write()

In fact, the probe() function of this driver will decide if the part is writable or not, and then setup function calls as needed, when it is writable. 实际上,此驱动程序的probe()函数将确定部件是否可写,然后在需要时调用setup函数。 And the write function isn't available, when the part is read-only. 当零件为只读时,写入功能不可用。 It takes care of this automatically. 它会自动处理此问题。

Here is the code for the at24.c driver for v3.3 of the linux kernel, as you indicate: https://elixir.bootlin.com/linux/v3.3/source/drivers/misc/eeprom/at24.c 如下所示,这是Linux内核v3.3的at24.c驱动程序的代码: https ://elixir.bootlin.com/linux/v3.3/source/drivers/misc/eeprom/at24.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM