通过APK 操作gpio驱动 点灯时,发现ioctl(gpio_fileHandler, cmd, arg) 函数返回值一直是-1.驱动无法执行
ioctl 中gpio request等其他操作.我怀疑是ioctl函数有问题.发现file_operations 中ioctl用的是 .unlocked_ioctl .
static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
// .unlocked_ioctl = gpio_test_ioctl,
.compat_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release,
};
查找资料得知, 正常的情况下,对Ioctl的调用,会走unlock_ioctl,但在32位系统64位的内核上面会走compat_ioctl接口,这就是compat_ioctl存在的意义,由于我使用的Android系统位32位,内核编译的是Arm64,这应该就是这个Bug产生的原因,果断替换位compat_ioctl,问题解决;
long (unlocked_ioctl) (struct file , unsigned int, unsigned long);
long (compat_ioctl) (struct file , unsigned int, unsigned long);