How to build Helloword in android custom kernel - android

insmod: failed to load hello.ko: Function not implemented
during kernel build to logout message like 'hello world', I've got such an error, following steps will reproduce the bug:
1)I downloaded goldfish kernel from git clone https://android.googlesource.com/kernel/goldfish/ -b android-goldfish-3.18
2)also downloaded the toolchain coming with the above repo using git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9
3)I changed directory to goldfish and created the paths mentioned in the documentation (github)
4)then i attempted to build the kernel using this sudo make ARCH=x86_64 CROSS_COMPILE=/home/ana/x86_64-linux-android-4.9-nougat-dev/bin/x86_64-linux-android- in the kernel directory (goldfish) and set LOADABLE_MODULES=y
5)In the next step, I created hello.c file and the Makefile related to it in helloKernel directory.
hello.c
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
MODULE_AUTHOR("Robert P. J. Day");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION("2:1.0") ;
MODULE_DESCRIPTION("You have to start somewhere.");
static int hello_init(void){
printk(KERN_ALERT "Hello TheLittleNaruto it’s your first driver.\n");
return 0;
}
static void hello_exit(void){
printk(KERN_INFO "Goodbye TheLittleNaruto No point in keeping this driv er running.\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile
obj-m := hello.o
KERNELDIR := /home/ana/goldfish/
PWD :=$(shell pwd)
ARCH=x86_64
CROSS_COMPILE=/home/ana/x86_64-linux-android-4.9-nougat-dev/bin/x86_64-linux-android-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
CFLAGS_MODULE=-fno-pic
modules:
make -C $(KERNELDIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) modules
clean:
rm *.o *.ko *.mod.c *.order *.symvers
in the same directory I created hello.ko with this sudo make ARCH=x86_64 CROSS_COMPILE=/home/ana/x86_64-linux-android-4.9-nougat-dev/bin/x86_64-linux-android-
7)and then i copied hello.ko to android emulator using sudo adb push hello.ko /data/local
8)and then i attempt insmod hello.ko in /data/local
and I get the above-mentioned error, please help me solve this problem. thanks in advance

two things to add in your code
function entry and exit routine
module_init(init_module);
module_exit(cleanup_module);
Let init_module function return 0 rather 1 because 0 means we are good.

Related

Tensorflow android cmake build can't find python

I'm trying to build tflite in my android project using cmake. I've managed to work this approach on the linux (debian) version of the same project.When compiling the arm64 version I followed the official docs When I open android studio and press build/run on top right corner, I get this error:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.cc:17:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.h:49:
In file included from /usr/include/python3.9/Python.h:8:
/usr/include/python3.9/pyconfig.h:9:12: fatal error: 'aarch64-linux-gnu/python3.9/pyconfig.h' file not found
When I open the file that throws the error I see the this line indicating that it's searching for it in the system:
#include <aarch64-linux-gnu/python3.9/pyconfig.h>
I ran sudo find / -name "aarch64-linux-gnu" to see whether I have that file or not and indeed I have this file installed:
user#debian:~$ sudo find / -name "aarch64-linux-gnu"
...
/home/user/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/aarch64-linux-gnu/include/c++/8.3.0/aarch64-linux-gnu
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib/mesa-diverted/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/usr/lib/aarch64-linux-gnu
/usr/include/finclude/aarch64-linux-gnu
/usr/include/aarch64-linux-gnu
I located inside /usr/include/aarch64-linux-gnu and indeed saw /python3.9/pyconfig.h.
The way I did everything is this:
sudo git clone https://github.com/tensorflow/tensorflow.git /home/user/Desktop/official_stuff/tensorflow_src
curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C ${HOME}/toolchains
ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
ARMCC_FLAGS="-funsafe-math-optimizations"
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
-DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
-DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
../tensorflow/lite/
And then I needed to ran dpkg --add-architecture arm64, apt-get update, sudo apt install libpython3-dev:arm64
I simply clicked build ran after connecting my android device. It compiled for a while and then throw the error.
Here is the cmake snippet I ran that contains my tflite inclusion:
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"/home/user/Desktop/official_stuff/tensorflow_src" ABSOLUTE)
endif()
add_library(tensorflowlite SHARED IMPORTED)
add_subdirectory(
"/home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL
)
...
target_link_libraries(
my_proj
tensorflow-lite
)
How can I fix this issue?
Note: I got to this point following a series of questions which all resolved:
An undefined error.
Question regarding android build.
More details about how I built everything can be found here. I'm on debian 11.

Creating APK from Kivy on Mac OS X fails after compile

