Jump to content

Compiling kernel from sources


Guest krab_mozga

Recommended Posts

Guest krab_mozga

I need help compiling kernel from sources from zte. 

I've skimmed through two guides available on xda and done this so far:

1) installed build-essential packages for host os, (opensuse linux x64 with gcc 48)

2) downloaded and extracted latest android NDK from official site

3) set enironment var CROSS_COMPILE

4) extracted sources 

I've stumbled upon .config. It's nowhere to be found. There's come configs in arch/arm/configs: for snapdragon 410 and 810 processor, but none for our 615.

I've copied 410 config (msm8916) to .config and started build with

 

make -j5 ARCH=arm

but get missing headers errors

What am I do wrong?

Edited by krab_mozga
Link to post
Share on other sites
Guest KonstaT

There's basically two ways to compile a kernel - as a standalone build and as a part of an Android build (CyanogenMod, CAF, etc). Latter is better on modern devices like this for few reasons. Headers are exported for the build so you don't have to make any 'hacks' like you'd need on standalone builds. Device tree image (dt.img) is created as part of the build. Downside is of course that you'll need to download the whole Android source which is huge and you have to prepare some other sources as well.

Since you're trying to do a standalone build, let's start with that.

1) No need for NDK. You'll only need the right toolchain, GCC 4.8 is used on Lollipop (https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/). Use 'git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8.git' to download it.

2) You can't just use any 'default' defconfig, you need to use one specifically for this device. Since CONFIG_IKCONFIG_PROC is not enabled on this device you can't extract it from a running device (/proc/config.gz). CONFIG_IKCONFIG is enabled so you can extract it from an existing zImage with extract-ikconfig tool (split stock boot.img with unpackbootimg, you can find extract-ikconfig in scripts directory in every linux kernel source). I've attached defconfig from AS B12 you can use to build. You were right about copying defconfig as .config to the root of the kernel source.

 defconfig

3) 'make -j5 ARCH=arm CROSS_COMPILE=path/to/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-'

You'll still get few errors because of 'missing' headers. Error will tell you the insulting file and exact line where you need to change <header.h> to "header.h" (or sometimes even the relative path e.g. "../header.h"). This would not be necessary when bulding kernel as part of an Android build. dt.img creation is also a completely another story but you can use dt.img extracted from the stock boot.img for now.

Edited by KonstaT
Link to post
Share on other sites
Guest krab_mozga

Big thanks!

Doing as you've said I've compiled zImage 

Is it feasible to produce not-standalone build? Isn't it porting cm to our device and a lot of work? 

 

I'm trying to get this image on my device.

1) I've made twrp backup. boot.emmc.win is boot image with kernel and ramdisk, am I right?

2) I've get unpack and repack scripts form here ,

3) extracted boot.img-kernel.gz and replaced it with my zImage

4) repacked everything back into boot.img

5) tried flashing it back with twrp with no luck

I guess I miss something. Extracted and my kernel sizes matches with delta about 200kb. But Boot.img sized differ: my is 8mb and old is 32 mb.

When I flash my boot.img I get device with display not working and just vibrates occasionally. TWRP was still operational so I got everything back.  

 

 

Edited by krab_mozga
Link to post
Share on other sites

Your tools are utterly outdated (a lot has happened in the Android world in the last seven(!!!) years :P). You need to use unpackbootimg/mkbootimg that supports dt.img. Also use stock boot.img extracted from ZTE stock firmware rather than dumping it from your device (it's a raw copy of the whole boot partition which is why it's so big). Stock boot.img is ~15.1mb in which zImage is ~6.9 and dt.img is ~6.8mb. Also make sure you have other mkbooting parameters right (cmdline, base, pagesize, ramdisk_offset, tags_offset).

You wouldn't have to port the whole ROM to build only the kernel as part of an Android build. You'd later need to use some external tools to pack it with your stock boot.img, though. Besides, I've already prepared (most of) the sources you'd need for this device to do that. TWRP was built as part of OmniROM build. You could compile the kernel as part of that build.

Currently TWRP sources use prebuilt kernel/dt.img on this device.
https://gitlab.com/Konsta/android_device_zte_p839f30

My Vodafone Smart Ultra 6 TWRP uses kernel/dt.img built from the source.
https://gitlab.com/Konsta/android_device_zte_p839v55

Edited by KonstaT
Link to post
Share on other sites

Could you, please, explain in detail what have you done there and on what purpose?

Not really. :P Explaining things takes a lot of time. It would be quicker for me to just build the kernel for you but I'm not going to do that and take all the fun from you. ;)

Just diff those two trees and see what's changed. Those are very bare to the bones trees and there's nothing much there. dtbtool directory and mkbootimg.mk are related to the dt.img creation. Other relevant stuff is in BoardConfig.mk under '# Kernel' section. Otherwise the differences are just p839v55->p839f30 rename in various places and small change in fstab. Those are insignificant to the kernel build.

