Building android kernel - android

since two weeks I try to build the kernel for my htc device. Getting the right sources is not the problem, but since gcc has been removed from toolchains it's a real nightmare. Following the proposals to use clang instead always ends in lot of error messages.
What I've done up to now?
Proper installation of latest android-ndk (21.3.6528147)
Successfully test cross-compiling (just a simple program) over commandline
setup ENV variables for kernel build: (export commands only if not set yet)
$ cd <kernel-source-root>
($ make mrproper) // just after failed attempt to build
$ export ARCH=arm64
$ export SUBARCH=arm64
$ export CROSS_COMPILE=<path-to-toolchain-llvm-bin-folder>
modify Makefile and AndroidKernel.mk
// replace all occurences of 'gcc' with 'clang'
-gcc
+clang
generate .config
$ make msm-perf_defconfig
perform build
$ make V=1
getting error messages:
// ...
../kernel/bounds.c:18:2: error: unexpected token at start of statement
DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->NR_PAGEFLAGS 21 __NR_PAGEFLAGS
^
../kernel/bounds.c:19:2: error: unexpected token at start of statement
DEFINE(MAX_NR_ZONES, __MAX_NR_ZONES);
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->MAX_NR_ZONES 3 __MAX_NR_ZONES
^
../kernel/bounds.c:21:2: error: unexpected token at start of statement
DEFINE(NR_CPUS_BITS, ilog2(CONFIG_NR_CPUS));
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->NR_CPUS_BITS 3 ilog2(CONFIG_NR_CPUS)
^
../kernel/bounds.c:23:2: error: unexpected token at start of statement
DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->SPINLOCK_SIZE 4 sizeof(spinlock_t)
^
4 errors generated.
make[2]: *** [kernel/bounds.s] Error 1
make[1]: *** [prepare0] Error 2
make: *** [sub-make] Error 2
Does someone see what goes wrong?

Adding -no-integrated-as to the build command fixed it.
According to clang developers:
Add -no-integrated-as. This is a known abuse of the compiler to output something other than assembly.
reference
make ARCH=arm64 -j64 -no-integrated-as

Related

How get fast pixel color on Android use ScreenshotClient?

I want get color pixel use an binary file with params x and y. The screencap is very slow. Using a virtual display also does not give the desired result.
I found and code screencap, and good project: sji-android-screen-capture-old and sji-android-screen-capture-new.
But those solutions don't run in my phone. If run get-raw-image.cpp after compile get-raw-image.cpp I get errors:
WARNING: linker: /data/local/tmp/get-raw-image-4.1.2: unused DT entry: type 0xf arg 0x21d
CANNOT LINK EXECUTABLE: cannot locate symbol "_ZN7android16ScreenshotClient6updateERKNS_2spINS_7IBinderEEE".
For compilation, I use the following settings:
/root/arm/bin/arm-linux-androideabi-clang -pie get-raw-image.cpp -lsupc++ libgui.so -o /get-raw-image-4.1.2 -Xlinker -rpath=/system/lib -DTARGET_JB
If run Android-fast-screen-capture:
/root/arm/bin/arm-linux-androideabi-clang -pie /screen/ascreencap.cpp -o /test -std=c++11
I had errors:
In file included from /screen/ascreencap.cpp:8:
In file included from /root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:21:
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:86:11: error: unknown type
name 'binder_size_t'
const binder_size_t* objects() const;
^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:220:47: error: unknown type
name 'binder_size_t'
const binder_size_t* objects, si...
^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:228:51: error: unknown type
name 'binder_size_t'
const binder_size_t* objects...
^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:264:5: error: unknown type
name 'binder_size_t'
binder_size_t* mObjects;
^
In file included from /screen/ascreencap.cpp:8:
/root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:114:50: error:
unknown type name 'binder_size_t'
const binder_size_t* objects...
^
5 errors generated.
Also I found the question how-to-use-screenshotclient-in-my-android-application but I don't understand how set link to ScreenshotClient, so that the compiler does not return an error.
My phone is Homtom HT16:
Processor : ARMv7 Processor rev 3 (v7l)
processor : 0
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 26.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
Maybe someone will tell you how to compile the code under my phone or which way to go to solve the problem.
I solved my problem.
Steps:
1) Copy need library from android phone (libgui.so, libui.so, libcutils.so, libutils.so, libbinder.so).
2) Add in sys_root (when save ndk lib code files from Android Android 6_r1 libs: utils, cutils, system, log, hardware, system, ports, core, include/gui, include/ui, include/binder). You can run this code for find your system root:
echo "#include <bogus.h> int main(){}" > t.c; GCC_OR_CLANG_BINARY_LINK -v t.c; rm t.c
Erors printed all paths where compiler search include files.
or use --sysroot=YOUR_PATH for set your path.
3) Add flags -Wl,--unresolved-symbols=ignore-all for ignore errors and --target=armv7-none-linux-androideabi23 (23 or other) for set target version.
Full my clang command:
/Users/macbookair/Documents/test/bin/clang -fPIE -pie fast-screen-capture.cpp *.so -o ./screencap --target=armv7-none-linux-androideabi23 -Wl,--unresolved-symbols=ignore-all -s
Successes!

