Skip to content

Commit

Permalink
build lineageos 20.0 for pixel 4, volte
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Nov 5, 2023
1 parent 5ab71fa commit 5da87a3
Show file tree
Hide file tree
Showing 55 changed files with 626 additions and 62 deletions.
2 changes: 2 additions & 0 deletions source/android/apps/termux_dev/termux_apt_tool
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ssh服务
pkg install openssh
# sudo工具
pkg install tsu
# ip工具和vim
Expand Down
15 changes: 12 additions & 3 deletions source/android/apps/termux_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ Termux安装

需要注意Termux不支持没有NEON SIMD的ARM设备,例如基于Nvidia Tegra 2 CPU。

可以安装 :ref:`f-droid` 客户端来安装应用,也可以直接下载安装 `termux apk <https://f-droid.org/en/packages/com.termux/>`_ APK软件包直接运行安装 - 安装方法和其他APK没有什么两样,安装后运行 ``Termux`` 会出现一个终端界面,然后有一些提示信息指导我们下一步操作。
可以采用如下两种方法之一:

- 安装 :ref:`f-droid` 客户端来安装应用
- 直接下载安装 `termux apk <https://f-droid.org/en/packages/com.termux/>`_ APK软件包直接运行安装

安装方法和其他APK没有什么两样,安装后运行 ``Termux`` 会出现一个终端界面,然后有一些提示信息指导我们下一步操作

更新系统
==========
Expand Down Expand Up @@ -52,11 +57,15 @@ Termux安装
:caption: 配置ssh登陆Termux环境 ~/.ssh/config
:emphasize-lines: 3

注意,Termux不是使用标准的22端口作为ssh访问端口,使用 ``8022``
.. note::

- Termux不是使用标准的22端口作为ssh访问端口,使用 ``8022``
- 登陆用户的账号名字以 ``termux`` 终端中输入 ``id`` 命令获得,请替换成你自己系统中的用户名


- 然后就可以ssh访问主机::

ssh pixel1
ssh pixel

顺利登陆系统之后,立即配置 :ref:`ssh_key` 方便后续无需密码直接访问系统

Expand Down
2 changes: 1 addition & 1 deletion source/android/apps/termux_install/ssh_config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Host pixel1
Host pixel
HostName 192.168.10.108
Port 8022
User u0_a184
92 changes: 79 additions & 13 deletions source/android/build/build_lineageos_20_pixel_4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@

- :ref:`android_build_env_ubuntu`

- 执行更新:

.. literalinclude:: android_build_env_ubuntu/apt_update_upgrade
:caption: 修改仓库配置后更新和升级

- 安装LineageOS编译依赖:

.. literalinclude:: android_build_env_ubuntu/apt_intsall_build_dependencies_container
:language: bash
:caption: 在容器中安装Ubuntu编译LineageOS需要的依赖软件包

- 添加一个普通用户账号,注意这里关闭了密码:

.. literalinclude:: android_build_env_ubuntu/adduser_admin
:caption: 添加一个 ``admin`` 账号并切换到这个账号

- 设置缓存 50G 并且在 ``admin`` 账号配置中启动 ``ccache`` :

.. literalinclude:: android_build_env_ubuntu/ccache
:caption: 启用 ``ccache``

.. note::

编译LineageOS需要惊人的磁盘空间,按照官方文档参考,linage-18.1就需要300GB空间,更高版本要求的空间更多...
Expand Down Expand Up @@ -36,23 +57,20 @@
.. literalinclude:: build_lineageos_20_pixel_4/git
:caption: 配置git

- 初始化android仓库以及获取源代码:

.. literalinclude:: build_lineageos_20_pixel_4/repo_sync
:caption: 初始化android仓库以及获取源代码
- **重要步骤** 安装 :ref:`git-lfs` :

这里我遇到一个提示:

.. literalinclude:: build_lineageos_20_pixel_4/repo_sync_err
:caption: 初始化android仓库以及获取源代码
.. literalinclude:: ../../devops/git/git-lfs/apt_install_git-lfs
:caption: 在Ubuntu上安装git-lfs

按照提示复制升级 ``repo`` ::
- 在用户目录下执行 ``git-lfs`` 初始化:

