2

I'm trying to compile kernel module files for Android. The goal is then build nfs-utils, to get a NFS server working on my Pixel 7 phone.

I downloaded the AOSP project and built a kernel:

$ mkdir android-kernel && cd android-kernel/
$ repo init --depth=1 --manifest-url=https://android.googlesource.com/kernel/manifest --manifest-branch=android-gs-pantah-5.10-android13-qpr1
$ repo sync --current-branch --network-only --jobs=4
$ repo sync --current-branch --local-only --jobs=16
$ BUILD_CONFIG=aosp/build.config.gki.aarch64 build/build.sh

But how do I build a .ko file? I tried to build exportfs.ko, said to be required in Cross-compiling nfs-utils package for Android, but have no idea how to do it. (That question lists sunrpc.ko, lockd.ko, nfs.ko, exportfs.ko, nfsd.ko.)

After I built the kernel, android-kernel/out/android13-5.10/dist/modules.builtin suggests that it's bundled into the kernel.

I tried the following which produced no .ko files:

$ cd ~/android-kernel/out/android13-5.10/aosp/
$ make \
    ARCH=arm64 \
    CC=~/android-kernel/prebuilts/clang/host/linux-x86/clang-r450784e/bin/clang \
    CROSS_COMPILE=~/android-kernel/aosp/scripts/dummy-tools/ \
    M=~/android-kernel/aosp/fs/exportfs \
    --directory=
    all

I googled around lots. It seems like most sources are rather old and don't make use of AOSP. Without AOSP, I tried to load my phone's kernel config in /proc/config.gz and use that to build, but this gives heaps of new build options that I must pick.

If modules can be built without AOSP that is acceptable too.

simonzack
  • 19,729
  • 13
  • 73
  • 118
  • try this https://github.com/Drjacky/How-to-compile-kernel-module, use NDK – k1r1t0 Jan 24 '23 at 12:35
  • @k1r1t0 I'm having lots of trouble trying to follow that. Both *AOSP* and *NDK* only has *Clang* now. After trying to use *Clang* to build I get errors like ``aarch64-linux-android-ld: net/xdp/xsk_buff_pool.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol `__stack_chk_guard' can not be used when making a shared object; recompile with -fPIC``. Honestly am quite stuck. I'd love to see a complete up-to-date method on how to build a kernel module. – simonzack Feb 04 '23 at 04:29
  • Maybe you can tell us what you want to do with the NFS server? Is it an option to use an FTP server instead of NFS for example? – zomega Feb 10 '23 at 11:37

1 Answers1

0

Instead of running a kernel mode NFS server you could run a user space NFS server. See unfs3 on github.

This means you only have to cross-compile unfs3 (using the NDK) and not any kernel modules.

zomega
  • 1,538
  • 8
  • 26