1
  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, e.g : $ 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

P.D: 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".

Peio
  • 43
  • 2
  • 8

2 Answers2

0

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,
};
domen
  • 1,819
  • 12
  • 19
  • Thank you for your response. – Peio Sep 25 '18 at 08:52
  • There is another driver to read/write I2C eeprom's?. In ARM environments were device tree is used the /sys/.../eeprom file is read/write. e.g: &i2c0 { eeprom: eeprom@50 { compatible = "at,24c32"; reg = <0x50>; }; }; Is possible to have the same configuration in X86 environments?, were device tree do not exist. – Peio Sep 25 '18 at 09:00
  • I don't know, possibly. Also check out userspace drivers that use i2c-dev - you might have more luck finding those. – domen Sep 25 '18 at 09:09
  • @Peio, There are comments in your previous question, read them. P.S. And update kernel to v4.19. – 0andriy Nov 07 '18 at 15:46
0

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

  • As you point out Mike, using the at24 driver I solved the problem @ransh. More information on how use the at24 driver: [link](https://stackoverflow.com/questions/52499762/linux-instantiate-from-user-space-eeprom-new-device?noredirect=1#comment93271727_52499762) – Peio Mar 05 '19 at 08:07
  • Thanks, I was glad to help. Is that the solution, then, in your mind? – Mike Hermann Mar 06 '19 at 16:51
  • The solution is using the at24 as explained [here](https://stackoverflow.com/questions/52499762/linux-instantiate-from-user-space-eeprom-new-device?noredirect=1#comment93271727_52499762) – Peio Mar 07 '19 at 11:05