cp /home/admin/android/lineage/.repo/repo/repo /home/admin/bin/repo
.. literalinclude:: ../../devops/git/git-lfs/git_lfs_install
:caption: 每个使用 ``Git Large File Storage`` 的用户账号下需要执行 git lfs 初始化

然后重新执行仓库同步::
- 初始化android仓库以及获取源代码:

repo init -u https://github.com/LineageOS/android.git -b lineage-20.0
.. literalinclude:: build_lineageos_20_pixel_4/repo_sync
:caption: 初始化android仓库以及获取源代码

.. note::

Expand Down Expand Up @@ -84,7 +102,7 @@
- ``-j 4`` 表示并发4个同步线程(连接)
- ``-c`` 表示 ``repo`` 值同步当前分支而不是GitHub上该仓库的所有分支

LineageOS 建议使用默认配置,不过我发现由于翻墙网络非常缓慢,适当增加同步并发可以加快同步。例如 ``repo sync -j 40`` (按照服务器的cpu core数量调整)
LineageOS 建议使用默认配置,不过我发现由于翻墙网络非常缓慢,适当增加同步并发可以加快同步。例如 ``repo sync -j 12`` (按照服务器的cpu core数量调整)

- 准备设备特定代码:

Expand Down Expand Up @@ -143,8 +161,56 @@
.. literalinclude:: build_lineageos_20_pixel_4/build_output
:caption: 编译生成的文件

:ref:`hpe_dl360_gen9` 服务器上编译完成时间大约是 1小时50分::

[100% 164133/164133] build bacon
Package Complete: out/target/product/flame/lineage-20.0-20231103-UNOFFICIAL-flame.zip

#### build completed successfully (01:49:31 (hh:mm:ss)) ####

可以开始 :ref:`lineageos_20_pixel_4`

编译问题排查
=============

``depmod`` 报错
------------------

- 首先遇到的是 ``depmod`` 报错:

.. literalinclude:: build_lineageos_20_pixel_4/build_depmod_err
:caption: 编译过程出现无法找到 modules 的 ``depmod`` 报错

这个问题的解决方法我没有google到,不过我发现是我忽略了 `Build LineageOS for Google Pixel 4 <https://wiki.lineageos.org/devices/flame/build>`_ 的一句话导致的:

If you receive an error here about vendor makefiles, jump down to Extract proprietary blobs. The first portion of breakfast should have succeeded, and **after completing you can rerun breakfast**

也就是我在首次执行 ``brekafast flame`` 来获取设备特定代码时失败(因为没有blobs),所以我转为采用 :ref:`extract_proprietary_blobs_from_lineageos_zip` 完成 blobs 提取。这个步骤完成后,我只执行了 ``source build/envsetup.sh`` 但是没有重新执行 ``breakfast flame`` 就会出现上述报错。

``webview.apk: Invalid file`` 报错
--------------------------------------

再次编译遇到错误:

.. literalinclude:: build_lineageos_20_pixel_4/webview.apk_invalid_file
:caption: ``webview.apk: Invalid file``
:emphasize-lines: 5

我检查了一下 ``external/chromium-webview/prebuilt/arm64/webview.apk`` ,发现这个文件是一个ASCII文件:

.. literalinclude:: build_lineageos_20_pixel_4/webview.apk
:caption: ``webview.apk``
:emphasize-lines: 1

但是我关注到这个文件中的版本 ``git-lfs`` 似乎是官方文档中提到的需要支持 ``--git-lfs``

这是因为我最初不知道必须支持 :ref:`git-lfs` (默认系统没有安装 ``git-lfs`` 软件包,所以 ``git lfs install`` 初始化命令是报错的),在初始化仓库使用去除了 ``--git-lfs`` 导致了这个后续仓库同步问题。

重新安装了 :ref:`git-lfs` 并重新同步仓库来完成

参考
======

