找回密码
 立即注册
查看: 295|回复: 0

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

[复制链接]
发表于 2022-6-29 18:49 | 显示全部楼层 |阅读模式
生产环境:Ubuntu-18.04,已有工具:repo、git、androidSDK
1.事先准备


  • 下载必需组件:apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib            git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev            liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2             libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev 注意:linux-libc-dev_4.15.0-188.199_amd64 在security.ubuntu.com仓库已经找不到,需要手动下载安装,下载地址:
      32位电脑: http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-188.199_i386.deb64位电脑:http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-188.199_amd64.deb

  • 如果ubuntu版本低于20.04仍需要安装: sudo apt-get install libwxgtk3.0-dev
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文件


  • 方法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
参考:https://wiki.lineageos.org/devices/gts4lvwifi/build
T725的编译参考:https://wiki.lineageos.org/devices/gts4lvwifi/build#prepare-the-device-specific-code
通过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。
1.从block-based OTA导出设备专有文件:


  • Create a temporary directory and move there:    mkdir ~/android/system_dump/     cd ~/android/system_dump/解压ROM安装包: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* where path/to/ is the path to the installable zip.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* where path/to/ is the path to the installable zip.
  • 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 brotlibrotli --decompress --output=system.new.dat system.new.dat.brAnd if you have a vendor.dat.new.br (or others) file: brotli --decompress --output=vendor.new.dat vendor.new.dat.br
  • 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.imgAnd if you have a vendor.dat.new (or others) file: python sdat2img/sdat2img.py vendor.transfer.list vendor.new.dat vendor.img
  • 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.img
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_dump/
    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_dump/system/vendor Then unmount the system dump: sudo umount ~/android/system_dump/systemFinally, unmount any other images before deleting the no longer needed files:
    rm -rf ~/android/system_dump/
2.从file-based OTA导出设备专有文件:


  • Create a temporary directory to extract the content of the zip and move there:mkdir ~/android/system_dump/cd ~/android/system_dump/Extract the system folder from the zip:
    unzip path/to/lineage-*.zip system/* where path/to/ is the path to the installable zip.
  • 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_dump/
    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_dump/
3.从payload-based OTA导出设备专有文件


  • Create a temporary directory to extract the content of the zip and move there:mkdir ~/android/system_dump/ cd ~/android/system_dump/
  • Extract the payload.bin file from the LineageOS installation zip file:
    unzip /path/to/lineage-*.zip payload.bin
    where /path/to/ is the path to the installable zip.
    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_dump/
    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_dump/system/rm -rf ~/android/system_dump/
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-26 02:21 , Processed in 0.124922 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表