Cross Compiling PALSIADE for android

we are trying to build PALISADE (https://git.njit.edu/palisade/PALISADE) for Android. We have made some Progress by building “gmp” and “ntl” successfully for Android.
GMP is able to cross compile out of the box. NTL was a bit more tricky. We used https://github.com/nemirst/ntl-android but changed the headers and src to the version provided within PALISADE (10.5.0)
We also did some changes to the PALISADE makefiles so they support cross compiling using the android standalone toolchains. The issue is now, when trying to compile PALISADE using the cross compiled NTL and GMP lib we get the following errors:
PALISADE/bin/build/toolchains/aarch64-linux-android/bin/aarch64-linux-android-gcc --sysroot=PALISADE/bin/build/toolchains/aarch64-linux-android/sysroot -g -Wall -Werror -O3 -fopenmp -pthread -I src -Isrc/core/lib -Isrc/pke/lib -Isrc/abe/lib -Isrc/signature/lib -I test -I /opt/local/include/libomp -fopenmp -I third-party/include -I third-party/include/rapidjson -c -o bin/build/core/lib/math/benative-math-impl.o src/core/lib/math/benative-math-impl.cpp
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:956:79: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
return (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:192:33: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimized' requested here
InputToFFT[i]=element[i].ModMulPreconOptimized((*rootOfUnityTable)[i],modulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
In file included from src/core/lib/math/benative-math-impl.cpp:36:
src/core/lib/math/transfrm.cpp:107:48: error: too many arguments to function call, expected 4, have 5
preconRootOfUnityInverseTable, cycloOrder, ans);
^~~
src/core/lib/math/transfrm.cpp:300:38: note: in instantiation of member function 'lbcrypto::NumberTheoreticTransform<native_int::NativeVector<native_int::NativeInteger<unsigned long> > >::InverseTransformIterative' requested here
NumberTheoreticTransform<VecType>::InverseTransformIterative(element, *rootOfUnityITable,
^
src/core/lib/math/transfrm.h:67:3: note: 'ForwardTransformIterative' declared here
static void ForwardTransformIterative(const VecType& element, const VecType &rootOfUnityTable, const usint cycloOrder, VecType* result) {
^
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:975:88: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
this->m_value = (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:313:21: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimizedEq' requested here
(*OpIFFT)[i].ModMulPreconOptimizedEq((*rootOfUnityITable)[i],nativeModulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
3 errors generated.
make[1]: *** [bin/build/core/lib/math/benative-math-impl.o] Error 1
make: *** [all] Error 2
We would greatly appreciate any help in getting this library to build for Android.
EDIT: Spelling
This is a little late in response, but if you are still interested, newer versions of Palisade do not require GMP or NTL (those are only enabled when the user explicitly enables them in the CMake build process), so it may be easier to build now. You should be using the newest stable version at https://gitlab.com/palisade/palisade-release or if you are willing to try it out, the development version at https://gitlab.com/palisade/palisade-development
Cross compiling is a bit tricky, but it can be done. We are working on some embedded targets but they are not yet in the release stream.
We are looking into supporting an Android port in a future release, so any progress you make that you can share with us is most appreciated.
Dave Cousins -- PALISADE Development team.

Build command failed on telegram

I got this error on the last version of the telegram.
telegram source code version: 4.9.0
envirement :
ubuntu 17.10.0
android studio:3.2 canary 9
ndk version: 14.1.3816874
[armeabi-v7a] Compile++ arm : tmessages.28 <= TgNetWrapper.cpp
/home/joker/telegram490/TMessagesProj/jni/./jni.c: In function
'listdir':
/home/joker/telegram490/TMessagesProj/jni/./jni.c:193:31: error:
'struct stat' has no member named 'st_atim'
if (attrib.st_atim.tv_sec != 0) {
^
/home/joker/telegram490/TMessagesProj/jni/./jni.c:194:35: error:
'struct stat' has no member named 'st_atim'
if (attrib.st_atim.tv_sec < time) {
^
/home/joker/telegram490/TMessagesProj/jni/./jni.c:198:35: error:
'struct stat' has no member named 'st_mtim'
if (attrib.st_mtim.tv_sec < time) {
^make: ***
[/home/joker/telegram490/TMessagesProj/build/intermediates
/ndkBuild/afat/
debug/obj/local/armeabi-v7a/objs-debug/tmessages.28/./jni.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from
/home/joker/telegram490/TMessagesProj/jni/./tgnet/TLObject.h:13:0,
from
/home/joker/telegram490/TMessagesProj/jni/./tgnet/ApiScheme.h:15,
from
/home/joker/telegram490/TMessagesProj/jni/./TgNetWrapper.cpp:2:
/home/joker/telegram490/TMessagesProj/jni/./tgnet/Defines.h: In
function 'std::string to_string_uint64(uint64_t)':
/home/joker/telegram490/TMessagesProj/jni/./tgnet/Defines.h:184:32:
error: expected ')' before 'PRIu64'
int len = sprintf(buf, "%" PRIu64, value);
Edit:
thanks to #anubhav-gupta, Through SDK Manager, I can only upgrade to version r18-beta1.
after the upgrade I face up with this error:
Android NDK: APP_STL gnustl_static is no longer supported. Please switch to either c++_static or c++_shared
Edit:
update NDK to r15 and The problem was solved.
The main problem is in this line 'struct stat' has no member named 'st_atim'
If you're using a modern version of the NDK, you'll have a modern struct stat: https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/stat.h
Note that you need to be using the NDK's unified headers to get the up to date headers. This is the default in r15, but opt-in for r14.

Error while compiling android 3.10 kernel source

Recently I tryed to crosscompile android kernel for my xiaomi mi4c.
To do this I have downloaded and configured toolchain like this:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b marshmallow-release toolchain64
export ARCH=arm64
export SUBARCH=arm64
export CROSS_COMPILE=`pwd`/toolchain64/bin/aarch64-linux-android-
then I cloned kernel source from here: https://github.com/AndropaX/android_kernel_xiaomi_msm8992
and do this:
make clean && make mrproper
make ARCH=arm64 resurrection_libra_defconfig
make ARCH=arm64 CROSS_COMPILE=$CROSS_COMPILE -j3
Then I have an error:
In file included from include/linux/kernel.h:14:0,
from include/linux/sched.h:15,
from /home/owner/android_kernel_xiaomi_msm8992/arch/arm64/include/asm/compat.h:25,
from /home/owner/android_kernel_xiaomi_msm8992/arch/arm64/include/asm/stat.h:23,
from include/linux/stat.h:5,
from include/linux/module.h:10,
from drivers/tspdrv/tspdrv.c:26:
drivers/tspdrv/ImmVibeSPI_ISA1000.c: In function 'ImmVibeSPI_ForceOut_SetSamples':
include/linux/dynamic_debug.h:64:16: error: implicit declaration of function 'KBUILD_STR' [-Werror=implicit-function-declaration]
static struct _ddebug __aligned(8) \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
<command-line>:0:27: error: 'tspdrv' undeclared (first use in this function)
include/linux/dynamic_debug.h:66:14: note: in expansion of macro 'KBUILD_MODNAME'
.modname = KBUILD_MODNAME, \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
<command-line>:0:27: note: each undeclared identifier is reported only once for each function it appears in
include/linux/dynamic_debug.h:66:14: note: in expansion of macro 'KBUILD_MODNAME'
.modname = KBUILD_MODNAME, \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
drivers/tspdrv/tspdrv.c: At top level:
drivers/tspdrv/tspdrv.c:94:37: fatal error: tspdrvOutputDataHandler.c: No such file or directory
#include <tspdrvOutputDataHandler.c>
^
cc1: some warnings being treated as errors
compilation terminated.
So, the question is, what am I doing wrong? Maybe I need another toolchain for crosscompilation? Can sombody suggest one? I dont think there is an error in the kernel code. So what can go wrong?
So, after a few days I found the answer. Thanks to kay2777 from 4pda.
Look for KBUILD_CFLAGS in the main Makefile, and add the following to suppress warnings as errors:
KBUILD_CFLAGS += -w
// if all errors are to be suppressed
KBUILD_CFLAGS += -Wno-error=unused-but-set-variable
// if that specific error is to be suppressed.

android source build fails: undeclared identifier 'ftruncate'

I wanted to build the android source code by using this documentation:
https://source.android.com/source/building-running.html
last step was: 'make -j16'
After a while the compilation is aborted with the following error message:
host C++: libart <= art/runtime/catch_block_stack_visitor.cc
host C++: libart <= art/runtime/catch_finder.cc
art/compiler/elf_stripper.cc:122:16: error: use of undeclared identifier 'ftruncate'
int result = ftruncate(file->Fd(), offset);
^
1 error generated.
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libart-compiler_intermediates/elf_stripper.o] Fehler 1
make: *** Warte auf noch nicht beendete Prozesse...
I have no idea.
Google did not help and I am really not into this topic, just wanted to do a little change to the android code (I have not changed anything yet).
My system is:
ubuntu 13.10
java 1.6.0_4
current android master branch
You could avoid this problem by adding
#include <unistd.h>
at the beginning of elf_stripper.cc

Categories

Resources