- `Build LineageOS for Google Pixel 4 <https://wiki.lineageos.org/devices/flame/build>`_
- `How to build LineageOS inside a container <https://dzx.fr/blog/how-to-build-lineageos-inside-a-container/>`_
- `Android源码的下载,编译,刷机 <https://juejin.cn/post/7172004153453969415>`_ 国内通过AOSP是非常困难的,可以采用中国科大或者清华大学开源镜像来完成,具体可以参考 `清华大学开源软件镜像站: Android 镜像使用帮助 <https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/>`_
1 change: 1 addition & 0 deletions source/android/build/build_lineageos_20_pixel_4/breakfast
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source build/envsetup.sh
# 这里同步pixel4对应的设备代码 flame
# 注意,如果 从LineageOS安装zip文件中提取专有blobs (解决第一次breakfast flame失败)之后,还是需要再执行一次 breakfast flame
breakfast flame
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEPMOD 4.14.326-gee1db14248b6
make[1]: Leaving directory '/home/admin/android/lineage/out/target/product/flame/obj/KERNEL_OBJ'
make: Leaving directory '/home/admin/android/lineage/kernel/google/msm-4.14'
depmod: WARNING: could not open modules.order at /home/admin/android/lineage/out/target/product/flame/obj/PACKAGING/depmod_vendor_intermediates/lib/modules/0.0: No such file or directory
depmod: WARNING: could not open modules.builtin at /home/admin/android/lineage/out/target/product/flame/obj/PACKAGING/depmod_vendor_intermediates/lib/modules/0.0: No such file or directory
00:51:28 ninja failed with: exit status 1

#### failed to build some targets (01:07:27 (hh:mm:ss)) ###
3 changes: 3 additions & 0 deletions source/android/build/build_lineageos_20_pixel_4/build_output
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# LineageOS recovery镜像
boot.img

# 分区镜像,在刷入LineageOS之前需要为手机增加一个recovery分区
dtbo.img

# LineageOS 安装包
lineage-20.0-20231102-UNOFFICIAL-flame.zip
4 changes: 2 additions & 2 deletions source/android/build/build_lineageos_20_pixel_4/repo_sync
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
mkdir -p ~/android/lineage/
cd ~/android/lineage/

# 初始化仓库(这里需要根据设备对应的代码分支):
repo init -u https://github.com/LineageOS/android.git -b lineage-20.0
# 初始化仓库(这里需要根据设备对应的代码分支): 一定要使用 --git-lfs 参数
repo init -u https://github.com/LineageOS/android.git -b lineage-20.0 --git-lfs

# 代码同步
repo sync
12 changes: 0 additions & 12 deletions source/android/build/build_lineageos_20_pixel_4/repo_sync_err

This file was deleted.

3 changes: 3 additions & 0 deletions source/android/build/build_lineageos_20_pixel_4/webview.apk
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
...
[ 11% 7599/63502] Verifying uses-libraries: external/chromium-webview/prebuilt/arm64/webview.apk
FAILED: out/target/common/obj/APPS/webview_intermediates/enforce_uses_libraries.status
/bin/bash -c "(rm -f out/target/common/obj/APPS/webview_intermediates/enforce_uses_libraries.status ) && (build/soong/scripts/manifest_check.py --enforce-uses-libraries --enforce-uses-libraries-status out/target/common/obj/APPS/webview_intermediates/enforce_uses_libraries.status --aapt out/host/linux-x86/bin/aapt --enforce-uses-libraries-relax external/chromium-webview/prebuilt/arm64/webview.apk )"
zipro W 11-03 11:39:22 13171 13171] Error opening archive external/chromium-webview/prebuilt/arm64/webview.apk: Invalid file
ERROR: dump failed because no AndroidManifest.xml found
error: Command '['out/host/linux-x86/bin/aapt', 'dump', 'badging', 'external/chromium-webview/prebuilt/arm64/webview.apk']' returned non-zero exit status 1
[ 12% 7637/63502] Building Kernel Config
make: Entering directory '/home/admin/android/lineage/kernel/google/msm-4.14'
make[1]: Entering directory '/home/admin/android/lineage/out/target/product/flame/obj/KERNEL_OBJ'
GEN ./Makefile
...
DTBOIMG arch/arm64/boot/dtbo.img
create image file: arch/arm64/boot/dtbo.img...
Total 12 entries.
make[1]: Leaving directory '/home/admin/android/lineage/out/target/product/flame/obj/DTBO_OBJ'
make: Leaving directory '/home/admin/android/lineage/kernel/google/msm-4.14'
11:40:32 ninja failed with: exit status 1

