Building arm64-v8a ndk toolchain to run on device - Android Q&A, Help & Troubleshooting

Now I know I've done this before. But I think I had to make an entire Application.mk file. I am trying to use either the Windows or Linux NDKr19 to build a standalone toolchain that contains ONLY the arm64 executable binaries. (essentially "aarch64-android-android" or "aarch64-android-arm64-v8a")
EDIT: So I'm dumb and figured it out. I've attached the binaries that can run on the device.

Related

[Q] kernel modules for ICS, 2.6.39.4, error loading module

Hi there,
I would have posted this in /dev but you know...first post.
I was trying to apply these kernel modules: http://forum.xda-developers.com/showthread.php?t=1557868
but I'm getting the error "insmod: init_module '/system/lib/modules/cifs.ko' failed (Exec format error)", or if i use the busybox insmod i get the following error: "insmod: can't insert '/system/lib/modules/cifs.ko': invalid module format"
Are updated versions available for 2.6.39.4? I'm guessing the ones for 2.6.36.3 aren't inter-operable.
I haven't used the other bash-4.2.zip and config from the above link, is that necessary for this to work?
Thanks for any tips on getting these kernel modules working.
Thanks,
abactor
IRC channel
Is there an IRC channel that's in use for sony tablet S, by any chance?
compile module yourself?
You might be successful compiling the kernel modules yourself from the available source code and a crossplatform compiler on linux. It has worked for me for the tun module
Source code at sony.net, I cannot publish external links yet. But you can find the link e.g. in this thread at first page http://forum.xda-developers.com/showthread.php?t=1473621
The free Sourcery G++ Lite for ARM GNU Linux did a good job for me.
I don't know of any Tablet S IRC channels, but it would be cool if there was.
As for the modules, you do need to recompile it. Kernel modules (in practically every Linux flavour) are completely incompatible, even across minor revisions, but recompiling against the newest code and headers should yield the same result with a new module.
The Sony.net link walsera mentioned is (I believe) this one
Thanks guys,
I'll look into it. I've compiled c code for android under mingw, but I don't have a linux toolchain setup. Anyone try to compile these sorts of things on the device itself (I.e. not cross_compiled)? I just started playing around with a native android/arm gcc toolchain, but I was having linker issues I think, with crt0.o and libc and whatnot.
Thanks and take care,
Abactor
I've never tried it natively on the device, but there have been a couple of developments into native versions of gcc and whatnot, so that may be worth a look. You can always compile on your PC, then copy the ko over...
After mounting a debian chroot on the tablet and installing the needed tools, unpacking the kernel source, and copying over config.gz, and editing .config to build the needed modules then calling make modules everything seems to work. What's the best way to make them available and what modules do people need? I've done ntfs and tun so far.
Take care
A

[Q] Help Running a C++ Application via Terminal

I have a C++ Application that work on Ubuntu/any Distro via Terminal, And all what i want is to run it on my Android.
I have a Compressed file of the source code, So if i Followed these:
HTML:
cd /src
make
it will work on Ubuntu like a charm, now the thing i Copied this to my Droid, i had some problems with noexec, so i moved it to /data/tmp and now i don't have this issue anymore, now i get an "Magic 7F bla bla.." Error, I Think this because the source code has been compiled for Intel Architecture, so how can i Compile it for ARM?:crying:

Building lz4 compression util for Android's ADB?

Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
kdar1987 said:
Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
Click to expand...
Click to collapse
If you want to build it for unnoficial devices such as the ones youve listed, follow any tutorial to download the CyanogenMod source (or other rom that supports those) and after lunching the device you want to build for, run 'make liblz4'
For device-independent tools like lz4, you can also lunch for some generic device with a matching CPU architecture.
And you need "make lz4" if you want the CLI tool.
kdar1987 said:
Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
Click to expand...
Click to collapse
It's ndk build/aosp build env methods aren't straight forward to make it a binary, only a lib, so i went ahead and compiled it into a binary. I didn't test it or anything, just compiled it statically for arm.
I tried using this and got
: Error 65 : Allocation error : not enough memory
Would this be because the program was built for 32-bit and my tablet is 64-bit? Can anyone tell if that message is from the system, that the program never loaded; or if that message is being printed by the program?

[REFERENCE] My experience building the Tucana kernel & Rom

