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

生产环境: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

最后编辑于
?著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,128评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,316评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事?!?“怎么了?”我有些...
    开封第一讲书人阅读 159,737评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,283评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,384评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,458评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,467评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,251评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,688评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,980评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,155评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,818评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,492评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,142评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,382评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,020评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,044评论 2 352

推荐阅读更多精彩内容