#### failed to build some targets (12:04 (mm:ss)) ####
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python3 android/tools/extract-utils/extract_ota.py lineage-20.0-20231026-nightly-flame-signed.zip
python3 ~/android/tools/extract-utils/extract_ota.py lineage-20.0-20231026-nightly-flame-signed.zip
94 changes: 82 additions & 12 deletions source/android/hack/magisk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ Magisk可以实现的功能包括:
- 现在需要检查设备是否使用独立的 ``vbmeta`` 分区:

- 如果官方firmware软件包中有一个 ``vbmeta.img`` ,就表明你的设备使用了 ``vbmeta`` 分区
- 也可以使用如下命令检查设备
- 也可以使用如下命令检查设备:

::

adb shell ls -l /dev/block/by-name
.. literalinclude:: magisk/adb_ls_block
:caption: 检查系统中是否有 ``vbmeta`` 分区

输出中有 ``vbmeta`` , ``vbmeta_a`` 或者 ``vbmeta_b`` ,则表示设备是使用独立的 ``vbmeta`` 分区的。例如,我的 :ref:`pixel_3` 输出就有::

Expand All @@ -82,14 +81,22 @@ Magisk可以实现的功能包括:
lrwxrwxrwx 1 root root 16 1971-01-10 12:45 vbmeta_b -> /dev/block/sde22
...

综上,对于我的 :ref:`pixel_3` :
我的 :ref:`pixel_4` 输出显示:

.. literalinclude:: magisk/adb_ls_block_output
:caption: 检查系统中是否有 ``vbmeta`` 分区, :ref:`pixel_4` 输出信息

综上,对于我的 :ref:`pixel_3` / :ref:`pixel_4` :

- 使用 boot ramdisk
- 使用独立的 ``vbmeta`` 分区
- 基于第一条,应该使用 ``boot.img`` 镜像

Patching Images
-----------------
===================

:ref:`pixel_3` 下载LineageOS镜像
----------------------------------

- 我之前在 :ref:`magisk_root_ota` 采用Google Android官方下载的 factory image 中的 ``boot.img`` ,但是目前我已经不再使用Google 官方 Android ,改为 :ref:`lineageos_19.1_pixel_3` 。所以参考 `How to Root LineageOS ROM via Magisk Boot.img <https://www.droidwin.com/root-lineageos-magisk-boot-img/>`_

Expand All @@ -109,9 +116,10 @@ Patching Images

就能获得 ``boot.img`` 文件(以及其他)

- 将 ``boot.img`` 推送到手机中::
- 将 ``boot.img`` 推送到手机中:

adb push boot.img /sdcard/Download/boot.img
.. literalinclude:: magisk/push_boot.img
:caption: 将安装启动镜像 ``boot.img`` 推送到手机中

- 在手机上运行前面安装好的 ``Magisk`` 程序,然后点击 ``Install`` 按钮,此时 ``Magisk`` 会让你选择需要patch的文件,则选择刚才上传到手机中的 ``boot.img`` 文件,并继续

Expand All @@ -121,13 +129,15 @@ Patching Images

adb pull /sdcard/Download/magisk_patched-24300_DHRRP.img

- 将Android设备重启到Bootlader/Fastboot模式::
- 将Android设备重启到Bootlader/Fastboot模式:

adb reboot bootloader
.. literalinclude:: ../startup/unlock_bootloader/reboot_bootloader
:caption: 重启设备进入 ``bootloader`` 模式

并检查设备状态::
输入如下命令验证设备已经进入 ``fastboot`` 模式:

fastboot devices
.. literalinclude:: ../startup/unlock_bootloader/fastboot
:caption: 验证设备是否进入 ``fastboot`` 模式

可以看到::

Expand All @@ -153,6 +163,65 @@ Patching Images

- 完成后检查 ``Magisk`` 应用,可以看到是 ``Installed`` 状态

:ref:`build_lineageos_20_pixel_4`
-----------------------------------