My background is in HTML/JS, so compiling is new for me. While attempting to build my python project in Kivy to an Android .apk, I am getting an error I do not understand:
Command failed: ./distribute.sh -m "kivy"
Here is a portion of the tail end of the debug output...
Compiling /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/xmllib.py ...
Compiling /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/xmlrpclib.py ...
Compiling /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/zipfile.py ...
make: [libinstall] Error 1 (ignored)
PYTHONPATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2: \
/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/compileall.py \
-d /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages -f \
-x badsyntax /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages
Listing /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages ...
PYTHONPATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2: \
/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t -O /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/compileall.py \
-d /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages -f \
-x badsyntax /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages
Listing /Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages ...
PYTHONPATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2: \
/Users/Travis/buildozer/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
Leaving ARM environment
cp: build/lib.linux-x86_64-2.7/_ctypes*.so: No such file or directory
# Command failed: ./distribute.sh -m "kivy" -d "myapp"
#
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2
Here is the full debug, for those who want it...
https://www.dropbox.com/s/45lgdhk5y4uj8eg/KivyDebug.txt?dl=1
Also, my buildozer.spec file...
https://www.dropbox.com/s/g5p43jjts49rzza/buildozer.spec?dl=1
EDIT: Downgrading Cython per the advice HERE did not help.
EDIT2: Tried changing requirements to kivy==master. No luck.
EDIT3: Tried chmod -R 777 on both source and buildozer folders. No luck.
OK, I came across the answer to my own problem a while ago and I'm posting it here in case someone else makes the same boneheaded mistake. Basically, I did not read the instructions carefully enough in the documentation. The instructions clearly state "navigate to your project directory and run: buildozer init". I did not navigate to the project folder. I was building in my user directory, hence "/Users/Travis/". Hence the "No such file or directory" error.
You may be asking "How do you expect buildozer to know where your project is?"
Well, the next step says to configure "buildozer.spec", and in there, there is a place to put your path to the main.py, which by default is ".", so I changed that. It actually worked up to the point that it has to write any files.
So, if you're having the same issue as me, you might just need to read more carefully.

Native libs cross compiled from ubuntu linux targeting arm (android)

I'm experimenting with native libs cross compiled from ubuntu. What I really want is to be able to compile my c++ libraries and use them in a Xamarin.Android app.
First, I have the arm gcc compiler: arm-linux-gnueabi-gcc. I have a simple lib (libmr.so) that has one function void Print(); that prints something to the console. I'm compiling with:
arm-linux-gnueabi-gcc -Wall -shared -o libmr.so mr.c
When inspecting it using file libmr.so everything seems to be good. However when I'm including it with my android app and try to load it, it is as if it doesn't exist. I'm certain it is there, the path is absolutely correct as I tried to load another lib (libmonodroid.so) from the same folder and it worked.
I tried inspecting both libs to find some kind of a difference:
$ objdump -x libmr.so | grep NEEDED
NEEDED libc.so.6
$ objdump -x libmonodroid.so | grep NEEDED
NEEDED libc.so
... (in addition to other libs)
This is the only difference I'm finding between the two. libmonodroid.so loads properly but libmr.so acts as if it doesn't exist. (I'm using dlopen to load a lib)
EDIT:
I built an executable using the same toolchain, gave me a clue:
Static linking with libc: arm-linux-gnueabi-gcc -Wall -o hi source.c -static. Pushed hi to my android devices and executed it with adb. Result: SUCCESS!
Dynamic linking with libc: arm-linux-gnueabi-gcc -Wall -o hi source.c. Result: it's not even there! Meaning ./hi gives /system/bin/sh: ./hi: not found although it's absolutely there.
So, looks like libc is really the culprit? Maybe I need to link dynamically with not libc.so.6 but with libc.so just like libmonodroid.so is doing?
Check this out for anyone having the same problem. Download the ndk, there's a standalone toolchain for building native libs that run on android that you can extract (you won't need the whole ndk).
I was able to run a basic app on ubuntu 15.04 with this Makefile in the same dir as my hi.c:
$ cat hi.c # create hi.c with favorite editor
#include <stdio.h>
int main(int argc, char** argv) {
int uid = getuid();
int eid = geteuid();
printf("Hello world\n");
printf("You are uid: %d and eid; %d", uid, eid);
return 0;
}
$ cat Makefile # create two line Makefile
CC=arm-linux-gnueabi-gcc
LDFLAGS=-static
$ make hi # build arm based hi executable file
arm-linux-gnueabi-gcc -static hi.c -o hi
$ file hi # check file type
hi: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=17b65e60cdd32449ac237bfd1b8238bfa1d416a0, not stripped
$ adb push hi /data/local/tmp # copy to droid fon
4403 KB/s (593252 bytes in 0.131s)
$ adb shell /data/local/tmp/hi # run hi executable
adb shell /data/local/tmp/hi
Hello world
You are uid: 2000 and eid; 2000
$ uname -a
Linux lenny 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Note that I do not have any NDK installed.

