zoukankan      html  css  js  c++  java
  • Android : 修改内核源码 and 编译、打包成新的boot.img

    一、Android内核源码的下载:

    1.Google GIT地址:

    $ git clone https://android.googlesource.com/kernel/common.git  

    $ git clone https://android.googlesource.com/kernel/exynos.git  

    $ git clone https://android.googlesource.com/kernel/goldfish.git  

    $ git clone https://android.googlesource.com/kernel/msm.git  

    $ git clone https://android.googlesource.com/kernel/omap.git  

    $ git clone https://android.googlesource.com/kernel/samsung.git  

    $ git clone https://android.googlesource.com/kernel/tegra.git  

    2.清华服务器地址:

     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/common.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/exynos.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/hikey-linaro.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/lk.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/omap.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/samsung.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/tegra.git
     git clone https://aosp.tuna.tsinghua.edu.cn/kernel/x86_64.git

    • goldfish 项目包含适用于所模拟的平台的内核源代码。
    • msm 项目包含适用于 ADP1、ADP2、Nexus One、Nexus 4、Nexus 5、Nexus 6、Nexus 5X、Nexus 6P、Nexus 7 (2013)、Pixel 和 Pixel XL 的源代码,可用作使用 Qualcomm MSM 芯片组的起点。
    • omap 项目用于 PandaBoard 和 Galaxy Nexus,可用作使用 TI OMAP 芯片组的起点。
    • samsung 项目用于 Nexus S,可用作使用 Samsung Hummingbird 芯片组的起点。
    • tegra 项目用于 Xoom、Nexus 7 (2012)、Nexus 9,可用作使用 NVIDIA Tegra 芯片组的起点。
    • exynos 项目包含适用于 Nexus 10 的内核源代码,可用作使用 Samsung Exynos 芯片组的起点。
    • x86_64 项目包含适用于 Nexus Player 的内核源代码,可用作使用 Intel x86_64 芯片组的起点。
    • hikey-linaro 项目用于 HiKey 参考板,可用作使用 HiSilicon 620 芯片组的起点。

    二、编译:
     1.代码库(msm) download之后会在对应的目录下可以通过 ls -al 查看到 .git , git branch -a 查看所有分支,我手上nexus平板刷的Android5.0的系统,所有选择以下内核版本:

      git checkout remotes/origin/android-msm-flo-3.4-lollipop-release

        2.分支代码下载好之后:

          (1)修改Makefile:

      #ARCH  ?= $(SUBARCH)
      #CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)

           修改为:

      ARCH ?= arm
      CROSS_COMPILE ?= arm-eabi-

    或者 手动设置环境变量:

      export ARCH=arm
      export SUBARCH=arm
      export CROSS_COMPILE=arm-eabi-
      export TARGET_PREBUILT_KERNEL=$你的内核目录/arch/arm/boot/zImage
           (特殊  Google Nexus5 这样设置 export TARGET_PREBUILT_KERNEL=$你的内核目录/arch/arm/boot/zImage-dtb ,其他平台遇到问题可以两个都试试)

          (2)配置:

           kernel/msm/arch/arm/configs/    ,目录下有很多配置文件
           make flo_defconfig                     ,选择默认配置,之后会生成 .config
           make menuconfig                       ,可以通过此命令进一步配置内核更新 .config

          
          (3)编译:     

           配置好内核后就可以输入 : make    ,等待 zImage 和 zImage-dtb 的生成。

    三、打包 zImage 到 boot.img,并刷机:

    第一种方法:将编译产生的新的Android内核文件 android-xxx/kernel/msm/arch/arm/boot/zImage-dtb 替换掉 Android xxx源码编译生成的内核文件。重启Nexus 5手机进入刷机模式 fastboot flashall -w 刷入手机。

    第二种方法:解包Android 源码编译生成的boot.img文件替换内核文件,具体的就是对Android 源码编译后产成的 android-xxx/out/target/product/flo/boot.img 镜像文件进行解包替换原来的Android内核文件然后进行打包。解包打包boot.img文件的工具比较多,

                         1.windows下使用bootimg.exe:

            -解包命令:bootimg.exe --unpack-bootimg      
            -打包命令:bootimg.exe --repack-bootimg   

          2.linux下
    使用bootimg-tools工具解包打包boot.img文件替换内核(bootimg-tools工具比较好用--推荐

           (1)下载bootimg-tools解包打包工具:  git clone https://github.com/pbatard/bootimg-tools.git      
           (2) make   编译生成可执行文件
           (3) ./unmkbootimg -i boot.img     : 解压原来android系统源码生成的boot.img,信息如下:

    ./unmkbootimg -i boot.img kernel written to 'kernel' (6730288 bytes) ramdisk written to 'ramdisk.cpio.gz' (619357 bytes)

    To rebuild this boot image, you can use the command:   mkbootimg --base 0 --pagesize 2048 --kernel_offset 0x80208000 --ramdisk_offset 0x82200000 --second_offset 0x81100000 --tags_offset 0x80200100 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=flo user_debug=31 msm_rtb.filter=0x3F ehci-hcd.park=3 vmalloc=340M' --kernel kernel --ramdisk ramdisk.cpio.gz -o boot.img

           (4)将内核源码编译生成的 zImage 或者 zImage-dtb   复制到 上面解压boot.img的目录下命名为kernel,使用以上红色指令进行打包生成新的boot.img,然后刷机:

              adb reboot bootloader

              fastboot erase boot

              fastboot flash boot boot.img

              fastboot reboot

                                       


      如果能正常开机,那就congratulation!!!^v^

    PS: 编译遇到的问题:

    (1)  warning: argument to 'sizeof' in 'strncmp' call is the same expression as the second source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

         解决方法:在相应位置的Makefile里加上:EXTRA_CFLAGS += -Wno-sizeof-pointer-memaccess

    (2)  Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.

         解决方法:把 kernel/timeconst.pl 脚本里该行的 defined( ) 去掉即可。 

    (3)编译的zImage打包后刷入无法正常开机,试了n久最后把编译工具 arm-eabi-4.7 换成  arm-eabi-4.6 编出来的正常 - -!

              下面提供msm的kernel源码和编译工具以及打包工具的下载链接

               msm内核源码:链接:http://pan.baidu.com/s/1eStNPVs 密码:7xj2

               编译工具: 链接:http://pan.baidu.com/s/1sloHLAt 密码:erjn

               打包工具:链接:http://pan.baidu.com/s/1mimkiG4 密码:qs0i

      -end-

  • 相关阅读:
    Oracle SQL语句收集
    SqlParameter In 查询
    SQL 性能优化
    Entity Framework
    【XLL API 函数】 xlfSetName
    【XLL API 函数】xlfUnregister (Form 2)
    【XLL API 函数】xlfUnregister (Form 1)
    【Excel 4.0 函数】REGISTER 的两种形式以及VBA等效语句
    【Excel 4.0 函数】REGISTER
    【Bochs 官方手册翻译】 第一章 Bochs介绍
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/7447178.html
Copyright © 2011-2022 走看看