I am trying to recompile the kernel for the Redmi Note 4 (MTK). I have successfully obtained a copy of the stock, pre-compiled kernel, and a variant of sources that seems to coincide quite well with the device's functionality. The kernel sources come from another device for which MediaTek has released the configuration (or rather, a configuration), but despite compiling the default provided configuration (which is presumably incompatible with my device), it will not boot with the newly compiled kernel. From the behavior, it seems that it raises a kernel panic and reboots.
Unfortunately, I do not have a UART connection to the device, so I'm trying to do this blind. My question is, what would be the best approach to attempting to reverse engineer the configuration used for my device?
The steps I've considered include:
- Import the current kernel compiled in Ghidra and use the sources to identify the functions, and by comparing the "output" I can manually figure out the configuration used.
- Write a static binary that opens the framebuffer (which is available!) and outputs the kernel ring buffer log to it. Change the kernel options until I get at least a screen, and see why it reboots. I have started development on this particular idea, but it seems inefficient and improbable to work.
While I am familiar with C and Linux, it is my first adventure of this kind.
EDIT: The stock kernel seems to be monolithic, as the OS is Android 6.0, and according to this link, it is not a requirement to support modules pre-Android 8.0. I could also not find any evidence of modules in the storage of the device.
EDIT: Among the experiments I've done,
- I have compiled a busybox initramfs, with the initial binary being
/bin/sh
, for the correct architecture. - And used that image to boot the stock kernel. As expected, the device hung and did not reboot.
- I have concluded that the shell did indeed launch, despite the screen not being initialized.
- I then proceeded to boot the compiled kernel as well, which with the busybox image did reboot.
- This confirms the assumption that the kernel panics.