[Q] ndk-building does not link stdio properly? - General Questions and Answers

I am working with some large open source projects and some smaller custom C code. I can successfully compile and link these using the ndk-build API even when linking against shared object files within the Android tree. I get functional shared object files and executables for the Android platform. However, it seems that when the applications are built as stand alone (meaning outside the Android source code tree using only ndk-build) the stdio functions do not operate properly. When the same code is placed under external within the Android source code tree and built with Android, the stdio functions work exactly as expected.
I have tried building with ndk r4 and r6, then we tried building with the ndk r4 from within the Android tree. (2.2.1)
the functions in question are
close() - hangs a process when the process is forked
fprintf() - nothing gets written
fopen() for write - the file does not get created as a new file
remove()
unlink()
etc.
I have not tested beyond these functions.
The question is why does the stand alone built code not function properly while the same code built within the Android tree executes properly?
Any insight would be greatly appreciated.
Thanks,
Adam

Edit your post and add a meaningfull thread title.

additional info
Seems in particular that close(0), close(1), and close(2) cause a process hang when fork() is used.
When built with Android code under the external directory, everything works as expected.

Related

Modifying android OS original source code

Okay so I'm looking to modify the original filesystem code how would I go about this by searching a certain string I've seen on one of the warning dialogs ?
Sent from my Nexus 7 using Tapatalk HD
Well if you pulled the aosp codebase then your gonna just have to know where to look, but its pretty easy to find what your looking for
most everything is in frameworks/base and hardware folders
Sent from my Nexus 4 @1.72 GHz on Stock 4.2.2
If you are in *nix and the string is fairly unique, you could try a grep search. At the very least, doing a search like that should narrow down the location of the files you are looking for.
If you've got the aosp sources then resgrep should sort you out which is a command in the android "build environment" . after running . build/envsetup.sh type "hmm" , this gives you a list of all the "aosp" functions
Code:
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
[B]Look at the source to view more functions. The complete list is:[/B]
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype
choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot
getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home
key_menu lunch _lunch m mangrep mm mmm pid printconfig print_lunch_menu resgrep runhat runtest set_java_home
setpaths set_sequence_number set_stuff_for_environment settitle smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump
If find godir pretty useful for traversing the sources.
If you haven't got the aosp sources then androidxref.com is the place to look, they offer fully indexed sources of all the major releases of android and also the main branches of the android kernel.
hope that helps :good:
Test-Bump

[FAQ/HOWTO] An introduction to how-to-build a kernel for MT6589

