I want make a dynamic loaded kernel module for android.
I don't want to install a linux, I just have cygwin and android NDK.
Yes, it is possible to build kernel modules with the NDK. Note, this works best with a Linux system (I'm told Linux x86_64 is the supported environment) because it's harder to cross-compile kernel code on case sensitive filesystems (such as those that come by default on Windows and Mac systems), and because building kernel modules requires building ELF-manipulation binaries (modpost) which require ELF headers typically only present on Linux.
That said...
First you need to get the source code to the same exact kernel on your device, and make sure that the configuration is the same as your device. (otherwise there's a chance you will confuse the build system)
Second, you need to determine where in your Android NDK the cross-compiler toolchain is. Here's how I found mine:
$ cd $NDK_HOME
$ find . | grep '\-gcc$'
./toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi-gcc
./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
(note, $NDK_HOME is where I installed the Android NDK)
Third, you need to add the $NDK_HOME/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin directory (or wherever it is on your system) to your PATH environment variable.
Then you need to export two environment variables:
export ARCH=arm
export CROSS_COMPILE=arm-eabi-
(note, the arm-eabi- prefix is the same as what we saw in the find command. When the kernel is built, commands such as gcc and ld will be prefixed with this. Note, if you were building for an x86 platform I expect you would have to adjust these. I have only built modules for ARM.)
Next, you should compile the kernel. (to do this, I pulled down /proc/config.gz from my Android device, ran zcat config.gz > .config within the kernel source directory, then ran make menuconfig && make.) Kernel build gurus may know some shortcuts here, but I wasn't able to set up the kernel source directory correctly for building a module without doing an actual build. (If the kernel in your build tree matches your device, you don't have to actually update the kernel, you can just insert the modules.)
Last, I used the normal process to build the kernel modules from source. Typically kernel modules will have a parameterized build which will read in the kernel source tree directory somehow, then invoke the build. At that point, as long as the kernel source tree is set up correctly and ARCH and CROSS_COMPILE are set up, your module should build!
Good luck with this. I'm sure there is some per-device variance.
Just now I found this URL where the user has attempted loading LKM and was successful, though on Android (Kernel core: 2.6.29) and I think it was on Linux and not on Cygwin. Hope you get it too!
There is one more resource here and here too!.
All the best!
Follow this URL, Android developer suggests to go for virtual Ubuntu image for this than cygwin.
Related
I am trying to cross-compile glibc (version 2.28) for ARM (because the libc.a distributed with Android NDK lacks the xdr_() routines I need) and I am hitting an issue in the configure.
This is my configure:
../glibc-2.28/configure --prefix=/home/me/TEST --host=arm-linux-androideabi --disable-multilib
The error output by configure is:
GNU libc requires kernel header files from Linux 3.2.0 or later to be
installed before configuring.
It is defaulting to kernel headers in /usr/include/linux. I know I can change where it looks for kernel header files with --with-headers, but don't know where to point this to? I tried apt-get upgrade (and update) but still get the same configure error.
Note 1:
I have already built my arm-linux-androideabi-() binaries successfully and have built other packages OK. I am running on a Linux debian 4.9.0-8-amd64 system.
Note 2:
I checked stackoverflow for similar questions and found one, very similar, but the suggestion was to replace --host with --target. However, the responder was mistaken in thinking that the --host argument defines the machine on which the code is being compiled.
On a fresh Ubuntu installation, I have installed build-essential package, amongst other packages that I've then used to compile Nvidia driver for my PC. Meaning kernel and module compilation works on the PC.
Now on the same PC, I tried to Cross compile an Android linux kernel, using the Google NDK Toolchain based on gcc 4.4.3.
Compilation proceeds smoothly, however at the end, it gives the following output:
CHK include/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
Building modules, stage 2.
MODPOST 0 modules
I have done 'make prepare' before invoking 'make menuconfig' and then doing a 'make'.
Note that the same toolchain, on a build server works with the same files cloned from a git repo. In short, same kernel source, same toolchain, builds modules on the server, doesnt build any modules on my PC.
.config has "Loadable modules support" enabled.
$cat modules.order
kernel/drivers/scsi/scsi_wait_scan.ko
kernel/drivers/net/wireless/bcmdhd/dhd.ko
kernel/drivers/net/wireless/btlock/btlock.ko
kernel/drivers/net/tun.ko
The Makefiles have correct obj-m and obj-$ setup, which is also obvious by the fact that it works on one PC.
I'll be glad to have some insight on why I cant get my PC to compile modules for my Android kernel.
After a lot of searching, I found the answer.
I'm sharing it here because it's almost inconceivable that anyone would think that this is the reason for this issue!
I have GREP_OPTIONS set for providing color automatically, and to number the results. It seems that a the script which builds modules depends on grep, and seems to get messed up.
unsetting the envt variable made it perform modpost successfully.
So the solution is to:
GREP_OPTIONS=
And remove the setting from the profile and .bashrc scripts.
I would like to use a PCAN with my device.
I have the program for it, and an otg cable, but i need to install the driver first.
And i found a linux driver on the manufacturers site.
I downloaded the kernel source, arm toolchain, and read a few sites about building and compiling but i havent find anything about adding driver.
So my question is, how can i add or install this driver on android?
The device is galaxy tab 10.1 P7510.
Thanks for your help.
Right, what you need to do is this:
Unzip the tarball source
Go into the respective directory of the source - cd peak-linux-driver-7.7/ as quoted by the above PDF
cd peak-linux-driver-x.y
make clean
make su -c “make install”
When the build completes, issue this command
/sbin/modprobe pcan
However, having stated this, I do not see any reference to building with Android, so it looks like a fair bit of messing around with the source to get this to actually work on Android.
From what I can ascertain, this is more orientated towards the desktop PC only...
As is mentioned in a later comment clarifying this answer; the kernel would need to be recompiled from source as an arm v7 or v8 target.
The part not mentioned was that it would also have to be statically linked to avoid requiring glibc in Android or bionic lib c in your computer.
I have successfully built and run a version of the goldfish kernel in the emulator. What I want to do now is include this in the platform source I have. So that I can build and run the platform from scratch with my custom kernel.
I have looked everywhere for help in replacing the kernel that is already there. I believe I need to change the 'TARGET_PREBUILT_KERNEL=' line in a build file somewhere but I can't find the right place.
Any help would be much appreciated.
You don't need to change the configuration files. You can override them at the command line. If you export TARGET_PREBUILT_KERNEL="Path to my zImage" and then build the platform. When you build the platform, it will use your zImage as part of mkbootimg instead of the default.
However, if you did want to change this its under $(ANDROID_ROOT)/device/<my device>/device.mk.
So if you were building for the Galaxy Nexus, you would modify the file device/samsung/tuna/device.mk.
I want to use some unix tools on my rooted android arm6 based phone. I will be using cross compiler tools provided here. If I want to compile gnu netcat, how can I set the cross compiler prefix to arm-none-linux-gnueabi- and how to enable static linking (no shared library).
I managed to cross-compile rsync for Android using Ubuntu's arm-linux-gnueabi toolchain. See this related question.
Unless you particularly need to build against a more standard libc than bionic, you can just use the ndk's toolchain, either by copying the hello-jni example and changing BUILD_SHARED_LIBRARY to BUILD_EXECUTABLE in the jni/Android.mk or using the script to generate a stand alone toolchain. You may want to use the V=1 option to the ndk-build script to see the commands it's issuing to its gcc.
Otherwise you may need to pass the prefix to the configure script or manually edit it into the Makefile for the project. This often has not gone well as many projects have make systems not really set up for cross compiling, I've had to resort to editing the configure script to set prefixes and skip tests where it tries to execute a test program.
An option that sometimes works when the build system is more complicated than the project requires is to do a configure for your host (let's hope that's linux). Then manually edit the generated Makefile to change anything needed to build for android instead. Might not be a bad idea to do a clean just in case (especially if you did a test host build). And then do the build which will pick up the arm compiler from your Makefile modifications.
Lastly, if you can be content with the original netcat by Hobbit rather than the gnu version, you hardly need to port it to android yourself as that's already been done. There's already an android version in the google tree at https://android.googlesource.com/platform/external/netcat
which may be on your device already (as 'nc'), and is definitely included in alternate ROMs such as Cyanogenmod.