5

Background: I am working with a Pixel 4, build QQ2A.200501.001.B2, which is Android 10. When I build the kernel from the official sources and flash it, the touchscreen, wlan and other features do not work. I tracked this down to the fact that the kernel modules in /vendor/lib/modules do not get updated, thus the new kernel can't load any of them. I tried flashing both only boot.img and the entire AOSP, same issue, they don't get updated. I can workaround this by manually pushing the kernel modules I built to the device and manually insmoding them in the right order.

So my questions are:

  • Why don't they get updated in the first place?
  • How can I update them along with the kernel when I flash?
  • Alternatively, how can I permanently update them after flashing?

Surely there must be an "official" way to do this? How are the kernel modules normally deployed?


Some notes:

I can't push them to /vendor/lib/modules because I can't remount /vendor writable:

flame:/ # mount -o rw,remount /vendor                                                                                                                                                   
'/dev/block/dm-5' is read-only

Disabling dm-verity doesn't seem to help.

I noticed that the AOSP source contains all the modules that are in /vendor/lib/modules, in the same place where it takes the kernel image form (in my case that's device/google/coral-kernel). So naturally, I tried replacing the modules there with the ones I built, but after building and flashing, I see that /vendor/lib/modules still contains the old modules.

The AOSP docs say that boot.img does not contain the ramdisk anymore, it's now in the system partititon. Also, OverlayFS is used and one should use a "vendor overlay" to update files there, if I read it right. However, on my device, there is no product/vendor_overlay directory like the docs say, only product/overlay/. I'm also not sure if this is the right way to tackle this or how I would go about creating such an overlay in my case.

Thanks

onetyone
  • 457
  • 4
  • 15

2 Answers2

1

Ok. Several questions, several answers:

  • Why don't they get updated in the first place?

    • Because they are expected to be in /vendor/lib/modules, and when you recompile a kernel you're only creating the kernel binary which goes into the boot.img.

    • How can I update them along with the kernel when I flash?

    You could compile the modules into the kernel. That makes your kernel a bit bigger, but relieves you from the need to insert these modules.

    • Alternatively, how can I permanently update them after flashing?

    You can indeed modify /vendor like you've tried - but not the DM-verity block device (/dev/block/dm-5 in your case) - the underlying partition (/dev/block/sd?#, something, which you can see if you look at the links from /dev/block/by-name/vendor).

    CAVEAT: This will cause dm-verity to fail mounting /vendor unless you correctly disable dm-verity!

    Another avenue to try for testing: Linux kernel modules have a strict vermagic requirement (in simpler terms, the module string must match the 'uname -r' of the kernel, to ensure that critical kernel structures have not been modified). If you don't change the kernel magic (VERSION, PATCHLEVEL, SUBLEVEL and EXTRAVERSION from Makefile) (or "fake" them to the original kernel version your device came with) the modules should load.

Technologeeks
  • 7,674
  • 25
  • 36
  • Thanks for the answer. For me building modules into the kernel is not an option, I avoid anything increasing boot.img size. Unfortunately, there is no `/dev/block/by-name/vendor` on my device or anything like it. – onetyone Aug 16 '20 at 18:40
  • I think I was able to correctly disable dm-verity (used `magiskboot dtb` to patch my `boot.img`), but maybe you could clarify how to find the underlying partition and actually make it writable? It also looks like I have to patch the right fstab file (for me it is `/vendor/etc/fstab.sm8150`) and remove the `ro` flag there, somehow. – onetyone Aug 17 '20 at 13:52
  • The direct /dev/block/by-name was added in 10 - try /dev/block/platform/*/by-name.. – Technologeeks Aug 17 '20 at 19:56
  • Easiest way to write to the partition would be to remount it "rw" under a new mount point. So mkdir /data/local/tmp/foo and mount under there, to make your changes. That way you don't have to mess with other files. – Technologeeks Aug 17 '20 at 22:01
0
  • Alternatively, how can I permanently update them after flashing?

You can use below command to disable verity :

adb root
adb disable-verity
adb shell sync
adb reboot

then push the .ko(s) to /vendor/lib/modules/ :

adb root
adb remount
adb push *.ko /vendor/lib/modules/
adb shell sync
adb reboot