Little info on what this all is.
If you are expecting a working kernel or rom after reading this all. That is not what this thread is.
What this all is intended for is material to help with getting you to the next step, if you are at a road block.
What will you gain from all this?
A fair bit of knowledge on working with msm-4.14 kernel and maybe others.
Make sure to have your search bar ready with a piece of the issue (key word of the error will do) and go through the hidden tabs until you pick up your error, with the browser search function (ctrl+f on most browsers)
Spoiler: OLD info
Method I used for building the kernel
1. Dowload AOSP common-kernel-4.14 through git
OR
ANDROID 10 Specific
refs/heads/q-common-android-4.14 - kernel/manifest - Git at Google
2. Download Xiaomi TUCANA-Q-SOURCE for android 10 source code from MiCode git.
ALL VARIANTS
GitHub - MiCode/Xiaomi_Kernel_OpenSource: Xiaomi Mobile Phone Kernel OpenSource
Xiaomi Mobile Phone Kernel OpenSource. Contribute to MiCode/Xiaomi_Kernel_OpenSource development by creating an account on GitHub.
github.com
**OR**
TUCANA Android 10
GitHub - MiCode/Xiaomi_Kernel_OpenSource at tucana-q-oss
Xiaomi Mobile Phone Kernel OpenSource. Contribute to MiCode/Xiaomi_Kernel_OpenSource development by creating an account on GitHub.
github.com
3. extract if you did not use git to download sources.
You will need AOSP 10 R29 downloaded. R29 Matches Stock MIUI 12.0.4
4. mkdir kernelbuild (can be what ever) then extract both AOSP KERNEL (git) ,build, common, kernel, prebuilts, master-prebuilts folders to the kernelbuild folder.
5. just use TUCANA source and don't merge with AOSP common source. Don't delete common either
4. copy AOSP kernel folder (contains 4.14) to TUCANA source and merge (Still not sure if you need to do this)
5. make sure you have AOSP-10 from git already. If not, repo it.
6. Go to AOSP-10 REPO>prebuilts>gcc>linux-x86>aarch64 location and get (aarch64-linux-android-4.9) folder and copy it to root Tucana source files folder make a directory call toolchain TUCANA source. in prebuilts>gcc>linux-x86>aarch64 folder replace and merge all
7. Not sure if this is outdated but got the export info from MSM section at https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki/How-to-compile-kernel-standalone
e.g.
export CROSS_COMPILE=/<toolchain-location/prebuilts>GCC>/bin/aarch64-linux-android-
mkdir out
cd out
Taken from mi code section for MSM 4.14
export ARCH=arm64
export SUBARCH=arm64
export DTC_EXT=dtc
Set CONFIG_BUILD_ARM64_DT_OVERLAY=y
(does not work from what i can tell. Have to enable using menuconfig)
if not inside the "out" folder use O=out on next command, will also have to type cd ../ to go back in source if using this command.
(-jN (N is for a number))
make -jN tucana_user_defconfig
make menuconfig (configure config to your liking)
use save button (highlight save and press enter, can use arrow key right and left as well)
make -jN
Or it could be
make -jN ARCH=arm64
After doing all this, for me the build fails. Its driving me insane!
I think I also was using the wrong AOSP kernel, was using common-4.14 and now using this one
refs/heads/q-common-android-4.14 - kernel/manifest - Git at Google
guessing the Q is for Android 10
MY DEMON!!!!!
1615228944041.png
i think it is not working because i am using Android 10 R41 and should be using Android 10 R29. Testing it now.
Alright, went from ubuntu version 20 to 18 (Bionic is more reliable and easier to set up).
Had 20, due to bionic auto updated (my own fault).
Version 20 does work with some modding and adding bionic to the repo's of ubuntu.
I tried using AOSP toolchain and also Qualcomm's (QQ-LLV) LLV toolchain 8.0 for clang.
The part from MiCode wiki on github is saying to use CLANG_Triple with aarch64-linux-gnu which I can not find this file anywhere.
Not in QQ-LLV, AOSP-10-R29 aarch64 that is located in prebuilts > gcc
so the main problem I am getting is the cpu timer failing, during the build process. I try to modify the config by typing "make menuconfig" and then change the cpu govern type from performance to ondemand and saving it as .config (not sure if it is supposed to be the same name as the tucana-user-defconfig, let me know if this is the problem)
the AOSP android version I am using is R29. The AOSP kernel I am using is common-4.14
none of these files have aarch64-linux-gnu.
I am starting to slowly give up on this whole thing. spent 7 days just to get a cpu timer problem during build.
Oh and the source i am using is from Micode github under tucana for android 10 (Q)
Just sprung up an idea. I think i am supposed to first use Qualcomms LLVM toolchain 8.0 with the Mi source code package to make up the files needed in order to use anything from AOSP. please let me know if this is correct.
No matter what guide i find for it, it shows CLANG_TRIPLE=aarch64-linux-gnu- and every time. it just can not find it. no idea how to get this.
it work in clang triple for -gnu
AOSP-Q-Kernel-4.14.117
refs/heads/q-common-android-4.14 - kernel/manifest - Git at Google
Spoiler: Kbuild config
ARCH=arm64
SUBARCH=arm64
BRANCH=android-4.14
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=aarch64-linux-android-
DEFCONFIG=tucana_user_defconfig
KERNEL_DIR=xsource
DTC_EXT=dtc
DTS_EXT=dts
CC=clang
LZ4_RAMDISK=1
POST_DEFCONFIG_CMDS=""
EXTRA_CMDS=''
CLANG_PREBUILT_BIN=prebuilts-master/clang/host/linux-x86/clang-r353983c/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
REAL_CC=prebuilts/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang
BUILDTOOLS_PREBUILT_BIN=build/build-tools/path/linux-x86
FILES="
O=/out
arch/arm64/boot/Image.gz
vmlinux
System.map
"
STOP_SHIP_TRACEPRINTK=1
OMFG!!!!!!! VICTORY!!!!!!!!
I think.
1615380568663.png
MAYBE!!!!!
1615380671546.png
Spoiler: New info
Alright Managed to fix most of the problems in the OLD area, mostly due to path issues, always check your paths (PATH).
Spoiler: build.config
ARCH=arm64
SUBARCH=arm64
BRANCH=K4.14Q
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=~/android/xkernel/tsource/toolchains/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
CROSS_COMPILE_ARM32=~/android/xkernel/tsource/toolchains/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-
KBUILD_DEFCONFIG=~/android/xkernel/tsource/arch/arm64/configs/tucana_user_defconfig
DEFCONFIG=tucana_user_defconfig
POST_DEFCONFIG_CMDS="check_defconfig"
DTC_EXT=dtc
DTC_PREBUILTS_BIN=/scripts/dtc
KBUILD_OUTPUT=out
HOSTCC=gcc
CC=clang
AS=clang
AR=ar
CLANG_PREBUILT_BIN=/toolchains/clang/host/linux-x86/clang-r353983c/bin
BUILDTOOLS_PREBUILT_BIN=/toolchains/build-tools/linux-x86/bin
FILES="
arch/arm64/boot/Image.gz
vmlinux
System.map
"
Don't know if most of what is in there is needed or if everything I need is there but that is what i have so far.
One thing that i know always does not work is the check_defconfig. fails to match every time.
Tried using ld.ldd and it just keeps saying the vmlinux file size is too large. I have not given up and can say i have learned a lot.
Will update more as I go.
Spoiler: Links
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...
forum.xda-developers.com
[SOLVED] dts not found
Hello. Been working on how to get a device kernel from source for the Mi note 10 pro (Mi CC9 Pro). I have gotten up to the point where it builds but fails due to dts folder is not found. I need an example of what goes in DTC_EXT= All I see on...
forum.xda-developers.com
Spoiler: UPDATE 2022 WORKING BUILD WITH ISSUES
Alright I decided to give it another shot in 2022 because of getting replies.
1. Get your source from device brand. (https://github.com/MiCode/Xiaomi_Kernel_OpenSource)
2. Use Mi code wiki to learn how to build (https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki)
3. Go right hand side for standalone kernel. Because the how to section just waste hours on end with nothing built and Soong and clang errors.
4. Follow msm-4.14 for a guide. (https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki/How-to-compile-kernel-standalone)
5. Make sure to have dtc binary file from aosp source (https://android.googlesource.com/platform/prebuilts/misc/) choose your android version. Check device for android version. Can use CPU ID in playstore under System, section API LEVEL.
6. Get llvm Snapdragon from Qualcomm. (https://developer.qualcomm.com/software/snapdragon-llvm-compiler-android) I used both but you should be able to use 8.0. both have off same results during the build process.
7. Get Aosp gcc
(https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/)
8. Put LLVM Snapdragon toolchain and AOSP gcc into a folder in root of kernel folder called toolchain.
9. Run the script mi provided. Change the 6.0 on the last 2 make commands to 8.0 unless you are already using 6.0, then you can leave it at 6.0.
10. Build.
11. Get a boot.img extractor from github or on these forums. I can't recommend one yet, due to not having full success. Can search boot.img extractor or boot.img unpacked as seperate search terms.
**Recommendation**
Boot and Recovery
GitHub - xiaolu/mkbootimg_tools: Unpack and repack boot.img,support dtb(dt.img).
Unpack and repack boot.img,support dtb(dt.img). Contribute to xiaolu/mkbootimg_tools development by creating an account on GitHub.
github.com
OR
Android Kitchen
GitHub - osm0sis/Android-Image-Kitchen: Automated scripts to unpack/repack Android kernel/recovery images + ramdisks
Automated scripts to unpack/repack Android kernel/recovery images + ramdisks - GitHub - osm0sis/Android-Image-Kitchen: Automated scripts to unpack/repack Android kernel/recovery images + ramdisks
github.com
OR
Android Kitchen
GitHub - cfig/Android_boot_image_editor: Parsing and re-packing Android boot.img/vbmeta.img/payload.bin, supporting Android 13
Parsing and re-packing Android boot.img/vbmeta.img/payload.bin, supporting Android 13 - GitHub - cfig/Android_boot_image_editor: Parsing and re-packing Android boot.img/vbmeta.img/payload.bin, supp...
github.com
12. Extract boot.img from stock rom.
13. Put image.gz.dtb in unpacked boot image. Delete original file and rename new one as the same name.
14. Repack boot.img and either upload using fastboot or use twrp to install the boot.img
The problem I have at the moment is I am unable to use touch input at all. It boots loads system but can't touch anything. No input at all. Hardware buttons work though.
Might be solution on 3rd post to no touch input. https://forum.xda-developers.com/t/reference-how-to-compile-an-android-kernel.3627297/page-43
VMLINUX FIX: HERE
Hi @Squida, I've also been on this road, I just hit a milestone when I actually have something booting (but not much working), see the thread I started if it works for you too
b100dian said:
Hi @Squida, I've also been on this road, I just hit a milestone when I actually have something booting (but not much working), see the thread I started if it works for you too
Click to expand...
Click to collapse
Spoiler: Reply
Hey mate, thanks for the reply. Could you put a link to your thread so I can check it out.
Found it: https://forum.xda-developers.com/t/building-lineageos-17-1-from-source.4245417/
I also have posted on Qualcomm forums.
LINK: https://developer.qualcomm.com/forum/qdn-forums/software/snapdragon-llvm-compiler-android/68403
I found out qcomm has its own builder for msm devices. It's known as QAEP. I have been trying to build the sm6150 with Tucana defconfig. The thread above is the issue I have in trying to build it. No idea how to get "SDClang" so as soon as I work that out. It should build with QAEP instead of using AOSP.
There's a commit where I add SDCLANG support (but I don't think that's needed, is backed out atm) https://github.com/alibei/android_d...mmit/efbb3c66aa0d385e58052675402489c13392576e )There's a similar commit in the kernel.
You need to register to Qualcomm to download it, and unzip it in kernel/toolchains, just as https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki/How-to-compile-kernel-standalone says under "You must get llvm clang from qcom". You just have to get the 8.x version.
Some snippets for the commands I've tried https://gist.github.com/b100dian/40c8dbe746ff181aff71ee10a75a5f3c
Spoiler: Reply
Yeah I am not trying to use Lineage sources. so far steps I have taken are as follows.
1. Mi source code download of Tucana android 10, data source, wifi source, audio source.
2. Extracted Mi tucana source in a directory (also tried the git way to update CAF tags).
3. using AOSP as the source for build. I tried using Clang with cross compile with gcc (GNU)
4. with using all AOSP toolchains so clang and gcc from AOSP and then using LLVM clang as reall cc, due to it does not contain clang itself.
all that for kernel and it builds but I feel its missing drivers. due to the warnings that Qcom gives. also got wifi modules installed but not audio. Audio source is a little different then the wifi source.
For the proprietary binaries. I used lineage Extract script with the lineage 17.1 tucana proprietary-files.txt list.
extraction worked on miui_TUCANAGlobal_V12.0.4.0.QFDMIXM_be49be8fa0_10.0.zip.
but of course the device tree is missing, found the platform sm6150 device tree on QAEP. so now trying to use QAEP to build not only the kernel but the rom as well using QAEP instead of AOSP. think we need to use QAEP, then using the files built. can then move over to aosp for upgrading, etc.
Could you explain this error considering you managed to get SDClang working. it may solve my problem. error provided below.
Spoiler: sdclang error
I have a SDCLANG_PATH set in BoardConfig.mk in the commit I pointed to earlier.
Basically is from a toolchains folder creaded with `tar -xvzf snapdragon-llvm-8.0.6-linux64.tar.gz` in the kernel/xiaomi/tucana folder
b100dian said:
I have a SDCLANG_PATH set in BoardConfig.mk in the commit I pointed to earlier.
Basically is from a toolchains folder creaded with `tar -xvzf snapdragon-llvm-8.0.6-linux64.tar.gz` in the kernel/xiaomi/tucana folder
Click to expand...
Click to collapse
what i have setup in boardconfig is as follows.
ifneq ($(HOST_OS),linux)
SDCLANG := true
SDCLANG_PATH := toolchain/ndk/android-ndk-r22/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin
SDCLANG_LTO_DEFS := device/qcom/common/sdllvm-lto-defs.mk
endif
this has been added just above wifi. still fails with same error.
Spoiler: Boardconfig.mk
Image:
I think I just solved it, so i noticed you talk about Boardconfig.mk and when i checked out your git code, it had in the same config the target. well QAEP is a little different it not only has a Boardconfig file but also a AndroidBoard config file. so i think i am supposed to be adding it in there instead of Boardconfig. testing it now.
Spoiler: AndroidBoard.mk
Something else i also noticed that is not working.
Spoiler: .ko files missing
And can confirm above configuration changes are not working, not sure where it is located to tell it the path.
I cannot speak for QAEP (I barely began reading about lineage but in my case I don't have out/target/product/sm6150 at all, only out/target/product/tucana, which seems to be the name of the kernel (or device or vendor). Do you also have other repos pulled in that contain kernel named sm6150? Like https://github.com/LineageOS/android_kernel_xiaomi_sm6150 Maybe you should not have both
b100dian said:
I cannot speak for QAEP (I barely began reading about lineage but in my case I don't have out/target/product/sm6150 at all, only out/target/product/tucana, which seems to be the name of the kernel (or device or vendor). Do you also have other repos pulled in that contain kernel named sm6150? Like https://github.com/LineageOS/android_kernel_xiaomi_sm6150 Maybe you should not have both
Click to expand...
Click to collapse
Spoiler: b100dian reply
So where yours is out/target/product/tucana, the one for QAEP is SM6150 which is in the same location. so I think maybe on the right track here. also thanks for the help for llvm dragon, had to set bin path, for it to work. but i have not gone a built the rom yet, doing the kernel build first now.
Instead of relying on QAEP builder. I went and got kernel/build from code-aurora for android 10 r40 and ended up getting misc linux folder in kernel also gcc and build tools from the device tag release repo on codeaurora.
Usually i was using AOSP but now switched over to all QAEP tools and sources.
I am testing the Micode Audio and wifi source. got wifi working during kernel build by adding this below.
EXT_MODULES="
mods/wlan/qcacld-3.0
"
IN_KERNEL_MODULES=1
I believe that installs the wifi drivers for the device as a module. but building with clang, gcc and gnu as clang tripple this is all related to only kernel building.
Spoiler: Update
Done an overhaul on everything for the kernel. decided to switch from QAEP to AOSP.
Reason for the switch, I noticed with AOSP I am able to not only download the kernel/msm4.14 common folder but it also downloads build, prebuilts, prebuilts-master folders with everything included.
Differences aside from what I mentioned above.
AOSP common-4.14 comes with up to date builder, gcc, clang, etc. But when I download the release tag for example, LA.UM.9.1.r1-06700-SMxxx0.0 at codeaurora on the otherhand, it only downloads the common folder and no extra folders for it.
So then in turn. you have to go on codeaurora and download by using git clone, the build folder for what ever android version it is. for example, I had android version 29 (r29) though it does not exist in the branch list on codeaurora so i went with 28.
I should also note that making the change from QAEP to AOSP I started again with the kernel source.
With making the change, I have noticed improvements right away, but also I noticed that having CC=clang, the build would not work untill I also put in HOSTCC=gcc. guessing its to do with the AOSP version being a little different. still using QualComms LLVM clang compiler for everything clang related.
Spoiler: Problems I have so far.
***Error-1***
Have it building but get this spam, been trying to solve it.
***Error-2***
This error pops up when using LD=ld.lld
this is what is set in the build.config
***CONFIG-1***
LD=ld.lld
LD_LIBRARY_PATH=toolchain/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/lib/clang/8.0.6/lib/linux/aarch64:$LD_LIBRARY_PATH
export O=out/android-4.14 LD_LIBRARY_PATH
**RESULTS**
***CONFIG-2***
LD=ld.lld
HOSTLDFLAGS="-fuse-ld=lld" (added it so i can modify)
LD_LIBRARY_PATH=toolchain/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/lib/clang/8.0.6/lib:$LD_LIBRARY_PATH
export O=out/android-4.14 LD_LIBRARY_PATH
**RESULTS**
Same as above.
Spoiler: Config commands
This right here may have just solved all my problems. can confirm in all my config tries. Never once thought to put aarch64-linux-android before all variable values.
SOURCE: https://developer.android.com/ndk/guides/standalone_toolchain
# Tell configure what tools to use.
target_host=aarch64-linux-android
export AR=$target_host-ar
export AS=$target_host-clang
export CC=$target_host-clang
export CXX=$target_host-clang++
export LD=$target_host-ld
export STRIP=$target_host-strip
Also discovered that LD=ld.lld is for clang compiler. could be why the above Problem is happening.
This is using the toolschains without NDK, may have to put qualcomm and gcc in NDK and path them.
So after trying to downgrade to android 10 from 11, had no luck in doing so.
So now sticking with android 11 and I can safely say that I have reached a mile stone.
I ended up downloading android 11 R30 and using all the tool chains from AOSP while still using Qualcomm's LLVM compiler 8.0.6 as REAL_CC. But the clang pre-built path is clang from AOSP. Just trying to work out how to include the Xiaomi audio source. Unable to work out where to put it. Still testing, have not given up.
Hi @Squida, where is `mods/wlan/qcacld-3.0` from, the qcom talos referenced above in BoardConfig.mk?
Do you have an exact link to the repo?
In the meantime I can confirm I am missing something form the kernel. If I build everything myself and replace _just_ the kernel (with my dtb appended etc) it has sound/wireless, so knowing what wifi / audio module to link in seems the way to go.
b100dian said:
Hi @Squida, where is `mods/wlan/qcacld-3.0` from, the qcom talos referenced above in BoardConfig.mk?
Do you have an exact link to the repo?
In the meantime I can confirm I am missing something form the kernel. If I build everything myself and replace _just_ the kernel (with my dtb appended etc) it has sound/wireless, so knowing what wifi / audio module to link in seems the way to go.
Click to expand...
Click to collapse
Spoiler: Reply
No problem at all, anything to get this build done lol.
All links are for Android 11
If you want Android 10, replace pheonix-r-oss with tucana-q-oss
**Example for Android 10**
GitHub - MiCode/Xiaomi_Kernel_OpenSource at tucana-q-oss
Xiaomi Mobile Phone Kernel OpenSource. Contribute to MiCode/Xiaomi_Kernel_OpenSource development by creating an account on GitHub.
github.com
******ANDROID 11******
***SOURCE***
GitHub - MiCode/Xiaomi_Kernel_OpenSource at phoenix-r-oss
Xiaomi Mobile Phone Kernel OpenSource. Contribute to MiCode/Xiaomi_Kernel_OpenSource development by creating an account on GitHub.
github.com
***DATA***
GitHub - MiCode/vendor_qcom_opensource_data-kernel at phoenix-r-oss
xiaomi opensource for data-kernel. Contribute to MiCode/vendor_qcom_opensource_data-kernel development by creating an account on GitHub.
github.com
***AUDIO***
GitHub - MiCode/vendor_qcom_opensource_audio-kernel at phoenix-r-oss
Contribute to MiCode/vendor_qcom_opensource_audio-kernel development by creating an account on GitHub.
github.com
***WIFI (mods/wlan/qcacld-3.0)***
MiCode/vendor_qcom_opensource_wlan
Contribute to MiCode/vendor_qcom_opensource_wlan development by creating an account on GitHub.
github.com
Thanks, I think I get now what you're saying with 'talos', I poked at those repos now.
It seems to me the modules are built out of tree, as they don't appear in the extracted kernel config. (See https://github.com/b100dian/Xiaomi_Kernel_OpenSource/commit/0f4b062ef806aaad6ad02e2efd87809e8b7250c6).
Also, having dlkm from https://source.codeaurora.org/quic/la/device/qcom/common/tree/?h=LA.UM.8.9.r1-03800-sm6150.0 does not seem to help automate the build, I get all sorts of errors when AndroidKernelModule.mk is included and it includes back the AndroidKernel.mk..
Getting these into drivers/staging seems easier at first but..for now, I've only managed to build wlan.ko but that still errors out with `wlan: disagrees about version of symbol module_layout` :-S
b100dian said:
Spoiler: Reply
Thanks, I think I get now what you're saying with 'talos', I poked at those repos now.
It seems to me the modules are built out of tree, as they don't appear in the extracted kernel config. (See https://github.com/b100dian/Xiaomi_Kernel_OpenSource/commit/0f4b062ef806aaad6ad02e2efd87809e8b7250c6).
Also, having dlkm from https://source.codeaurora.org/quic/la/device/qcom/common/tree/?h=LA.UM.8.9.r1-03800-sm6150.0 does not seem to help automate the build, I get all sorts of errors when AndroidKernelModule.mk is included and it includes back the AndroidKernel.mk..
Getting these into drivers/staging seems easier at first but..for now, I've only managed to build wlan.ko but that still errors out with `wlan: disagrees about version of symbol module_layout` :-S
Click to expand...
Click to collapse
Spoiler: Reply
It seems you are having a similar issue.
When doing everything I have done so far, The biggest wall for me is getting <LD=LD.lld> to work properly, I either get clang error with a file having a linking problem with using clang from QQ llvm compiler. And when I switch over to using AOSP's 4.14 stable kernel prebuilts-master clang. It works but then another error to do with CPU timer pops up. Which was originally because of using gcc instead of clang in the CC=clang environment variable, or removing it out of the build.config file.
i myself did a major overhaul of Ubuntu and have upgraded to LTS 20.04 from 18 bionic.
Noticed some things right away.
When you install gcc-multilib and g++-multilib. You get version 9 instead of you being on Ubuntu bionic and getting version 7. Also faster in general with general use of the operating system using Oracle vmbox. On windows 10.
Apart from linking errors, kernel is buding but only with not having LD=LD.lld in the build.config file.
Spoiler: wifi-info
And for the wifi qcom. Mods folder I added manually. Inside the devices source folder. Then copied WLAN sources inside and renamed the folder to just WLAN.
Spoiler: where I am at now
I have got both android 11 and android 10 kernel and ROMs. Also went and downloaded the kernel for coral. That's how I found out about the wifi and how I got a lot of the settings for the build.config.
I am gonna have a break on this whole thing, gotten to a point where with android 11 Xiaomi Phoenix. I get one error with a file in kbuild, using the same config settings for android 10. I get none. Apart from the qcom space which is either DTC not working or failing at some point. Not sure if we need to use LD=LD.lld I have been reading it is not needed due to the builder choosing the correct one for you.
Overall though it builds. Just the spam for qcom warnings I just can not get rid of and it's to do with the sensors.
If anyone has information on what causes the qcom spam. Please let me know, thank you.
Plus this all started with vmlinux not working right. Something to do with channel scratch. Can not fix it.
Spoiler: My Thoughts
I have just found this exploring info on the rom.
Build AOSP with LineageOS device tree
My device (Xiaomi Redmi Note 5, whyred) have official LineageOS support and therefore there is device tree and kernel. I want to build AOSP without any modifications or tweaks. How can I use (or po...
stackoverflow.com
Key part taken from above link.
**Its hard to build pure AOSP than other ROMs. While building a custom ROM a lot of components wont work**
I think for our devices we have no choice but to use QAEP instead of AOSP, it explains why it fails to build properly. we first need a full working rom and then I think we can move over to AOSP and modify lets say, coral device and match it for our device. Though I think it is just easier using QAEP and why QAEP exists in the first place.
When I used QAEP, I got the SDCLANG problem, the build process according to the Micode git wiki, section "How to use" explains on how to configure and by the looks of the guide. It seems simple as cooking a boiled egg with only a couple of modifications to a device tree and adding your kernel to the kernel folder. It is supposed to build. I myself get SDClang path problems when using QAEP though.
I will go back to QAEP but i will be using all android 11 sources. due to unable to downgrade my phone from android 11 to 10. Having issues at the moment with TWRP installing. Shows my folder structure folder and file names. all random characters.
I will update as i get further in building the kernel and rom
Spoiler: Thoughts2
So I am now merging the built kernel into the kernel directory of AOSP 10. Made a folder called common and moved the built kernel into it. Also made a folder called prebuilts and put in all the .gz into it under a folder called 4.14. discovered that the AOSP 10 picked up the common folder with the built kernel but is having errors with Android.bp, will update as I find out more. Right now, just tinkering.
This is the issue when you have the build tools outside the source folder.
Could be a path I have not set properly. once I removed the command from POST_DEFCONFIG_CMDS="" it is now building.
Couple of things to note.
REAL_CC= I believe has now changed to HOSTCC=. Command is not found in any files in the build directory of the AOSP 4.14 STABLE Kernel.
QualComms LLVM 8.0.6 Compiler does not contain clang files. you still need to either download it, or just use the one in AOSP 4.14 Stable kernel, plus the clang version in AOSP stable kernel is a later version and also contains clang version for android 10+ instead of android 9.
New error I get after changes mentioned above are made.
Not sure where to put -fPIC to make the command function.
Fixed it, was a pathing issue with folders.
But now I am stuck now on finding out the directory for LD_LIBRARY_PATH=
Code:
DTC arch/arm64/boot/dts/qcom/apq8016-sbc.dtb
dtc: error while loading shared libraries: /home/avm/dev/source/kernel/prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/lib/libc++.so: file too short
make[4]: *** [scripts/Makefile.lib:325: arch/arm64/boot/dts/qcom/apq8016-sbc.dtb] Error 127
make[3]: *** [/home/avm/dev/source/kernel/mi10/scripts/Makefile.build:676: arch/arm64/boot/dts/qcom] Error 2
make[2]: *** [arch/arm64/Makefile:187: dtbs] Error 2
make[2]: *** Waiting for unfinished jobs....
CC lib/rhashtable.o
Spoiler: Extra Discovered Info
${ROOT_DIR} is used. With it and you don't need to export it. Builder already knows what it is. so you use it like this for example
************************************
CC=${ROOT_DIR}/path-to-QQ_LLVM_COMPILER clang binary file, located in bin folder.
Also do this for ld.lld
LD=${ROOT_DIR}/path-to-ld.lld
************************************
Found another odd thing that happens
Having CC=PATH-TO-QQ-llvm-compiler/clang with CC_PREBUILT_BIN as aosp's location and HOSTCC=clang
It builds.
But with LD=
It fails.
I try using QQ-LLVM-Compiler as CC_Prebuilt_bin=
Fails.
So far I have managed to get to this point.
And can safely say that using QualComs LLVM 8.0.6 compiler does not work with android 10 so stick with AOSP's prebuilt clang either in Kernel stable git or AOSP android-Number-Revision
Again, REAL_CC does not work, nor show up in the enviroment as a used command.
These below all do.
<CC=>, <HOSTCC=>, <HOSTLDFLAGS=-fuse-ld=lld>, <NM=llvm-nm>, <OBJCOPY=llvm-objcopy>, <HOSTLD=>, <LD=>,
HOSTCC= will use what is put in CLANG_PREBUILT_BIN=
CC= you are able to add QQ-LLVM-COMPILER's clang and it will run.
Proof of QQ-LLVM-COMPILER failing, when using it for <CLANG_PREBUILT_BIN=>
Instead of using AOSP's clang.
So far that is all I have seen pop up.
All these changes were done with the Kernel AOSP-COMMON-4.14-STABLE build, kernel, prebuilts, prebuilts-master folders and then with the devices source in a folder with a build.config file in the same location as the AOSP-kernel build folders. this all seems to work, Only thing I lose out on, is using POST_DEFCONFIG_CMDS="" to use make menuconfig.
Reason that make does not work is because according to AOSP coral's kernel you have another build.config file which is with the build folder, prebuilts, master-prebuilts folders which connects to the main build.config.common and clang config that has the extra commands. So in turn I do not think we use LD=ld.lld
We let the builder choose it for us.
95% sure that the DTC is what is causing qcom to have that warning spam.
Device tree compiler (DTC) linking seems to be the full cause of all the issues.
Okay to prevent fixdep.c:105:10: error all you need to do is have HOSTCC=gcc and it works. so then in turn. You can now use QQ LLVM Clang compiler in CLANG_PREBUILT_BIN= instead of AOSP.
Spoiler: Helpful Links
GitHub - nathanchance/android-kernel-clang: Information on compiling Android kernels with Clang
Information on compiling Android kernels with Clang - GitHub - nathanchance/android-kernel-clang: Information on compiling Android kernels with Clang
github.com
Spoiler: Still going
Still going at it, manage to find out a couple of things.
If your build is failing due to files missing, check your build directory and make sure the files in the path folder and in Linux-x86>bin folders are indeed "symlinked" something I was unaware of with Linux due to me being a windows user. none of the icons can have an X on it. it means its broken. this solved a ton of my issues during Rom building.
the build folder itself is a symlink folder. (Not all files)
Just locate and put files in correct places. so instead of having a folder called toolchains, like we are told on the Micode wiki, etc. If you use the AOSP-kernel build, prebuilts, prebuilts-master. which contains all kernel and build tools. and are already linked. so then you just add QQ-LLVM-Compiler to either prebuilts or pre-builts master and link it in the config.
If you do all this correctly and having all files in the proper location, you should not have any more build errors in regards to missing files.
Summed up
Build directory contains symlinks to binary files which are located in prebuilts and prebuilts-master. you need all 3 folders in the device source root directory.
Inside the build directory you will find a file called build.config, its not a config. its a symlink for one. Rename it to the build.config.Aarch64 for example, or what ever your config is called located in your root devices source directory. this solved a **** load of my problems.
The problem I have now is actually got to do with Repo, AOSP, QAEP. found out using the manual install method of repo makes it so you can download off google when you have the pgp key installed. but having it installed this way, stuffs up gpg for QAEP. I am looking for a way to merge all PGP keys in one location.
and to get QAEP downloading without showing this error.
All you have to do is remove the manual repo you installed and then also deleting the .repoconfig folder and .gnupg folder.
Then install repo with <sudo snap install git-repo>
it will work, you will get a public key under john doe and it will use CAF as well. problem is. You lose out on public key to AOSP and also the repo that is inside the AOSP folder needs to be replaced. trying it just causes errors though.
What happens when you do above by removing the manual repo and adding the snap git-repo
So why does it matter that I need both public keys to work?
Because I am using AOSP and also QAEP for testing.
I'll be sticking with the snap instal git-repo for now. i'll have to work out how to add the key from AOSP.
**Error when going back to AOSP**
**what happens when you delete the repo folder inside .repo of AOSP**
Only way I got it to work is by removing the snap install version of repo and install the manual way.
But then I lose out on CAF.
Think i may have worked out what is happening with the keys. 2 folders are being made. .repoconfig and .gnupg.
.gnupg only gets created when using AOSP pgp key.
and there is a gnupg folder in .repoconfig, might be a command to merge the files.
this command below makes it so you can change the name.
--config-name
put it at the end of the repo init command.
from what I understand for the tucana_user_defconfig.
#CONFIG_BUILD_ARM64_DT_OVERLAY does not need to be set. for mi 9, yes. not for mi note 10. Just pulled the defconfig from my device using the command below.
**EXTRACT DEFCONFIG FROM DEVICE**
MSM devices
CMD> adb pull /proc/config.gz
files appears as config.gz in same directory
I should also note that I ran 2 builds one with DT_OVERLAY=Y and then one =N
the outcome was with the change of CONFIG_BUILD_ARM64_DT_OVERLAY=n
That is not how it is setup, the proper way to disable it is as follows.
#CONFIG_BUILD_ARM64_DT_OVERLAY is not set
I got a bigger file size for Image.gz-dtb. instead of under 20MB
Have it on so you can extract DTBO and dtb files. having it off stops it from extracting.
THIS error or what ever the hell it is, is driving me insane.
My understanding is that DTBO (overlay), when enabled, ends up in dtbo.img, and when disabled, probably ends up in dtb which is appened to the kernel Image.gz.
The gsi_write_channel_scratch error is... maybe this helps? https://github.com/ClangBuiltLinux/linux/issues/931#issuecomment-599681910
Spoiler: reply
Btw, thank you @Squida for pointing me out the correct repos for wifi and audio, I managed to compile both into my build and the audio one inline (the wifi needs to be insmod'ed).
b100dian said:
My understanding is that DTBO (overlay), when enabled, ends up in dtbo.img, and when disabled, probably ends up in dtb which is appened to the kernel Image.gz.
The gsi_write_channel_scratch error is... maybe this helps? https://github.com/ClangBuiltLinux/linux/issues/931#issuecomment-599681910
Spoiler: reply
Btw, thank you @Squida for pointing me out the correct repos for wifi and audio, I managed to compile both into my build and the audio one inline (the wifi needs to be insmod'ed).
Click to expand...
Click to collapse
Spoiler: Reply
You sir, are a Legend!
Okay So if I am reading that right.
If you mean DT_OVERLAY=y in defconfig, makes it so I can get the dtbo.img file. I tried adding the dtbo.img to the list of files for extraction and with it on, no dtbo image is made nor found, with it off. still the same thing but unable to extract any dtb or dtbo images from the boot directory. have to have it on.
dtbo.img just does not want to extract for me.
Again, using the clang config and not the mi 9 config used on Micode wiki.
the Micode Wiki settings do not work correctly. you lose out on about a GB of stuff and I know its a DTC issue I have been having due to the Qcom spam.
I have reduced the space though so now you can actually scroll through the whole build process, including the spam.
I will definitely be looking into that solution for channel scratch.
Also if you could please show me the config for the SDClang settings you put it to get it to detect. I tried looking over your git page and failed to understand why you have it in boardconfig.mk and if lineage has other files for the device.
Reason being is because on QAEP it talks about SDclang-3.8 and i have no idea where it is.. Supposed to be in QQ-LLVM-compiler and you copy it to the prebuilts folders, it just does not exist to do that.
the major problem I have is building the device tree when building the kernel. from my understanding, Xiaomi have set it up so DTC creates a Device tree for you. well that is the part that is failing and the whole reason why I can not make a rom.
My guess because you are using lineage sources, everything I am talking about. they already did for you. I am trying to do it all manually. learning purposes.
Okay so it turns out, we need LD=ld.lld
Though we must modify files, this is ridiculous just to get your own rom for xiaomi devices.
This thread below may have the solution for me and an easier one then having to modify files manually. Might have to update the Devices Kernel to the stable aosp 4.14 kernel. this is my theory anyway.
[REFERENCE] How to get an Android kernel up to date with linux-stable
Introduction Hello everyone! This will be a thread to assist people with getting their device's Android kernel up to date with the latest linux-stable tag from kernel.org. This process will henceforth be referred to as "upstreaming". This thread...
forum.xda-developers.com
Squida said:
Spoiler: Reply
You sir, are a Legend!
Okay So if I am reading that right.
If you mean DT_OVERLAY=y in defconfig, makes it so I can get the dtbo.img file. I tried adding the dtbo.img to the list of files for extraction and with it on, no dtbo image is made nor found, with it off. still the same thing but unable to extract any dtb or dtbo images from the boot directory. have to have it on.
dtbo.img just does not want to extract for me.
Again, using the clang config and not the mi 9 config used on Micode wiki.
the Micode Wiki settings do not work correctly. you lose out on about a GB of stuff and I know its a DTC issue I have been having due to the Qcom spam.
I have reduced the space though so now you can actually scroll through the whole build process, including the spam.
I will definitely be looking into that solution for channel scratch.
Also if you could please show me the config for the SDClang settings you put it to get it to detect. I tried looking over your git page and failed to understand why you have it in boardconfig.mk and if lineage has other files for the device.
Reason being is because on QAEP it talks about SDclang-3.8 and i have no idea where it is.. Supposed to be in QQ-LLVM-compiler and you copy it to the prebuilts folders, it just does not exist to do that.
the major problem I have is building the device tree when building the kernel. from my understanding, Xiaomi have set it up so DTC creates a Device tree for you. well that is the part that is failing and the whole reason why I can not make a rom.
My guess because you are using lineage sources, everything I am talking about. they already did for you. I am trying to do it all manually. learning purposes.
Click to expand...
Click to collapse
Spoiler: Reply
My guess because you are using lineage sources, everything I am talking about. they already did for you. I am trying to do it all manually. learning purposes.
Click to expand...
Click to collapse
Of course, this is the reason. I don't know exactly how the lineage build scripts generate dtbo.img. There's make bootimage, make vendorimage and maybe make dtboimage too. Probably this command helps you generate it, but I don't think I had success with that: https://forum.xda-developers.com/t/...nel-dtbo-for-redmi-k20.3973787/#post-80354635
The image size differs and the one created by lineage build scripts is the same size as the original one.
I also have console spam when the device tree is generated, I just didnt sweat on it as being an error.
BoardConfig is probably central to the lineage build, but I assume the variables set here are available to kernel's make commands.
For a lineage-less built I used the first two commands here: https://gist.github.com/b100dian/40c8dbe746ff181aff71ee10a75a5f3c (the rest of the things are my attempts to construct back the boot.img with the kernel).
To actually boot the kernel you can gzip it, and append the dtb file to it (
like
Code:
cat Image.gz dtb > Image.gz-dtb
).
, and _then_ reconstruct a deconstructed original boot.img with that (w/o the --dtb parameter if I remember correctly). But I think kernel output already has -dtb concatenated in out/arch/arm64/boot
b100dian said:
Spoiler: Reply
Of course, this is the reason. I don't know exactly how the lineage build scripts generate dtbo.img. There's make bootimage, make vendorimage and maybe make dtboimage too. Probably this command helps you generate it, but I don't think I had success with that: https://forum.xda-developers.com/t/...nel-dtbo-for-redmi-k20.3973787/#post-80354635
The image size differs and the one created by lineage build scripts is the same size as the original one.
I also have console spam when the device tree is generated, I just didnt sweat on it as being an error.
BoardConfig is probably central to the lineage build, but I assume the variables set here are available to kernel's make commands.
For a lineage-less built I used the first two commands here: https://gist.github.com/b100dian/40c8dbe746ff181aff71ee10a75a5f3c (the rest of the things are my attempts to construct back the boot.img with the kernel).
To actually boot the kernel you can gzip it, and append the dtb file to it (
like
Code:
cat Image.gz dtb > Image.gz-dtb
).
, and _then_ reconstruct a deconstructed original boot.img with that (w/o the --dtb parameter if I remember correctly). But I think kernel output already has -dtb concatenated in out/arch/arm64/boot
Click to expand...
Click to collapse
Thanks for the quick reply.
Spoiler: Might be the solution to DTC
Code:
DTC_EXT=~/android/lineage/prebuilts/tools-lineage/linux-x86/dtc/dtc ARCH=arm64 SUBARCH=arm64 CROSS_COMPILE=${PWD}/toolchain/bin/aarch64-linux-android- make O=../tucana-out REAL_CC=${PWD}/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu - vendor/tucana_user_defconfig
DTC_EXT=~/android/lineage/prebuilts/tools-lineage/linux-x86/dtc/dtc ARCH=arm64 SUBARCH=arm64 CROSS_COMPILE=${PWD}/toolchain/bin/aarch64-linux-android- make -j8 O=../tucana-out/ REAL_CC=${PWD}/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- 2>&1 | tee ../kernel.log
Above solution might be the key thing to solving my issues with DTC. i can safely say I never once put the ARCH= and SUBARCH= in DTC_EXT= this may have solved it.
As for the rom building itself, I may have to use AOSP over QAEP, due to the whole SDCLANG issue
Link:
https://developer.qualcomm.com/forum/qdn-forums/software/snapdragon-llvm-compiler-android/68403#comment-18264
Those issues are all related to QAEP, I have less problems with AOSP.
Just don't have a device tree for it. that is why I need DTC working perfectly.
For what it is worth, tried looking for a default device tree that was not based off lineage-os. No luck thus far.
But isn't the device tree what's in arch/arm64/boot/dts/qcom/ in the kernel sources?
There's even a Makefile there where you can see CONFIG_BUILD_ARM64_DT_OVERLAY in use
b100dian said:
But isn't the device tree what's in arch/arm64/boot/dts/qcom/ in the kernel sources?
There's even a Makefile there where you can see CONFIG_BUILD_ARM64_DT_OVERLAY in use
Click to expand...
Click to collapse
Spoiler: Reply
Lmao holy ****, I think I know where I stuffed up. I was navigating extract only at boot. Did not go further then boot directory lol. I'll test now with navigating to qcom. Thanks for the tip.
***UPDATE***
Managed to work out why all these problems are occurring.
Okay so from what I understand, there is 2 building methods.
1. Using terminal and using export commands.
2. build.config file
To test the theory to make sure that indeed there is a double up on builds, I decided to put the whole Micode Mi 9 export guide into the build.config that I have (made a backup of it) after executing it did indeed show errors.
so then I investigate how it is failing and it came to my attention that the export method for the make defconfig and then build is seperate for build.config.
for the kbuild, we issue the environment variables for example, these below.
When I say its Kbuild variables, it could be clang or gcc. Not 100% sure though.
Spoiler: Kbuild Environment Variables
# PRE_DEFCONFIG_CMDS
# Command evaluated before `make defconfig`
#
# POST_DEFCONFIG_CMDS
# Command evaluated after `make defconfig` and before `make`.
#
# POST_KERNEL_BUILD_CMDS
# Command evaluated after `make`.
#
# EXTRA_CMDS
# Command evaluated after building and installing kernel and modules.
#
# DIST_CMDS
# Command evaluated after copying files to DIST_DIR
#
# VENDOR_RAMDISK_CMDS
# When building vendor boot image, VENDOR_RAMDISK_CMDS enables the build
# config file to specify command(s) for further altering the prebuilt vendor
# ramdisk binary. For example, the build config file could add firmware files
# on the vendor ramdisk (lib/firmware) for testing purposes.
Spoiler: extra-info
and instead of having "make" command by itself I put it for example in PRE_DEFCONFIG_CMDS="make <code>*
and it will add in REAL_CC, etc to the defconfig and upon making the build it should inturn do the rest.
Does anyone know the environment variable for kernel build so i can then put in the make command for the build and include REAL_CC=, etc. I managed to get the first make command for the defconfig working.
PRE_DEFCONFIG_CMDS="make O=out/android-4.14 REAL_CC=${PWD}/prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- tucana_user_defconfig"
I just now have to get the below command working. not sure what environment variable to put it under.
make -j$(nproc) O=out/android-4.14 REAL_CC=${PWD}/prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- 2>&1 | tee kernel.log
Found it!
By searching in build directory then build.sh file.
and *_setup_env.sh* has settings as well that will help.
***********************************
export MAKE_ARGS=$*
Could be useful
CC_LD_ARG
***********************************
echo "========================================================"
echo " Building kernel"
set -x
(cd ${OUT_DIR} && make O=${OUT_DIR} ${CC_LD_ARG} ${MAKE_ARGS})
set +x
***Linux update script***
GitHub - android-linux-stable/script: A script to help with merging linux-stable into your own repository
A script to help with merging linux-stable into your own repository - GitHub - android-linux-stable/script: A script to help with merging linux-stable into your own repository
github.com
Better to use CAF for MSM devices.
[REFERENCE] Merge latest CAF Tag in Kernel
Introduction: Hello folks! In this thread I will be guiding you about how you can merge latest CAF tags in your CAF based kernel. Many people who just started compiling the kernels still don't know how to merge a CAF tag because there isn't any...
forum.xda-developers.com
Upon further research on the topic of MAKE_ARGS=$*
from what I now understand and please keep in mind, I am in no way a programmer or good with Linux overall.
I think the $* symbol is a value itself, so from my understanding. If i use lets say $S=Something I have just made an variable that will be used in MAKE_ARGS=$*
If my theory for this is correct, this is how I add in the make variables for the last build command to start the build.
Should be able to do this.
make -j$(nproc) O=out/android-4.14 REAL_CC=${PWD}/prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- 2>&1 | tee kernel.log
Oh and the config is make commands, found that out as well. you have MAKE and SOONG commands and configs. I so prefer Make variables over Soong. looks easier to read for me.
Found a build config on mi code, sources, issues section
SOURCE
Spoiler: build.config-mi11
#!/bin/bash
export OUT=${PWD}/out
export ARCH=arm64
export SUBARCH=arm64
export TARGET_BUILD_VARIANT=userdebug
#export DTC_EXT=dtc
export CROSS_COMPILE=${PWD}/toolchains/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export KERNEL_DEFCONFIG=venus-qgki_defconfig
#set CONFIG_BUILD_ARM64_DT_OVERLAY=y
#set BUILD_CONFIG=build.config.gki.aarch64
O=$OUT REAL_CC=${PWD}/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- ${PWD}/scripts/gki/generate_defconfig.sh $KERNEL_DEFCONFIG
make O=$OUT REAL_CC=${PWD}/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- vendor/$KERNEL_DEFCONFIG
make -j$(nproc) O=$OUT REAL_CC=${PWD}/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- 2>&1 | tee kernel.log
The build config above is indeed for Mi11, we do not need gsi settings or the 3rd command starting with O=$OUT for Mi note 10 pro
By implementing the changes above, outcome below.
Just now have to resolve kernel issues and this should build with no more issues. it has been a massive adventure.
the errors above are due to remnants of old files from merges that were not undone properly. deleted the devices source and recreated it again. problems are now gone will update on outcome.
I still can not seem to get it completely built. Max Image.gz-dtb file size is 28.5MB so far. and the highest I have gotten. still get VMLINUX issues which tells me just maybe Xiaomi themselves have not updated the build scripts to suite the latest CAF changes.
All speculation at the moment.
Had a look at this area
GitHub - MiCode/kernel_build
Contribute to MiCode/kernel_build development by creating an account on GitHub.
github.com
Turns out, build config for CC9 Pro. does not exist hence why all the problems Using AOSP's.
I believe it needs to be full modified in order to work with Tucana, due to Xiaomi not releasing a build script for it. so another solution would be to modify or try and use another device on the list in the link to be able to build it. not even export using the Mi 9 works so I have to dig deeper on getting a config and build script for it.
Spoiler: Current build.config
ARCH=arm64
SUBARCH=arm64
BRANCH=android-4.14
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=aarch64-linux-android-
TARGET_BUILD_VARIANT=userdebug
DEFCONFIG=tucana_user_defconfig
SKIP_DEFCONFIG=1
PRE_DEFCONFIG_CMDS="make O=out/android-4.14 REAL_CC=${ROOT_DIR}/prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin/clang CLANG_TRIPLE=aarch64-linux-gnu- ${DEFCONFIG} && make O=out/android-4.14 menuconfig"
POST_DEFCONFIG_CMDS=""
KERNEL_DIR=.
EXTRA_CMDS=""
HOSTCC=gcc
CC=clang
DTC_EXT=${ROOT_DIR}/prebuilts-master/misc/linux-x86/dtc/dtc
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
CLANG_PREBUILT_BIN=prebuilts-master/ndk/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/bin
LZ4_PREBUILTS_BIN=prebuilts-master/misc/linux-x86/lz4
DTC_PREBUILTS_BIN=prebuilts-master/misc/linux-x86/dtc
LIBUFDT_PREBUILTS_BIN=prebuilts-master/misc/linux-x86/libufdt
BUILDTOOLS_PREBUILT_BIN=build/build-tools/path/linux-x86
OUT_DIR=out/android-4.14
FILES="
arch/arm64/boot/Image
arch/arm64/boot/Image.gz
arch/arm64/boot/Image.gz-dtb
arch/arm64/boot/dts/qcom/tucana-sdmmagpie-overlay.dtbo
arch/arm64/boot/dts/qcom/sdmmagpie.dtb
vmlinux
System.map
.config
"
EXT_MODULES="
private/msm-tucana-modules/wlan/qcacld-3.0
"
IN_KERNEL_MODULES=1
STOP_SHIP_TRACEPRINTK=1
The config does not build vmlinux, DTC properly, dtbo.img. Still working on it.
I also did try first doing the standalone export way. Just constantly getting ld error --fix-something and to fix it, by using CC=clang and HOSTCC=gcc
but then you resort to having to use the build.config file. for some reason the standalone export method just does not work with cc and hostcc
and that is using the QQ LLVM/clang 8.0 toolchain with AOSP's GCC while having 2 directories. toolchain(GCC) and toolchains(QQ-LLVM/Clang) with QQ-llvm/clang's build directory inside the devices source root directory as well, according to MiCode Wiki under MSM-4.14.
Tried attaching the last make command to the DTC_EXT= and it fails, still unable to find the build kernel argument to change the command manually. Only have POST_KERNEL_BUILD
No luck at all with the export combo.
As for the build.config.
I get a build using AOSP'S GCC and QQ-LLVM/CLANG 8.0
But it is not complete.
I also use the build, prebuilts, prebuilts-master from AOSP's 4.14 Common kernel repo.
the reason for this, is because Xiaomi have not released kernel build files for the device. from what I have found.

Matching a kernel's config for compatible kernel modules

(I'm cross-posting from "General Discussion", I think I picked the wrong forum. Sorry!)
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