[Nexus 4 Q&A, Help & Troubleshooting] DrHongo:
Booting with insecure boot image has broken all my sensors in my Nexus 4 / Android 5

I have been using a boot insecure image made for Nexus 4 / Android 4.2 downloaded from here :

http://xdaforums.com/nexus-4/development/boot-img-obsolete-please-lock-t1990170

to boot my phone to have root access through adb by doing:

$ fastboot boot bootinsecure.img

But after upgrading to Android 5 the process of booting with this image was ruining all my sensors and my wifi.

My wifi was fixed by deleting the content in /data/misc/wifi but leaving wpa_supplicant.conf to keep my saved wifis.

But I cannot fix the sensors. I tried this fix for Nexus 5 but it didn't work:

http://xdaforums.com/google-nexus-5/general/sensors-fix-nexus-5-t2704915

If I delete the user data the problem is solved but I don't want to remove all my data.

There is something in that boot image that brakes my sensors by changing something in the userdata partition

For testing purposes, I deleted the user data. Booted again and the problem was fixed. I saved a image of the userdata partition by doing as root:

$ adb pull /dev/block/mmcblk0 mmcblk0.img

and mounting the userdata partition in my linux as root to keep al the original permissions

# sudo mount -o loop,offset=1627389952,defaults,ro,noload mmcblk0.img mnt/userdata

I booted from my boot insecure image and reboot normally and all the sensors where ruined as expected

So I created another image and I mounted the userdata in another folder

and then I compared all the files that where changed using rsync after and before the boot with the insecure image.

I found a few extra files in the "after" image so I deleted them but the problem was not fixed.

I think that maybe the problem is related to folder/files permissions, attributes or extended attributes (like SElinux) that were changed and cannot be detected when comparing using rsync

Any ideas what might have been and what to do to fix it?

SOLVED:

Solution:

Apparently the problem was not in the userdata partition was in the persist partition. I solved by cloning a working persist partition from another Nexus 4.

I realized that something was wrong in the probably extended attributes in the file /persist/sensors/sns.reg since a

$ adb logcat

was giving this error:

W/sensors.qcom( 282): type=1400 audit(0.0:5): avc: denied { getattr } for path="/persist/sensors/sns.reg" dev="mmcblk0p20" ino=15 scontext=u:r:sensors:s0 tcontext=u:object_r:unlabeled:s0 tclass=file

So I fixed in this way:

First I downloaded a modified busybox dd from:

http://d-h.st/cFA

Don't use the default one it will ruin your partition:

I downloaded recovery-clockwork-touch-6.0.4.7-mako.img from:

http://download2.clockworkmod.com/recoveries/recovery-clockwork-6.0.4.7-mako.img

1) Then I booted from a recovery image like ClockWorkMod. With the phone in the bootloader:

$ fastboot boot recovery-clockwork-touch-6.0.4.7-mako.img

2) Created a ramdisk in the phone

$ adb shell mkdir /dev/ramdisk

$ adb shell mount -o size=1536M -t tmpfs tmpfs /dev/ramdisk

3) Copied dd to the phone

$ adb push dd /

$ adb shell chmod 755 /dd

4) Extract persist from the working phone

$ adb shell /dd if=/dev/block/mmcblk0 of=/dev/ramdisk/persist.img bs=4096 skip=34816 count=4096

5) Pull file to our PC

$ adb pull /dev/ramdisk/persist.img

6) Reboot working phone

$ adb reboot-bootloader

With our not working Nexus 4

Repeat steps 1 to 3

7) Push your persist image to the phone

$ adb push persist.img /dev/ramdisk/

8) Overwrite image

$ adb shell /dd if=/dev/ramdisk/persist.img of=/dev/block/mmcblk0 bs=4096 seek=34816 conv=notrunc

9) Wipe cache and dalvik cache

10) Reboot

Should be fixed if that was the problem