I managed to make some headway here. Since I don’t want to actually replace the kernel, but rather get the correct configuration for compiling kernel modules, I don’t have to patch the actual buggy kernel source. I need to do the following:
- download a working cross compiler. We cannot use gcc on the device, as the kernel must be compiled with gcc 4.9 due to newer versions coming with better warnings, tripping up the Makefile and aborting. Isn’t old code great? I’ve downloaded the linaro aarch64 cross compiler for this.
- I take the kernel config from /proc/config.gz and extract it to a build (which I’ve unoriginally called
/build
)
- I then select the default values for those options not in the config. How that’s possible, I have no idea, maybe Jolla did something funky to their kernel?
make ARCH=arm64 CROSS_COMPILE=/toolchain/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- O=/build olddefconfig
- I then install the header and scripts necessary for module compilation with this:
make ARCH=arm64 CROSS_COMPILE=/data/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- O=/build prepare headers_install scripts
At this point I’m almost ready to compile my kernel module. Apparantly CONFIG_MODVERSIONS
is turned on for the kernel (see: zcat /proc/config.gz | grep CONFIG_MODVERSIONS
), so I need a valid Module.symvers
. This is where I’m stuck now.
I did find a very old python script that should be able to do this given a binary blob: extract-symvers. The script initially borked on a syntax error, until I figured out that since it’s so old, it needs python2. Now it doesn’t work, I think because I’m not giving it the right address for the kernel .init
. According to the accompanying blog post you should check by inspecting the output of dmesg
for .init
, but apparantly that’s no longer a thing (other people mention this too).
Somebody else mentioned using readelf and objdump for this, but I couldn’t get this to work. I’ve copied the hybris-boot.img
to my workstation and unpacked it using abootimg -x
, giving me the zImage
. I’ve unzipped it and have tried various things to find the init section in it, but nothing I try will give me useful information. All I get is that the ‘format isn’t recognized’. If I run file
on it, it recognizes it correctly and tells me Image: Linux kernel ARM64 boot executable Image, little-endian, 4K pages
So, unless extract-symvers.py
no longer works due to changes in the linux kernel, all that’s stopping me now is finding the correct offset to feed it.
Does anybody have any idea how to get the right offset to feed it to give me the Module.symvers
information?