# Need help building kernel (that works) from source: Galaxy SII (SGH-T989)



## aldj0293 (Nov 29, 2012)

I didn't get any replies in the Galaxy SII forum, so I added some more details and reposted here:

I've been trying to build a custom kernel for my Galaxy SII (SGH-T989). I figured the easiest place to start would be to just build the stock source and make sure it works correctly before making any modifications. So I downloaded the SGH-T989_GB_Opensource_Update1.zip and got my dev environment setup [Ubuntu 10.04 LTS with arm-none-linux-gnueabi-g++ (Sourcery CodeBench Lite 2012.03-57) 4.6.3]. I used the build steps and configuration specified in the kernel source readme, and after fixing some errors (smc #0) in assembly language definitions, I had a zImage.

Then I used this kernel kitchen to tear apart boot.img and recovery.img files from both the stock and CMW recovery, and repack them comparing to make sure the output was correct. After a modification to the ramdisk base in mkbootimg, I was able to pull apart the image and repack it to get an identical binary output.

During this process I noticed that the stock recovery image and boot image use the same kernel (2.6.35.11-T989UVKID), and so did several of the CWM recovery images. The stock kernel is signed, but I have some other versions of CWM recoveries that use unsigned kernels with the same version (2.6.35.11), so I didn't figure it would be an issue. I decided to just flash the recovery so I could still use my phone without having to reflash the boot image if I ran into problems. I pulled the recovery image apart and repacked it with my newly build zImage. I flashed it with Odin, and booted into recovery, and it hung with just a black screen after the Samsung logo. I either have to hold the power button for a long time or pull the battery to get it to reboot. If I flash a stock or CMW recovery image with Odin, it works fine. I have tried several times with the same results. I have also tried with the ICS source and still no luck.

So, what am I missing? I would really appreciate guidance from someone who has actually built a kernel for this phone.

Also, in general how do you go about troubleshooting the boot process since it doesn't get far enough for adb to start. Is there a way to get serial output using a Riff box or something?

Thanks


----------



## imnuts (Jun 9, 2011)

First look, you are using the wrong toolchain. Samsung kernels are very picky with their toolchain, even if you update all the modules as well. I believe they want you to use the 2009q3 toolchain, so I would try using that to build your zImage and see if it works.


----------



## aldj0293 (Nov 29, 2012)

Great! Thanks. I have a place to start now. I'll let you know how it goes.

What are the differences in the various toolchains? What are the differences in the code that requires a specific toolchain?
I noticed that there are a lot of warnings as it builds, is that typical?


----------



## imnuts (Jun 9, 2011)

Warnings are typical, though it could also be the source of the issues. I'm not completely familiar with the specifics of why one toolchain will work but another won't, but they are based on different versions of GCC and other development libraries and binaries. I believe that 2009q3 is based on GCC 4.4 (or close to that). From what I've heard, it allows for "sloppy" coding to producing working binaries, where the same code will either not compile, or cause a bad binary with newer versions. In my experiences, Samsung doesn't have the cleanest code, so using newer versions of GCC can cause problems.


----------



## aldj0293 (Nov 29, 2012)

That was it! Today I finally built my first working kernel! Thanks!

All I had to do was make clean, change the CROSS_COMPILE definition in the Makefile, and follow the normal build steps.

When I first tried, the errors related to smc #0 showed up again because the ".arch_extension sec" was not supported, so I just extracted the kernel source into another directory and started from scratch. Just to be sure, I went back to my original tree and undid the code changes, and when I changed the toolchain, it worked too.

Originally I didn't notice the recommended toolchain in the kernel text document when I was first starting, but it was right there (2009q3-68) and I didn't know how important the compiler versions were.

Thanks again!


----------



## headcreepz (Mar 22, 2012)

I also have a t989....is there any reason you wouldnt post this kernel for the rest of us? Thanks in advance.


----------



## M4570D0N (Jun 7, 2012)

Seems like it would be a whole lot easier to use the kernel source, Hercules device configs, proprietary vendor blobs, etc. from Cyanogenmod, and the arm-eabi-4.4.3 toolchain from AOSP:
https://github.com/TheMuppets/proprietary_vendor_samsung
https://github.com/CyanogenMod/android_kernel_samsung_msm8660-common
https://github.com/CyanogenMod/android_device_samsung_celox-common
https://github.com/CyanogenMod/android_device_samsung_msm8660-common/tree/jellybean
https://github.com/CyanogenMod/android_device_samsung_hercules/tree/jellybean
https://github.com/android/platform_prebuilt/tree/jb-release

Also, any reason in particular why you would even consider working on gingerbread at this point?


----------



## aldj0293 (Nov 29, 2012)

headcreepz said:


> Also, any reason in particular why you would even consider working on gingerbread at this point?


I mainly did this just for the experience. There is a world of difference between having an idea about how a process works and actually doing it, because the devil is in the details. I went with GB because it was the kernel used for the CWM recovery image I was using and I figured it would be best to stick with the same kernel so it would be more likely to be compatible with the same ramdisk image.


----------

