当前位置:   article > 正文

Android内核编译_安卓编译内核

安卓编译内核

安装ubuntu虚拟机

首先安装粘贴板

sudo apt-get install open-vm-tools
sudo apt-get install open-vm-tools-desktop
  • 1
  • 2

然后换软件源

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
sudo gedit /etc/apt/sources.list
  • 1
  • 2

阿里云源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted
universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main
restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main
restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main
restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main
restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted
universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main
restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main
restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main
restricted universe multiverse


sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

安装环境

配置环境

sudo apt-get install git-core gnupg flex bison build-essential zip
curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386
libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-
dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
  • 1
  • 2
  • 3
  • 4

安装配置git

sudo apt-get install git
git config --global user.email "xxx@gmail.com"
git config --global user.name "xxx"
  • 1
  • 2
  • 3

安装配置curl

sudo apt-get install curl
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo >
~/bin/repo
chmod a+x ~/bin/repo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

安装python

add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9
sudo ln -s /usr/bin/python3 /usr/bin/python
  • 1
  • 2
  • 3

这里查看自己的源码分支

下载源码

repo init -u https://android.googlesource.com/kernel/manifest -b
android-msm-coral-4.14-android12
repo sync
  • 1
  • 2
  • 3

使用adb shell cat /proc/version查看自己的内核版本号, 我的内核版本是Linux version
4.14.261-gdbc92b7a2b83-ab8577204

然后进入private/msm-google文件夹checkout一下

git checkout dbc92b7a2b83
  • 1

修改swap大小

sudo swapoff /swapfile
sudo rm /swapfile
## 我设置了32g交换区, 防止编译失败
sudo dd if=/dev/zero of=/swapfile bs=1GB count=32
sudo chmod 600 /swapfile
sudo mkswap -f /swapfile
sudo swapon /swapfile
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

编译源码

打开下面这个链接下载android-image-kitchen
链接: android-image-kitchen

将boot.img放到其文件夹下面, 运行unpackimg.bat得到命令行参数

将解压后的boot.img-ramdisk.cpio放在源码的根目录下

下载: 文件到源码的根目录下

修改build/build.sh, 在echo " Files copied to ${DIST_DIR}"之前加上下面这几句

if [ -f "${VENDOR_RAMDISK_BINARY}" ]; then
cp ${VENDOR_RAMDISK_BINARY} ${DIST_DIR}
fi
  • 1
  • 2
  • 3

下载rwProcMem33源码

git clone https://github.com/abcz316/rwProcMem33
  • 1

驱动模块放到源码的drivers目录下, 修改Makefile文件为

obj-m += rwProcMem.o
  • 1

将drivers目录下的Makefile文件加一行

obj-m += rwProcMem/
  • 1

修改ver_control.h, 将使用pagemap的宏定义启用

输入命令开始编译, 命令参数需要自己按照自己的配置修改

BUILD_CONFIG=private/msm-google/build.config.floral
BUILD_BOOT_IMG=1 MKBOOTIMG_PATH=mkbootimg.py
VENDOR_RAMDISK_BINARY=boot.img-ramdisk.cpio KERNEL_BINARY=Image.lz4
BOOT_IMAGE_HEADER_VERSION=2
KERNEL_CMDLINE="console=ttyMSM0,115200n8
androidboot.console=ttyMSM0 printk.devkmsg=on msm_rtb.filter=0x237
ehci-hcd.park=3 service_locator.enable=1 androidboot.memcg=1
cgroup.memory=nokmem usbcore.autosuspend=7
androidboot.usbcontroller=a600000.dwc3 swiotlb=2048
androidboot.boot_devices=soc/1d84000.ufshc loop.max_part=7
buildvariant=user" BASE_ADDRESS=0x00000000 PAGE_SIZE=4096
build/build.sh
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/551772
推荐阅读
相关标签
  

闽ICP备14008679号