문제

We are developing android kernel drivers in a team. The drivers are developed as loadable modules and are compiled separately from the kernel source. However we need to first build android kernel source in order to build driver modules. Each developer pull kernel changes from git and builds the kernel binary. Since kernel binaries are different on each developer's local system, we need to replace both kernel binary and driver modules each time. Is there a better solution to build drivers apart from sharing kernel source on a common system?

도움이 되었습니까?

해결책

One of you should do this locally. Assume your kernel source directory is $kern_dir and you will build the below artifacts in a new staging area (outside the kernel source hierarchy). Call this $stage.

Within the staging area, create a subdirectory hierarchy: $stage/lib/modules/$kernel_version/build ($kernel_version should match the KERNEL_VERSION in your kernel Makefile; the resulting path will be the same directory name as you're currently installing modules into on the target system); call this $build.

# Configure and build the kernel as you currently do.
cp <my-kernel-config> to $kern_dir
cd $kern_dir
make oldconfig          # or whatever is needed to set your config
make

# Create the staging area and build directory
mkdir -p $build

# Copy updated kernel config to staging area:
cp .config $build

# Create necessary kernel configuration support (in staging area) to support out-of-tree modules
make O=$build modules_prepare

# Add Module.symvers to build directory
cp Module.symvers $build

You should now have a completely configured build directory that everyone can install on their own system. This is a directory containing all the header files needed to build with that kernel, together with the info describing what configuration options your kernel was built with and the Module.symvers file that describes kernel exported symbols.

Bundle that up ("cd $stage; tar czf kernel-devel.tgz lib/modules/$kernel_version/build") and distribute it to all developers.

Separately commit the "package" containing the built kernel and the associated modules (i.e. all the ones that come with the kernel and that you're not modifying); for this, use whatever mechanism you're using now. Have everyone install this kernel and build directory onto their target (run-time) system. (This should give everyone a common /boot/ and /lib/modules hierarchy.)

On their build system, everyone should install your kernel-devel.tgz from above. Assuming that the build system is running the same kernel as the target systems and you installed the kernel-devel.tgz relative to root (i.e. it's actually in /lib/modules/$kernel_version/build on your build system), you can then use the "standard" module Makefile model to build your modules. Should be something like this:

obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

If your build system is not running the same kernel, then simply change KDIR to wherever you've installed the kernel-devel.tgz tarball.

Now anyone on your team should be able to build modules that install against the same kernel.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top