简体   繁体   中英

Linux i2c eeprom /sys/bus/i2c/…/eeprom file is read only

  1. I have a X86 CPU with custom I2C Master Harware. My Linux is Ubuntu 14.04, kernel 3.13.
  2. I wrote an I2c driver for my custom I2C Master Hardware.
  3. When I load my driver the device /sys/bus/i2c/devices/i2c-11 is created.
  4. Attached to my I2C bus there is a I2C eeprom memory.
  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.
  6. PROBLEM: this file /sys/bus/i2c/devices/i2c-11/11-0050/eeprom is READ ONLY.
  7. Read from eeprom file WORKS OK, eg : $ sudo cat /sys/bus/i2c/devices/i2c-11/11-0050/eeprom | hexdump -C.
  8. But I can't write to /sys/bus/i2c/devices/i2c-11/11-0050/eeprom because is read only. Why is this file created READ ONLY?.

Thank you.

Peio

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".

It appears eeprom Linux driver only implements drivers/misc/eeprom/eeprom.c read sysfs attribute:

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.

Consider using instead the driver at24.c. It has functions for writing, for example 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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