aosp_013.下载,配置、编译内核并刷入手机

 


查看内核版本

adb shell
cat /proc/version

输出

Linux version 3.18.120-gd46a6fb646f9-dirty (sucom@super-pc) (gcc version 4.9.x 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Tue Apr 16 10:34:08 CST 2019

https://appuals.com/how-to-build-a-custom-android-kernel/


AOSP

https://source.android.com/setup/build/building-kernels#customize-build

#下载内核源码
repo init -u https://android.googlesource.com/kernel/manifest -b common-android-4.19
repo sync

下表列出了可通过此方法获取的内核的 BRANCH 名称:

设备AOSP 树中的二进制文件路径Repo 分支
Pixel 3 (blueline)device/google/crosshatch-kernelandroid-msm-crosshatch-4.9-pie-qpr2
Pixel 3 XL (crosshatch)
Pixel 2 (walleye)device/google/wahoo-kernelandroid-msm-wahoo-4.4-pie-qpr2
Pixel 2 XL (taimen)
Pixel (sailfish)device/google/marlin-kernelandroid-msm-marlin-3.18-pie-qpr2
Pixel XL (marlin)
Hikeydevice/linaro/hikey-kernelandroid-hikey-linaro-4.4
android-hikey-linaro-4.9
android-hikey-linaro-4.14
android-hikey-linaro-4.19
Hikey960device/linaro/hikey-kernelandroid-hikey960-linaro-4.4
android-hikey960-linaro-4.9
android-hikey960-linaro-4.14
android-hikey960-linaro-4.19
Android 通用内核common-android-4.4
common-android-4.9
common-android-4.14
common-android-4.19

 

#编译
build/build.sh
#运行
将 Image.lz4-dtb 复制到 AOSP 树中相应的内核二进制文件位置,然后重新编译启动映像。

在使用 make bootimage(或用于编译启动映像的任何其他 make 命令行)时定义 TARGET_PREBUILT_KERNEL 变量。所有设备均支持该变量,因为它是通过 device/common/populate-new-device.sh 进行设置的,修改

export TARGET_PREBUILT_KERNEL=DIST_DIR/Image.lz4-dtb

#check kernel version
grep -a 'Linux version' Image.lz4-dtb

自定义编译

编译流程和结果可能会受环境变量的影响。它们中的大多数是可选的,并且每个内核分支都应该具有适当的默认配置。此处列出了最常用的变量。如需完整(且最新)的列表,请参阅 build/build.sh

环境变量说明示例
BUILD_CONFIG要从中初始化编译环境的编译配置文件。系统会相对于 repo 根目录定义具体位置。默认为“build.config”。
必须为通用内核指定此变量!
BUILD_CONFIG=common/build.config.cuttlefish.x86_64
OUT_DIR内核编译的基本输出目录。OUT_DIR=/path/to/my/out
DIST_DIR内核分发的基本输出目录。OUT_DIR=/path/to/my/dist
CC替换要使用的编译器。回退至 build.config 定义的默认编译器。CC=clang
SKIP_MRPROPER跳过 make mrproperSKIP_MRPROPER=1
SKIP_DEFCONFIG跳过 make defconfigSKIP_DEFCONFIG=1

本地编译的自定义内核配置

如果您需要定期切换内核配置选项(例如,在开发某项功能时),或者需要设置一个用于开发用途的选项,可以通过维护编译配置的本地修改或副本来实现这种灵活性。

将 POST_DEFCONFIG_CMDS 变量设为一个可在常规 make defconfig 步骤完成后立即进行评估的语句。由于 build.config 文件源于编译环境,因此 build.config 中定义的函数可以作为 post-defconfig 命令的一部分进行调用。

一个常见示例是在开发期间针对 crosshatch 内核停用 LTO(链接时优化)。虽然 LTO 对已发布的内核有益,但编译时产生的开销可能巨大。添加到本地 build.config 的以下代码段将在使用 build/build.sh 时永久停用 LTO。

POST_DEFCONFIG_CMDS="check_defconfig && update_debug_config"
function update_debug_config() {
    ${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
         -d LTO \
         -d LTO_CLANG \
         -d CFI \
         -d CFI_PERMISSIVE \
         -d CFI_CLANG
    (cd ${OUT_DIR} && \
     make O=${OUT_DIR} $archsubarch CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}

 


 

使用linaro工具链编译ARM64架构内核

apt-get install binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu
或

https://gts3.org/2017/cross-kernel.html

https://wiki.linaro.org/HowTo/BuildArm64Kernel



http://releases.linaro.org/components/toolchain/binaries/
选择下载版本,这里以7.4-2019.02为例
7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz下载

或者直接输入

wget http://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz

#解压
tar xvJf gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz 

#将工具链的bin目录添加到执行路径中
vim ~/.profile

#验证
aarch64-linux-gnu-gcc -v


同理下载
wget http://releases.linaro.org/components/toolchain/gcc-linaro/7.4-2019.02/gcc-linaro-7.4-2019.02.tar.xz
解压、配置变量、验证
aarch64-linux-gcc -v



cd android-kernel
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image

nanoPi编译器

http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO4#Install_Cross_Compiler

13.5 Compile FriendlyCore/FriendlyDesktop/Lubuntu/EFlasher Kernel Source Code
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
cd kernel-rockchip
make ARCH=arm64 nanopi4_linux_defconfig
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make ARCH=arm64 nanopi4-images
After compilation is done a kernel.img and a resource.img will be generated. You can simply copy them to replace the existing files in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory and you can run the following commands to update system:

# for Lubuntu
cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/
 
# for FriendlyCore
cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/
 
# for FriendlyDesktop
cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/
Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.

 

Lineage OS

#源代码树中
. build/envsetup.sh
make clean
make bootimage

 

https://github.com/LineageOS/android_kernel_xiaomi_msm8996

编译kernel工具目录

#arm32文件目录
lineage-16/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin

#arm64文件目录
ineage-16/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin

可以将文件拷出来或者直接export设置

 

#清空编译内容,包括配置文件
make mrproper 

#自定义配置
make nconfig

#更多配置选项
     "make config"      Plain text interface.

     "make menuconfig"  Text based color menus, radiolists & dialogs.

     "make nconfig"     Enhanced text based color menus.

     "make xconfig"     X windows (Qt) based configuration tool.

     "make gconfig"     X windows (Gtk) based configuration tool.

     "make oldconfig"   Default all questions based on the contents of
                        your existing ./.config file and asking about
                        new config symbols.

     "make silentoldconfig"
                        Like above, but avoids cluttering the screen
                        with questions already answered.
                        Additionally updates the dependencies.

     "make olddefconfig"
                        Like above, but sets new symbols to their default
                        values without prompting.

     "make defconfig"   Create a ./.config file by using the default
                        symbol values from either arch/$ARCH/defconfig
                        or arch/$ARCH/configs/${PLATFORM}_defconfig,
                        depending on the architecture.

     "make ${PLATFORM}_defconfig"
                        Create a ./.config file by using the default
                        symbol values from
                        arch/$ARCH/configs/${PLATFORM}_defconfig.
                        Use "make help" to get a list of all available
                        platforms of your architecture.

     "make allyesconfig"
                        Create a ./.config file by setting symbol
                        values to 'y' as much as possible.

     "make allmodconfig"
                        Create a ./.config file by setting symbol
                        values to 'm' as much as possible.

     "make allnoconfig" Create a ./.config file by setting symbol
                        values to 'n' as much as possible.

     "make randconfig"  Create a ./.config file by setting symbol
                        values to random values.

     "make localmodconfig" Create a config based on current config and
                           loaded modules (lsmod). Disables any module
                           option that is not needed for the loaded modules.

===================================================================================



执行make menuconfig找不到头文件

ubuntu

sudo apt-get install libncurses5-dev

centos

yum install ncurses-devel ncurses

 

 

https://blog.csdn.net/RadianceBlau/article/details/74275728

Android编译kernel时make menuconfig是没有作用的
Android 中编译时会以arch/arm64/configs/xxxdefconfig和各级kconfig文件生成到out\target\product\msm8953_64\obj\KERNEL_OBJ\.config。

执行完Make menuconfig 在对android进行全编,menuconfig的操作是无效的,因为android下编译脚本去out\target\product\msm8953_64\obj\KERNEL_OBJ\目录寻找.config 文件,而menuconfig生成在kernel根目录,除非将menuconfig生成的.config替换掉arch/arm64/configs/xxxdefconfig文件。
 

 

 

编译脚本

#!/bin/bash

mkdir out
make mrproper

export ARCH=arm64
export CROSS_COMPILE=/home/sucom/zhq/google_gcc/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export CROSS_COMPILE_ARM32=/home/sucom/zhq/arm32toolchain/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-
mkdir ../out
make -C ./ O=./out natrium_defconfig
make -C ./ O=./out

https://github.com/LineageOS/android_kernel_xiaomi_msm8996/pull/2

输出结果

cd ../out/arch/arm64/boot
ll

===================================================================================
total 54968
drwxrwxr-x 3 sucom sucom     4096 Jun 11 10:08 ./
drwxrwxr-x 9 sucom sucom     4096 Jun 11 10:06 ../
-rw-rw-r-- 1 sucom sucom      203 Jun 11 10:08 .Image.cmd
-rw-rw-r-- 1 sucom sucom      257 Jun 11 10:08 .Image.gz-dtb.cmd
-rw-rw-r-- 1 sucom sucom      147 Jun 11 10:08 .Image.gz.cmd
-rwxrwxr-x 1 sucom sucom 33770496 Jun 11 10:08 Image*
-rw-rw-r-- 1 sucom sucom 12849852 Jun 11 10:08 Image.gz
-rw-rw-r-- 1 sucom sucom 13801129 Jun 11 10:08 Image.gz-dtb
drwxrwxr-x 6 sucom sucom     4096 Jun 11 10:06 dts/
===================================================================================





cd ../out/arch/arm64/boot/dts/qcom
ll

===================================================================================
total 2816
drwxrwxr-x 2 sucom sucom   4096 Jun 11 10:08 ./
drwxrwxr-x 6 sucom sucom   4096 Jun 11 10:06 ../
-rw-rw-r-- 1 sucom sucom  11281 Jun 11 10:08 .b7-msm8996-v3.0-pmi8996-mtp.dtb.cmd
-rw-rw-r-- 1 sucom sucom    124 Jun 11 10:08 .b7-msm8996-v3.0-pmi8996-mtp.dtb.d.dtc.tmp
-rw-rw-r-- 1 sucom sucom   9651 Jun 11 10:08 .b7-msm8996-v3.0-pmi8996-mtp.dtb.d.pre.tmp
-rw-rw-r-- 1 sucom sucom 912409 Jun 11 10:08 .b7-msm8996-v3.0-pmi8996-mtp.dtb.dts.tmp
-rw-rw-r-- 1 sucom sucom  11247 Jun 11 10:08 .b7-msm8996pro-pmi8996-mtp.dtb.cmd
-rw-rw-r-- 1 sucom sucom    120 Jun 11 10:08 .b7-msm8996pro-pmi8996-mtp.dtb.d.dtc.tmp
-rw-rw-r-- 1 sucom sucom   9645 Jun 11 10:08 .b7-msm8996pro-pmi8996-mtp.dtb.d.pre.tmp
-rw-rw-r-- 1 sucom sucom 946531 Jun 11 10:08 .b7-msm8996pro-pmi8996-mtp.dtb.dts.tmp
-rw-rw-r-- 1 sucom sucom 477678 Jun 11 10:08 b7-msm8996-v3.0-pmi8996-mtp.dtb
-rw-rw-r-- 1 sucom sucom 473599 Jun 11 10:08 b7-msm8996pro-pmi8996-mtp.dtb
-rw-rw-r-- 1 sucom sucom      0 Jun 11 10:06 modules.order
===================================================================================

 

 

 

 


 

一加

https://blog.csdn.net/qq910689331/article/details/85765090

https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/

xiaomi 

参考文章:https://blog.csdn.net/u014418171/article/details/82659887

编译工具链:https://bitbucket.org/jonascardoso/toolchain_aarch64_travis/downloads/

小米内核开源代码:https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki/How-to-compile-kernel-standalone

WIKI:https://github.com/MiCode/Xiaomi_Kernel_OpenSource/wiki/How-to-compile-kernel-standalone

# 这里以小米5s plus为例,下载内核源代码与编译工具链
cd kernel
export ARCH=arm64
export SUBARCH=arm64
export DTC_EXT=dtc
#填写自己的toolchain路径
export CROSS_COMPILE=/toolchain/aarch64-linux-android-4.9/bin/aarch64-linux-android-

make O=out gemini_user_defconfig

make O=out 


cd out/arch/arm64/boot
ll

===================================================================================

total 61992
drwxrwxr-x 3 sucom sucom     4096 Jun  4 11:25 ./
drwxrwxr-x 9 sucom sucom     4096 Jun  4 11:24 ../
-rw-rw-r-- 1 sucom sucom      203 Jun  4 11:25 .Image.cmd
-rw-rw-r-- 1 sucom sucom     1268 Jun  4 11:25 .Image.gz-dtb.cmd
-rw-rw-r-- 1 sucom sucom      147 Jun  4 11:25 .Image.gz.cmd
-rwxrwxr-x 1 sucom sucom 33643520 Jun  4 11:25 Image*
-rw-rw-r-- 1 sucom sucom 12634411 Jun  4 11:25 Image.gz
-rw-rw-r-- 1 sucom sucom 22154900 Jun  4 11:25 Image.gz-dtb  #内核二进制文件
drwxrwxr-x 6 sucom sucom     4096 Jun  4 11:24 dts/

===================================================================================


 

 

XDT

https://forum.xda-developers.com/mi-5/development/mi5-floppy-kernel-t3712244


报错:

 

  按照步骤配置厂商的config并编译不会出现任何错误,如果报错,大概率是编译步骤出错,请不要在修改源代码上浪费时间

1.

No rule to make target 'arch/x86/mm/memtest.o', needed by 'arch/x86/mm/built-in.o' . stop
recipe for target 'arch/x86/mm' failed

解决方法
make mrproper

然后重新make config重来一遍

2.

cc1: all warnings being treated as errors

解决方法
vim Makefile
找到下面的语句

KBUILD_CFLAGS   :=

之后添加上这个参数:

-Wno-error, 如果还不起作用的话,就使用下面最强的开关

-w , 注意w小写

找不到头文件

https://github.com/MiCode/Xiaomi_Kernel_OpenSource/issues/71

Sometimes, you need compile wlan and audio(sdm845) modules if you find wifi and audio not work after flashing boot.img

maybe some of you face compile error like this error: msm_isp.h: No such file or directory

In android source code (caf), It is already setup environment. like O=out/target/product/{TARGET_PRODUCT}/obj/kernel/, toolchain= ARCH=arm64/arm/x86/mips

it's not a problem with kernel at all! This can be fixed by redirecting output to a out folder as done in steps above

 


https://www.youtube.com/watch?v=cUSKlqkoe9s

Steps to Configure, Build & Flash your own Custom Android Kernel:

Requirements:
A PC/Laptop with Linux-based OS & Quad/Dual Core CPU (hyper-threaded processors preferable)
8 / 4 GB of RAM
Android Device with Unlocked Bootloader
Patience


STEPS TO SETUP THE ENVIRONMENT FOR BUILDING THE ANDROID KERNEL:

1. Open Terminal

2. Execute this command:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2



3. Download the Source Code of your device from GitHub:
LineageOS: https://github.com/LineageOS?utf8=%E2%9C%93&q
Motorola: https://www.youtube.com/redirect?event=video_description&v=cUSKlqkoe9s&redir_token=QOpJN4BzpiIRAJ9XR6-31IoHNS58MTU1OTM1Mjg1OEAxNTU5MjY2NDU4&q=https%3A%2F%2Fgithub.com%2FMotorolaMobilityLL
Samsung: https://opensource.samsung.com/
OnePlus: https://github.com/OnePlusOSS?utf8=✓&...
Xiaomi: https://github.com/MiCode/Xiaomi_Kernel_OpenSource
LG: http://opensource.lge.com/osSch/list?...
HTC: https://www.htcdev.com
Sony: https://github.com/sonyxperiadev/kern...
Others: Google and XDA are your best Friends


4. Download the Toolchain
  https://www.youtube.com/redirect?redir_token=gF10LKw744-TP6Q-y2R5ZN97uO58MTU1OTM3NzAzNEAxNTU5MjkwNjM0&v=cUSKlqkoe9s&q=https%3A%2F%2Fandroid.googlesource.com%2Fplatform%2Fprebuilts%2Fgcc%2Flinux-x86%2Faarch64%2Faarch64-linux-&event=video_description
  ----arm64 devices
   git clone https://android.googlesource.com/plat...   ---arm32 devices

5. Extract both the Source Code and toolchain

6. Make a new folder and rename it to "kernel" for easy reference

7. Move both Extracted "Source Code" and "toolchain Folders" to "kernel" folder

8. Rename The Source Code folder to the name of device and other folder to toolchain

********************************************************************

STEPS TO CONFIGURE & BUILD THE KERNEL:

9. cd kernel

 cd Lenovo
(cd to your Source Code Directory)

10. export CROSS_COMPILE=/home/aman05382/kernel/toolchain/bin/aarch64-linux-android-
    
(Here replace the yourusername with the username of your terminal or just copy the path)


12. make clean && make mrproper
(Make sure you execute this command in Source Code folder)

13. export ARCH=arm64
(The Architechture of my phone's CPU os ARM based & it's 32-bit CPU. If yours is a 64-bit processor then you need to type arm64)

14. Open your kernel source code folder go to "arch/arm/configs"
  
15. Find that "yourdevicecode_defconfig"
(Replace yourdevicecode_defconfig with the codename of your device. A6020 in my case for Lenovo Vibe K5)


16. make yourdevice_defconfig
   
  make lineage_A6020_defconfig

17. make menuconfig
(Make whatever Changes you want and finally save it with somename.config)

18. make -j4
(4 is the number of cores of the CPU of my Laptop. You need to change it according to your Laptop/PC)

 


打包boot.img

https://android.stackexchange.com/questions/69954/how-to-unpack-and-edit-boot-img-for-rom-porting

 

https://www.cnblogs.com/helloworldtoyou/p/6473661.html

在win下, 使用 Android Image Kitchen (软件请百度,注意分6.x 7.x 8.x 可用版本)

但是"This project is retired as of 2013, as I have become overwhelmed with the number of devices to support, the demand, bad health, and the constant requests for help".

先取出你的手机ROM中的 boot.img 拖到unpackimg.bat去解包, 然后把image.gz-dtb 该文件替换掉原本的内核文件 split_img/boot.img-zImage
然后执行repackimg.bat 得到 image-new.img
执行如下命令 刷入

adb reboot bootloader && fastboot flash boot C:\你的路径\image-new.img  && fastboot reboot


前提是 你刷入的rom正好是 刚才取出boot.img的那个. 否则可能无法正常开机
或者直接把原本的rom中的boot.img替换成编译好的boot.img 再 从recovery双清刷


————————————————————————————————————————————————————————————————————————

#lineage源代码树中自带打包、解包工具

#要求python环境2.7

cd lineage/lineage-16/system/core/mkbootimg
sudo cp ./mkbootimg ./unpack_bootimg /usr/bin/

#如果没有这两个执行文件
gcc -o ./mkbootimg -I ../include ../libmincrypt/*.c ./mkbootimg.c
gcc -o ./unpack_bootimg -I ../include ../libmincrypt/*.c ./unpackbootimg.c



file boot.img
#输出
boot.img: Android bootimg, kernel, ramdisk, page size: 4096, cmdline (androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firm)


#解包
unpack_bootimg --help

usage: unpack_bootimg [-h] --boot_img BOOT_IMG [--out OUT]

Unpacks boot.img/recovery.img, extracts the kernel,ramdisk, second bootloader
and recovery dtbo

optional arguments:
  -h, --help           show this help message and exit
  --boot_img BOOT_IMG  path to boot image
  --out OUT            path to out binaries

例:unpack_bootimg --boot_img  boot.img 


输出结果:
boot_magic: ANDROID!
kernel_size: 13768302
kernel load address: 2147516416
ramdisk size: 2313918
ramdisk load address: 2164260864
second bootloader size: 0
second bootloader load address: 2163212288
kernel tags load address: 2147483904
page size: 4096
boot image header version: 0
os version and patch level: 301990197
product name: 
command line args: androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firmware_class.path=/vendor/firmware_mnt/image loop.max_part=7 buildvariant=userdebug
additional command line args:

cd out
ll

输出结果:
total 15716
drwxrwxr-x 2 sucom sucom     4096 Jun  5 13:37 ./
drwxrwxr-x 3 sucom sucom     4096 Jun  5 13:37 ../
-rw-rw-r-- 1 sucom sucom 13768302 Jun  5 13:37 kernel
-rw-rw-r-- 1 sucom sucom  2313918 Jun  5 13:37 ramdisk
-rw-rw-r-- 1 sucom sucom        0 Jun  5 13:37 second


file kernel
#输出
kernel: gzip compressed data, max compression, from Unix




=====================================================================

#打包
mkbootimg -h

usage: mkbootimg [-h] --kernel KERNEL [--ramdisk RAMDISK] [--second SECOND]
                 [--recovery_dtbo RECOVERY_DTBO] [--cmdline CMDLINE]
                 [--base BASE] [--kernel_offset KERNEL_OFFSET]
                 [--ramdisk_offset RAMDISK_OFFSET]
                 [--second_offset SECOND_OFFSET] [--os_version OS_VERSION]
                 [--os_patch_level OS_PATCH_LEVEL] [--tags_offset TAGS_OFFSET]
                 [--board BOARD]
                 [--pagesize {2048,4096,8192,16384,32768,65536,131072}] [--id]
                 [--header_version HEADER_VERSION] [--dt DT] -o OUTPUT

optional arguments:
  -h, --help            show this help message and exit
  --kernel KERNEL       path to the kernel
  --ramdisk RAMDISK     path to the ramdisk
  --second SECOND       path to the 2nd bootloader
  --recovery_dtbo RECOVERY_DTBO
                        path to the recovery DTBO
  --cmdline CMDLINE     extra arguments to be passed on the kernel command
                        line
  --base BASE           base address
  --kernel_offset KERNEL_OFFSET
                        kernel offset
  --ramdisk_offset RAMDISK_OFFSET
                        ramdisk offset
  --second_offset SECOND_OFFSET
                        2nd bootloader offset
  --os_version OS_VERSION
                        operating system version
  --os_patch_level OS_PATCH_LEVEL
                        operating system patch level
  --tags_offset TAGS_OFFSET
                        tags offset
  --board BOARD         board name
  --pagesize {2048,4096,8192,16384,32768,65536,131072}
                        page size
  --id                  print the image ID on standard output
  --header_version HEADER_VERSION
                        boot image header version
  --dt DT               path to the device tree image
  -o OUTPUT, --output OUTPUT
                        output file name



#打包命令

./mkbootimg --kernel ./out/kernel --ramdisk ./out/ramdisk --pagesize 4096 --cmdline 'androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firmware_class.path=/vendor/firmware_mnt/image loop.max_part=7 buildvariant=userdebug' --base 0x80000000 -o new-boot.img

file boot.img
boot.img: Android bootimg, kernel, ramdisk, page size: 4096, cmdline (androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firm)

file new-boot.img
new-boot.img: Android bootimg, kernel, ramdisk, page size: 4096, cmdline (androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firm)









第三方打包、解包工具

https://www.theandroidsoul.com/how-to-unpack-and-repack-boot-and-ramdisk-files-easily/

chmod a+x boot_info mkbootimg repack_ramdisk split_boot unpack_ramdisk


boot_info :file included in the package allows you to the base address and the ramdisk address of the boot.img file which you will later need for repackaging.

split_boot (split_bootimg.pl) :helps you extract the ramdisk and zImage from the boot.img file into a separate folder.

unpack_ramdisk : allows you to unpack the ramdisk file using the following command:
Usage: unpack_ramdisk <ramdiskFile>

repack_ramdisk : feature will let you repack the ramdisk file from the given directory using the following command:
Usage: repack_ramdisk <ramdiskDirectory> [outputFile]

mkbootimg : command helps you create a brand new boot.img file from the ramdisk and zImage files you have (useful for creating modified boot.img files).

umkbootimg : does the very opposite and splits up the kernel and boot image.

unpack : will simply extract the boot.img file in one directory and the ramdisk in a separate directory for convenience.



===================================================================================
#查看信息
./boot_info boot.img
Page size: 4096 (0x00001000)
Kernel size: 13767879 (0x00d214c7)
Ramdisk size: 2313918 (0x00234ebe)
Second size: 0 (0x00000000)
Board name: 
Command line: 'androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firmware_class.path=/vendor/firmware_mnt/image loop.max_part=7 buildvariant=userdebug'
Base address: 2147483648 (0x80000000)

#解包
./split_boot boot.img 
Page size: 4096 (0x00001000)
Kernel size: 13767879 (0x00d214c7)
Ramdisk size: 2313918 (0x00234ebe)
Second size: 0 (0x00000000)
Board name: 
Command line: 'androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firmware_class.path=/vendor/firmware_mnt/image loop.max_part=7 buildvariant=userdebug'
Base address: (0x80000000)

Writing boot/boot.img-kernel ... complete.
Writing boot/boot.img-ramdisk.cpio.gz ... complete.
Unpacking ramdisk... complete.
cd ./boot
ll

total 15720
drwxrwxr-x  3 sucom sucom     4096 Jun 12 10:09 ./
drwxrwxr-x  3 sucom sucom     4096 Jun 12 10:09 ../
-rw-rw-r--  1 sucom sucom 13767879 Jun 12 10:09 boot.img-kernel
-rw-rw-r--  1 sucom sucom  2313918 Jun 12 10:09 boot.img-ramdisk.cpio.gz
drwxrwxr-x 17 sucom sucom     4096 Jun 12 10:09 ramdisk/

./unpack_ramdisk ./boot/boot.img-ramdisk.cpio.gz 
11920 blocks

cd ./ramdisk
ll

total 3256
drwxrwxr-x 17 sucom sucom    4096 Jun 12 10:17 ./
drwxrwxr-x  4 sucom sucom    4096 Jun 12 10:17 ../
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 acct/
lrwxrwxrwx  1 sucom sucom      11 Jun 12 10:17 bin -> /system/bin
lrwxrwxrwx  1 sucom sucom      19 Jun 12 10:17 bt_firmware -> /vendor/bt_firmware
lrwxrwxrwx  1 sucom sucom      50 Jun 12 10:17 bugreports -> /data/user_de/0/com.android.shell/files/bugreports
drwxrwx---  2 sucom sucom    4096 Jun 12 10:17 cache/
lrwxrwxrwx  1 sucom sucom      13 Jun 12 10:17 charger -> /sbin/charger
dr-xr-xr-x  2 sucom sucom    4096 Jun 12 10:17 config/
lrwxrwxrwx  1 sucom sucom      17 Jun 12 10:17 d -> /sys/kernel/debug/
drwxrwx--x  2 sucom sucom    4096 Jun 12 10:17 data/
lrwxrwxrwx  1 sucom sucom      23 Jun 12 10:17 default.prop -> system/etc/prop.default
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 dev/
lrwxrwxrwx  1 sucom sucom      11 Jun 12 10:17 dsp -> /vendor/dsp
lrwxrwxrwx  1 sucom sucom      11 Jun 12 10:17 etc -> /system/etc
lrwxrwxrwx  1 sucom sucom      20 Jun 12 10:17 firmware -> /vendor/firmware_mnt
-rwxr-x---  1 sucom sucom 2217088 Jun 12 10:17 init*
-rwxr-x---  1 sucom sucom    1222 Jun 12 10:17 init.environ.rc*
-rwxr-x---  1 sucom sucom   29747 Jun 12 10:17 init.rc*
-rwxr-x---  1 sucom sucom    7690 Jun 12 10:17 init.usb.configfs.rc*
-rwxr-x---  1 sucom sucom    5646 Jun 12 10:17 init.usb.rc*
-rwxr-x---  1 sucom sucom     511 Jun 12 10:17 init.zygote32.rc*
-rwxr-x---  1 sucom sucom     875 Jun 12 10:17 init.zygote64_32.rc*
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 mnt/
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 odm/
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 oem/
-rw-r--r--  1 sucom sucom   26662 Jun 12 10:17 plat_file_contexts
-rw-r--r--  1 sucom sucom    8683 Jun 12 10:17 plat_hwservice_contexts
-rw-r--r--  1 sucom sucom    9384 Jun 12 10:17 plat_property_contexts
-rw-r--r--  1 sucom sucom    1647 Jun 12 10:17 plat_seapp_contexts
-rw-r--r--  1 sucom sucom   16072 Jun 12 10:17 plat_service_contexts
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 proc/
lrwxrwxrwx  1 sucom sucom      15 Jun 12 10:17 product -> /system/product
drwxr-xr-x  3 sucom sucom    4096 Jun 12 10:17 res/
drwxr-x---  2 sucom sucom    4096 Jun 12 10:17 sbin/
lrwxrwxrwx  1 sucom sucom      21 Jun 12 10:17 sdcard -> /storage/self/primary
-rw-r--r--  1 sucom sucom  788761 Jun 12 10:17 sepolicy
drwxr-x--x  2 sucom sucom    4096 Jun 12 10:17 storage/
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 sys/
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 system/
-rw-r--r--  1 sucom sucom    5359 Jun 12 10:17 ueventd.rc
drwxr-xr-x  2 sucom sucom    4096 Jun 12 10:17 vendor/
-rw-r--r--  1 sucom sucom   72167 Jun 12 10:17 vendor_file_contexts
-rw-r--r--  1 sucom sucom    6684 Jun 12 10:17 vendor_hwservice_contexts
-rw-r--r--  1 sucom sucom   15786 Jun 12 10:17 vendor_property_contexts
-rw-r--r--  1 sucom sucom    3126 Jun 12 10:17 vendor_seapp_contexts
-rw-r--r--  1 sucom sucom    1831 Jun 12 10:17 vendor_service_contexts
-rw-r--r--  1 sucom sucom     468 Jun 12 10:17 vndservice_contexts

./repack_ramdisk ramdisk/

cpio: File ./.cpio.gz grew, 131072 new bytes not copied
12337 blocks
 find -name ".cpio*"

./ramdisk/.cpio.gz

./mkbootimg --kernel ./boot/boot.img-kernel --ramdisk ./ramdisk
/.cpio.gz -o new-boot.img


./mkbootimg --kernel ./boot/boot.img-kernel --ramdisk ./boot/boot.img-ramdisk.cpio.gz --pagesize 4096 --cmdline 'androidboot.hardware=qcom ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff firmware_class.path=/vendor/firmware_mnt/image loop.max_part=7 buildvariant=userdebug' --base 0x80000000 -o new-boot.img

 


 

 

 

ramdisk.img 简介

https://blog.csdn.net/allon19/article/details/37818905

ramdisk:ram disk虚拟内存盘,将ram模拟成硬盘来使用的文件系统。ramdisk文件系统是在系统上电后直接从磁盘一次性加载到内存,在整个运行期间都不会有写回操作,所以,任何修改都掉电后丢失。

ramdisk.img:ramdisk.img是编译Android生成的一个镜像文件,最后和kernel一起打包生成boot.img镜像。ramdisk.img中主要是存放android启动后第一个用户进程init可执行文件和init.*.rc等相关启动脚本以及sbin目录下的adbd工具。

#解压ramdisk.img

file ramdisk.img

#输出  ramdisk.img: gzip compressed data, from Unix

#备份
cp ramdisk.img ramdisk.img.backup

mv ramdisk.img ramdisk.img.gz
gunzip ramdisk.img.gz
mkdir temp
cd temp
cpio -i -F ../ramdisk.img

 


将打包后的boot.img刷入手机

1、fastboot 

adb reboot bootloader
fastboot flash boot new_boot.img
fastboot reboot

2、recovery


自定义kernel配置

https://blog.csdn.net/Qidi_Huang/article/details/77984575

【前言】 
  昨天将 Android N 上的驱动代码移植到 Android O 上,xxxx_defconfig 文件是我手动修改的,但因为公司将内核版本切换到 4.9 之后开启了强制代码格式检查,所以 Patch 在提交到服务器之后无法通过格式检测,一直提示存在如下问题:

checkpatch found errors or warnings:
  $ git log -1 | ./scripts/xxx/merge_pre_check.pl -; total 3 errors.
    1: xxxx64_defconfig not generated by savedefconfig
    2: xxxx32_defconfig not generated by savedefconfig


  说来惭愧,在之前的项目开发过程中我没有使用过 checkpatch.pl 脚本对代码修改进行过格式检查,这个问题我搞了一整天才搞好。所以这里记录一下。

【检查 Kconfig 文件】 
  在最新的内核提交规范中,要求 Kconfig 文件中所有模块的默认配置都设置为 n,并且不允许使用 select 语句。这是为了让使用者必须手动显示地去选择上驱动模块的配置。所以如果我们的老代码中将模块默认配置设置成的 y 或者使用的 select 语句隐式地打开了某些依赖模块的开关,我们都需要在移植过程中进行修改:将 y 改成 n,将 select 改成 depends on,不再使用的菜单或配置项则应该被去掉或注释掉。 
  比如我所负责模块里老的 Kconfig 文件写法如下:

menu "Audio Interface"
config XXX_AUDIO
    bool "XXX Audio Interface"
    default y
    select SOUND
    select SND_SOC
    select SND
    select XXX_AUDIO_DSP
    select SND_XXX_SOC
    select SWITCH
    help
      "XXX Audio Interface"
endmenu

将上方的内容按要求进行修改后则是像下方这样:

menu "Audio Interface"
config XXX_AMAUDIO
    bool "XXX Audio Interface"
    default n
    depends on SOUND
    depends on SND_SOC
    depends on SND
    depends on XXX_AUDIO_DSP
    #depends on SND_XXX_SOC
    #depends on SWITCH
    help
      "XXX Audio Interface"
endmenu

【修改 defconfig 文件】 
  我使用的平台分 32 位和 64位,我们要对这 2 个 defconfig 文件都进行修改。文件分别位于 arch/arm/configs/xxxx32_defconfig 和 arch/arm64/configs/xxxx64_defconfig。 
  首先执行以下命令从老的 xxxx_defconfig 文件生成临时使用的 .config 文件:

$ make ARCH=arm xxxx32_defconfig

其中 ARCH=arm 用来指明当前修改的是 32 位配置,如果要修改的是 64 位配置就应该将这个参数指定为 ARCH=arm64,后文均以 32 位为例。然后在 menuconfig 菜单中手动选择上我们需要添加的模块。执行以下命令打开配置菜单:

$ make ARCH=arm menuconfig

手动选择好要使用的模块,保存并退出后,我们的配置就写入到 .config 文件中了。然后我们再执行下方的命令将配置保存到 defconfig 文件中:

$ make ARCH=arm savedefconfig

上方这条命令在成功被执行之后,我们可以在内核的根目录下发现新增了一个名为 defconfig 的文件,这个文件里包含了所有模块的配置。我们只需要将要移植的模块配置添加到 xxxx32_defconfig 文件中就行了,可以使用下方的命令查看要添加的内容:

$ diff -u arch/arm/configs/xxxx32_defconfig defconfig
或者用
$ vim -d arch/arm/configs/xxxx32_defconfig defconfig


 最后将上方命令打印出的那部分改动合入到 arch/arm/configs/xxxx32_defconfig 文件中就好了。 
 通过这种方式修改的 defconfig 文件在提交到服务器后就不会再被提示 xxxx32_defconfig not generated by savedefconfig 了。 
 关于代码格式的一些更详细的说明,感兴趣的朋友可以阅读《谈谈Linux内核驱动的coding style》
 

 


修改kernel,获取root权限

找到initrd目录下的init.rc和init.aosp.rc,如果只能找到一个也没有关系,打开所有找到的文件,搜索class_start core,哪个文件能搜索到,我们就修改那个文件。
我们在class_start core这条语句的上面添加一条语句

start sysinit


在这个文件的最底下插入以下代码

service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
disabled
oneshot


全部保存,然后我们再修改initrd文件夹下的default.prop文件,将ro.secure=1改为ro.secure=0
 

 

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值