Skip to content

perdubug/LG_G3_D858_Android4.4_Kernel

Repository files navigation

NOTE: Too slow to access github in China, so I will use https://code.csdn.net/m7yang/lg_g3_d858_android4-4_kernel.git for 
this project.

----------------------------
About this kernel source
----------------------------
    I got this kernel(4.4.2) source from LG(http://opensource.lge.com/index),which is for LG G3 D858(Duam SIM,G3 CHINA CMCC
variant) device.



Preconditions
-----------------------------------------------------
    - Ubuntu 14.04(64bit) for building kernel,etc;
    - Windows PC for root and flash facroty img files,etc. Win10 is fine;
    - abootimg on Ubuntu. You can get it by running 'sudo apt-get install abootimg';
    - D858 factory image file - in case you need to restore everything
    - boot.img get from your device




Step 1. root D858 device
-------------------------------------------
    Download root tool from http://pan.baidu.com/s/1sjFX4Yx and then:
       - Unzip it on Windows;
       - Open a Windows cmd as Admin;
       - Go to tool folder and run 'LG Root Script.bat' and follow the instructions;
       - After that, you will get SuperSU app in your device;
    P.S. If you encrypt your device for whatever reason,like your exchange email security policy required,then the root operation will 
    fail. Please flash factory image first to make sure you have a 'normal' device configuration.