Loading kernel module in Android kernel

I am listing my problem here.
I have a Google Nexus one a.k.a. "passion" phone with me. Fastboot and adb tools are installed in the phone. And the boot loader is unlocked.
My task: I have to add a linux kernel module to the Android kernel.
What I have done:
I followed the steps in http://source.android.com/source/initializing.html and downloaded the kernel for android-2.3.6_r1 (passion) and have built it. I am also able to flash it on the phone and the new android kernel also works fine. Now what I want is to modify the kernel and add my own kernel module and then flash it on the phone, so that the kernel on the phone is my modified kernel.
Now I have come across two approaches to do this.
1)
Cross Compile my kernel module with the android kernel and push it on the device with adb command. The Makefile I use in the kernel is as follows.
VERSION = 2
PATCHLEVEL = 3
SUBLEVEL = 6
EXTRAVERSION = -00054-g5f01537
obj-m += hello-1.o
KDIR=/home/apurva/android_dir
PWD := $(shell pwd)
all:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=/home/apurva/android_dir/prebuilt/linux- x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- SUBDIRS=$(PWD) modules
clean:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=/home/apurva/android_dir/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- SUBDIRS=$(PWD) clean
Now this is not able to generate new hello-1.ko. I do not know why, I guess there is some problem with the VERSION, PATCHLEVEL, SUBLEVEL and EXTRAVERSION values. Are these necessary? I tried these value from android-2.3.6_r1 also but still it does not work. I am not sure what is this EXTRAVERSION value?
I even tried with the hello-1.ko generated from the compiler in my ubuntu. I pushed this hello-1.ko into the emulator with the following adb command.
/root/bin/src/out/host/linux-x86/bin/adb shell mount
/root/bin/src/out/host/linux-x86/bin/adb push hello-1.ko /data
/root/bin/src/out/host/linux-x86/bin/adb insmod /data/hello-1.ko
But that hello-1.ko is not able to insmod and I get the following error.
insmod : Error in init_module() hello-1.ko function not implemented
Whereas the hello-1.c is quite simple:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
2)
The second approach of doing this can be placing my source files of the kernel module in the kernel directory of android. May be in the system directory or somewhere else and ask the make to build these source files also along with the other source. But I am not sure where to ask the make process to do so. I tried to do so in main.mk and created a Android.mk file in the source directory of my source files but it did not work. May be this is a better solution but I could not find any help on this.
After doing this, my kernel modules should be able to control the wnic (Wireless Network Interface device) of the android phone. It should be able to put the wnic in sleep mode and then wake it up after receiving command from my kernel module. If you have some pointers on how to do this, that will be a help. I have found that on Android it is controlled through wpa_supplicant private driver. Commands, like:
wpa_cli driver powermode 0 - auto
wpa_cli driver powermode 1 - active
can do my task, but I am not sure since I have not tried. I have not reached that stage.
Please look into this and provide some help/guidance.
Thanks,
Apurva
Kernel modules (KO's) are much easier to work with than a static kernel - as long as the kernel has enabled them. The easiest way to tell is do an "adb shell lsmod". Second is to see if the kernel .config has enabled CONFIG_MODULES=y and CONFIG_MODULE_UNLOAD=y. Lots of info on the web about linux KO development.
Hummm, you're close but it looks like the makefile is screwy. First try to build the hello KO on your host for unit test, then build on your target. Here's a sample makefile I use on an OMAP36xx running gingerbread:
# Makefile for trivial android kernel module
obj-m += mod_hello.o
CROSS_COMPILE=/opt/distros/ARM/bin/arm-none-linux-gnueabi-
TARG_KDIR ?= /opt/android/dal/nook_kernel
HOST_KDIR=/lib/modules/$(shell uname -r)/build
# target creates:
# .<obj>.o: CC command line for the .o, including dependencies
# .<obj>.mod.o.cmd: CC command line for the mod.o, including dependencies
# .<obj>.ko.cmd: LD command line which links the .o and .mod.o to create the .ko
target:
#echo "Make module for target arm"
make -C $(TARG_KDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
host:
#echo "Make module for host"
make -C $(HOST_KDIR) M=$(PWD) modules
clean:
#echo "cleaning target"
make -C $(TARG_KDIR) M=$(PWD) clean
#echo "cleaning host"
make -C $(HOST_KDIR) M=$(PWD) clean
First check in the .config if the module support is enabled. (CONFIG_MODULES=y and CONFIG_MODULE_UNLOAD=y) if not enable them using menuconfig.
Then place your module on the root of the kernel source and add this to the main makefile you find at the root
core-y := usr/ yourModule/
and this to the yourModule folders makefile
obj-m := yourModule.o

How do you create a loadable kernel module for Android?

I know there a number of walkthroughs and tutorials floating around out there which describe this activity, but after having read many of them I still can't get this working. If anyone has the patience to wade through the steps I've taken (posted below) and suggest where I may have gone off track I'd be very appreciative. I've spent about a day and a half staring at make files and reading walkthroughs so literally any suggestions would be helpful.
Environment:
I'm using an Ubuntu 10.04 32 bit vm.
I'm hosting from a 64 bit windows 7
My Core 2 Duo does not have the hardware support for 64 bit VMs so i'm trying to compile against Android 2.1 kernel
I have installed Java 1.5 from the Dapper repo and removed my 1.6 installation
The rest of the tooling has been acquired according the Android dev documentation...
As per Initializing a Build Environment:
Java:
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
Other required:
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline5-dev libz-dev libgl1-mesa-dev
$ sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386
Then from Downloading the Source Tree:
Repo:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
$ repo init -u https://android.googlesource.com/platform/manifest -b eclair
$ repo sync
$ gpg --import (imported the huge key)
And from Building the System:
Initialize:
$ source build/envsetup.sh
Choose a Target:
$ lunch generic-user
Build the Code:
$ make -j4
Added!
Output of make -j4:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Install: out/host/linux-x86/bin/acp
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: aapt <= frameworks/base/tools/aapt/AaptAssets.cpp
host C++: aapt <= frameworks/base/tools/aapt/Command.cpp
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.HDF
class file for org.clearsilver.HDF not found
javadoc: error - Class org.clearsilver.HDF not found.
Error: No classes were specified on the command line. Try -help.
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h] Error 15
make: *** Waiting for unfinished jobs....
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.CS
class file for org.clearsilver.CS not found
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/AaptAssets.cpp:5:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
javadoc: error - Class org.clearsilver.CS not found.
Error: No classes were specified on the command line. Try -help.
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/Main.h:14,
from frameworks/base/tools/aapt/Command.cpp:6:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_CS.h] Error 15
Added!
So it turns out i've got some problems here. I assume that once i've overcome these issues, i'll have an environment capable of compiling kernel modules. Please do correct me if I'm wrong.
Next I head into my directory containing my module.c file and it's makefile. Contents of makefile below:
obj-m += mymodule.o
CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY
VERSION = v1.1
all:
make -C $(KERNEL_DIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
I have very little experience with make and makefiles, but this looked reasonable to me. My main concern with this file is the KERNEL-DIR variable. I tried a few different values for that variable, but got all sorts of errors where I do not with it's current value. Of course, it could still be wrong, so any comments here are welcome.
So, as far as I know, I should be able to execute make with no args or anything and will figure out what it needs to do. I have tried make, make -f both with and without sudo. All four permutations yield the same results:
make -C /home/<myuser>/WORKING_DIRECTORY M=/home/<myuser>/Desktop/<MyModuleDir> ARCH=arm CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- modules
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Available sub-modules:
01-test dumpsys libminui LotsOfApps
20-dns.conf dvz libminzip lowstoragetest
95-configured dx libmp4recognizer_utility lsd
aapt dx-tests libmtdutils LunarLander
acc edify libnativehelper LunarLanderTests
AccountAndSyncSettings Email libneo_cgi MagicSmokeWallpapers
accRuntimeTest EmailTests libneo_cs make_cfst
acp emma libneo_util makedict
adb emmalib libnetutils make_g2g
adbd emulator libocr makekeycodes
add-property-tag emulator-arm libomx_aac_component_lib make_ve_grammar
afar emulator-hw libomx_aacdec_sharedlibrary mediaframeworktest
aidl emulator-tcg libomx_amr_component_lib MediaProvider
AlarmClock EnabledTestApp libomx_amrdec_sharedlibrary mediaserver
AliasActivity etc1tool libomx_amrenc_component_lib memtest
am eventanalyzer libomx_amrenc_sharedlibrary minigzip
android event-log-tags libomx_avc_component_lib mkbootfs
android.core.tests.annotation exc_dump libomx_avcdec_sharedlibrary mkbootimg
android.core.tests.archive ext libomx_baseclass_lib mksdcard
android.core.tests.concurrent Fallback libomx_common_lib mkstubs
android.core.tests.crypto fastboot libomx_m4v_component_lib mkyaffs2image
android.core.tests.dom FixedGridLayout libomx_m4vdec_sharedlibrary Mms
android.core.tests.logging flash_image libomx_mastercore_lib MmsTests
android.core.tests.luni.io FontLab libomx_mp3_component_lib monkey
android.core.tests.luni.lang framework libomx_mp3dec_sharedlibrary monkeyrunner
android.core.tests.luni.net FrameworkPermissionTests libomx_queue_lib mtpd
android.core.tests.luni.util framework-res libomx_sharedlibrary MultiResolution
android.core.tests.math FrameworkTest libop Music
android.core.tests.nio framework-tests libopencore_author MusicTests
android.core.tests.nio_char FrameworkTestTests libopencore_common nc
android.core.tests.prefs fsck_msdos libopencore_download netcfg
android.core.tests.regex fs_config libopencore_downloadreg netperf
android.core.tests.runner fs_get_stats libopencore_mp4local netserver
android.core.tests.security Gallery libopencore_mp4localreg ninepatch
android.core.tests.sql Gallery3D libopencore_net_support NinePatchLab
android.core.tests.text GalleryTests libopencore_player NoShareUidApp
android.core.tests.xml gdbserver libopencore_rtsp NotePad
android.core.tests.xnet genext2fs libopencore_rtspreg NotePadTests
android.cts.dpi GestureBuilder libosclbase opcontrol
android.cts.refapp GL2JNI libosclerror openssl
android.policy GLJNI libosclio OpenWnn
android.policy_mid GlobalSearch liboscllib oprofiled
android.policy_phone GlobalSearchBenchmarks libosclmemory org.eclipse.core.commands_3.4.0.I20080509-2000
androidprefs GlobalSearchPermissionTests libosclproc org.eclipse.equinox.common_3.4.0.v20080421-2006
android.test.runner GlobalSearchTests libosclregcli org.eclipse.jface_3.4.2.M20090107-0800
AndroidTests GlobalTime libosclregserv org-netbeans-api-visual
angeles GoogleContactsProvider libosclutil org-openide-util
ant GoogleContactsProviderTests libpagemap osgi
antlr-2.7.7 google-framework libpassthru_oma1 PackageInstaller
anttasks googlelogin-client libpcap parseStringTest
apicheck GoogleSearch libpixelflinger perm_checker
ApiDemos gpustate libpixelflinger_armv6 perm_checker.conf
ApiDemosReferenceTest gralloc.default libpixelflinger_static Phone
ApiDemosTests groovy-all-1.6.5 libplatform_library_jni PicoTts
apkbuilder grxmlcompile libpng ping
ApplicationsProvider gtest-filepath_test libpopt PinyinIME
applypatch gtest-linked_ptr_test libprotocolenginenode_base PlatformLibraryClient
applypatch_static gtest-message_test libprotocolenginenode_common platform.xml
app_process gtest-options_test libprotocolenginenode_download_common pm
AppWidgetHostTest gtest-port_test libprotocolenginenode_pdl post_trace
AppWidgetProvider gtest_pred_impl_unittest libprotocolenginenode_ps pppd
apriori gtest_prod_test libpv_aac_dec preload
archquery gtest-test-part_test libpvaacffparsernode ProcessTests
asm-3.1 gtest-typed-test2_test libpvaacffrecognizer procmem
atree gtest-typed-test_test libpvaacparser procrank
AudioHardwareRecord gtest_unittest libpvamrffparsernode profile_pid
AudioHardwareRecordLoop gzip libpvamrffrecognizer profile_trace
AudioInRecord HelloActivity libpv_amr_nb_common_lib Provision
backup_helper_test HelloActivityTests libpvamrwbdecoder pvplayer
BackupTest hierarchyviewer libpvauthorengine q2dm
BatteryWaster hist_trace libpv_avc_common_lib q2g
bb2sym Home libpvavcdecoder qemud
bb_dump hosttestlib libpvavifileparser qemu-props
bbprof hprof-conv libpv_config_parser qwerty2.kcm
bison HTMLViewer libpvdecoder_gsmamr qwerty.kcm
Bluetooth icache libpvdownloadinterface racoon
BluetoothChat icudata libpvdownloadmanagernode radiooptions
BluetoothDebug idegen libpvdownloadreginterface read_addr
bmgr ime libpvencoder_gsmamr read_method
bookmarks.xml ImfTest libpvfileoutputnode read_pid
bootanimation ImfTestTests libpvfileparserutils read_trace
Browser imgdiff libpvframemetadatautility recovery
BrowserPowerTests init libpvgendatastruct required_hardware.xml
BrowserTestPlugin input libpvgsmamrparser rgb2565
BrowserTests installd libpv_http_parcom rild
bsdiff invoke_mock_media_player libpvid3parcom rsg-generator
bspatch iptables libpvjitterbuffer RSSReader
btool ip-up-vpn libpvjitterbuffernode run-core-tests
bugreport iself libpvjitterbufferrtp run-core-tests-on-ri
BusinessCard isprelinked libpvlatmpayloadparser safe_iop_test
Calculator jarjar libpvmediadatastruct SampleBrowserPlugin
CalculatorTests jarutils libpvmediainputnode schedtest
Calendar jasmin libpvmedialayernode scp
CalendarProvider jasmin.jar libpvmediaoutputnode screenshot2
CalendarProviderTests javax.obex libpvmf sdklib
CalendarTests jcommon-1.0.12 libpvmfrecognizer sdkmanager
Camera jdiff libpvmimeutils SdkSetup
CameraTests jdwpspy libpvmioaviwavfileinput sdkstats
CertInstaller JETBoy libpvmiofileinput sdkuilib
cfassembler jfreechart-1.0.9 libpvmiofileoutput sdutil
check-lost+found jfreechart-1.0.9-swt libpvmp3 SearchableDictionary
check_prereq junit libpvmp3ff sensors.goldfish
check_stack jython libpvmp3ffparsernode service
check_trace kcm libpvmp3ffrecognizer servicemanager
clearsilver keystore libpvmp4decoder services
cmu2nuance keystore_cli libpvmp4ff Settings
com.android.inputmethod.pinyin.lib KeyStoreTests libpvmp4ffcomposer SettingsProvider
com.example.android.platform_library kxml2-2.3.0 libpvmp4ffcomposernode SettingsTests
commons-compress-1.0 latencytop libpvmp4ffparsernode sh
Compass LatinIME libpvmp4ffrecognizer ShareUidApp
ContactManager Launcher libpvmp4interface showlease
Contacts Launcher2 libpvmp4reginterface showmap
ContactsProvider launchperf libpvomxaudiodecnode showslab
ContactsProviderTests layoutlib libpvomxbasedecnode sig
ContactsTests layoutlib_api libpvomxencnode sig-check
core layoutlib_create libpv_omx_interface sig-create
core-tests layoutlib_utils libpvomx_proxy_lib signapk
CoreTests layoutopt libpvomxvideodecnode SignatureTest
coverage libabi libpvplayer_engine SignatureTestTests
cpueater libacc libpvpvxparser signature-tools
cpufeatures libaes libpvrtsp_cli_eng_node SimpleJNI
crasher libandroidpv libpvrtspinterface SkeletonApp
create_test_dmtrace libandroidpvauthor libpv_rtsp_parcom SkeletonAppTests
cts libandroid_runtime libpvrtspreginterface skia_bench
CtsAccessibilityServiceTestCases libandroid_servers libpvsdpparser skia_gm
CtsAccountManagerTestCases libapplypatch libpvsocketnode SlowSuggestions
CtsAppAccessData libarity libpvstreamingmanagernode SmokeTest
CtsAppSecurityTests libastl libpvthreadmessaging SmokeTestApp
CtsAppTestCases libaudioflinger libpvwav Snake
CtsAppWithData libaudiointerface libpvwavffparsernode SnakeTests
CtsBluetoothTestCases libaudiopolicygeneric libpvwavffrecognizer SoftKeyboard
CtsContentTestCases libbinder librank soslim
cts-dalvik-buildutil libbz libreference-cdma-sms sound
CtsDatabaseTestCases libc libreference-ril SoundRecorder
CtsDelegatingAccessibilityService libcameraservice libril SpammySuggestions
CtsDpiTestCases libcamerastub libRS SpareParts
CtsDpiTestCases2 libc_common librs_jni spec-progress
CtsExampleTestCases libc_debug librtppayloadparser sqlite3
CtsGestureTestCases libclearsilver-jni librtprtcp SRecTest
CtsGraphicsTestCases libc_nomalloc libsafe_iop SRecTestAudio
CtsHardwareTestCases libcolorconvert libsampleplugin ssh
CtsInstrumentationAppDiffCert libcpm libSDL SslLoad
CtsJniTestCases libcrypto libSDLmain stack_dump
CtsLocationTestCases libctest libsimplejni StatusBarTest
CtsMediaTestCases libcts_jni libskia Stk
CtsNetTestCases libctspermission_jni libskiagl strace
CtsOsTestCases libcutils libsonivox stringtemplate
CtsPerformance2TestCases libdb libsoundpool su
CtsPerformance3TestCases libdbus libspeex surfaceflinger
CtsPerformance4TestCases libdbus-tools-common libsqlite svc
CtsPerformance5TestCases libdex libsqlite3_android swing-worker-1.1
CtsPerformanceTestCases libdl libsqlite3_phone_number_utils_test swt
CtsPermission2TestCases libdrm1 libsqlite3_phonetic_string_utils_test system_server
CtsPermissionDeclareApp libdrm1_jni libSR_AcousticModels tcpdump
CtsPermissionTestCases libdrm2 libSR_AcousticState TelephonyProvider
CtsProviderTestCases libdvm libSR_AudioIn telephonytest
CtsSharedUidInstall libebl libSR_Core temp_layoutlib
CtsSharedUidInstallDiffCert libebl_arm libsrec_jni Term
CtsSimpleAppInstall libedify libSR_EventLog test_defs.xml
CtsSimpleAppInstallDiffCert libEGL libSR_G2P TestDeviceSetup
CtsSpeechTestCases libelf libSR_Grammar test-fb-refresh
CtsTargetInstrumentationApp libelfcopy libSR_Nametag test-fb-simple
CtsTelephonyTestCases libembunit libSR_Recognizer test_g2g
CtsTestStubs libemoji libSR_Semproc test-mdp
CtsTextTestCases libESR_Portable libSR_Session test-opengl-codegen
CtsUsePermissionDiffCert libESR_Shared libSR_Vocabulary test-opengl-fillrate
CtsUtilTestCases libETC1 libssl test-opengl-filter
CtsViewTestCases libexif libstagefright test-opengl-finish
CtsWebkitTestCases libexpat libstagefright_omx test-opengl-gl2_basic
CtsWidgetTestCases libext libstdc++ test-opengl-gl_basic
CubeLiveWallpapers libfdlibm libsurfaceflinger test-opengl-gralloc
CustomLocale libFFTEm libsvoxpico test-opengl-linetex
daemonize libfst libsystem_server test-opengl-swapinterval
dalvikvm libft2 libsysutils test-opengl-textures
dasm libgetactualaacconfig libterm test-opengl-tritex
dbus-daemon libgif libtestplugin test-progress
dbus-monitor libgl2jni libthread_db test-progress-new
dbus-send libGLES_android libthreadsafe_callback_ao test_swiarb
ddmlib libGLESv1_CM libtinyxml test_zipfile
ddms libGLESv2 libtomcrypt timeinfo
ddmuilib libgljni libtommath timetest
debuggerd libgoogleclient libttspico toolbox
DensityTest libgtest libttssynthproxy traceview
descGen libgtest_main libui TransformTest
DeskClock libhardware libunz TtsService
Development libhardware_legacy libutil tuttle2.kcm
dexdeps libhost libutils uix
dexdump libicudata-default libvorbisidec updater
dexlist libicudata-eu libwbxml UpgradeExample
dexopt libicudata-jp libwbxml_jni usbtest
dexopt-wrapper libicudata-large libwebcore UserDictionaryProvider
dexpreopt libicudata-us libwnndict VisualizationWallpapers
dex-tools libicui18n libWnnEngDic vm-tests
dhcpcd libicuuc libWnnJpnDic VoiceDialer
dhcpcd-run-hooks libiptc libwpa_client Voiper
dictTest libjavacore libxml2 vold
DisabledTestApp libjni_latinime libxml2wbxml VpnServices
dmtracedump libjni_pinyinime libz wbxmltest
DownloadProvider libjnitest libzipfile wdsclient
draw9patch libjpeg LightingTest webkitmerge
DrmProvider liblog line_endings Wiktionary
droiddoc libm linker WiktionarySimple
dumpeventlog libm4v_config LiveWallpapers xmlwriter
dumpkey libmedia LiveWallpapersPicker yuv420sp2rgb
dump_regions libmedia_jni localize zipalign
DumpRenderTree libmediaplayerservice logcat
dumpstate libmincrypt logwrapper
make[1]: Leaving directory `/home/<myuser>/WORKING_DIRECTORY'
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
You'll notice a few screwy warnings, but as best as I can tell, they are not real problems. If anyone feels differently about these, please say so.
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
I guess that last line sounds pretty suspicious but I have no idea what to do about it. Apart from the few strange things i've mentioned, it would appear that this all went smoothly. However, after the whole thing completes, I can't find the *.ko file anywere. I did a ls -alRg | grep *.ko on my home directory and it turns up nothing. I'm stumped. If I can provide any more information or run any tests or try anything differently i'll be checking in frequently.
Sorry for being late, but hope it helps:
http://tthtlc.wordpress.com/2011/12/29/how-to-write-a-kernel-module-on-android-sony-ericsson-xperia-arc-s/
I wrote and tested the code on my Sony Ericsson Xperia Arc S and it works (in general in should work for any Android phone).
Connecting via adb and USB, and “su” to root, the “lsmod” listed all the kernel module (in general, the article at
http://web.archive.org/web/20121106004141/http://developer.sonymobile.com/2011/05/06/how-to-build-a-linux-kernel gave a very good coverage of what to do in Linux kernel compilation for SonyEricsson phone):
lsmod
android_module 654 0 - Live 0x7f007000 (P)
sdio 16532 0 - Live 0x7f000000
“android_module” was the one I had inserted via insmod android_module.ko.
Here’s how to do it:
First the original program was copied from:
http://rechtzeit.wordpress.com/2011/03/21/77/
Or reproduced as follows:
android_module.c:
#include"linux/module.h"
#include"linux/kernel.h"
//replace the "" with angular brackets
int init_module(void)
{
printk(KERN_INFO "Hello android kernel...\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye android kernel...\n");
}
Makefile:
obj-m += android_module.o
all:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) modules
clean:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) clean
The directory where the kernel is located (“-C” above) is where kernel is located.
And the following command will use the Makefile from above:
ARCH=arm CROSS_COMPILE=/opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- make
As shown above, the cross compiler I had used is from CodeSourcery.
And after insmod android_module.ko you can see the debugging message in dmesg output:
<6>[11184.063507] Hello android kernel...
<7>[11619.209655] msmrtc_timeremote_set_time: 11/29/2011 10:09:36 (04)
<6>[11619.210418] RPC CALL -- TOD TIME UPDATE: ttick = 404244221
<6>[11619.210418] stamp=52910543933046785, freq = 0
<7>[11619.211578] msmrtc_tod_proc_result: 12/29/2011 10:09:36 (03)
<6>[11619.211578] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:09:36 UTC (1325153376)
<6>[11662.112365] device rmnet0 left promiscuous mode
<6>[11662.112579] device rmnet0 entered promiscuous mode
<6>[11669.958221] device rmnet0 left promiscuous mode
<6>[11669.958435] device rmnet0 entered promiscuous mode
<7>[11698.181060] msmrtc_timeremote_set_time: 11/29/2011 10:10:55 (04)
<6>[11698.187622] RPC CALL -- TOD TIME UPDATE: ttick = 406832008
<6>[11698.187652] stamp=52910548228014081, freq = 0
<7>[11698.193939] msmrtc_tod_proc_result: 12/29/2011 10:10:55 (03)
<6>[11698.194030] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:10:55 UTC (1325153455)
<6>[11814.442901] bq27520 0-0055: bq27520_handle_soc_worker() capacity=97 (100) flags=0x229 ctrl_status=0x28b soh_state=0x3, valid=1
<6>[11984.057373] Goodbye android kernel...
And the “Goodbye” is when rmmod android_module is executed. In between are debugging message from other components in the kernel.
Final words:
The above are written in 2011, for more modern resources, please refe to the following to get started:
https://source.android.com/docs/core/architecture/kernel/modular-kernels
https://source.android.com/docs/core/architecture/kernel
https://source.android.com/docs/setup/build/building-kernels
https://source.android.com/docs/core/architecture/kernel/loadable-kernel-modules
I think I've red that emulator kernel does not support module, so you must compile also the kernel with modules support.
I hope that this link will help you
There are two things you'll need to do. Firstly, create an emulator kernel that supports loadable kernel modules.
There's a comprehensive post here covering the process of setting up the emulator kernel.
There are 2 parts of the instructions to alter:
I find it easiest to keep the kernel within the repo area (in this case, ~/WORKING_DIRECTORY), like so:
cd ~/WORKING_DIRECTORY
mkdir kernel
cd kernel
git clone git://android.git.kernel.org/kernel/common.git
The branch information is no longer correct, however, so where it says:
git checkout -t origin/android-goldfish-2.6.29 -b goldfish
use this instead:
git checkout -t archive/android-gldfish-2.6.29 -b goldfish
As you've found out, the kernel by default is not configured with loadable module support. Enable before compiling. After, this step:
make ARCH=arm goldfish_defconfig
do this:
make ARCH=arm menuconfig
A text-based menu will show up. Use the Up/Down arrow keys to navigate, Space to select an option, Enter to expand a menu (menus have --->) at the end of the line, and Esc-Esc to go back a menu.
Select "Enable loadable module support" by scrolling down and hitting Space
Hit Esc-Esc to exit, and hit Enter to save the new configuration
Now build. Using your setup, it would be:
make ARCH=arm CROSS_COMPILE=/home/<myuser>/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
Now that that's done you can do the second part, which is making a loadable kernel module. You were almost there, but because you didn't have the kernel source for the emulator, it didn't work. Just take the makefile you have and change KERNEL_DIR to:
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY/kernel/common

Categories

Resources