1

I am trying to write to eeprom (at24) from user space in android. I got the exception

com.ipil.ipilMdm.service.lib I/System.out: java.io.FileNotFoundException: /sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom (No such file or directory)

The path mentioned works perfect from echo and cat in command line. It is also tested in linux based application where it is opened as a read-write file.

I have added the permissions in manifest file. What else might be the issue?

Below is my code:

@Override
public void prod_eeprom_write(String data, int id) {


String someText = "Writesomething";

 //String fileName = Environment.getRootDirectory().getAbsolutePath();
    final File permFile = new File("/sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom");

    try {

    /*  if (file == null) {
            System.out.print("error open\n");
            return;
        }*/

        //=================== Condition for action==========================

        switch (id) {

            case IMEI_NUMBER:
                offset = IMEI_NUMBER_OFFSET;
                length = IMEI_NUMBER_LENGTH;
                break;
            case HARDWARE_REVISION:
                offset = HW_REV_OFFSET;
                length = HW_REV_LENGTH;
                break;
            case WIFI_MAC_ADDRESS:
                offset = WIFI_MAC_OFFSET;
                length = WIFI_MAC_LENGTH;
                break;
            case BT_MAC_ADDRESS:
                offset = BT_MAC_OFFSET;
                length = BT_MAC_LENGTH;
                break;
            default : return;
        }


        /* now got offset and length, so update max buffer */
        //strncpy(data,max_data.length + offset, length);
        if (data.length() < length)
            length = data.length();

        if(data.length() > length){
            System.out.print("LENGTH OF DATA IS TOO BIG : CAN NOT WRITE\nMAX LENGTH IS %d BYTES\n"+ length);
            return;
        }

            //strncpy(data, max_data.length + offset, data.length());
        max_data[INFO_MAX_LENGTH] = '\0';
        System.out.println("DATA TO BE WRITTEN TO EEPROM: "+ data);

        //if(file.canWrite()){
            fileOutputStream = new FileOutputStream(permFile);

            byte[] b = data.getBytes(); //new byte[max_data.length];
                //for (int i = 0; i < b.length; i++)
                //      b[i] = (byte) max_data[i];


                    fileOutputStream.write(b, max_data.length + offset, data.length());
                    Log.i(TAG, " prod_eeprom_written-----------ok : hogya ");

                    Thread.sleep(10);
                    fileOutputStream.close();
                    System.out.println("success...");

    }catch (Exception io){
        io.printStackTrace();
    }

    }
manstud
  • 39
  • 1
  • 7
  • check whether you got permission to write – Jyoti JK Jan 30 '18 at 11:14
  • i have checked and i have got the permission to write. – manstud Jan 30 '18 at 11:23
  • can you post your code – Jyoti JK Jan 30 '18 at 11:27
  • public void prod_eeprom_write(String data, int id) { final File permFile = new File("/sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom"); fileOutputStream = new FileOutputStream(permFile); byte[] b = data.getBytes(); //new byte[max_data.length]; fileOutputStream.write(b, max_data.length + offset, data.length()); Log.i(TAG, " prod_eeprom_written-----------ok : hogya "); fileOutputStream.close(); System.out.println("success..."); .... } – manstud Jan 30 '18 at 11:46
  • i am not able to post the code properly and full code. can you give me your mail id? – manstud Jan 30 '18 at 12:17
  • Please do not put your code in the comments section, edit your question instead. And also avoid sharing personal information like email addresses on SO as everyone can see whatever you post – Niza Siwale Jan 30 '18 at 12:23
  • @NizaSiwale : Ok. posted. – manstud Jan 30 '18 at 12:37
  • Do you have root access? I.e. is your device rooted – Niza Siwale Jan 30 '18 at 12:41
  • @NizaSiwale : yes the board is rooted – manstud Jan 30 '18 at 13:07
  • Try to remove the call to `Thread.sleep(10);` – Niza Siwale Jan 30 '18 at 17:25
  • 1
    And if you are running on android API 23 and later you have to give your activity `runtime` permission to read and write to the file system, not just a declaration in the manifest – Niza Siwale Jan 30 '18 at 17:27

0 Answers0