May I suggest you first try updating your tools and trying the zImage you already built. Correct mkbooting command would be

mkbootimg --kernel boot.img-zImage --ramdisk boot.img-ramdisk.gz --cmdline "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=30 msm_rtb.filter=0x3F ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci androidboot.selinux=permissive lpm_levels.sleep_disabled=1" --base 80000000 --pagesize 2048 --ramdisk_offset 01000000 --tags_offset 00000100 --dt boot.img-dt -o boot.img

where boot.img-zImage is zImage you built, boot.img-ramdisk.gz is ramdisk extracted from stock boot.img, and boot.img-dt is dt.img extracted from stock boot.img.

Edited by KonstaT
Link to post
Share on other sites

More thanks!

These tools produced boot.img of right size, it's available here . I've flashed it with Flashify and it is ok.

Good. :) Wifi works too? It's not given that the old wlan module loads with the kernel you built.

You can also do

cat /proc/version

in adb shell/Terminal Emulator and verify that you're really running the kernel you built.

Edited by KonstaT
Link to post
Share on other sites
Guest krab_mozga

Good. :) Wifi works too? It's not given that the old wlan module loads with the kernel you built.

You can also do

cat /proc/version

in adb shell/Terminal Emulator and verify that you're really running the kernel you built.

Wifi works, but now I'm not sure It's kernel I've built. /proc/version shows same thing. Is it compile time there? Or am I to edit some version file to track compiled kernel? 

Link to post
Share on other sites

Yes, it has your [email protected] as well as the build time.

Next step would be to also build the dt.img from source. We can do a standalone build for that too if you can find/build dtbTool first.

Edit. This dtbToolCM should work. Run

dtbToolCM -2 -o dt.img -s 2048 -p scripts/dtc/ arch/arm/boot/dts/

from the root of the kernel source.

Edited by KonstaT
Link to post
Share on other sites
Guest krab_mozga

Yes, it has your [email protected] as well as the build time.

Next step would be to also build the dt.img from source. We can do a standalone build for that too if you can find/build dtbTool first.

Sure, but why? What can I do with that? Could it help to produce custom rom for this device?

I was aiming for source built kernel to get rid of CwMcu driver. Now I found it in android/kernel/drivers/misc/zte-sensor and I want to cut it off.

P. S. I've created dt.img like you've said and it's here

Edited by krab_mozga
Link to post
Share on other sites

No, nothing like that. It's just part of any modern Linux kernel that any device specific hardware is in a separate data structure. Let's say if you wanted to mess around with overclocking/voltages/etc that would be in the dt. It's essentially part of the kernel build, now you've only built a half of it.

Your dt.img looks reasonable in size. Did you try it?

Noooo, don't disable any drivers that you're using. Disabling CwMcu will most likely just break your sensors (you can have just removed userspace sensor HAL if you wanted all your sensors broken :P).

Edited by KonstaT
Link to post
Share on other sites
Guest krab_mozga

No, nothing like that. It's just part of any modern Linux kernel that any device specific hardware is in a separate data structure. Let's say if you wanted to mess around with overclocking/voltages/etc that would be in the dt. It's essentially part of the kernel build, now you've only built a half of it.

Your dt.img looks reasonable in size. Did you try it?

Noooo, don't disable any drivers that you're using. Disabling CwMcu will most likely just break your sensors (you can have just removed userspace sensor HAL if you wanted all your sensors broken :P).

I've tried dt.img and it is ok. 

Are you sure it would break any sensor? Here is CwMcuSensor source and it seems to me that thing just queries other sensors. Why should it break everyting?

Link to post
Share on other sites
Guest krab_mozga

Well, there's nothing stopping you from trying but of course it's expected to break something.

I have to admit that CwMcuSensor is the thing that make all sensors work. It can be disabled and cwmcu-wake-lock would be gone but light/proximity/accel sensors would not work.

This is very sad. I think it's either "too smart" android 5 that want to "feel" user presence by constantly polling sensors or greedy zte that implemented sensor polling in software and saved two pennies on some chip.

I've enabled CwMcuSensor back. But I have one more idea: I've commented out wakelock related code. I hope this would make sensors work with screen on and prevent phone from leaving deep sleep on sensor input. 

Link to post
Share on other sites
Guest TheDeath
  • 4 months later...
Guest Nonta72

I'm trying to compile a 64bit kernel but I'm getting "mnemonic error" !

Any tip ?

 

BTW, zte is a real s**t ! how can this device have 32 bit kernel and os ? The Octa Core and the 2gb of ram are perfectly enough to handle the arm64!

Link to post
Share on other sites
  • 10 months later...
Guest Pou_chi

Trying to compile cm12 kernel for s6, almost everything is ok, but after loading wifi isn't working. How can i figure out what module used?

On 10.09.2015 at 1:21 PM, KonstaT said:

Good. :) Wifi works too? It's not given that the old wlan module loads with the kernel you built.

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.