android i2c权限,linux - Android i2c permission denied - Stack Overflow

I’ve developed an NDK application to access an i2c device via the i2c-dev interface. This application is running on an Android development kit, on which we have connected an MPU6050 device via i2c.

I’ve setup the DT binding for the device, as shown below

i2c@78b5000 {

MPU6050@68 {

compatible = "qcom, i2c-msm-v2";

reg = <0x68>;

};

};

and enabled the i2c-1 bus – which is the i2c bus the device is connected to – by changing the following line from “disabled” to “okay”

&i2c_1 {

status = "okay";

};

The issue is that when I try to open the i2c-1 file in my application via open()

char *filename = "dev/i2c-1";

const int file = open(filename, O_RDWR);

I get the permission denied error code returned.

I have only once successfully read from the WHO-AM-I register, by the following steps:

Adjust the permissions of the /dev/i2c-1 file to 666 using

$ chmod 666 i2c-1

Modify the ueventd.rc file to include this line

/dev/i2c-1 0666 root root

Kill the ueventd process to allow it to reload.

$ pgrep ueventd

$ kill xxx

Running ls -la in the /dev folder showed the permissions for i2c-1 as

crw-rw-rw- root root

The issue with applying this process is that each time the device reboots the ueventd file will be restored back to the original state and the permissions reverted.

I have since tried repeating this exact process, rebuilding the boot image with the altered files/permissions and flashing the new boot image to the device. This doesn't seem to work as I still receive the same "permission denied" error.

In an attempt to get around this I included i2ctools into the system image (did not come stock). When trying to run i2cdetect I initially got permission denied, so I followed the same procedure outlined above. This process successfully allowed i2ctools to access /dev/i2c-1 and detect my device.

The problem is that the NDK application - which uses /dev/i2c-1 - is still returning permission denied even after applying the process.

I could potentially modify my application to use i2ctools but my thinking is that if i2ctools can access i2c-1 after modifying the permissions, then my application should be able to - please correct me if i’m wrong.

UPDATE:

It seems that I can only use i2ctool if I am running a shell as root; this is with the permissions of i2c-1 set to global read/write. I've also tried setting the permissions of the parent folders in which i2c-1 resides in to 777 - still the same issue.

Can someone please tell me what i'm doing wrong or how I might stop the permission denied error?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值