cancel
Showing results for 
Search instead for 
Did you mean: 

Helping building Android driver modules for STM32MP25 running OpenSTDroid

ozi
Associate II

I've been trying to build compatible Android modules (.ko) for my STM32MP25F7-EV1 running OpenSTDroid Distribution. I've successfully built these modules, but I cannot enable them with the `insmod` command because they're incompatible.

insmod: ERROR: could not insert module btusb.ko: Exec format error

 

I ran `strings btusb.ko | grep vermagic` and it looks like the `btusb.ko` is using a slightly different kernel version than the target's kernel version (6.1.78-00024-ge4076639eb90 for module v.s. 6.1.78-00024-gf31b8a21afa8 for kernel).

vermagic=6.1.78-00024-ge4076639eb90 SMP preempt mod_unload aarch64
__UNIQUE_ID_vermagic330
__UNIQUE_ID_vermagic330

I don't understand where I'm going wrongly. Here's my module build process so far

  1. Download OpenSTDroid Distribution (following the wiki linked here).
  2. Build OpenSTDroid using the wiki linked here.
  3. Set the following environment variables
export BUILD_TOP=$(pwd) /* AOSP root/top directory */
export ARCH=arm64 
export CROSS_COMPILE=aarch64-linux-gnu- 
export KERNEL_src=${BUILD_TOP}/device/stm/stm32mp2-kernel/linux-stm32mp2​
  1. Ran `./device/stm/stm32mp2-kernel/source/load_kernel.sh` to load the kernel.
  2. I entered `$KERNEL_SRC` and ran `make menuconfig` to enable the Bluetooth USB configuration options.
  3. I ran `make olddefconfig`, `make prepare`, and then `make –C $KERNEL_SRC ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE –j$(nrpoc)` to build the kernel.
  4. Finally, I run `make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=drivers/bluetooth modules` to successfully build `btusb.ko`.

Am I in the wrong kernel folder? Am I building the module incorrectly? Any insight would be helpful.

Target Hardware Platform: STM32MP25F7-EV1

Target Operating System: OpenSTDroid Distribution (st-android-13.0.0-2024-07-31) [Wiki link]

Target Kernel Version: 6.1.78-00024-gf31b8a21afa8

 

1 ACCEPTED SOLUTION

Accepted Solutions
Nicolas L
ST Employee

 

Sorry for the late answer.

As far as I remember, it's not possible with insmod to force the installation. Did you try with modprobe ?

Now to rebuild kernel modules, up to now, I suggest to follow directives (https://wiki.st.com/stm32mpu/wiki/How_to_build_kernel_for_Android) :

1- Load the kernel source (as your performed) : load_kernel

2- Build the kernel : build_kernel

3- Modify the kernel config : build_kernel menuconfig

4- Re-build and install the kernel and modules : build_kernel -i

5- Re-build the Android distribution : make -j

 

Then you'll have to flash your updates : https://wiki.st.com/stm32mpu/wiki/How_to_populate_boards_for_Android

 

Regards

Nicolas

View solution in original post

3 REPLIES 3
Nicolas L
ST Employee

 

Sorry for the late answer.

As far as I remember, it's not possible with insmod to force the installation. Did you try with modprobe ?

Now to rebuild kernel modules, up to now, I suggest to follow directives (https://wiki.st.com/stm32mpu/wiki/How_to_build_kernel_for_Android) :

1- Load the kernel source (as your performed) : load_kernel

2- Build the kernel : build_kernel

3- Modify the kernel config : build_kernel menuconfig

4- Re-build and install the kernel and modules : build_kernel -i

5- Re-build the Android distribution : make -j

 

Then you'll have to flash your updates : https://wiki.st.com/stm32mpu/wiki/How_to_populate_boards_for_Android

 

Regards

Nicolas

Thanks Nicolas. This is exactly what I need!

I loaded the kernel again using load_kernel -f

I ran build_kernel --verbose=1 and received an error on Step [3/7].

[3/7]: Generate dtb binaries
make: Entering directory '/home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/device/stm/stm32mp2-kernel/linux-stm32mp2'
make -C /home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/out-bsp/stm32mp2/KERNEL_OBJ -f /home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/device/stm/stm32mp2-kernel/linux-stm32mp2/Makefile dtbs
make[1]: Entering directory '/home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/out-bsp/stm32mp2/KERNEL_OBJ'
make[1]: *** No rule to make target 'dtbs'.  Stop.
make[1]: Leaving directory '/home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/out-bsp/stm32mp2/KERNEL_OBJ'
make: *** [Makefile:256: __sub-make] Error 2
make: Leaving directory '/home/ozi/STM32MP25_Workspace/OpenSTDroid/Distribution_Package/device/stm/stm32mp2-kernel/linux-stm32mp2'

 I did a grep dtbs on my Makefile in the KERNEL_SRC. I can see the dtbs command is there. I attached my Makefile, too.

I tried calling build_kernel mrproper before building the kernel. No dice.

I'm also calling build_kernel from KERNEL_SRC, too. Any advice?

no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
%.dtb: dtbs_prepare
%.dtbo: dtbs_prepare
PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
dtbs: dtbs_prepare
# dtbs_install depend on it as dtbs_install may run as root.
dtbs_prepare: include/config/kernel.release scripts_dtc
ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
dtbs: dt_binding_check
dtbs_check: dtbs
dtbs_install:
all: dtbs
                echo '* dtbs             - Build device tree blobs for enabled boards'; \
                echo '  dtbs_install     - Install dtbs to $(INSTALL_DTBS_PATH)'; \
                echo '  dtbs_check       - Validate device tree source files';\

 

ozi
Associate II

Update!

I apparently needed CONFIG_ARCH_STM32=y in my .config file to fix the dtbs error. I ran build_kernel menuconfig, pressed the "/" key to search for CONFIG_ARCH_STM32, then enabled it. After that, build_kernel command worked flawlessly.

I ran build_kernel -i successfully. Now my custom modules have the same kernel version as prebuilt Android image! I will flash my device tomorrow and modprobe the modules to see if they work properly.