美文网首页
利用LineageOS构建自己的android-12 ROM

利用LineageOS构建自己的android-12 ROM

作者: 鹈鹕醍醐 | 来源:发表于2022-06-29 17:56 被阅读0次

    生产环境:Ubuntu-18.04,已有工具:repo、git、androidSDK。已有设备三星tab s5e

    1.事先准备

    2.下载源码

    • 创建代码仓库文件夹:mkdir ~/LineageOS
    • 初始化repo:repo init -u https://github.com/LineageOS/android.git -b lineage-19.1
    • 下载lineageos:repo sync
    • 初始化device: source build/envsetup.sh && breakfast gts4lvwifi

    3.提取设备专有blob文件 & 构建系统

    • 提取设备专有blob文件有两种途径可选:
      • 方法1:设备专有文件可以通过一个已经刷入lineageOS的设备中导出:准备一个可root 调试并且已刷入lineageOS的设备,连接电脑。然后在device/samsung/gts4lvwifi/文件夹下执行./extract-files.sh,导出proprietary文件。
        (注意这个方式会有libantradio.lib等20个文件导出失败,可结合 https://github.com/TheMuppets/proprietary_vendor_samsung.git 仓库补全丢失文件)
      • 方法2:从zip安装包提取设备专有blob文件 (见第4节)
    • 构建系统(第一次需要好几个小时):
      croot
      brunch gts4lvwifi
      

    4.通过lineageOS的ROM包提取设备专有blob文件

    在rom包中有三种不同类型的OTA:

    • block块类型的OTA:系统分区内容存储在.dat或者.dat/br文件内。
    • file文件类OTA:系统分区内容存储在一个名叫system的zip文件内
    • payload类OTA:系统分区内容存储在payload.bin文件内的img文件。

    如何判别:

    • 如果zip压缩包内没有System文件夹或者system文件夹几乎是空的,并且在zip的根目录存在一个system.transfer.list文件,那么它就是一个block块类型的OTA文件。
    • 如果zip文件内没有system.transfer.list文件,而且system文件夹内内容很全面,那么它就是一个file类OTA
    • 如果设备使用了A/B分区,那么需要一个payload类的OTA。
    4.1:从block-based OTA导出设备专有文件(三星tab s5e用的此方案):
    • 创建临时文件夹:Create a temporary directory and move there:

      mkdir ~/android/system_temp/ 
      cd ~/android/system_temp/
      
    • 解压ROM里的system文件(注意path/to/替换为本地文件路径):Extract system.transfer.list and system.new.dat.br or system.new.dat from the installable LineageOS zip:
      unzip path/to/lineage-*.zip system.transfer.list system.new.dat*

    • 解压ROM里的vendor文件:If your OTA includes vendor.transfer.list and vendor.new.dat.br or vendor.new.dat (or others), extract them from the installable LineageOS zip as well:
      unzip path/to/lineage-*.zip vendor.transfer.list vendor.new.dat*

    • 将new.dat.br转换成new.dat:In the case of system.new.dat.br/vendor.new.dat.br/super.new.dat.br/etc. (a brotli archive) exists, you will first need to decompress them using the brotli utility:

      sudo apt-get install brotli
      brotli --decompress --output=system.new.dat system.new.dat.br
      And if you have a vendor.dat.new.br (or others) file: 
      brotli --decompress --output=vendor.new.dat vendor.new.dat.br
      
    • 将new.dat转换成镜像文件:You now need to get a copy of sdat2img. This script can convert the content of block-based OTAs into dumps that can be mounted. sdat2img is available at the following git repository that you can clone with:
      git clone https://github.com/xpirt/sdat2img
      Once you have obtained sdat2img, use it to extract the system image:
      python sdat2img/sdat2img.py system.transfer.list system.new.dat system.img
      And if you have a vendor.dat.new (or others) file:
      python sdat2img/sdat2img.py vendor.transfer.list vendor.new.dat vendor.img

    • 挂载system镜像和vendor镜像:You should now have a file named system.img that you can mount as follows:
      mkdir system/ sudo mount system.img system/
      If you have a file named vendor.img, or similar, you can mount them as follows:

      sudo rm -r system/vendor 
      sudo mkdir system/vendor 
      sudo mount vendor.img system/vendor/ 
      

      Unlike the above, if you have a super.dat.new file: (如果不是上面那种情况,需要这个)
      python sdat2img/sdat2img.py super.transfer.list super.new.dat super.img9+
      You will now have a file named super.img, You need to get a copy of lpunpack to extract images from it. This script can extract the content of the Super partition into it’s respective component partitions that can be mounted. Luckily, lpunpack is easily buildable, executing the following from a LineageOS 17.1 or greater tree:
      source build/envsetup.sh
      breakfast your_device_codename
      m lpunpack
      Once you have built lpunpack, use it to extract the super image:
      lpunpack super.img /output/dir
      You must also now mount any other image files that you have in their respective directories as shown above with vendor.img.

    • 导出文件:After you have mounted the image(s), move to the root directory of the sources of your device and run extract-files.sh as follows:(在LineageOS/device/samsung/gts4lvwifi 目录下,不要再common目录)
      ./extract-files.sh ~/android/system_temp/
      This will tell extract-files.sh to get the files from the mounted system dump rather than from a connected device.

    • 解除镜像挂载:Once you have extracted all the proprietary files, unmount the vendor dump if you mounted it earlier:
      sudo umount ~/android/system_temp/system/vendor
      Then unmount the system dump:
      sudo umount ~/android/system_temp/system

    • 移除临时文件夹:Finally, unmount any other images before deleting the no longer needed files:
      rm -rf ~/android/system_temp/

    4.2:从file-based OTA导出设备专有文件:
    • Create a temporary directory to extract the content of the zip and move there:
      mkdir ~/android/system_temp/
      cd ~/android/system_temp/
      
    • Extract the system folder from the zip:
      unzip path/to/lineage-*.zip system/*
    • After you have extracted the system folder, move to the root directory of the sources of your device and run extract-files.sh as follows:
      ./extract-files.sh ~/android/system_temp/
      This will tell extract-files.sh to get the files from the extracted system dump rather than from a connected device.
    • Once you’ve extracted all the proprietary files, you can delete the files that were extracted from the zip:
      rm -rf ~/android/system_temp/
    4.3:从payload-based OTA导出设备专有文件
    • Create a temporary directory to extract the content of the zip and move there:
      mkdir ~/android/system_temp/ 
      cd ~/android/system_temp/
      
    • Extract the payload.bin file from the LineageOS installation zip file (注意要把以下的path/to 替换为文件的真实路径):
      unzip /path/to/lineage-*.zip payload.bin
      You will now need to use a tool called update-payload-extractor. To use the tool, you will need python-protobuf, if you do not already have it:
      sudo apt-get install python-protobuf
    • You can now extract the .img files from the payload:
      • If you have a LineageOS build tree checked out already, you can just run the script to extract the payload:
        python /path/to/lineage-tree/lineage/scripts/update-payload-extractor/extract.py payload.bin --output_dir ./
      • If you don’t have a LineageOS build tree checked out, you can clone our scripts repo, and then run the script to extract the payload:
        git clone https://github.com/LineageOS/scripts 
        python /path/to/scripts/update-payload-extractor/extract.py payload.bin --output_dir ./
        
    • It will take a few moments. Once it’s done, we will need to mount the system.img file, and the vendor.img and product.img and system_ext.img files if they exist, to obtain the complete set of proprietary blobs:
      mkdir system/ 
      sudo mount -o ro system.img system/ 
      sudo mount -o ro vendor.img system/vendor/ 
      sudo mount -o ro product.img system/product/ 
      sudo mount -o ro system_ext.img system/system_ext/ 
      
    • Move to the root directory of the sources of your device and run extract-files.sh as follows:
      ./extract-files.sh ~/android/system_temp/
      This will tell extract-files.sh to extract the proprietary blobs from the mounted system dump rather than a connected device.
    • Once it is done, unmount the system dump and remove the now unnecessary files:
      sudo umount -R ~/android/system_temp/system/
      rm -rf ~/android/system_temp/
      

    参考:https://wiki.lineageos.org/devices/gts4lvwifi/build

    相关文章

      网友评论

          本文标题:利用LineageOS构建自己的android-12 ROM

          本文链接:https://www.haomeiwen.com/subject/wytxbrtx.html