现在我的最新实践是采用 :ref:`build_lineageos_20_pixel_4` ,所以 :ref:`lineageos_20_pixel_4` 可以直接使用自己编译过程生成的 ``boot.img`` 来进行补丁(也就是跳过上述从官方安装包解压 ``boot.img`` 的步骤)。方法和上述 :ref:`pixel_3` 实践类似:

- 将 ``boot.img`` 推送到手机中:

.. literalinclude:: magisk/push_boot.img
:caption: 将安装启动镜像 ``boot.img`` 推送到手机中

- 在手机上运行前面安装好的 ``Magisk`` 程序,然后点击 ``Install`` 按钮,此时 ``Magisk`` 会让你选择需要patch的文件,则选择刚才上传到手机中的 ``boot.img`` 文件,并继续

此时生成patch过的文件可以通过 ``adb ls /sdcard/Download/`` 看到,名为 ``magisk_patched-26300_NHXW1.img``

- 将patched过的镜像下载到电脑上:

.. literalinclude:: magisk/push_boot_patched.img
:caption: 将patched的镜像下载

- 然后将手机重启到 ``fastboot`` 模式:

.. literalinclude:: ../startup/unlock_bootloader/reboot_bootloader
:caption: 重启设备进入 ``bootloader`` 模式

输入如下命令验证设备已经进入 ``fastboot`` 模式:

.. literalinclude:: ../startup/unlock_bootloader/fastboot
:caption: 验证设备是否进入 ``fastboot`` 模式

可以看到:

.. literalinclude:: ../startup/unlock_bootloader/fastboot_output
:caption: 验证正确的 ``fastboot`` 模式输出信息

- 将补丁过的 ``boot.img`` 刷入当前激活的slot:

.. literalinclude:: magisk/flash_boot_patched.img
:caption: 将patched的镜像刷入手机

此时显示补丁过的boot镜像是刷入到手机当前激活的slot:

.. literalinclude:: magisk/flash_boot_patched.img_output
:caption: 将patched的镜像刷入手机,可以看到刷入的是当前激活的slot ``boot_b``

- 这里只flash了当前激活的 ``boot_b`` ,那么还有一个 ``boot_a`` 需要flash,则使用命令(需要明确指定分区 ``boot_a`` ,前面没有明确指定 ``boot_b`` 则是因为 ``boot_b`` 是当前激活分区,所以用 ``boot`` 指代就行 ):

.. literalinclude:: magisk/flash_boot_patched.img_boot_a
:caption: 另一个非当前激活分区需要明确指定刷入分区 ``boot_a`` 才能刷入

完成显示:

.. literalinclude:: magisk/flash_boot_patched.img_boot_a_output
:caption: 另一个非当前激活分区需要明确指定刷入分区 ``boot_a`` 才能刷入

- 重启设备:

.. literalinclude:: magisk/fastboot_reboot
:caption: ``fastboot`` 重启手机

旧版Magisk安装(归档)
======================

Expand Down Expand Up @@ -265,6 +334,7 @@ Magisk Hide可以绕过这些检测。
参考
=======

- `Magisk Installation <https://topjohnwu.github.io/Magisk/install.html>`_ 官方文档,基本参考
- `How to Root LineageOS ROM via Magisk Boot.img <https://www.droidwin.com/root-lineageos-magisk-boot-img/>`_
- `神奇的 Magisk <https://www.jianshu.com/p/393f5e51716e>`_
- `Android 玩家不可错过的神器:Magisk Manager <https://zhuanlan.zhihu.com/p/61302392>`_
Expand Down
1 change: 1 addition & 0 deletions source/android/hack/magisk/adb_ls_block
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adb shell ls -l /dev/block/by-name | grep vbmeta
4 changes: 4 additions & 0 deletions source/android/hack/magisk/adb_ls_block_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lrwxrwxrwx 1 root root 16 1970-07-02 10:21 vbmeta_a -> /dev/block/sde10
lrwxrwxrwx 1 root root 16 1970-07-02 10:21 vbmeta_b -> /dev/block/sde26
lrwxrwxrwx 1 root root 16 1970-07-02 10:21 vbmeta_system_a -> /dev/block/sda12
lrwxrwxrwx 1 root root 16 1970-07-02 10:21 vbmeta_system_b -> /dev/block/sda13

0 comments on commit 5da87a3

Please sign in to comment.