Step 2. install TWRP on D858 device
-------------------------------------------
    Use AutoRec apk(http://yun.baidu.com/s/1dD4QCBR).But that apk only works for D858HK variant. So you need to change your device 
 to D858HK first by following steps:
       - Download ES File Explorer apk and install it;
       - Open ES File Explorer->Click Menu icon on top right corner->Root Explorer->Mount R/W->Set '/system' as 'RW';
       - In ES File Explorer,go to /system folder and open build.prop file and edit it;
       - In build.prop file, change 'ro.product.model=LG-D858' to 'ro.product.model=LG-D858HK';
       - Set phone to flight mode to avoid system auto updating any stuff related to D858HK after reboot;
       - Reboot the device;
       - Run AutoRec app and follow the instructions to install TWRP;
       - Reboot the device;
       - Open build.prop and change 'ro.product.model=LG-D858HK' back to 'ro.product.model=LG-D858';
       - Open ES File Explorer->Click Menu icon on top right corner->Root Explorer->Mount R/W->Set '/system' back to 'R';
       - Reboot deviec again and now you can turn off flight mode;


    How to enter TWRP mode on D858 device?
    -------------------------------------------
       - Power off the device;
       - Hold Volume Down and Power key;
       - Once you see LG logo then release both keys for 1 second(approx) and then hold them again;
       - You will getls  white recovery UI. 
       - Answer 'Yes' for next two prompts and then you would see TWRP UI;





Step 3. build kernel source
-----------------------------
    Specify CROSS_COMPILE path to your Android source or NDK. Since LG G3 D858 is for CMCC,set kernel config as
g3-cmcc_cn-perf_defconfig. Then you can start build kernel.
    $export PATH=$PATH:tools/lz4demo
    $make ARCH=arm CROSS_COMPILE=../prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/arm-eabi- g3-cmcc_cn-perf_defconfig zImage -j4

    After build, you can find the build image(zImage) at arch/arm/boot





Step 4. generate D858 dt.img file
------------------------------------
   $scripts/dtc/dtc -O dtb -o arch/arm/boot/msm8974pro-ac-g3-cn.dtb -b 0 -d arch/arm/boot/.msm8974pro-ac-g3-cn.dtb.d arch/arm/boot/dts/msm8974pro-g3-cn/msm8974pro-ac-g3-cn.dts

   Option 1. Use dtbToolCM
   $dtbToolCM -s 2048 -o arch/arm/boot/dt.img -p scripts/dtc/ arch/arm/boot/
   
   Option 2. Use mkbootimg
   Now download mkbootimg_tool from github since we need dtbTool from that repo, and then
   $~/src/android_utilites/mkbootimg_tools/dtbTool -s 2048 -o arch/arm/boot/dt.img -p scripts/dtc/ arch/arm/boot/
     DTB combiner:
       Input directory: 'arch/arm/boot/'
       Output file: 'arch/arm/boot/dt.img'
     Found file: msm8974pro-ac-g3-cn.dtb ... chipset: 194, platform: 119, rev: 65537
     => Found 1 unique DTB(s)

     Generating master DTB... completed





Step 5. Add zImage and dt.img into sample flashable zip file and flash it
---------------------------------------------------------------------------
     - Don't unzip/decompress sample flashable zip file. Drag your zImage and dt.img into sample flashable zip(under kernel folder) to replace the old ones. Please make sure the file name is same;
     - Copy flashable zip to device;
     - Enter recovery mode and install the zip via TWRP;
    P.S. Please get sample flashable file at http://pan.baidu.com/s/1qWvbrCo. In this flashable file, the most important file is /tmp/install.sh, which will:
             - get your device current kernel parameters(e.g. cmdline, offset,etc)
             - generate boot.img
             - 'sign' boot.img (to avoid security issue) 



=============================HOW-TOs=======================================

How to flash facroty image to restore everything?
----------------------------------------------------
    I use 'LGMobile Support Tool'(http://pan.baidu.com/s/1bn2mTbD) on Windows to do that:
        - Install above flash tool on Windows(For my case,I installed it on Win10 RTM);
        - Install LG USB driver(http://pan.baidu.com/s/1i3lLHgp) on Windows;
        - Enter Download Mode(see 'How to enter Download Mode on D858 device?' in this page)
        - Launch flash tool(On Windows Desktop named 'LGMobile Support Tool'). The tool will show your device type if everything works fine;
        - On flash tool UI, click 'Options' menu and select 'Upgrade Recovery' option. Then the flash tool would start to download factory image;
        - After download done, it starts to flash your device. What you can do here is just watching...
        - Once done, the device will reboot;
    
    You can also use LG flash tool which need KDZ file to do that. 

    factory image files(KDZ) - http://pan.baidu.com/s/1c015wek
        - D85810c.kdz is for 4.4
        - D85820b.kdz is for 5.0

    Since KDZ file is too big, I split it via 7z. For example D85820b.kdz,you can use below command on Linux:
         $7z a -v500m -mx0 D85820b_00.kdz.7z D85820b_00.kdz
    After download all parts,you can merge them like:
         $7z x D85820b_00.kdz.7z.001





How to enter Download Mode on D858 device?
-------------------------------------------
    - Power off D858 device and disconnect USB between device and PC;
    - Hold Volume UP key and connect USB between device and PC. You will see the device enter Download Mode;





How to get boot img from your device?
-------------------------------------------
   You need to get boot img from your device in case something wrong with your new kernel and you can flash back to the original&good one. You can use adb tools to retrieve the desired boot image from your D858 device, after that, use Root Explorer to copy the file, so that we can copy the file to computer through MTP:

   ;use the following commands to found the boot partition,note:msm_sdcc.1 is different on different android device
   $adb shell
   $ls -l /dev/block/platform/
   ;now we know the device platform is msm_sdcc.1
   $ls -l /dev/block/platform/msm_sdcc.1/by-name
   ; now we know the boot partition is cat mmcblk0p18 by [boot -> /dev/block/mmcblk0p18]
   ;use the following command to retrieve the boot.img
   $su
   $cat /dev/block/mmcblk0p18 > /sdcard/Download/boot.original.img
   $chmod 0666 /sdcard/Download/boot.original.img





How to get correct cmdline and initrd.img from boot img?
-----------------------------------------------------------
   Once getting boot img, you need to get more for later making new boot img...Please unpack boot.img you got above by using abootimg 
on Ubuntu:
   $abootimg -x boot.original.img 
     writing boot image config in bootimg.cfg
     extracting kernel in zImage
     extracting ramdisk in initrd.img
 
    Open generated bootimg.cfg, remove the line contains 'bootsize' and copy the containt following 'cmdline='.





How to generate and sign boot img?
-------------------------------------------
    $mkbootimg --kernel zImage --ramdisk initrd.img --cmdline "console=ttyHSL0,115200,n8 user_debug=31 ehci-hcd.park=3 msm_rtb.filter=0x0 androidboot.hardware=g3" --dt dt.img -o newboot.img
 
    For initrd.img and comdline, see "How to get correct cmdline and initrd.img from boot img?"
    For dt.img. see "How to generate D858 dt.img file?"
    For zImage, see "How to build kernel source?"

    After that, you need to 'sign' your boot img by using bump(http://pan.baidu.com/s/1kTF4qZ9) tool:
    $./open_bump.py newboot.img  
    
    It will generate a newboot_bumped.img. Rename it to boot.img and replace the one in flashable zip(http://yun.baidu.com/s/1dDubJRr) for TWRP installation.






Device configuration for LGE G3 D858
---------------------------------------
Release date  August 2014
CPU           Quad-core 2.5 GHz Krait 400
CHIPSET       Qualcomm MSM8975AC Snapdragon 801
GPU           Adreno 330
Memory        3GB RAM
Android       5.01
Storage       32GB
MicroSD       Yes,Up to 128GB
Battery       3000 mAh
Screen size   5.50
Dimensions    146.3 x 74.7 x 9.10 mm
Display       1440 x 2560 pixels True HD-IPS
Camera        13 MP, 4160 x 3120 pixels, Hybrid infared autofocus
2G Network    850/900/1800/1900MHz(SIM 1)
3G Network    WCDMA and TD-SCDMA
4G Network    FDD:1800(B3)/2600(B7)MHz TDD:2600(B38)/1900(B39)/2300(B40)/2600(B41)MHz

About

LG G3 D858 Android4.4.2 Kernel source

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published