Hi guys,
I was working on this since some time and here it is
Please read FAQ first
FAQ :
Can I compile a MT6589 kernel for every phone ?
As you know, a MT6589 kernel won't fit in every MT6589 smartphone because of specific configs/files in the kernel source tree.
So, if you compile my kernel which is expected to work on a Faea F2S don't expect it to work on a Acer Liquid E3 for example.
Conclusion : You have to get the kernel source for your phone​
How can I check my kernel source ?
Of course, this is not enough to see "source code for ZTE N986", you have to check if it's full or not and if it works.
Most people don't know what is working kernel source. You just have to read the GPL guidelines that every manufacturer have to complain with :
“ The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. ”
The part which has not to be included is the toolchain but there should reference to it (which toolchain to use)
For MT6589 kernel, the toolchains arm-eabi-4.6 and arm-linux-androideabi-4.6 should be used. (mtk used arm-linux-androideabi-4.6 for kernel but it should be arm-eabi-4.6)
So now you know which toolchain to grab and then for kernel source you have to check this minimal structure :
bionic
kernel
mediatek
build
config
custom
kernel
platform​README​
If I have kernel source, can I build it for my device ?
Erm... Sometimes the structure is here but the kernel source is messy... Why ?
Because you were not provided the matching source of the kernel used on your smartphone and the reasons are multiple (I won't give details).
So, the idea is to run a first build. If you get errors, then check the step above about toolchain and structure.
The next step for fixing errors is to play with source. Good luck for that.​
What are the benefits of a custom kernel for MT6589 ?
First big benefit is to introduce kitkat compatibility because there was an issue on android binder driver in mtk kernel source.
Next benefit is to be able to remove some stuff from mtk which is useless on user side and waste ressources (a lot of debug for example).
Others benefits will be in optimizations or new features (see frandom for example)​
HOWTO :
Build from my repo (specific devices supported) - It's not for compiling your kernel source but to understand how kernel build works​I explain how to build from my repo first because it can help you to understand how you should build kernel source
Prerequisites : A build environment (actually Ubuntu Saucy x64 with build-essentials, ccache, repo, java, perl v5.14+ and openssl) and I won't explain how to get one as there is multiple howto on the net.
For repo, the idea is to create a bin directory in your $HOME (usually /home/accountname/), copy repo binary inside it and then add this bin to $PATH var.
BE CAREFULL TO WHAT YOU DO WITH $PATH VAR ! I always see people doing :
Code:
export PATH=/home/foo/bin
this is erasing $PATH var, just check before and after with echo $PATH
So the idea is to introduce your path AFTER the actual $PATH var
This is easy...
Code:
export PATH=[COLOR="red"]$PATH:[/COLOR]/home/foo/bin
And of course, $PATH is reset once you close terminal and I won't explain how to set $PATH automatically.
Once you got this, everything should be working and it will be easy
Code:
mkdir workdir
cd workdir
repo init -u https://github.com/Dr-Shadow/android_kernel_mt6589_manifest.git -b master
repo sync
Then you should get this in your workdir :
kernel
manifest
mtk-tools
out
ramdisk
scripts
toolchain​Just do :
Code:
cd kernel
./certificates.sh
./build.sh
./certificates.sh is needed only once (it's for signing flashable zip and it will setup some keys for it, just reply to questions and don't add passphrase)
And of course, the build.sh contains most things you need to know on steps for building kernel (which commands to use) and you need to know how it works ​Build from your own kernel source​
I'm building the doc... I have to remind which vars need to be overriden
Reserved
Reserved #2
Thanks for making this thread brother it will help us to learn... Subscribed
Looking forward to the how-to to build with your own kernel source.
Dr-Shadow said:
Hi guys,
I was working on this since some time and here it is
Click to expand...
Click to collapse
Thank you Dr-Shadow! This is very cool. I'm going to try it out!
Great
It's always nice to see further development on MTK Based Devices.
Regards
I'll chip in and say thanks too. Finally getting around to trying to compile Alcatel's OneTouch Hero (aka TCL Y910) provided sources.
I might be in as well with A820, but I'm relatively new to Android and have only done porting of 4.1 and 4.2 so far.
Haven't built anything although I have some knowledge about the source code and SDK, which I've only used for reference purposes and the tools from it.
Will try to compile the stock kernel this weekend, but I'm not quite sure if something else is needed, even if the kernel source seems complete to me.
I'm a quick learner and have a lot of programming experience in other technologies, even thought I'm more of a front-end developer these days.

Adding files to Android ROM source

Hello! I've just used phh's Treble Build script to sync and build a GSI ROM, but now I would like to add/modify some files in the source files, specifically in regards to the ROM apps (packages/apps/). I suspect that I cannot just drop the source files of the new apps in there without the build script complaining (uncommited changes in repo sync or something like that), so how can I add the files in there? And do I need to specifically tell the build script to compile the new files? Thank you!
"Android source code has apps under the path packages/apps/, likewise services are located under packages/services, etc.
To add an application to your compiled Android build, you need to
Make a new dir under packages/apps/ for your app, eg. MyNewApp
Add your app source code into that dir
To tell the build process about the app available to build and it's properties (here you have flags for src path, resource path, location to ship in system, shared libs, etc) Android.mk/Android.bp is used. You can refer to Android.mk from other apps under packages/apps/ to get an idea.
Blueprint or .bp is a new soong build system that is in process to replace Makefile-based system/Android.mk (src: AOSP)
Add 'MyNewApp' entry to 'PRODUCT_PACKAGES' flag under your target device tree makefile (device/<vendor>/<model>/) or if you want it to build globally into system, you can add the entry to 'PRODUCT_PACKAGES' under build/target/product/."

Toolchain and kbuild config help

Hello I have been trying to extract the kernel from Tucana android 10 source. I would like to know if anyone has a working config to be able to build up the kernel.
I have a config but it does not extract everything, well I don't think it does and would like to know what toolchain is best for Xiaomi devices. Been using Google's AOSP toolchain from pre-builts and I can build the kernel. It becomes 16mb for Image.gz-dtb I flash it using fastboot boot Image.gz-dtb and phone boots to splash screen but does not go any further. Is it normal?
This thread has the config and information https://forum.xda-developers.com/t/my-experience-building-the-tucana-kernel.4240985/
I think this is the solution
How To Use
Xiaomi Mobile Phone Kernel OpenSource. Contribute to MiCode/Xiaomi_Kernel_OpenSource development by creating an account on GitHub.
github.com
Taken from above source link.
need this in order to get the device files for the xiaomi mobile of your choice in the android revision branch of your choice.
Dont think I can use AOSP untill i use this to first get the kernel files built and then able to use the same files with AOSP.
Download Qualcomm Android Enablement Project​
Acutally, this step is optional. But this project integrates many tools such as cross compiler which are required for building our kernel. Of course you can use your own tools to compile kernel, but it may be a tough work to configure.
You can download the whole QAEP on Codeaurora
Can indeed confirm that you need the project from Codeaurora instead of AOSP. it has the platform SM6150. over 100+GB download though.
Make sure when after choosing the release branch with your device and about to sync. only use a max of 3 processors. no more then 3. Codeaurora has a bandwidth limiter. so the more you have the longer it will take.
Tested the theory myself.
Downloaded first time, took 9 hours with max -jN then restricted the -jN to -j3, process for over 100GB took only an hour.

Matching a kernel's config for compatible kernel modules

I have:
Downloaded the exact kernel version running on my device from an AOSP mirror (4.9.170) (https://github.com/aosp-mirror/kernel_common.git)
Downloaded the exact compiler used to compile the kernel from my device:
Ran `cat /proc/version`, which returns "Linaro GCC 5.3-2016.05", which I downloaded from https://releases.linaro.org/components/toolchain/binaries/5.3-2016.05/aarch64-linux-gnu/
Took the kernel configuration from `/proc/config.gz`, copied it to the kernel source directory `kernel_common` as `.config`
Ran `make ARCH=arm64 CROSS_COMPILE=xxx oldconfig`
What I'm seeing:
First, the downloaded kernel source for 4.9.170 seems to think that my `config` is incomplete, since it will prompt me to answer ~15 extra configuration questions.
Second, this old Linaro compiled doesn't appear to support `-fstack-protector-strong` despite it being explicitly enabled in the `/proc/config.gz` file. So I end up disabling it with `./scripts/config --disable CONFIG_CC_STACKPROTECTOR_STRONG`
Finally, after successfully compiling, I take `net/ipv4/tcp_westwood.ko`, just as a test module, and try to load it on my Android device, and it fails:
`insmod: failed to load tcp_westwood_5.ko: Exec format error`
And in dmesg output: `tcp_westwood: disagrees about version of symbol module_layout`
My questions:
Can I assume that the `/proc/config.gz` file is not the actual file used to compile the running kernel, considering it doesn't completely configure the 4.9.170 kernel?
Am I on the right path to getting a kernel module that my kernel will load?
Background information:
I'm hoping this isn't very relevant, but just to head off some questions
This is a T95 Android TV device running what appears to be, to this newbie's eyes, a very Frankenstein'd Android 10 install (See https://www.cnx-software.com/2020/0...-comes-with-mali-g31-gpu-supports-android-10/)
I can't find any official - or unofficial - source for this device, which is why I'm going to all the trouble above.
I really appreciate any help, thank you!

Categories

Resources