<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>流云疏影</title>
        <link>https://notion.iliuqi.com/</link>
        <description>人生南北多歧路君向潇湘我向秦</description>
        <lastBuildDate>Thu, 02 Jan 2025 01:00:47 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2025, iLiuqi</copyright>
        <item>
            <title><![CDATA[Linux物理内存管理三大结构体之struct zone]]></title>
            <link>https://notion.iliuqi.com/article/linux_memory_management_zone</link>
            <guid>https://notion.iliuqi.com/article/linux_memory_management_zone</guid>
            <pubDate>Wed, 23 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[从Linux 物理内存管理涉及的三大结构体之struct page 中，大概知道了UMA和NUMA概念，同时也知道在每个node对应的内存范围内，都会将其分成不同的内存管理区域zone。之所以分成几类zone，下面在介绍enum zone_type时将会讲述，然后开始struct zone结构体的拆解分析]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-31d24fe11f8242eaab28164a6a7448bf"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ecadab1b579045dd9f49d159b6439c47" data-id="ecadab1b579045dd9f49d159b6439c47"><span><div id="ecadab1b579045dd9f49d159b6439c47" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ecadab1b579045dd9f49d159b6439c47" title="一、Zone type"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、Zone type</span></span></h2><div class="notion-text notion-block-c66db6f716084d988ee64e6868184ac6">因此Linux内核对不同区域的内存需要采用不同的管理方式和映射方式</div><div class="notion-text notion-block-18398e1835414947abbf96c26f31393f">为了解决这些制约条件，Linux使用了三种区：</div><ol start="1" class="notion-list notion-list-numbered notion-block-ed14c47e3a4a4d84b7324efa37a92e91"><li>ZONE_DMA : 这个区包含的页用来执行DMA操作</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-e703d7df71a1422db2bc128e517bcd68"><li>ZONE_NOMAL : 这个区包含的都是能正常映射的页</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-87605a9776cc4d889652653be49b7e0f"><li>ZONE_HIGHEM : 这个区包&quot;高端内存&quot;，其中的页能不永久地映射到内核地址空间</li></ol><div class="notion-text notion-block-9cb112d3b458454fa532d9c28484c719">而为了兼容一些设备的热插拔支持以及内存碎片化的处理, 内核也引入一些逻辑上的内存区</div><ol start="1" class="notion-list notion-list-numbered notion-block-5ed7420a3d584de982b09111fee19e52"><li>ZONE_MOVABLE : 内核定义了一个伪内存域ZONE_MOVABLE, 在防止物理内存碎片的机制memory migration中需要使用该内存域. 供防止物理内存碎片的极致使用</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-6a7eeacc42444314a7ee5f9b266f9922"><li>ZONE_DEVICE : 为支持热插拔设备而分配的Non Volatile Memory非易失性内存</li></ol><div class="notion-text notion-block-1c816a04256842148e6bcd7969c20099">这部分的定义可以在<code class="notion-inline-code">mmzone.h</code>中的<code class="notion-inline-code">enum zone_type</code>中得到</div><div class="notion-blank notion-block-ca98929075344c718be0829ee78118bd"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-17f35ad90c584718ad183906418b6417" data-id="17f35ad90c584718ad183906418b6417"><span><div id="17f35ad90c584718ad183906418b6417" class="notion-header-anchor"></div><a class="notion-hash-link" href="#17f35ad90c584718ad183906418b6417" title="二、struct zone结构体"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、struct zone结构体</span></span></h2><div class="notion-text notion-block-d1e3f9e0b7404dc3b90614c4e5b62ba0">内核将每个簇所对应的node又被分成的称为管理区(zone)的块，它们各自描述在内存中的范围。一个管理区(zone)由<code class="notion-inline-code">struct zone</code>结构体来描述</div><div class="notion-text notion-block-b377f0f431ac4cd78a539e46960cd41f">下面详细介绍一下这个结构体的知识点：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-3b7839205eab4bfc96ca5702fc20f225" data-id="3b7839205eab4bfc96ca5702fc20f225"><span><div id="3b7839205eab4bfc96ca5702fc20f225" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3b7839205eab4bfc96ca5702fc20f225" title="2.1 watermark"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 watermark</span></span></h3><div class="notion-text notion-block-6dba33cb678c41a5a0bda3bb45544abc">每个zone都有三个水线标准，如下enum定义，分别叫做WMARK_MIN，WMARK_LOW，WMARK_HIGH，借助水线值与zone的free pages对比，可以知道当前zone的内存压力有多大。这三个值在系统启动阶段memory init时会计算得出，首先是通过init_per_zone_wmark_min函数计算出min_free_kbytes，后面根据这个值，计算出这三个水线标准值，这块后面会细讲。这三个水线标准在内存分配和kswapd线程进行内存回收时会用到。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-51d19ad5e58c4baab9e12e16a968628b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F3da58e10-df3c-4f36-a6eb-4144568cc6cb%2FUntitled.png?table=block&amp;id=51d19ad5-e58c-4baa-b9e1-2e16a968628b&amp;t=51d19ad5-e58c-4baa-b9e1-2e16a968628b&amp;width=707.96875&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-callout notion-gray_background_co notion-block-1b835da43b8a41f8a37ecb11b7b71f2e"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="💡">💡</span></div><div class="notion-callout-text">我们可以通过 cat /proc/vmstat,其中的&quot;pageoutrun&quot;和&quot;allocstall_(dma/dma32/normal/movable)&quot;，分别查看kswapd和各个zone的direct reclaim启动的次数。</div></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-6bd897b382a24a69a4ae2cb8a5278e1b" data-id="6bd897b382a24a69a4ae2cb8a5278e1b"><span><div id="6bd897b382a24a69a4ae2cb8a5278e1b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6bd897b382a24a69a4ae2cb8a5278e1b" title="2.1.1 __setup_per_zone_wmarks"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1.1 <b><b>__setup_per_zone_wmarks</b></b></span></span></h4><div class="notion-text notion-block-78dd5a31086d4cc7b11ad7c2798af727">现在开始讲是如何设置这三个水线值的。函数的调用关系是：init_per_zone_wmark_min-&gt;setup_per_zone_wmarks-&gt;__setup_per_zone_wmarks</div><div class="notion-blank notion-block-4b8c52a4c4934119a244e08c3542e51a"> </div><div class="notion-text notion-block-fe246174e25749cfb89ea69ed91d47f0">init_per_zone_wmark_min</div><div class="notion-text notion-block-2aef0a9a8d7143e4888d29a4e679b7f9">calculate_min_free_kbytes</div><div class="notion-text notion-block-ca80be0c518b4342ab560b556969520d">总结：</div><ol start="1" class="notion-list notion-list-numbered notion-block-bf1e59642b94474b8c8de86e50b937bf"><li>lowmem_kbytes： 代表的意思是lowmem中超过高水位的页的总和，这里的单位是kbytes, 这就是lowmem中超过high水位的页乘以4这就是lowmem_kbytes</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-df8838d928474a04b473fbc59060fef9"><li>new_min_free_kbytes = sqrt(lowmem_kbytes * 16) = √(lowmem_kbytes * 16)</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-d9392244545c434d9fbb071b446b468a"><li>min_free_kbytes最小不能小于128K，最大不能超过65536K
</li></ol><div class="notion-blank notion-block-5ba5480d0d2c43ebbbae551cf72fd045"> </div><div class="notion-text notion-block-fe058dda9afa436bbd8bbec9a2093184">setup_per_zone_wmarks</div><div class="notion-text notion-block-f6732dc6daea40b683e76ead0a081614">一个zone的&quot;low&quot;和&quot;high&quot;的值都是根据它的&quot;min&quot;值算出来的，&quot;low&quot;比&quot;min&quot;的值大1/4左右，&quot;high&quot;比&quot;min&quot;的值大1/2左右，三者的比例关系大致是4:5:6。</div><div class="notion-text notion-block-fbad8e7acdb949398f57170dd5c48347">下面以一个项目来验证</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-a33e67418a2c442eb45c37f72974e6fb" data-id="a33e67418a2c442eb45c37f72974e6fb"><span><div id="a33e67418a2c442eb45c37f72974e6fb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a33e67418a2c442eb45c37f72974e6fb" title="2.1.2 实例计算水位"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1.2 实例计算水位</span></span></h4><div class="notion-text notion-block-42d1a822509b4853acddbfa5b62b2283">首先明确几点：</div><ol start="1" class="notion-list notion-list-numbered notion-block-6d73e90147e945e9bf823e218f73271a"><li>WATERMARK_MIN是由min_free_kbytes计算出</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-ffa9d247616247e289768d4978c205ef"><li>WATERMARK_LOW和WATERMARK_HIGH由WATERMARK_MIN计算得来</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-74917bae30c4483baa48c7c65e20baac"><li>min_free_kbytes是在calculate_min_free_kbytes函数中得到</li></ol><div class="notion-blank notion-block-4f3471347f254b3c98703b12e2647b9e"> </div><div class="notion-text notion-block-4bd5a14ee20848b0933bcdaaf09a03de">根据calculate_min_free_kbytes函数，</div><ul class="notion-list notion-list-disc notion-block-778f877ba0404124b19a3d1fa7c73e5c"><li>计算min_free_kbytes</li><ul class="notion-list notion-list-disc notion-block-778f877ba0404124b19a3d1fa7c73e5c"><blockquote class="notion-quote notion-block-88354f874d544c0ca5676c78f3d60c51"><div>lowmem_kbytes = 949265*(PAGE_SIZE&gt;&gt;10) = 3797060
min_free_kbytes = 4 * int_sqrt(lowmem_kbytes) = 7794</div></blockquote><div class="notion-text notion-block-ac5d91d41f394878bb66876750954487">计算值与设备查询的值相近</div></ul></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-ab4e8acd42b64b6c9c2f172b9fcd0189"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:327.9971618652344px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc2c92781-585f-480d-bc69-7a7b8f226a1e%2FUntitled.png?table=block&amp;id=ab4e8acd-42b6-4b6c-9c2f-172b9fcd0189&amp;t=ab4e8acd-42b6-4b6c-9c2f-172b9fcd0189&amp;width=327.9971618652344&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-df7d7eceb73f42378124598a3b3c044c"> </div><ul class="notion-list notion-list-disc notion-block-5961d3a60c0a4f8b841e6f10f178fa24"><li>计算watermark[WMARK_MIN]</li><ul class="notion-list notion-list-disc notion-block-5961d3a60c0a4f8b841e6f10f178fa24"><blockquote class="notion-quote notion-block-e9019ae63e1543f6b063c9827bbb7e50"><div>pages_min = min_free_kbytes &gt;&gt; (PAGE_SHIFT - 10)=7794/4=1948
watermark[WMARK_MIN]=pages_min*zone_managed_pages(zone)/lowmem_pages= 1948</div></blockquote><div class="notion-text notion-block-e5bd051cdb3d4a39a1350c233b451b71">由于当前手机只有ZONE_NORMAL，所以zone_managed_pages(zone)=lowmem_pages，</div><div class="notion-text notion-block-2cc4026cd51c429b952f18ce6e800477">所以watermark[WMARK_MIN] = 1948</div></ul></ul><div class="notion-blank notion-block-dcaa3e7f8f864d9eab5def0919960f59"> </div><ul class="notion-list notion-list-disc notion-block-ba536fb62f70469e97d81de0390e6087"><li>计算watermark[WMARK_LOW]和计算watermark[WMARK_HIGH]</li><ul class="notion-list notion-list-disc notion-block-ba536fb62f70469e97d81de0390e6087"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-65ff08b38ef3419e8b7dbf395aae0f17"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:412.99713134765625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fedbf8d00-6f10-492a-b21f-30d18b3aa29e%2FUntitled.png?table=block&amp;id=65ff08b3-8ef3-419e-8b7d-bf395aae0f17&amp;t=65ff08b3-8ef3-419e-8b7d-bf395aae0f17&amp;width=412.99713134765625&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><blockquote class="notion-quote notion-block-c6d280256f9d47e2844a7db997c869c4"><div>tmp=max_t(u64, 1948&gt;&gt;2, 949265*60/10000)=5695
watermark[WMARK_LOW]=watermark[WMARK_MIN]+tmp=1948+5695=7643
watermark[WMARK_HIGH]=watermark[WMARK_MIN]+tmp*2=1948+5695*2=13338</div></blockquote></ul></ul><div class="notion-text notion-block-779fdaa562264d7f8196bd1e6925cbd4">由此我们计算出三条水位为：</div><div class="notion-text notion-block-b9d25b81612848ab9d773120d67d9352">watermark[WMARK_MIN]=1948</div><div class="notion-text notion-block-cd320a34640a49a89085ac6d04e6dd05">watermark[WMARK_LOW]=7643</div><div class="notion-text notion-block-5484744da22940aba7a7ce7737cb2b20">watermark[WMARK_HIGH]=13338</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-7b1784b899974976835939e2b10abbd6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:278.9630432128906px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F02ead167-6a14-4ed9-920a-46d8224ae40e%2FUntitled.png?table=block&amp;id=7b1784b8-9997-4976-8359-39e2b10abbd6&amp;t=7b1784b8-9997-4976-8359-39e2b10abbd6&amp;width=278.9630432128906&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-43401a3798474742a8296ae42013b256">这与我们从设备中查询到的也是符合的！</div><div class="notion-text notion-block-a9c72954062448e3813d6c2d11be086d">引入<code class="notion-inline-code">watermark_scale_factor</code>这个参数原因：避免突然遇到网络流量增大，需要短时间内申请大量的内存来存放网络请求数据，导致 <code class="notion-inline-code">kswapd </code>回收内存的速度可能赶不上内存分配的速度，从而达到watermark min，造成直接内存回收 <code class="notion-inline-code">direct reclaim</code>，影响系统性能，解决直接内存回收导致的性能抖动问题</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c57a8a36cbe641afb6137afeba104efb" data-id="c57a8a36cbe641afb6137afeba104efb"><span><div id="c57a8a36cbe641afb6137afeba104efb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c57a8a36cbe641afb6137afeba104efb" title="2.1.3 watermark_boost"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1.3 <b><b>watermark_boost</b></b></span></span></h4><div class="notion-text notion-block-c6de5c6ac5604c33a44254122d965ed1">该参数通过细粒度控制内存回收的尺度，使系统可动态提升三个watermark的值，使kswapd线程提前开始回收内存而且也可以回收更多内存。这样一方面可以减少内存规整（memory compact）的次数，另一方面发生内存规整，也可以更快的整合出大的连续物理内存，从而优化内存碎片对内存分配的影响。</div><div class="notion-text notion-block-1e6bcdb8154e47a5992e55ee1af7de6c">对于watermark_boost，在boost_watermark()函数中，会对其设置，可以临时修改该值。跟其直接相关的参数是watermark_boost_factor，位于/proc/sys/vm下面。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android编译原理之make编译过程]]></title>
            <link>https://notion.iliuqi.com/article/make_of_android_compilation_principle</link>
            <guid>https://notion.iliuqi.com/article/make_of_android_compilation_principle</guid>
            <pubDate>Fri, 18 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[从源码角度一层一层的分析android编译时make的流程]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-7c008f00fc064fbcb5934c518e7e2c27"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-42d31b3cd76244d2b8fbfd9689d239b7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Faab10876-2daf-4b91-aca3-923916f47b63%2FUntitled.png?table=block&amp;id=42d31b3c-d762-44d2-b8fb-fd9689d239b7&amp;t=42d31b3c-d762-44d2-b8fb-fd9689d239b7&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-8343663d5e304d7299d66b00ca268b62" data-id="8343663d5e304d7299d66b00ca268b62"><span><div id="8343663d5e304d7299d66b00ca268b62" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8343663d5e304d7299d66b00ca268b62" title="一、make"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、make</span></span></h3><div class="notion-text notion-block-c3514e0e45ff4365937dfa12bb185cfe">以高通的代码为例，高通在编译时使用如下的指令进行编译，实质是对make的封装</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b59602a26aa84225b1ba6a513aead003"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2852638d-6e16-40cd-bbcc-267435c1642e%2FUntitled.png?table=block&amp;id=b59602a2-6aa8-4225-b1ba-6a513aead003&amp;t=b59602a2-6aa8-4225-b1ba-6a513aead003&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-b5fb25f3b2c549f18207a7590fb9e8dd">在执行一系列check的函数后，最终调用make执行执行编译。而make函数是在build/envsetup.sh时声明。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-548c2054cf804996a1b51db842ebe966"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:646px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Febe11ef5-2ac3-4747-b5a3-90bedc21a73c%2FUntitled.png?table=block&amp;id=548c2054-cf80-4996-a1b5-1db842ebe966&amp;t=548c2054-cf80-4996-a1b5-1db842ebe966&amp;width=646&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-978943ce84534818b8f70b4c7e89df30">从get_make_command函数可知，make后，真正然后执行编译的入口是：build/soong/soong_ui.bash</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-106b7014822d44d7a606bdc4a6068c78"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F024d2a81-7d3b-414a-ba23-d73ae278a512%2FUntitled.png?table=block&amp;id=106b7014-822d-44d7-a606-bdc4a6068c78&amp;t=106b7014-822d-44d7-a606-bdc4a6068c78&amp;width=707.953125&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-24874ae7c46344ae8f607cf439611790" data-id="24874ae7c46344ae8f607cf439611790"><span><div id="24874ae7c46344ae8f607cf439611790" class="notion-header-anchor"></div><a class="notion-hash-link" href="#24874ae7c46344ae8f607cf439611790" title="二、soong_ui.bash"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、soong_ui.bash</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-c6dd4bcff54c4974be0811f22ce376c1"><li>source microfactory.bash，得到一些函数命令， 例如：soong_build_go</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-69680a36baa6444b825f40f3bff1df77"><li>编译/build/soong/cmd/soong_ui/main.go，生成 out/soong_ui这个可执行程序</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-c5f91ebf246341a29ddda89c2b66560d"><li>执行命令：out/soong_ui --make-mode ，执行了make命令，会把&quot;build/make/core/main.mk&quot; 加到构建环境中，同时启动kati、blueprint-soong、ninja的编译。</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-8d2a06b70cee4b8d8a49c37f86acf835" data-id="8d2a06b70cee4b8d8a49c37f86acf835"><span><div id="8d2a06b70cee4b8d8a49c37f86acf835" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8d2a06b70cee4b8d8a49c37f86acf835" title="2.1 build/soong/scripts/microfactory.bash"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 build/soong/scripts/microfactory.bash</span></span></h4><div class="notion-text notion-block-75fe36afca454f26bf981ace4c0a568c">build/soong/scripts/microfactory.bash</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-5f017b256d6045a1acb6ee0fa3d3cfdb"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fedf6c702-15af-4795-9fb1-6af5e598d32c%2FUntitled.png?table=block&amp;id=5f017b25-6d60-45a1-acb6-ee0fa3d3cfdb&amp;t=5f017b25-6d60-45a1-acb6-ee0fa3d3cfdb&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-81c3047363e140ed96edfd449055d29f">microfactory.bash得到build_go的函数命令,并提供 soong_build_go的函数执行方法并继续调用</div><div class="notion-text notion-block-36f2a4b800a14193961c4b53d8d91486">build/blueprint/microfactory/microfactory.bash</div><div class="notion-text notion-block-653edc344f914172a5e69df598d4b525"><b>GOROOT=prebuilts/go/linux-x86</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-6873da060e0f4c69a63a9ea6d03cb19b" data-id="6873da060e0f4c69a63a9ea6d03cb19b"><span><div id="6873da060e0f4c69a63a9ea6d03cb19b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6873da060e0f4c69a63a9ea6d03cb19b" title="2.2 build/blueprint/microfactory/microfactory.bash"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 build/blueprint/microfactory/microfactory.bash</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-86cdc283740946afab58a134ba5f87da"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F3bfd53d6-24b9-40ef-b719-39fde9bbb14d%2FUntitled.png?table=block&amp;id=86cdc283-7409-46af-ab58-a134ba5f87da&amp;t=86cdc283-7409-46af-ab58-a134ba5f87da&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-3ee282231fa04f9eaf16f4b498e4d02d">build_go函数做了以下事情：</div><ol start="1" class="notion-list notion-list-numbered notion-block-e3251b9aa288425982432452c0a4dc36"><li>第一次执行编译时调用go run out/.microfactory_Linux/intermediates/src/microfactory.go编译出</li></ol><div class="notion-text notion-block-46d16c82375642d3bb0748598c2a8a9a">microfactory_linux，第二次执行会执行检查，如果已编译则跳过go run</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3d568cff55cb4b31bb545dff895e3aab"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fdb12ceea-54b4-4dd2-b209-ec8077fccc72%2FUntitled.png?table=block&amp;id=3d568cff-55cb-4b31-bb54-5dff895e3aab&amp;t=3d568cff-55cb-4b31-bb54-5dff895e3aab&amp;width=707.84375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><ol start="1" class="notion-list notion-list-numbered notion-block-5faa6d75ac264bf8b995e88dec39cfd7"><li>通过microfactory_Linux编译出soong_ui</li></ol><div class="notion-text notion-block-8feebcbf22dc4472b25723307008ded1">soong_build_go soong_ui android/soong/cmd/soong_ui</div><ul class="notion-list notion-list-disc notion-block-0046de7eb27d45cf805cacf5341fd879"><li>&gt; build_go soong_ui android/soong/cmd/soong_ui</li></ul><div class="notion-text notion-block-08e299a7e8b64bd5bb97300c1011a1fe">实际调用逻辑为：</div><div class="notion-text notion-block-8cb7c3acd2af407fab7bab8637ffae62">从这儿可以知道soong_build_go soong_ui android/soong/cmd/soong_ui的意思就是从soong/cmd/soong_ui/下的go文件编译生成soong_ui</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f9641737699a41789eacb65fd88c238f" data-id="f9641737699a41789eacb65fd88c238f"><span><div id="f9641737699a41789eacb65fd88c238f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f9641737699a41789eacb65fd88c238f" title="2.3 soong_ui的源文件main.go"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.3 soong_ui的源文件main.go</span></span></h4><div class="notion-text notion-block-ebc06b2e24084976a8602c7f248dd69f">soong_ui 是通过编译 build/soong/cmd/soong_ui/main.go得来</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-24a822d6d0c44132b631506dc5e672a2"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Febf46fe6-64a2-413c-9b5f-90d4569fce1e%2FUntitled.png?table=block&amp;id=24a822d6-d0c4-4132-b631-506dc5e672a2&amp;t=24a822d6-d0c4-4132-b631-506dc5e672a2&amp;width=2260&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-61d2e9b122da4902a9d532ca4ff62856">主要执行soong/ui/build/build.go，从build.go就可以看到执行soong的大体流程。</div><div class="notion-text notion-block-803a009732ba478094cbe6544d10afc0">main.go中配置的toBuild为 BuildProductConfig | BuildSoong | BuildKati | BuildNinja，支持productconfig\soong\kati\ninja的构建</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-829658b9fade40e0b2e8213cf0d40782" data-id="829658b9fade40e0b2e8213cf0d40782"><span><div id="829658b9fade40e0b2e8213cf0d40782" class="notion-header-anchor"></div><a class="notion-hash-link" href="#829658b9fade40e0b2e8213cf0d40782" title="2.4 build.go流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4 build.go流程</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-a9c3e1b55b8645949f6fc545104d8c2e"><li>runMakeProductConfig 主要配置编译参数</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-a1862e194d654f7fa98a2b005b1b4767"><li>runSoong 对工具进行编译，编译出blueprint等编译工具, 把*.bp 编译成 out/soong/build.ninja</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-e7115bdd00d44f25ba3a8b2d364a840a"><li>runKatiBuild, 加载 build/make/core/main.mk， 搜集所有的Android.mk文件生成ninja文件:out/build-${product}.ninja</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-abc472c81ccb401c995ca1d0422b7a8f"><li>runKatiPackage, 加载build/make/packaging/main.mk, 编译生成out/build-aosp_arm-package.ninja</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-b5ed8928b4764ebba839fd833892f9d4"><li>createCombinedBuildNinjaFile,将out/soong/build.ninja 、out/build-aosp_arm.ninja和out/build-aosp_arm-package.ninja， 合成为out/combined-aosp_arm.ninja</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-e1c971ab9cb6492981e8d673b1639ddf"><li>runNinja，运行Ninja命令， 解析combined-aosp_arm.ninja，执行编译过程</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-cfe96e20f57644c693545b319ab2d26a" data-id="cfe96e20f57644c693545b319ab2d26a"><span><div id="cfe96e20f57644c693545b319ab2d26a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cfe96e20f57644c693545b319ab2d26a" title="2.4.1 runMakeProductConfig"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.1 runMakeProductConfig</span></span></h4><div class="notion-text notion-block-7fbf8600f9d04ec78289de1f70a682f0">build/soong/ui/build/dumpvars.go</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b101f630fc7241d68b1c967bce8b357e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7b745646-e3d7-4256-8a5e-eba00b830af2%2FUntitled.png?table=block&amp;id=b101f630-fc72-41d6-8b1c-967bce8b357e&amp;t=b101f630-fc72-41d6-8b1c-967bce8b357e&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-bc6ae2bcdbaf4595a393a0ba3d5367ab">只是配置编译需要的参数</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-323b1ebd691d40309423593d13bdbf93" data-id="323b1ebd691d40309423593d13bdbf93"><span><div id="323b1ebd691d40309423593d13bdbf93" class="notion-header-anchor"></div><a class="notion-hash-link" href="#323b1ebd691d40309423593d13bdbf93" title="2.4.2 runSoong"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.2 runSoong</span></span></h4><div class="notion-text notion-block-3f027245a67a4bdeb2815b33ee9c97f2">主要功能：</div><ol start="1" class="notion-list notion-list-numbered notion-block-1e7a3052be884b91a9008a32dd4bc43d"><li>对工具进行编译，编译出blueprint等编译工具</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-84e1d3292bcc42299b31ae869d334ca1"><li>把*.bp 编译成 out/soong/build.ninja</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ca4cf72011ed43f99737fedb1f722169" data-id="ca4cf72011ed43f99737fedb1f722169"><span><div id="ca4cf72011ed43f99737fedb1f722169" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ca4cf72011ed43f99737fedb1f722169" title="2.4.2.1 Android R版本"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.2.1 Android R版本</span></span></h4><div class="notion-text notion-block-fa1613262a314a329159d2700a7ef3bd">runSoong()的执行过程：</div><ol start="1" class="notion-list notion-list-numbered notion-block-20fa780f4cb747c5abe55d9faee055f2"><li>执行build/blueprint/bootstrap.bash 生成.minibootstrap/build.ninja 和.bootstrap/build.ninja</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-f3b38a88f55244e0b0113fed8b0aaa8f"><li>生成minibp\bpglob</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-4c5250bea6134cfcb1f8773943c1c2d0"><li>通过ninja来编译.minibootstrap/build.ninja 和.bootstrap/build.ninja</li></ol><div class="notion-text notion-block-266cf5cff6ef421e92ed38267b400c6d">首先执行build/blueprint/bootstrap.bash</div><div class="notion-text notion-block-869b807cce134349aeebec2af652c24e">bootstrap.bash的作用：</div><ol start="1" class="notion-list notion-list-numbered notion-block-d2fa1531059349089914fee43c40b6ca"><li>它可以引导独立的blueprint来生成minibp二进制文件，可以直接运行 ./build/blueprint/bootstrap.bash。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-972a3db9e7394d839d064392edf9b22a"><li>也可以从另一个脚本调用它来引导基于Bleprint的自定义构建系统。</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4f85cea3dcfe402896bb30f512376c87" data-id="4f85cea3dcfe402896bb30f512376c87"><span><div id="4f85cea3dcfe402896bb30f512376c87" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4f85cea3dcfe402896bb30f512376c87" title="2.4.2.2 Android T版本"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.2.2 Android T版本</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2477f332f0e544afbe2ee93c6dbd9cbb" data-id="2477f332f0e544afbe2ee93c6dbd9cbb"><span><div id="2477f332f0e544afbe2ee93c6dbd9cbb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2477f332f0e544afbe2ee93c6dbd9cbb" title="2.4.3 runKatiBuild"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.3 runKatiBuild</span></span></h4><div class="notion-text notion-block-4dea3a5011c645fa8ba59c7cffc065f1">主要功能：</div><ol start="1" class="notion-list notion-list-numbered notion-block-337f68e2b84044f28c88315044ee1e8d"><li>加载 build/make/core/main.mk</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-ed2316f169ca4f7e8c0f91c184b1b768"><li>所有的Android.mk文件生成ninja文件:out/build-aosp_arm.ninja</li></ol><div class="notion-text notion-block-8c0a90a77b104a7e818b86edda4e1d73">runKati中会启动Kati程序，开始解析main.mk</div><div class="notion-text notion-block-8212adfd88164bf6b2cf8a6421323c65">最终是调用系统准备好的prebuilts/build-tools/linux-x86/bin/ckati参与编译，其中传入的参数有 --ninja\ --regen\--detect_android_echo 等，kati解析完build/make/core/main.mk后，就会⽣成相应的ninja编译规则，runKatiBuild()函数最后⽣成out/build-{product}.ninja⽂件</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-861f24e25fc248ebbc3c82d64ae43b94" data-id="861f24e25fc248ebbc3c82d64ae43b94"><span><div id="861f24e25fc248ebbc3c82d64ae43b94" class="notion-header-anchor"></div><a class="notion-hash-link" href="#861f24e25fc248ebbc3c82d64ae43b94" title="2.4.4 runKatiPackage"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.4 runKatiPackage</span></span></h4><div class="notion-text notion-block-ed37b1a52f1b414fba6c058b0832be64">也是运行runKati，只不过携带的参数不同，runKatiPackage函数最后会生成out/build-{product}-package.ninja</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-df7fa600fa1b4a8d968ef74f6c5a440e" data-id="df7fa600fa1b4a8d968ef74f6c5a440e"><span><div id="df7fa600fa1b4a8d968ef74f6c5a440e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#df7fa600fa1b4a8d968ef74f6c5a440e" title="2.4.5 createCombinedBuildNinjaFile"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.5 createCombinedBuildNinjaFile</span></span></h4><div class="notion-text notion-block-f9eb5ae39b1f401a9b5bc80b2ebf053a">会将kati和soong_build两个程序⽣成的ninja⽂件都包含进来，再⽣成⼀个out/combined-${product}.ninja⽂件</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-091ae1f8ff784113bc0ab567df2ca201" data-id="091ae1f8ff784113bc0ab567df2ca201"><span><div id="091ae1f8ff784113bc0ab567df2ca201" class="notion-header-anchor"></div><a class="notion-hash-link" href="#091ae1f8ff784113bc0ab567df2ca201" title="2.4.6 runNinja"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4.6 runNinja</span></span></h4><div class="notion-text notion-block-481a4104757a454581bd062284522997">启动ninja程序解析out/combined-${product}.ninja⽂件，得到我们执⾏的命令⾥指定target-files-package模块的依赖⽂件,最后只要按照拓扑顺序挨个执⾏他们的rule去⽣成他们就可以了</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android编译原理之编译步骤]]></title>
            <link>https://notion.iliuqi.com/article/an_overview_of_android_compilation_principles</link>
            <guid>https://notion.iliuqi.com/article/an_overview_of_android_compilation_principles</guid>
            <pubDate>Fri, 18 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[在 Android 7.0 之前，Android 编译系统使用 GNU Make 描述和shell来构建编译规则，模块定义都使用Android.mk进行定义，Android.mk的本质就是Makefile，但是随着Android的工程越来越大，模块越来越多，Makefile组织的项目编译时间越来越长。这样下去Google工程师觉得不行，得要优化]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-dd593a2376dc4bcbbe26d11b05236628"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-026c77f3292f475f8771c81ce193a37c" data-id="026c77f3292f475f8771c81ce193a37c"><span><div id="026c77f3292f475f8771c81ce193a37c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#026c77f3292f475f8771c81ce193a37c" title="一、概述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、概述</span></span></h3><div class="notion-text notion-block-33f3a75be80041259fdde163bee9c2da">在 Android 7.0 之前，Android 编译系统使用 GNU Make 描述和shell来构建编译规则，模块定义都使用Android.mk进行定义，Android.mk的本质就是Makefile，但是随着Android的工程越来越大，模块越来越多，Makefile组织的项目编译时间越来越长。这样下去Google工程师觉得不行，得要优化。</div><div class="notion-text notion-block-a59f48e932c940128011941479018023">因此，在Android7.0开始，Google采用ninja来代取代之前使用的make，由于之前的Android.mk数据实在巨大，因此Google加入了一个kati工具，用于将Android.mk转换成ninja的构建规则文件buildxxx.ninja,再使用ninja来进行构建工作。</div><div class="notion-text notion-block-f33452fa6f5f48fa832eced1260c28bb">编译速度快了一些，但是既然要干， 那就干个大的，最终目标要把make都取代，于是从Android8.0开始，Google为了进一步淘汰Makefile，因此引入了Android.bp文件来替换之前的Android.mk。</div><div class="notion-text notion-block-6479915b8cb7402881e6f8dca20e9f28">Android.bp只是一个纯粹的配置文件，不包括分支、循环语句等控制流程，本质上就是一个json配置文件。Android.bp  通过Blueprint+soong转换成ninja的构建规则文件build.ninja，再使用ninja来进行构建工作。</div><div class="notion-text notion-block-e79f876f49284e64814cd59c172c5251">Android10.0上，mk和bp编译的列表可以从 out/.module_paths中的Android.bp.list、Android.mk.list中看到，Android10.0还有400多个mk文件没有被替换完，Google任重道远。</div><div class="notion-text notion-block-d41d7585d4ab42cf8cf79f0e6a50f610">Android编译演进过程：</div><div class="notion-text notion-block-b74bb2ba240a4633a93639910d18220f">Android7.0之前 使用GNU Make</div><div class="notion-text notion-block-2bdf03db185d40cdadcc4a3f71c85d43">Android7.0 引入ninja、kati、Android.bp和soong构建系统</div><div class="notion-text notion-block-4e33d20211dc4652a5681cc8afadf726">Android8.0 默认打开Android.bp</div><div class="notion-text notion-block-ee811c8299394766821832ae016008e0">Android9.0 强制使用Android.bp</div><div class="notion-text notion-block-012d9cf60d024633938e252c2ca1fe37">Google在 Android 7.0之后，引入了Soong构建系统，旨在取代make，它利用 Kati GNU Make 克隆工具和 Ninja 构建系统组件来加速 Android 的构建。</div><div class="notion-text notion-block-d1b3f566463b4b739bac978cb0673f4a">Make 构建系统得到了广泛的支持和使用，但在 Android 层面变得缓慢、容易出错、无法扩展且难以测试。Soong 构建系统正好提供了 Android build 所需的灵活性。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-91ba1d02eb124593bb777c47ad7b94dd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc30545d6-bfbe-451a-89da-d1af9ec6358c%2FUntitled.png?table=block&amp;id=91ba1d02-eb12-4593-bb77-7c47ad7b94dd&amp;t=91ba1d02-eb12-4593-bb77-7c47ad7b94dd&amp;width=592.96875&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-45c1de33d8494c1b960c96b84b98fd7c" data-id="45c1de33d8494c1b960c96b84b98fd7c"><span><div id="45c1de33d8494c1b960c96b84b98fd7c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#45c1de33d8494c1b960c96b84b98fd7c" title="二、编译流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、编译流程</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-72885d1c378d40acb511b21a0ce0e7e0" data-id="72885d1c378d40acb511b21a0ce0e7e0"><span><div id="72885d1c378d40acb511b21a0ce0e7e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#72885d1c378d40acb511b21a0ce0e7e0" title="2.1 编译构成"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 编译构成</span></span></h4><div class="notion-text notion-block-2b73e84622af454085f1efd895cf1a37">Android的编译目录在build 中，看一下源码中的build目录，现在是这个样子</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-9fb3d3e770ce4467b8d7673c97270dd1"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:560px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2ff77566-dcf8-4733-81f9-eb1ac893b644%2FUntitled.png?table=block&amp;id=9fb3d3e7-70ce-4467-b8d7-673c97270dd1&amp;t=9fb3d3e7-70ce-4467-b8d7-673c97270dd1&amp;width=560&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-7f2ca0e3e81c42cd86863985d9f4f335">这个目录中可以看到core文件夹被link到了make/core，envsetup.sh被link到make/envsetup.sh，这主要是为了对使用者屏蔽切换编译系统的差异。</div><div class="notion-text notion-block-bf40622ef41044688d08fa4bfef81f4b">这里重点看四个文件夹：blueprint、kati、make、soong</div><table class="notion-simple-table notion-block-4799bf08142f4262b962c16cd64dc38b"><tbody><tr class="notion-simple-table-row notion-block-43a847b13689479b9d4099a38bb8ca87"><td class="" style="width:120px"><div class="notion-simple-table-cell">blueprint</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用于处理Android.bp，编译生成*.ninja文件，用于做ninja的处理</div></td></tr><tr class="notion-simple-table-row notion-block-6aecfdd9a00c411697aa78aa803a45ec"><td class="" style="width:120px"><div class="notion-simple-table-cell">kati</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用于处理Android.mk，编译生成*.ninja文件，用于做ninja的处理</div></td></tr><tr class="notion-simple-table-row notion-block-4f7826b9d1f14c76a78838436b7d86be"><td class="" style="width:120px"><div class="notion-simple-table-cell">make</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">文件夹还是原始的make那一套流程，比如envsetup.sh</div></td></tr><tr class="notion-simple-table-row notion-block-a41ae453b45642f0a5d417f2f599d345"><td class="" style="width:120px"><div class="notion-simple-table-cell">soong</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">构建系统，核心编译为<b>soong_ui.bash</b></div></td></tr></tbody></table><div class="notion-text notion-block-67414b51e44e44e0b76719bf68515d86"><b>Soong编译系统家族成员及各自关系如下图所示：</b></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a567ad435e2146dd8dd04f2f52b73fc7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F54f195c3-1d84-4097-a2d2-eac0dbee4bca%2FUntitled.png?table=block&amp;id=a567ad43-5e21-46dd-8dd0-4f2f52b73fc7&amp;t=a567ad43-5e21-46dd-8dd0-4f2f52b73fc7&amp;width=592.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-a1bebe230ae5480f978d32a70df0a6a1">在编译过程中，Android.bp会被收集到out/soong/build.ninja.d,blueprint以此为基础，生成out/soong/build.ninja</div><div class="notion-text notion-block-2d758b52151c4a56b07a95a6b6da5e32">Android.mk会由kati/ckati生成为out/build-aosp_arm.ninja</div><div class="notion-text notion-block-aeea5ebfb58c436b9442f9e773d7aad3">两个ninja文件会被整合进入out/combined-aosp_arm.ninja</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4c4163acee3e4bc8b827cddd26bf5a2d" data-id="4c4163acee3e4bc8b827cddd26bf5a2d"><span><div id="4c4163acee3e4bc8b827cddd26bf5a2d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4c4163acee3e4bc8b827cddd26bf5a2d" title="2.2 编译步骤"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 编译步骤</span></span></h4><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-2d0da44450b54d41886e5fcd8dfd9a38" data-id="2d0da44450b54d41886e5fcd8dfd9a38"><span><div id="2d0da44450b54d41886e5fcd8dfd9a38" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d0da44450b54d41886e5fcd8dfd9a38" title="三、编译工具链"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">三、编译工具链</span></span></h3><div class="notion-text notion-block-3c96fc2677434f11a9f17dbce2e241d0">编译系统中，涉及以下一些工具链，由这些工具链相辅相成，才最终编译出了我们所需要的镜像版本。</div><div class="notion-text notion-block-4d27be0501a04634a121f14a59e44c6b">prebuilts/build_tools/linux-x86/bin/ninja</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-dcd1ac2c5df244aa9f04ec591a1d5622" data-id="dcd1ac2c5df244aa9f04ec591a1d5622"><span><div id="dcd1ac2c5df244aa9f04ec591a1d5622" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dcd1ac2c5df244aa9f04ec591a1d5622" title="3.1 soong说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 soong说明</span></span></h4><div class="notion-text notion-block-5d55b4b79b494dfb80ae586735387a5a">Soong 构建系统是在 Android 7.0 (Nougat) 中引入的，旨在取代 Make。它利用 Kati GNU Make 克隆工具和 Ninja 构建系统组件来加速 Android 的构建。</div><div class="notion-text notion-block-0a933ebe4f214a4bb44c02cd6f4e6fd8">Soong是由Go语言写的一个项目，从Android 7.0开始，在prebuilts/go/目录下新增了Go语言所需的运行环境，Soong在编译时使用，解析Android.bp，将之转化为Ninja文件，完成Android的选择编译，解析配置工作等。故Soong相当于Makefile编译系统的核心，即build/make/core下面的内容。</div><div class="notion-text notion-block-cde11d64042245088df589d4405b0b64">另外Soong还会编译产生一个androidmk命令，可以用来手动将Android.mk转换成Android.bp文件。不过这只对无选择、循环等复杂流程控制的Android.mk生效。</div><div class="notion-text notion-block-8823106385124f5498f323eff191aa22"><b>soong脚本和代码目录：/build/soong</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c5c0f4caf7a14f7b860f8c6bf21a8af3" data-id="c5c0f4caf7a14f7b860f8c6bf21a8af3"><span><div id="c5c0f4caf7a14f7b860f8c6bf21a8af3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c5c0f4caf7a14f7b860f8c6bf21a8af3" title="3.2 kati说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.2 kati说明</span></span></h4><div class="notion-text notion-block-0bb87120d2f04ef98a9967995dd2c234">kati是一个基于Makefile来生成ninja.build的小项目。主要用于把Makefiel转成成ninja file，自身没有编译能力，转换后使用Ninja编译。</div><div class="notion-text notion-block-b72e52bb9201446096fc140676a10eaf">在编译过程中，kati负责把既有的Makefile、Android.mk文件，转换成Ninja文件。在Android 8.0以后，它与Soong一起，成为Ninja文件的两大来源。Kati更像是Google过渡使用的一个工具，等所有Android.mk都被替换成Android.bp之后，Kati有可能退出Android编译过程.</div><div class="notion-text notion-block-69fcc340e8fa437887f240760f9d1537">在单独使用时，它对普通的小项目还能勉强生效。面对复杂的、多嵌套的Makefile时，它往往无法支持，会出现各种各样的问题。当然，也可以理解为，它只为Android而设计。</div><div class="notion-text notion-block-b5fbc97496d24257868a149259d5adb1"><b>kati脚本和代码目录：/build/kati</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-14a606176d074eaea8b9545315dc49c1" data-id="14a606176d074eaea8b9545315dc49c1"><span><div id="14a606176d074eaea8b9545315dc49c1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#14a606176d074eaea8b9545315dc49c1" title="3.3 blueprint说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.3 blueprint说明</span></span></h4><div class="notion-text notion-block-6c1a6c4a9db44fc5a6caa62cf0604a49">Blueprint由Go语言编写，是生成、解析Android.bp的工具，是Soong的一部分。Soong则是专为Android编译而设计的工具，Blueprint只是解析文件的形式，而Soong则解释内容的含义。</div><div class="notion-text notion-block-8e44bc95ada845c7a4f9023a860aa1a8">在Android编译最开始的准备阶段，会执行build/soong/soong_ui.bash进行环境准备。</div><div class="notion-text notion-block-2c80207f32244e838d578d44a6bd4686">对blueprint项目编译完成之后会在out/soong/host/linux-x86/bin目录下生成soong编译需要的5个执行文件(bpfix,bpfmt,bpmodify,microfatory,bpmodify)。</div><div class="notion-text notion-block-7d50024c5b7441bf98e11dff9dd4ba44">Soong是与Android强关联的一个项目，而Blueprint则相对比较独立，可以单独编译、使用。</div><div class="notion-text notion-block-cce82622f35243a0851e99cfd6b12f28"><b>blueprint代码目录：/build/blueprint</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-711533a87bac4f6ebbc7de0d6440f5dd" data-id="711533a87bac4f6ebbc7de0d6440f5dd"><span><div id="711533a87bac4f6ebbc7de0d6440f5dd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#711533a87bac4f6ebbc7de0d6440f5dd" title="3.4 ninja说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.4 ninja说明</span></span></h4><div class="notion-text notion-block-df79bbb9f9ce4c4697787f25ba866b47">Ninja是一个致力于速度的小型编译系统（类似于Make），如果把其他编译系统比做高级语言的话，Ninja就是汇编语言。通常使用Kati或soong把makefile转换成Ninja files，然后用Ninja编译。</div><div class="notion-text notion-block-59e1c67e89bb4f68909364f55c671fbf">主要两个特点：</div><div class="notion-text notion-block-8688f8ad86a34287a5004807f31f950c">1)可以通过其他高级的编译系统生成其输入文件；</div><div class="notion-text notion-block-4094235bbf7949b790c390024ec6229c">2)它的设计就是为了更快的编译；</div><div class="notion-text notion-block-3b6c4667d81444a2b3f522cbbae5938e">ninja核心是由C/C++编写的，同时有一部分辅助功能由python和shell实现。由于其开源性，所以可以利用ninja的开源代码进行各种个性化的编译定制。</div><div class="notion-text notion-block-c5986542bb2041bea914ec7f4311ec91">从Android 7开始，编译时默认使用Ninja。但是，Android项目里是没有.ninja文件的。遵循Ninja的设计哲学，编译时，会先把Makefile通过kati转换成.ninja文件，然后使用ninja命令进行编译。这些.ninja文件，都产生在out/目录下，共有三类：</div><ol start="1" class="notion-list notion-list-numbered notion-block-c1d96f98d60b40f38ab83beb8294c470"><li>build-*.ninja文件，通常非常大，几十到几百MB。对make全编译，命名是build-&lt;product_name&gt;.ninja。如果Makefile发生修改，需要重新产生Ninja文件。</li><ol class="notion-list notion-list-numbered notion-block-c1d96f98d60b40f38ab83beb8294c470"><div class="notion-text notion-block-a0b50053f2b0436483f38f911bd8021e">mm、mma的Ninja文件，命名是build-&lt;product_name&gt;-&lt;path_to_Android.mk&gt;.ninja。而mmm、mmma的Ninja文件，命名是build-&lt;product_name&gt;-_&lt;path_to_Android.mk&gt;.ninja。</div></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-50a08376eb2b4006b0429014e8720ac0"><li>combined-*.ninja文件。在使用了Soong后，除了build-*.ninja之外，还会产生对应的combined-*.ninja，二者的*内容相同。这类是组合文件，是把build-*.ninja和out/soong/build.ninja组合起来。所以，使用Soong后，<b>combined-*.ninja是编译执行的真正入口。</b></li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-119abfd81ee6462bb6d76165486b4a6b"><li>out/soong/build.ninja文件，它是从所有的Android.bp转换过来的</li></ol><div class="notion-text notion-block-b78a931b49a34c7f9f4fec459b0d67f8">build-*.ninja是从所有的Makefile，用Kati转换过来的，包括build/core/*.mk和所有的Android.mk。所以，在不使用Soong时，它是唯一入口。在使用了Soong以后，会新增源于Android.bp的out/soong/build.ninja，所以需要combined-*.ninja来组合一下。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b0ab0dceac9043d18c8999e83d98eec3" data-id="b0ab0dceac9043d18c8999e83d98eec3"><span><div id="b0ab0dceac9043d18c8999e83d98eec3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b0ab0dceac9043d18c8999e83d98eec3" title="3.5 工具链的关系"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.5 工具链的关系</span></span></h4><div class="notion-text notion-block-ac0e6b67111b4810ba4933e9cf89228c"><b>Android.mk文件、Android.bp、kati、Soong、Blueprint、Ninja之间的关系如下：</b></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-8d6d790e1f7b4c87b4fc33a786193805" data-id="8d6d790e1f7b4c87b4fc33a786193805"><span><div id="8d6d790e1f7b4c87b4fc33a786193805" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8d6d790e1f7b4c87b4fc33a786193805" title="四、编译步骤之envsetup.sh"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">四、编译步骤之envsetup.sh</span></span></h3><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-e028e0d173964824946fb6f2e739771c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4392d222-aa21-4cdd-ad62-9bef8f7c22ab%2FUntitled.png?table=block&amp;id=e028e0d1-7396-4824-946f-b6f2e739771c&amp;t=e028e0d1-7396-4824-946f-b6f2e739771c&amp;width=592.96875&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-70cab3a5f4cd4adc957b38b7d619ec7d" data-id="70cab3a5f4cd4adc957b38b7d619ec7d"><span><div id="70cab3a5f4cd4adc957b38b7d619ec7d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#70cab3a5f4cd4adc957b38b7d619ec7d" title="4.1 validate_current_shell"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1 <b>validate_current_shell</b></span></span></h4><div class="notion-text notion-block-2f65a2830a354bbb8ef94768fff930b1">确定当前的shell环境，建立shell命令</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-44128cc86c9b4874bcda3c18badea2a7" data-id="44128cc86c9b4874bcda3c18badea2a7"><span><div id="44128cc86c9b4874bcda3c18badea2a7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#44128cc86c9b4874bcda3c18badea2a7" title="4.2 source_vendorsetup"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2 <b>source_vendorsetup</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4d6f8f5fa519490386b64361ca566d1c" data-id="4d6f8f5fa519490386b64361ca566d1c"><span><div id="4d6f8f5fa519490386b64361ca566d1c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4d6f8f5fa519490386b64361ca566d1c" title="4.3 addcompletions"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.3 <b>addcompletions</b></span></span></h4><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-d6491886c45d4299beaf85df92026b78" data-id="d6491886c45d4299beaf85df92026b78"><span><div id="d6491886c45d4299beaf85df92026b78" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d6491886c45d4299beaf85df92026b78" title="五、编译步骤之lunch"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">五、编译步骤之lunch</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-012dfde002fe443f84b44865375eae61" data-id="012dfde002fe443f84b44865375eae61"><span><div id="012dfde002fe443f84b44865375eae61" class="notion-header-anchor"></div><a class="notion-hash-link" href="#012dfde002fe443f84b44865375eae61" title="5.1 lunch说明"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.1 lunch说明</span></span></h4><div class="notion-text notion-block-24c8802289824c228baf51cdbc8fe929">环境变量初始化完成后，我们需要选择一个编译目标。lunch 主要作用是根据用户输入或者选择的产品名来设置与具体产品相关的环境变量。</div><div class="notion-text notion-block-cbb3dfb18c084a3686eddbe1eaf37f84">如果你不知道想要编译的目标是什么，直接执行一个lunch命令，会列出所有的目标，直接回车，会默认使用aosp_arm-eng这个目标。</div><table class="notion-simple-table notion-block-0c611c0b2d2b463fb2e3e33cb2dbad0a"><tbody><tr class="notion-simple-table-row notion-block-586f5180cbab453abb6cbaeeff768c58"><td class="" style="width:120px"><div class="notion-simple-table-cell">参数</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-9c257dbad052460fa3705fbbc2efbb95"><td class="" style="width:120px"><div class="notion-simple-table-cell">PLATFORM_VERSION_CODENAME=REL</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示平台版本的名称</div></td></tr><tr class="notion-simple-table-row notion-block-ab45199f4a0b4223904182534e9ae5bf"><td class="" style="width:120px"><div class="notion-simple-table-cell">PLATFORM_VERSION=13</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Android平台的版本号</div></td></tr><tr class="notion-simple-table-row notion-block-c29170f0da344cb4a5f724b32ed77790"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_PRODUCT=miodm_topaz_native</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">所编译的产品名称</div></td></tr><tr class="notion-simple-table-row notion-block-6768cb9dcd1f45238d3ef87e5e4d2c1e"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_BUILD_VARIANT=userdebug</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">所编译产品的类型</div></td></tr><tr class="notion-simple-table-row notion-block-1cadba5be74d4ae4865d9947c0411d35"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_BUILD_TYPE=release</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">编译的类型，debug和release</div></td></tr><tr class="notion-simple-table-row notion-block-d4452ae2b251478b9c363275cdcaf37f"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_ARCH=arm64</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示编译目标的CPU架构</div></td></tr><tr class="notion-simple-table-row notion-block-e9b983330ff5436cbfcb1d248d7949ec"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_ARCH_VARIANT=armv8-a</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示编译目标的CPU架构版本</div></td></tr><tr class="notion-simple-table-row notion-block-216115ac120143a5978d71b22f77d859"><td class="" style="width:120px"><div class="notion-simple-table-cell">TARGET_CPU_VARIANT=generic</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示编译目标的CPU代号</div></td></tr><tr class="notion-simple-table-row notion-block-4ca39ad5c4fa4dc8bf4e463e0a6baac6"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_ARCH=x86_64</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示编译平台的架构</div></td></tr><tr class="notion-simple-table-row notion-block-e0fe834c0c754101b6d11bf584e9e06b"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_2ND_ARCH=x86</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-f7da46463cbf4a2483cd78199258d328"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_OS=linux</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">表示编译平台的操作系统</div></td></tr><tr class="notion-simple-table-row notion-block-f727af45cc0e46c6b133b20bd6f450ae"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_OS_EXTRA=linux-5.4.0-124-generic-x86_64-Ubuntu-18.04.6-LTS</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">编译系统之外的额外信息</div></td></tr><tr class="notion-simple-table-row notion-block-13a5af5006a54afda0371f9f2645d841"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_CROSS_OS=windows</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-e85a4c8887d340c99f1b6e0939934af5"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_CROSS_ARCH=x86</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-a861e021a21c43109ef7b4f225181808"><td class="" style="width:120px"><div class="notion-simple-table-cell">HOST_BUILD_TYPE=release</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-535472d3f879441790a2ebc72bb1a745"><td class="" style="width:120px"><div class="notion-simple-table-cell">BUILD_ID=TKQ1.220710.001</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">BUILD_ID会出现在版本信息中，可以利用</div></td></tr><tr class="notion-simple-table-row notion-block-17818552dbed4675ab36775e91d91bb4"><td class="" style="width:120px"><div class="notion-simple-table-cell">OUT_DIR=out</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">编译结果输出的路径</div></td></tr></tbody></table><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-e932568c671949a7a7b95a455bb67fd6" data-id="e932568c671949a7a7b95a455bb67fd6"><span><div id="e932568c671949a7a7b95a455bb67fd6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e932568c671949a7a7b95a455bb67fd6" title="5.2 lunch"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.2 lunch</span></span></h4><div class="notion-text notion-block-1f6d768fd86343fab1d11c2ef9bd76dc">lunch指令是在envsetup.sh中被定义的。主要就是用来设置 TARGET_PRODUCT、TARGET_BUILD_VARIANT、TARGET_PLATFORM_VERSION、TARGET_BUILD_TYPE、TARGET_BUILD_APPS等环境变量</div><div class="notion-text notion-block-00c67a9eb8a242c6ba4f65af734b0018">lunch操作流程如下：</div><ol start="1" class="notion-list notion-list-numbered notion-block-79caad739f714e279a447dfcd71df2f4"><li>获取lunch操作的参数，如果参数不为空，参数则为指定要编译的设备型号和编译类型；如果参数为空，会调用print_lunch_menu来显示Lunch菜单项，读取用户的输入，存入answer</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-4b6accfa5a024a0b90b0ea3d40f1d941"><li>如果answer为空，即之前在lunch菜单用，用户只敲了一个回车。会将默认选项改为aosp_arm-eng，结果存入selection</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-4e0febd426b14734b42ffddcd7b3903b"><li>如果lunch操作得到的输入是数字，则将数字转换为LUNCH_MENU_CHOICES中的字符串，结果存入selection</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-76cf6142f49742828731a11867be283c"><li>解析selection的值，得到product = aosp_arm 和variant = eng, 把他们分别保存到TARGET_PRODUCT 和 TARGET_BUILD_VARIANT 中</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-f3ae8c39aedb4afabb5d33a62f5063d4"><li>根据前面的设置，调用build_build_var_cache 来更新编译环境相关变量</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-b0f0a312bbf24ae5be989c807ce13e38"><li>export 编译选项TARGET_PRODUCT, TARGET_BUILD_VARIANT和TARGET_BUILD_TYPE三元组</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-e601962d78024e9a9fb4b8cec16ac52d"><li>调用set_stuff_for_environment 来设置其他环境变量，如PROMPT_COMMAND，编译toolchain和tools相关的路径等</li></ol><ol start="8" class="notion-list notion-list-numbered notion-block-13c2dbf3b3204652845b5575ac7fa4e6"><li>调用printconfig 来输出当前的设置选项</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-fb2ec451d7f14264afa43c84f7d49198" data-id="fb2ec451d7f14264afa43c84f7d49198"><span><div id="fb2ec451d7f14264afa43c84f7d49198" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fb2ec451d7f14264afa43c84f7d49198" title="5.3 build_build_var_cache"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.3 <b>build_build_var_cache</b></span></span></h4><div class="notion-text notion-block-7b1845a6de6048a98b4f5355e6871dc7">根据前面的设置，更新编译环境相关变量</div><div class="notion-text notion-block-6ed211ebbdb541b0a48de08921110ce0">主要通过执行 &quot;build/soong/soong_ui.bash --dumpvars-mode&quot; 完成</div><div class="notion-text notion-block-522db15a121346028acd26df2f22d1b2">最终执行的是 &quot;./out/soog_ui  --dumpvars-mode&quot;</div><div class="notion-text notion-block-22035d1cead84e1db5a24b22cba7c44d">soong_ui 由build/soong/cmd/soong_ui/main.go编译生成</div><div class="notion-text notion-block-ec1f8a10a0cb4393a66cf75a95cb6012">最后调用到了ckati执行-f build/make/core/config.mk</div><div class="notion-text notion-block-8fefcda0843d43cdaec09cf6c89e07f2">下面我们单独研究一下config.mk。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-52948882b4d4417cb05206ea8c4d0105" data-id="52948882b4d4417cb05206ea8c4d0105"><span><div id="52948882b4d4417cb05206ea8c4d0105" class="notion-header-anchor"></div><a class="notion-hash-link" href="#52948882b4d4417cb05206ea8c4d0105" title="5.4 config.mk"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.4 config.mk</span></span></h4><div class="notion-text notion-block-202bd8296ade47bb8067bee259b70f6c">说明：config.mk首先加载了build/make/common 中的core.mk、math.mk、strings.mk、json.mk 用来配置一些shell环境、math函数、string和json的一些支持函数。最主要的操作还是加载build/make/core中的envsetup.mk和dumpvar.mk</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-cfbdbe9d58884d5f8143ffa3ee7d730e" data-id="cfbdbe9d58884d5f8143ffa3ee7d730e"><span><div id="cfbdbe9d58884d5f8143ffa3ee7d730e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cfbdbe9d58884d5f8143ffa3ee7d730e" title="5.4.1 build/make/core/envsetup.mk"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.4.1 <b>build/make/core/envsetup.mk</b></span></span></h4><div class="notion-text notion-block-45940f19cab64caf872fc12087c96dac">envsetup.mk 主要加载了product_config.mk和board_config.mk，用来得到TARGET_DEVICE和其他变量。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-99a6194cd6524787b559f7238590a525" data-id="99a6194cd6524787b559f7238590a525"><span><div id="99a6194cd6524787b559f7238590a525" class="notion-header-anchor"></div><a class="notion-hash-link" href="#99a6194cd6524787b559f7238590a525" title="5.4.2 build/make/core/product_config.mk"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.4.2 <b>build/make/core/product_config.mk</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4b879dca35624bcea9036fc316b0f4f5" data-id="4b879dca35624bcea9036fc316b0f4f5"><span><div id="4b879dca35624bcea9036fc316b0f4f5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4b879dca35624bcea9036fc316b0f4f5" title="5.4.3 build/make/core/board_config.mk"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.4.3 <b>build/make/core/board_config.mk</b></span></span></h4><div class="notion-text notion-block-f024e29fe41c4866963d32bd23b6f6ac">板级可以在$（SRC_TARGET_DIR）/board/$（TARGET_DEVICE）下定义，也可以在vendor/*/$（TARGET_DEVICE）下定义。</div><div class="notion-text notion-block-2dda2658ed704d829b46c556c6061251">在这两个地方搜索，但要确保只存在一个。真正的板级应始终与OEM vendor相关联。``</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-982978c19a2a4c8b9836fe675727f887" data-id="982978c19a2a4c8b9836fe675727f887"><span><div id="982978c19a2a4c8b9836fe675727f887" class="notion-header-anchor"></div><a class="notion-hash-link" href="#982978c19a2a4c8b9836fe675727f887" title="六、总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">六、总结</span></span></h3><div class="notion-text notion-block-03f48e0d26ec47f2807a5b10eb4a332f">至此，envsetup.sh 和lunch()的初始化流程基本上理清了，主要就是加载了环境变量，并选择了编译目标，后面只要执行一下make就能够进行启动编译，下一节让我们一起看看敲下make后到底发生了什么。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a76176a7a6294bdd9aba2a47c440eb95"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc012afa0-c6cb-4016-a2db-c10b24842070%2FUntitled.png?table=block&amp;id=a76176a7-a629-4bdd-9aba-2a47c440eb95&amp;t=a76176a7-a629-4bdd-9aba-2a47c440eb95&amp;width=592.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android系统中各image文件解压缩]]></title>
            <link>https://notion.iliuqi.com/article/android_images_unpack</link>
            <guid>https://notion.iliuqi.com/article/android_images_unpack</guid>
            <pubDate>Fri, 18 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[Android系统编译之后的打包阶段，会将所有编译出来的有需要的执行文件，库文件以及各种配置文件等打包到各个镜像文件中。有时候我们需要看一下镜像文件中都打包了什么东西，那就可以通过一些方法将其挂载到一个目录，然后进行查看。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-9554b9c945e74e48a207d28eb6d22d64"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-89972b1d63204e5abf44fea800df963b">Android系统编译之后的打包阶段，会将所有编译出来的有需要的执行文件，库文件以及各种配置文件等打包到各个镜像文件中。有时候我们需要看一下镜像文件中都打包了什么东西，那就可以通过一些方法将其挂载到一个目录，然后进行查看。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-5645f42122e440279cbaccc9166f73df" data-id="5645f42122e440279cbaccc9166f73df"><span><div id="5645f42122e440279cbaccc9166f73df" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5645f42122e440279cbaccc9166f73df" title="一、所用到的工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、所用到的工具</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-39d97942e12a47fcae890ad6736d91d9" data-id="39d97942e12a47fcae890ad6736d91d9"><span><div id="39d97942e12a47fcae890ad6736d91d9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#39d97942e12a47fcae890ad6736d91d9" title="1.1 simg2img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.1 simg2img</span></span></h4><div class="notion-text notion-block-aba143cdf15742f2824f3d15ba8a6d45"><b>简述：</b>将<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://so.csdn.net/so/search?q=sparse&amp;spm=1001.2101.3001.7020">sparse</a>格式的image文件转化为raw格式的image文件。
编译android源码默认会生成。</div><div class="notion-text notion-block-cabe4dc44da64c5c802c164a239ac5e8">路径：out/host/linux-x86/bin/simg2img</div><div class="notion-text notion-block-d678b35e623d4dc8bd4b9a63aa6d79ba">如果没有请用如下的指令编出</div><div class="notion-text notion-block-f940a75f3a9a46c0b49d8b745841f874"><code class="notion-inline-code">source build/envsetup.sh
lunch miodm_topaz_native-userdebug
export OUT_DIR=out &amp;&amp; nj simg2img</code></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-bd9bd8631d3a49c79116468b8ff94ab4" data-id="bd9bd8631d3a49c79116468b8ff94ab4"><span><div id="bd9bd8631d3a49c79116468b8ff94ab4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bd9bd8631d3a49c79116468b8ff94ab4" title="1.2 lpunpack"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.2 lpunpack</span></span></h4><div class="notion-text notion-block-3e41efdb829c4b87afc25337ee8aac5e"><b>简述：</b>这个工具可以将system.img，product.img，vendor.img等文件从super.img解析出来。</div><div class="notion-text notion-block-bbd645259b2e4dd4a88e0f6edf0ff417"><b>路径：out/host/linux-x86/bin/lpunpack</b></div><div class="notion-text notion-block-893b947c64a74de99f5283aec68506cf">如果没有请用如下的指令编出</div><div class="notion-text notion-block-99f7f1a69b6345eeb70e28d84ca81c78"><code class="notion-inline-code">source build/envsetup.sh
lunch miodm_topaz_native-userdebug
export OUT_DIR=out &amp;&amp; nj lpunpack</code></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-963b5e0bb9144d04964b1dc79e638d05" data-id="963b5e0bb9144d04964b1dc79e638d05"><span><div id="963b5e0bb9144d04964b1dc79e638d05" class="notion-header-anchor"></div><a class="notion-hash-link" href="#963b5e0bb9144d04964b1dc79e638d05" title="1.3 unpack_bootimg"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.3 unpack_bootimg</span></span></h4><div class="notion-text notion-block-a67fdff1e73746b4b890ef9ed1731bb8"><b>简述：</b>专门用于解析boot.img的工具。</div><div class="notion-text notion-block-3d4c804bc9a34b0c8986f3007aa206ad"><b>路径：</b>out/host/linux-x86/bin/unpack_bootimg
system/core/mkbootimg/unpack_bootimg.py</div><div class="notion-text notion-block-687e5775b84345ef8be95018995869d2">如果没有请用如下的指令编出</div><div class="notion-text notion-block-92593d083a964cba9d457a26580482d5"><code class="notion-inline-code">source build/envsetup.sh
lunch miodm_topaz_native-userdebug
export OUT_DIR=out &amp;&amp; nj unpack_bootimg</code></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4b634d596bb04dbebaaf182a6a87e0b3" data-id="4b634d596bb04dbebaaf182a6a87e0b3"><span><div id="4b634d596bb04dbebaaf182a6a87e0b3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4b634d596bb04dbebaaf182a6a87e0b3" title="1.4 mkdtimg"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.4 mkdtimg</span></span></h4><div class="notion-text notion-block-59f2024b78e74e44badeb9000abda960"><b>简述：</b>将dtbo.img文件转化为dtb文件，一个dtbo.img会包含多个dtb文件；
编译android源码默认会生成。</div><div class="notion-text notion-block-1d188dcd7d5744a99b1cf0804275bd2d"><b>路径：</b>out/host/linux-x86/bin/mkdtimg</div><div class="notion-text notion-block-456c3b8638cf4b37aca05f7800e8a025">如果没有请用如下的指令编出</div><div class="notion-text notion-block-ebedb8adf122437daf6890c6cf930bcb"><code class="notion-inline-code">source build/envsetup.sh
lunch miodm_topaz_native-userdebug
export OUT_DIR=out &amp;&amp; nj mkdtimg</code></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ca454d8d2ef24438879cee285644ef96" data-id="ca454d8d2ef24438879cee285644ef96"><span><div id="ca454d8d2ef24438879cee285644ef96" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ca454d8d2ef24438879cee285644ef96" title="1.5 dtc"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.5 dtc</span></span></h4><div class="notion-text notion-block-1b4c1aab46f344c297868a558ba44f30"><b>简述：</b>将dtb文件转化为可阅读的dts文件；
编译android源码默认会生成。</div><div class="notion-text notion-block-08796212a5784019a7f306345c264611"><b>路径：</b>out/host/linux-x86/bin/dtc</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-db169396db18411bb367381a11fdc085" data-id="db169396db18411bb367381a11fdc085"><span><div id="db169396db18411bb367381a11fdc085" class="notion-header-anchor"></div><a class="notion-hash-link" href="#db169396db18411bb367381a11fdc085" title="二、解压缩各image文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、解压缩各image文件</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-e6270cefb93b450794a8f7be86be8e16" data-id="e6270cefb93b450794a8f7be86be8e16"><span><div id="e6270cefb93b450794a8f7be86be8e16" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e6270cefb93b450794a8f7be86be8e16" title="2.1 boot.img/recovery.img/vendor_boot.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 boot.img/recovery.img/vendor_boot.img</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-5ff507186c5b447d9e1cf1c35c131da3" data-id="5ff507186c5b447d9e1cf1c35c131da3"><span><div id="5ff507186c5b447d9e1cf1c35c131da3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5ff507186c5b447d9e1cf1c35c131da3" title="2.1.1 解压缩"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1.1 解压缩</span></span></h4><div class="notion-text notion-block-721167be2df94103a42319c8259058d9">指令如下：</div><ol start="1" class="notion-list notion-list-numbered notion-block-948e5cc9f737408c8a9adfd5023b7e4f"><li>boot.img</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-196e9ebd20854a858fd43eb5f0d8a2a3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F08c2aa5a-0117-404e-9b26-704fa4ec341d%2FUntitled.png?table=block&amp;id=196e9ebd-2085-4a85-8fd4-3eb5f0d8a2a3&amp;t=196e9ebd-2085-4a85-8fd4-3eb5f0d8a2a3&amp;width=590.953125&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><ol start="1" class="notion-list notion-list-numbered notion-block-bb8fff838285461e8fc5ba34efbdabf7"><li>recovery.img</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-fddbbf70d634478580dca2125b64957c"><li>vendor_boot.img</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-5edb25804ccd4e47971ccc1bd22219dc"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff3919a8e-ce3f-43c5-bd4b-9e7099a4f139%2FUntitled.png?table=block&amp;id=5edb2580-4ccd-4e47-971c-cc1bd22219dc&amp;t=5edb2580-4ccd-4e47-971c-cc1bd22219dc&amp;width=590.953125&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-0ae9c8ab03494fe8ab94d85bb814137e" data-id="0ae9c8ab03494fe8ab94d85bb814137e"><span><div id="0ae9c8ab03494fe8ab94d85bb814137e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0ae9c8ab03494fe8ab94d85bb814137e" title="2.2 dtbo.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 dtbo.img</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-2d2d6082895049d99d8b405a37a59f15"><li>先从dtbo.img中解析出dtb文件</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-089d4096f8ce4b54a41c16fe7c853d84"><li>将上一步的dtb文件转化为可以阅读的dts文件</li></ol><div class="notion-text notion-block-24dc8c28eabd4f169824b91355410716">也可以使用fdtdump</div><div class="notion-text notion-block-dc5a7218ac3b4573ae8eb9a42b346fde">fdtdump -sd dtbo.img &gt; dtbo.txt</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-22c97755d325414292f15f54b9f035ff" data-id="22c97755d325414292f15f54b9f035ff"><span><div id="22c97755d325414292f15f54b9f035ff" class="notion-header-anchor"></div><a class="notion-hash-link" href="#22c97755d325414292f15f54b9f035ff" title="2.3 dtb.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.3 dtb.img</span></span></h4><div class="notion-text notion-block-fd1b1f04674e45a48cbfda141675ca71">也可以使用fdtdump</div><div class="notion-text notion-block-de869a66602c4a6aafc5c6fd1d957777">fdtdump -sd dtb.img &gt; dtb.txt</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-567a4e6b89a5443db071830041e3ae48" data-id="567a4e6b89a5443db071830041e3ae48"><span><div id="567a4e6b89a5443db071830041e3ae48" class="notion-header-anchor"></div><a class="notion-hash-link" href="#567a4e6b89a5443db071830041e3ae48" title="2.4 metadata.img/userdata.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4 metadata.img/userdata.img</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-aa2ea62285674a6f8381971ecbeb42ff"><li>将sparse格式的metadata.img转化为raw格式的metadata_raw.img</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-366efd44023e45e6bb50fcff39406ba9"><li>将metadata_raw.img挂载到一个目录上，此时访问这个目录就可以访问镜像文件的内容了</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3a053e0733294a5e9c2c7e4afc5e1ebd" data-id="3a053e0733294a5e9c2c7e4afc5e1ebd"><span><div id="3a053e0733294a5e9c2c7e4afc5e1ebd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3a053e0733294a5e9c2c7e4afc5e1ebd" title="2.5 super.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.5 super.img</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-5d6c052afd7d4ed5b0b2e685c03b1433"><li>sparse格式转化为raw格式</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-35157dc3480c43b4ba2c22babd4c8e03"><li>使用lpunpack解析super_raw.img</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-e3bed6dbc34e4b189893b642e7ea715e"><li>挂载解析出来的镜像文件</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1be477cdf4864fd990590e3d84a3571a" data-id="1be477cdf4864fd990590e3d84a3571a"><span><div id="1be477cdf4864fd990590e3d84a3571a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1be477cdf4864fd990590e3d84a3571a" title="2.6 persist.img"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.6 persist.img</span></span></h4><div class="notion-text notion-block-e704994d92da42eb9091f460a30608eb">这个镜像是linux ext4格式的，直接挂载即可</div><div class="notion-blank notion-block-b6800c17ff3446b7bd1d7b55857d68ad"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[高通Android启动代码流程分析(SBL->ABL)]]></title>
            <link>https://notion.iliuqi.com/article/qcom_android_start_process</link>
            <guid>https://notion.iliuqi.com/article/qcom_android_start_process</guid>
            <pubDate>Fri, 18 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[从原理以及代码上来分析高通平台android的启动流程]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-e4b48ae227734314935208ad340a9f9b"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-d3c0da1a72924e7ba0f523175eab4256" data-id="d3c0da1a72924e7ba0f523175eab4256"><span><div id="d3c0da1a72924e7ba0f523175eab4256" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d3c0da1a72924e7ba0f523175eab4256" title="一、前言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、前言</span></span></h3><div class="notion-text notion-block-ac7435d25b1942cd9a5a3a5282729c1c">在面对UEFI阶段代码移植以及开机故障问题，需要对开机启动流程有一定的了解</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-ccc4bc6181394224a400d774544aca7b" data-id="ccc4bc6181394224a400d774544aca7b"><span><div id="ccc4bc6181394224a400d774544aca7b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ccc4bc6181394224a400d774544aca7b" title="二、芯片的冷启动"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、芯片的冷启动</span></span></h3><div class="notion-text notion-block-0d79a11b33f6430eaf9a43f27976e500">Cold boot flow: 冷启动</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a427b885c58d471c922a5ea4f9bbbe7e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fd1863af2-f05a-4090-82d4-c5182d2fe251%2FUntitled.png?table=block&amp;id=a427b885-c58d-471c-922a-5ea4f9bbbe7e&amp;t=a427b885-c58d-471c-922a-5ea4f9bbbe7e&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-66b1f5c7a72241efbed52d9030dd2c9f">可以看出，在设备上电后，先跑的是 APPS PBL，接着运行XBL SEC、XBL Loader，通过Loader引出XBL CORE APPSBL，最后进入HLOS</div><div class="notion-text notion-block-f964aa6ac1064a20a2b7f915f0d3f270">备注：</div><div class="notion-text notion-block-35e13805231344a2835875b0c6ed5c2f">下面补充点arm架构的知识点，以便可以看懂上图</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7d93432c7f184ce88d184031718a5c96" data-id="7d93432c7f184ce88d184031718a5c96"><span><div id="7d93432c7f184ce88d184031718a5c96" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7d93432c7f184ce88d184031718a5c96" title="2.1 异常级别"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 异常级别</span></span></h4><table class="notion-simple-table notion-block-f3ffb442e4b1401d8a1eb130aa86a1e3"><tbody><tr class="notion-simple-table-row notion-block-348c12901c6c423798a10286ee8fd38e"><td class="" style="width:120px"><div class="notion-simple-table-cell">异常级别</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">运行的软件</div></td></tr><tr class="notion-simple-table-row notion-block-b9a1a99231a345fc8266ecd20c2678d9"><td class="" style="width:120px"><div class="notion-simple-table-cell">EL0</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Application</div></td></tr><tr class="notion-simple-table-row notion-block-791ec7790b2845f8b076290e5b56afb4"><td class="" style="width:120px"><div class="notion-simple-table-cell">EL1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Linux kernel- os</div></td></tr><tr class="notion-simple-table-row notion-block-bdbd11096c8941c4a24483104d8ddf95"><td class="" style="width:120px"><div class="notion-simple-table-cell">EL2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Hypervisor（可理解为上面跑多个虚拟OS）</div></td></tr><tr class="notion-simple-table-row notion-block-55790258f3e745cda9a6201b54a1e5ab"><td class="" style="width:120px"><div class="notion-simple-table-cell">EL3</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Secure Monitor（ARM Trusted Firmware）</div></td></tr></tbody></table><ol start="1" class="notion-list notion-list-numbered notion-block-4db3eefa9adf4a0895989922cdfa9e1e"><li>ELx(x&lt;4)，x越大等级越高，执行特权越高</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-76437390e07f42b187082b0bbe867d7a"><li>执行在EL0，称为非特权执行</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5836fdb4bab04b638182357e32872d93"><li>EL2没有Secure state，只有Non-secure state</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-f1005420c0e34ea5802a7cfb672381dd"><li>EL3 只有Secure state，支持EL0/EL1的Secure 和Non-secure之间的切换</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-ef561a31128a4602a6791dc881e53da9"><li>EL0 &amp; EL1 必须要实现，EL2/EL3则是可选实现</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-4eb8e2acab5744afbd442cd2d807dbbb"><li>当接收到一个异常时，异常级别只能调高或保持；</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-d880c99ed91042c6af6cc2655cc74018"><li>当从异常返回时，异常级别只能调低或保持</li></ol><ol start="8" class="notion-list notion-list-numbered notion-block-ae43c937c98d41d38d3591f8857e1ef3"><li>在接收到异常将要切换或保持的异常级别称为目标异常级别</li></ol><ol start="9" class="notion-list notion-list-numbered notion-block-0ed08e5ed65f46b6ae5d2cba42a9737f"><li>每个异常级别本身有一个默认固定的目标异常级别，还可以通过寄存器设置目标异常级别，目标异常级别不能为EL0</li></ol><ol start="10" class="notion-list notion-list-numbered notion-block-3f3067e0f016472ca8787d123b04936d"><li>当PE运行在一个异常级别时，可以访问如下两种资源：1)当前异常级别和安全状态组合下的资源；2)低异常级别可访问的资源（要符合安全状态）</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-562549c9255b4827b0f2c320f12be60b" data-id="562549c9255b4827b0f2c320f12be60b"><span><div id="562549c9255b4827b0f2c320f12be60b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#562549c9255b4827b0f2c320f12be60b" title="2.2 secure state"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 secure state</span></span></h4><table class="notion-simple-table notion-block-16ae4c3b98f0450282e1a8f1f8f0deca"><tbody><tr class="notion-simple-table-row notion-block-887b82bceb3942a1976b5525d49aa375"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>状态</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>特点</b></div></td></tr><tr class="notion-simple-table-row notion-block-537441f1bd8241e3b7967ed35daf0c45"><td class="" style="width:120px"><div class="notion-simple-table-cell">Non-secure</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">EL0/EL1/EL2, 只能访问Non-secure 物理地址空间</div></td></tr><tr class="notion-simple-table-row notion-block-0d202c87a3fe4bf9abd6dc661277a03c"><td class="" style="width:120px"><div class="notion-simple-table-cell">Secure</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">EL0/EL1/EL3, 可以访问Non-secure 物理地址空间 &amp; Secure 物理地址空间,可起到物理屏障安全隔离作用</div></td></tr></tbody></table><div class="notion-text notion-block-697f0084c5e2459e9f7d0d353f207beb">这几个涉及的模块大概功能</div><ol start="1" class="notion-list notion-list-numbered notion-block-76c98fc8262b45f0ad718fb58ac0321b"><li><b>Application primary boot </b><b>loader</b><b> (APPS PBL)</b></li></ol><div class="notion-text notion-block-37061935819946fa9764add22ee080a7">PBL 启动时，CPU只开启了第一个核心 CPU Core 0，运行固件在ROM中，这部分是高通写死在芯片中的固件，外部开发人员是无法修改这部份的。</div><div class="notion-text notion-block-7252bc01a96145e59609a8b70392af00">主要功能为：</div><div class="notion-text notion-block-1d55ce5abe54409eaef6d981e5ab448d">（1）系统安全环境的初始化，以确保后续的XBL中的APPS 能够正常运行。</div><div class="notion-text notion-block-515e2d0b4e31494c8be7a75f9ce49710">（2）根据boot gpio的配置选择从什么设备启动操作系统（如 Nand，USB等）。</div><div class="notion-text notion-block-f4e542ccc92743adb8cd026a331b61e1">（3）通过检测GPIO判断是否进入Emergency Download mode，用户可以通过QFIL来下载完整的系统镜像。</div><div class="notion-text notion-block-30497d25b7f84cd1ba86d70fde03b41a">（4）通过L2 TCM来加载XBL1 ELF，OCIMEM 和 RPM CodeRAM 代码。</div><ol start="1" class="notion-list notion-list-numbered notion-block-1a4a2fb5b622402695c02ad2f0ff3f98"><li><b>Extensible boot </b><b>loader</b><b> (XBL)</b></li></ol><div class="notion-text notion-block-1078c158c99142d5af5bfeb563d2c1c5">从XBL开始，跑的就是我们编译下载进eMMC/UFS的系统镜像了，在XBL中主要是初始化相关的硬件环境，及代码安全环境。</div><div class="notion-text notion-block-f679fc40d81343628e589813b8da3362">（1）初始化 Buses、DDR、Clocks、CDT，启动QSEE，QHEE,RPM_FW, XBL core images。</div><div class="notion-text notion-block-b83ca6e4b3dc466fb7397778d19f9d9a">（2）使能memory dump through USB and Sahara（系统死机时memory dump），看门狗，RAM dump to SD support等功能。</div><div class="notion-text notion-block-af98e411f3424f5f84783a674e96b222">（3）初始化 USB驱动，USB充电功能，温升检测，PMIC驱动初始化，和 DDR training模块。</div><ol start="1" class="notion-list notion-list-numbered notion-block-9ee98c2a3add430fb75d483c61742dca"><li><b>XBL core (</b><b>UEFI</b><b> or LK，ABL)</b></li></ol><div class="notion-text notion-block-f9a9f8e128a8415fa4cf27ceae206fd4">XBL core，就是之前的bootloader，主要功能就是初始化display驱动，提供fastboot功能，引导进入HLOS kernel操作系统。
注意，在ABL中，同样也只有CPU Core0在工作，其他的CPU核以是在进入HLOS Kernel后才开始初始化启用的。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-821fc82390a94708b86d345a0d85c244" data-id="821fc82390a94708b86d345a0d85c244"><span><div id="821fc82390a94708b86d345a0d85c244" class="notion-header-anchor"></div><a class="notion-hash-link" href="#821fc82390a94708b86d345a0d85c244" title="三、代码目录架构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">三、代码目录架构</span></span></h3><div class="notion-text notion-block-38be6cca5e0a408cbc11aeb7220c1a4f">以前的lk相关代码移到了boot_images/QcomPkg路径下，编译方式和之前也不同了</div><div class="notion-text notion-block-f10dc93bbf64475f8b6ea2bfe79637ca">代码位于：${BP_ROOT}/BOOT.XF.1.4/boot_images/</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-be3bc2e66d984abcbf5659299930660a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff3e19cf5-f8df-4661-bdc2-e9706d785a32%2FUntitled.png?table=block&amp;id=be3bc2e6-6d98-4abc-bf56-59299930660a&amp;t=be3bc2e6-6d98-4abc-bf56-59299930660a&amp;width=707.953125&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-53e8c3735e2f4e5491c5d66df8b089a4" data-id="53e8c3735e2f4e5491c5d66df8b089a4"><span><div id="53e8c3735e2f4e5491c5d66df8b089a4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#53e8c3735e2f4e5491c5d66df8b089a4" title="四、PBL-&gt;SBL"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">四、PBL-&gt;SBL</span></span></h3><div class="notion-text notion-block-85406f1be3a74f0392873a9c7a3b8c83">PBL是上电后芯片执行的第一行代码，位于ROM中，PBL代码未开源，无法查看，之后通过PBL启动SBL。SBL1负责初始化部分硬件以进行后续引导，初始化DDR内存，加载TrustZone,加载RPM固件，加载ABL</div><div class="notion-text notion-block-97e9b6ccfe1440d7ab5c688e880af3cd">从SBL开始就进入了XBL中，而我们所说的SBL1也就是XBL REG#1，代码为</div><div class="notion-text notion-block-f984f200e41945688bbd88ebf83bd79a"><span class="notion-inline-underscore">BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_Aarch64.s</span></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-33fb65c9e56f4bce93f087b806691b88" data-id="33fb65c9e56f4bce93f087b806691b88"><span><div id="33fb65c9e56f4bce93f087b806691b88" class="notion-header-anchor"></div><a class="notion-hash-link" href="#33fb65c9e56f4bce93f087b806691b88" title="4.1 sbl1_main_ctl函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1 sbl1_main_ctl函数</span></span></h4><div class="notion-text notion-block-dfb14f5c3e9940bba33c54939171ac66">主要工作：一些重要外设的初始化，如RAM的初始化，为下一步程序的运行做准备</div><div class="notion-text notion-block-8f95dbdb453347f2ac9ed657284b2f5d">在<b>sbl1_main_ctl</b>中使用了<b>sbl1_boot_logger_init</b>进行了logger的初始化，这其中就会调用boot_log_init_uart，将串口进行初始化</div><div class="notion-text notion-block-4ca06c6ffe8b46b7a0608a222eb4c279">在这个阶段如果需要加log，有下面几种方式：</div><ol start="1" class="notion-list notion-list-numbered notion-block-75d1d1779b1d4e81b26668a29ef09ae0"><li>boot_log_dump(boot_log_ram_to_uart)将ram中的所有log从串口输出</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-a8a467b136334d97a839152cca34d23f"><li>boot_log_message，此函数是加log比较方便的方式，此函数会将需要打印的log同时写入ram以及输出到串口</li></ol><div class="notion-text notion-block-36d6523aaba74f9889d10c31ed693117">上面分析的函数在开机串口log中的体现如下：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-113999743cb24ac38abd88d935c63a9d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:478px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ffb434cfa-1a63-4f7a-b794-cb44d347da68%2FUntitled.png?table=block&amp;id=11399974-3cb2-4ac3-8abd-88d935c63a9d&amp;t=11399974-3cb2-4ac3-8abd-88d935c63a9d&amp;width=478&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c31b584a20354f0f91d57311f4035fce" data-id="c31b584a20354f0f91d57311f4035fce"><span><div id="c31b584a20354f0f91d57311f4035fce" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c31b584a20354f0f91d57311f4035fce" title="4.2 boot_config_process_bl函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2 boot_config_process_bl函数</span></span></h4><div class="notion-text notion-block-5a9b01ace3434ed1b6f937f97a96c564">此函数为核心函数，形参包括sbl共享数据结构，SBL1镜像文件，和sbl1配置表。函数循环调用boot_config_process_entry对配置表中 各项进行配置，配置列表中包含PMIC、APDP、QSEE (Qualcomm secure execution environment）、QHEE( Qualcomm secure execution environment）、RPM、STI、ABL、APPSBL等子系统。</div><div class="notion-text notion-block-1ab9b2c266fd4503bf454545642d1874">在sbl1_config_table结构体数组中，每个数组按照对应顺序对应PMIC、RPM等子系统，在子系统中的load_..._pre_procs函数和load...post_procs，两个函数中分别对应相应系统加载前要做的初始化和配置操作以及加载后操作。</div><div class="notion-text notion-block-19fc770e36074344b231826d8fcdf9ff">这部分的代码有点难以理解：</div><div class="notion-text notion-block-36bb624073ea4b47858f68bd88cd4e64">对应的串口如下：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-00c94030efde4d71ab9633fcdea53dcd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F5aa85700-7121-41be-8aa0-e563538f7935%2FUntitled.png?table=block&amp;id=00c94030-efde-4d71-ab96-33fcdea53dcd&amp;t=00c94030-efde-4d71-ab96-33fcdea53dcd&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-051cda8adadd4314adad99ff1d8ef923"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fb78b8ade-f0e8-4cba-97ce-a9c035ce51f1%2FUntitled.png?table=block&amp;id=051cda8a-dadd-4314-adad-99ff1d8ef923&amp;t=051cda8a-dadd-4314-adad-99ff1d8ef923&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-d6a37592762647a5a99b05446ca66719">在串口中对应的打印信息Image load Start，APDP Image Loaded,Delta；Image_Load,Start......就是对应函数boot_config_process_entry函数该阶段的image加载、验证与执行都是类似RPM、QSEE、这种子系统环境的搭建，之后在ABL部分会正式进行kernel的加载进而启动HLOS</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-7e4cabb90155480b88d4ce8a89ff1fe4" data-id="7e4cabb90155480b88d4ce8a89ff1fe4"><span><div id="7e4cabb90155480b88d4ce8a89ff1fe4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7e4cabb90155480b88d4ce8a89ff1fe4" title="五、SBL"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">五、SBL</span></span></h3><div class="notion-text notion-block-9f4139c72c6c47c49234bbb085167303">其实第四节已经将SBL的流程梳理了，本章节独立出来是希望能更加细节的研究一下这部分的代码</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2dfe4a5dfb58482397c9081cf1566850" data-id="2dfe4a5dfb58482397c9081cf1566850"><span><div id="2dfe4a5dfb58482397c9081cf1566850" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2dfe4a5dfb58482397c9081cf1566850" title="5.1 sbl1_xblconfig_init"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.1 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://10.240.232.60:8080/k7t/xref/vendor/qcom/non-hlos-mid-2020-spf101/BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_config.c?r=d3df121f#224">sbl1_xblconfig_init</a></span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0ddd67ab556341af87abc70fb42401e5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fb22d1b42-6b0c-41be-9eb8-cb0c17b48fe2%2FUntitled.png?table=block&amp;id=0ddd67ab-5563-41af-87ab-c70fb42401e5&amp;t=0ddd67ab-5563-41af-87ab-c70fb42401e5&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-846cc022d8f446c0b3d7e0433f0a4924" data-id="846cc022d8f446c0b3d7e0433f0a4924"><span><div id="846cc022d8f446c0b3d7e0433f0a4924" class="notion-header-anchor"></div><a class="notion-hash-link" href="#846cc022d8f446c0b3d7e0433f0a4924" title="5.2 sbl1_hw_pre_ddr_init"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.2 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://10.240.232.60:8080/k7t/xref/vendor/qcom/non-hlos-mid-2020-spf101/BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_hw.c?r=92d1b130#557"><b>sbl1_hw_pre_ddr_init</b></a></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3b4284e855c64e6bbe2c44ee6c82c084" data-id="3b4284e855c64e6bbe2c44ee6c82c084"><span><div id="3b4284e855c64e6bbe2c44ee6c82c084" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3b4284e855c64e6bbe2c44ee6c82c084" title="5.2.1 boot_pm_device_init"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.2.1 boot_pm_device_init</span></span></h4><div class="notion-text notion-block-fee64dca1b644f0ab154e34654bbb958">PMIC相关的逻辑不扩展，可查看这一系列文章<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://opqqrjk1dc.feishu.cn/wiki/wikcnInnsr6xEA3RxI5EZ2raHMc">SBL PMIC 流程分析</a></div><div class="notion-text notion-block-0fb00f7d9f9a45c581a0178b2654a20f">https://wiki.n.miui.com/pages/viewpage.action?pageId=610308677</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f621dc86450e438396051dfe58c15f99" data-id="f621dc86450e438396051dfe58c15f99"><span><div id="f621dc86450e438396051dfe58c15f99" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f621dc86450e438396051dfe58c15f99" title="5.2.2 sbl1_hw_reset_platform_type和sbl1_hw_reset_platform_version"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.2.2 sbl1_hw_reset_platform_type和sbl1_hw_reset_platform_version</span></span></h4><div class="notion-text notion-block-9e03a3b022184d1e96cd9d5efed3d023">这部分涉及高通平台boardid的设计，详细可查看小米古明涛大神的文章</div><div class="notion-text notion-block-21a61ccacd7846c2beb514af380e7c4f">https://wiki.n.miui.com/pages/viewpage.action?pageId=135269079</div><div class="notion-text notion-block-0080db44e80d40c48f1411a3033c9ceb">https://wiki.n.miui.com/display/~gumingtao/2018/12/18/How+to+select+Dtb</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-504818c1293343f386b891f2bd1c7827" data-id="504818c1293343f386b891f2bd1c7827"><span><div id="504818c1293343f386b891f2bd1c7827" class="notion-header-anchor"></div><a class="notion-hash-link" href="#504818c1293343f386b891f2bd1c7827" title="六、UEFI背景介绍"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">六、UEFI背景介绍</span></span></h3><div class="notion-text notion-block-ff7156156c0646a498fd6c0f403d5745">要详细了解UEFI，还得从BIOS讲起。我们都知道，每一台普通的电脑都会有一个BIOS，用于加载电脑最基本的程式码，担负着初始化硬件，检测硬件功能以及引导操作系统的任务。UEFI就是与BIOS相对的概念，这种接口用于操作系统自动从预启动的操作环境，加载到一种操作系统上，从而达到开机程序化繁为简节省时间的目的。传统BIOS技术正在逐步被UEFI取而代之，在最近新出厂的电脑中，很多已经使用UEFI，使用UEFI模式安装操作系统是趋势所在。</div><div class="notion-text notion-block-c27fcc73172047f8b816e3d2b9fac245">主要是由于安腾处理器芯片组的创新，64位架构的处理器已经不再适用于传统BIOS的16运行模式，因此intel将系统固件和OS的接口完全重新定义成一个可扩展、标准化的固件接口规范。</div><table class="notion-simple-table notion-block-0b93e3a0678c4742a5ca1f3595f5d8a0"><tbody><tr class="notion-simple-table-row notion-block-819391651a174fa0b87acf6741b25983"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>优化项</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>UEFI</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>BIOS</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>描述</b></div></td></tr><tr class="notion-simple-table-row notion-block-4be742b7a61c432eae85fad4933d8284"><td class="" style="width:120px"><div class="notion-simple-table-cell">开发效率</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">• <!-- -->开源<!-- -->
• <!-- -->标准接口<!-- -->
• <!-- -->绝大部分是c代码</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">• <!-- -->闭源<!-- -->
• <!-- -->接口混乱<!-- -->
• <!-- -->主要采用汇编</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">正是由于BIOS的闭源以及混乱的接口导致其停滞不前，并最终无法适用于新架构的芯片。UEFI的开源且指定了标准的接口规范，并且也同提供接口，将大部分代码替换成c进行编写，不再使用晦涩的汇编进行开发，这样大大降低了开发的难度，这也是其迅速发展的根本原因。</div></td></tr><tr class="notion-simple-table-row notion-block-33be26dc3184439b8813afa70285cb4a"><td class="" style="width:120px"><div class="notion-simple-table-cell">性能</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">异步+时钟中断</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">中断机制</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">UEFI舍弃了硬件外部中断的低效方式，只保留了时钟中断机制，然后通过异步+事件来实现对外部设备的操作，性能由此得到了极大的提升。</div></td></tr><tr class="notion-simple-table-row notion-block-61eec81ddc4445209527b88ff3e68a67"><td class="" style="width:120px"><div class="notion-simple-table-cell">扩展和兼容性</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">模块化驱动设计</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">静态链接</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">UEFI采用了规范的模块化设计，在扩展功能的时候只需要动态链接其模块就可以实现，这样的扩展十分方便便捷。而传统的BIOS必须运行在16位的指令模式之下，寻址范围也十分有限，而UEFI支持64位程序，并兼容32位，这也是为什么老古董windows XP出现这么久了，稍微改改就可以安装在新的设备上。</div></td></tr><tr class="notion-simple-table-row notion-block-b5cae60278ea4bb48b47031eccecbc11"><td class="" style="width:120px"><div class="notion-simple-table-cell">安全性</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">安全</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">未考虑安全性问题</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">UEFI安装的驱动设备是需要经过签名验证才可以安装的，并且还采用了一定的加密机制进行验证，这样的安全机制一定程度上可以保障我们设备的安全。</div></td></tr><tr class="notion-simple-table-row notion-block-2eab79591b6c472b92a15010e768c156"><td class="" style="width:120px"><div class="notion-simple-table-cell">驱动器容量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">支持容量&gt;2TB的驱动器</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">不支持容量&gt;2TB的驱动器</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">• <!-- -->传统的BIOS只支持容量不超过2TB的驱动器，因为常见的512Byte扇区的分区表的单个分区的第13-16字节是用来进行LAB寻址的，也就是以扇区为单位进行寻址。总共4个字节，也就是4*8 = 32位，也就是2^32个单位空间，以扇区为单位进行寻址，也就是每次512Byte，那么：<!-- -->      2^32*512 = 2^41B = 2^31KB = 2^21MB = 2^11GB = 2TB.<!-- -->      所以传统的BIOS支持的最大容量的驱动器不超过2TB，以硬件厂商1000：1024的计算方式，实际容  量是小于2TB的。<!-- -->
• <!-- -->UEFI支持64位的地址空间，所以其寻址偏移刚好为一个机器长度——64位，即8Byte，还是按照LAB寻址方式进行计算：<!-- -->2^64*512 = 2^73B = 2^13EB = 8ZB<!-- -->但是，微软官方给的资料显示是18EB（按照硬件厂商1000：1024计算）(10^60)/(10^60) = 18EB</div></td></tr><tr class="notion-simple-table-row notion-block-7ca49c2c687b4fb9aab6254e917099ae"><td class="" style="width:120px"><div class="notion-simple-table-cell">文件系统</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">拥有文件系统的支持</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">无</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">由于UEFI本身已经相当于一个微型的OS了，具备了文件系统的支持，能够直接读取FAT分区中的文件。</div></td></tr><tr class="notion-simple-table-row notion-block-b47c2ed004b54274b44cc1ed4e706eb8"><td class="" style="width:120px"><div class="notion-simple-table-cell">应用程序</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">可以开发出直接在UEFI下运行的应用程序</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">无</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">这类程序文件通常以efi结尾。既然，UEFI既可以直接识别FAT分区中的文件，又可以直接在其中运行应用程序，那么完全可以将win安装程序做成efi类型的应用程序，然后放在任意的FAT分区中，直接运行即可。这样一来，原来安装win操作系统这个过去看起来有些许小复杂的事情忽然变得异常简单，就像在win中打开一个qq一样简单。<!-- -->而这在BIOS上是无法做到，因为BIOS下启动OS之前，必须从硬盘上指定扇区读取系统的启动代码（包含在主引导记录中），然后从活动分区中引导OS的启动。对扇区的操作远远比不上对分区中的文件的操作来得直观和简单，所以在BIOS上安装win这类的OS，不得不使用一些工具对设备进行配置以达到启动要求。</div></td></tr></tbody></table><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-e1ade504652843bb85bf0e547d450997" data-id="e1ade504652843bb85bf0e547d450997"><span><div id="e1ade504652843bb85bf0e547d450997" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e1ade504652843bb85bf0e547d450997" title="6.1 Android的bootloader"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.1 Android的bootloader</span></span></h4><div class="notion-text notion-block-9aab768063fc430c93a6dfddb4f25bfa">UEFI的出道是在PC领域，UEFI+gpt以其自身优点干翻了传统bios+mbr，UEFI也成为了未来bootloader的发展方向，计算机软件界有一个名言，计算机科学领域的任何问题都可以通过增加一个间接的中间层来解决（抽象），UEFI也不例外，之所以bios不行一个重要的点就是因为他的兼容性，UEFI为固件和操作系统提供了统一的接口，打通了PC固件之间的鸿沟；安卓bootloader从最初使用uboot，到lk（目前大多数依然是lk），一直到现在选择使用uefi，也足以证明UEFI的优势；
        原来的安卓启动是采用boot loader这种引导启动方式。在有的文章中，会将bootloader进行比较，有的又会说现在的安卓bootloader是使用UEFI，而且在查找有关Android启动流程或者说开机流程的文章里，大部分还是在loader层以bootloader作为启动流程中的一部分。这里，算是给自己统一下说法，早期的bootloader是一种引导程序的名称，后来采用了LK、UEFI之后，bootloader就是代指某种的引导程序的统称，换句话说，UEFI、LK都是安卓bootloader采用的一种引导方式。所以，在学习安卓开机流程的时候，如果不关注loader层，完全可以忽略这里的bootloader采用的是哪种方式。这里说的有点绕，简单来说bootloader可以理解为一种过时的引导程序（古早且已经被时代淘汰了），也可以理解为引导程序的统称（比如，UEFI是一种bootloader、LK是一种bootloader，甚至可以说BIOS是一种bootloader），现在我们讲bootloader就是在第二种理解。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-546b85525ef84778bd72195cd639cf1f" data-id="546b85525ef84778bd72195cd639cf1f"><span><div id="546b85525ef84778bd72195cd639cf1f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#546b85525ef84778bd72195cd639cf1f" title="6.2 UEFI概述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.2 UEFI概述</span></span></h4><div class="notion-text notion-block-80be36d7eab64afe842b050c8bca655f">UEFI: 统一可扩展固件接口（Unified Extensible Firmware Interface，UEFI），是一种详细描述全新类型接口的标准，是适用于电脑的标准固件接口，旨在代替BIOS（基本输入/输出系统）。此标准由UEFI联盟中的140多个技术公司共同创建，如intel、IBM、Microsoft、AMI等等。UEFI旨在提高软件互操作性和解决BIOS的局限性。它用来定义操作系统和系统固件之间的软件界面，作为BIOS的替代方案，其主要目的是为了提供一组在 OS 加载之前（启动前）在所有平台上一致的、正确指定的启动服务，被看做是有近20多年历史的 BIOS 的继任者，并且UEFI的security有所加强，在手机这个微型PC，或者说在android系统启动之中替代了bootloader和litter kernel，是新时代系统启动引导程序。</div><div class="notion-text notion-block-e062cd35fd8c4b0186a14c8050b17b04">总的来说，UEFI是一个规范，被定义为一个软件接口，用于连接OS和遵守这个规范的平台固件platform firmware。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-cb7c53fed2994afe822d3b2afc8540e6" data-id="cb7c53fed2994afe822d3b2afc8540e6"><span><div id="cb7c53fed2994afe822d3b2afc8540e6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cb7c53fed2994afe822d3b2afc8540e6" title="七、UEFI流程分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">七、UEFI流程分析</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-af9261de4bcf4dcb8cd243b933beea7d" data-id="af9261de4bcf4dcb8cd243b933beea7d"><span><div id="af9261de4bcf4dcb8cd243b933beea7d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#af9261de4bcf4dcb8cd243b933beea7d" title="7.1 XBL Loader Architecture"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.1 XBL Loader Architecture</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-d83b6750ab104b0bace87b9830494fbf"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F8a7499e4-0b5a-4ffe-9002-f9b3f3c0be0a%2FUntitled.png?table=block&amp;id=d83b6750-ab10-4b0b-ace8-7b9830494fbf&amp;t=d83b6750-ab10-4b0b-ace8-7b9830494fbf&amp;width=707.96875&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c7c647d1fe37409fab3491a35d64b2dd" data-id="c7c647d1fe37409fab3491a35d64b2dd"><span><div id="c7c647d1fe37409fab3491a35d64b2dd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c7c647d1fe37409fab3491a35d64b2dd" title="7.2 xbl代码运行流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2 xbl代码运行流程</span></span></h4><div class="notion-text notion-block-e96a338741e74020b3c8547fb3c011dc">从图中可以看出，UEFI代码运行流程为：
<code class="notion-inline-code">SEC(安全验证)---&gt;PEI(EFI前期初始化)---&gt;DXE(驱动执行环境)---&gt;BDS(启动设备选择)---&gt;UEFI Loader(操作系统加载前期)---&gt;RT(Run Time)</code>。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0123178cb97d45b898ad986e8969f0c9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Facde5087-f90f-4f01-b114-7a88fafe6c16%2FUntitled.png?table=block&amp;id=0123178c-b97d-45b8-98ad-986e8969f0c9&amp;t=0123178c-b97d-45b8-98ad-986e8969f0c9&amp;width=708&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-663e30d453294d8fa3ec194499008552" data-id="663e30d453294d8fa3ec194499008552"><span><div id="663e30d453294d8fa3ec194499008552" class="notion-header-anchor"></div><a class="notion-hash-link" href="#663e30d453294d8fa3ec194499008552" title="7.2.1 SEC(安全验证)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.1 SEC(安全验证)</span></span></h4><div class="notion-text notion-block-f1a2d4eff3f84602b5eef8bd5a20fbf0">SEC的汇编代码入口位于：BOOT.XF.4.1/boot_images/QcomPkg/XBLCore/ModuleEntryPoint.masm的_ModuleEntryPoint</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-a08354431c4a4f8d96c24c13eaa1a83d" data-id="a08354431c4a4f8d96c24c13eaa1a83d"><span><div id="a08354431c4a4f8d96c24c13eaa1a83d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a08354431c4a4f8d96c24c13eaa1a83d" title="7.2.1.1 ModuleEntryPoint.masm 代码分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.1.1 ModuleEntryPoint.masm 代码分析</span></span></h4><div class="notion-text notion-block-479c47e85dbd4b51bb7ce20a59a08ddc">该汇编代码中，主要工作为：</div><ol start="1" class="notion-list notion-list-numbered notion-block-7a09bc8fc4684a96b8dcfd9131315147"><li>关闭所有中断</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-5fb5a22a9a5d4834b3616fbd2b6945c0"><li>关闭MMU和Caches</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5a4bf0deb9f74d59a8a75eed6276889a"><li>关闭TLB缓存表</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-b5dc489f20124cd088d29604633f850b"><li>获得当前运行的安全环境：EL1、EL2、EL3</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-fd25e13f91804b3581f646a1eb205f37"><li>初始化ELX 安全环境</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-a46a460bd39946039e52247ba9f45ad7"><li>使能 Cache</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-36a38a88bbcb43b8a9f64ab8bb639e06"><li>初始化栈</li></ol><ol start="8" class="notion-list notion-list-numbered notion-block-459f942651a64e2da8bf063daaebdd4b"><li>调用 CEntryPoint，传参 _StackBase、_StackSize</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-05fa6f7e8b894f509f3d5586f1d10eec" data-id="05fa6f7e8b894f509f3d5586f1d10eec"><span><div id="05fa6f7e8b894f509f3d5586f1d10eec" class="notion-header-anchor"></div><a class="notion-hash-link" href="#05fa6f7e8b894f509f3d5586f1d10eec" title="7.2.1.2 XBLCore\Sec.c 代码分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.1.2 XBLCore\Sec.c 代码分析</span></span></h4><div class="notion-text notion-block-7c0ebea0ac4a478fb48da92deec88a22">前面汇编代码中主要目的是初始化C运行环境，初始化栈，以便可以调C代码运行。</div><div class="notion-text notion-block-785722c930604ac0b5f1e6cb34a5b234">SEC的C代码入口位于：BOOT.XF.4.1/boot_images/QcomPkg/XBLCore/Sec.c</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-9802f11704504154b383b7c28f4fdfb8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:589px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fae592c56-e0af-4e53-a6ca-c87b391348bd%2FUntitled.png?table=block&amp;id=9802f117-0450-4154-b383-b7c28f4fdfb8&amp;t=9802f117-0450-4154-b383-b7c28f4fdfb8&amp;width=589&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-1f4277c3cf104fcdac1b581af880b2ea">主要就是main函数</div><div class="notion-text notion-block-c610e09968c44a61a4b55ace7055fc5e">lib源码位置：BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/DivarPkg/LAA/Core.dsc</div><div class="notion-text notion-block-558c9a4876bf4c98a11b334cc6bf7061">至于dsc、inf、fdf之间的关系可以查看文章：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://opqqrjk1dc.feishu.cn/wiki/wikcnWQ1WtYdLT7Px0FQJxVqHIb">UEFI学习</a></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-795dcd9a615640f1a26556b192174a72" data-id="795dcd9a615640f1a26556b192174a72"><span><div id="795dcd9a615640f1a26556b192174a72" class="notion-header-anchor"></div><a class="notion-hash-link" href="#795dcd9a615640f1a26556b192174a72" title="7.2.1.2.1 LoadAndParsePlatformCfg"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.1.2.1 LoadAndParsePlatformCfg</span></span></h4><div class="notion-text notion-block-747953e773fe41628ab01c829b651f66">主要工作流程如下：</div><ol start="1" class="notion-list notion-list-numbered notion-block-b92e9d6c43a940c7844a56f330fa5054"><li>初始化相关全局变量</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-f70681a9c00449dcb05bedd6d6aaa165"><li>加载并解析 uefiplat.cfg 配置文件 #define UEFIPLATCFG_FILE &quot;uefiplat.cfg&quot;,文件内容保存在 CfgBuffer 中，解析器描述符保存在MemParserDesc 中。在cfg文件中包含了内存相关的信息及系统相关的配置，BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/DivarPkg/LAA/uefiplat.cfg</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-92b65f4c647d4a7187eb6c8c3dd29c7d"><li>解析 uefiplat.cfg 中的 [Config] 区域</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-247771419acd4710a72ea980c4768b75"><li>解析 uefiplat.cfg 中的 [MemoryMap] 区域</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-002cef15be7143c9a439ebd391ecb76d"><li>解析 uefiplat.cfg 中的 [RegisterMap] 区域，内容保存在mMemRegions中</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-4f73b6b896b04f0b92979eb8d0eefa1f"><li>解析 uefiplat.cfg 中的 [ConfigParameters] 区域，内容保存在 ConfigTable 中，ConfigTableEntryCount表示其内容的数量</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-95f867c8a9414d68b07623f5a42f1adf"><li>解析 uefiplat.cfg 中的 [ChipIDConfig] 区域</li></ol><div class="notion-blank notion-block-b25078ad79284697833118ef3d3abedf"> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-597e40c11081434384ec4cd7ed7bf960"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F1c15aafb-07da-44c1-a473-7d2de847520f%2FUntitled.png?table=block&amp;id=597e40c1-1081-4343-84ec-4cd7ed7bf960&amp;t=597e40c1-1081-4343-84ec-4cd7ed7bf960&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b7a4b5ddf1794f7c88ab44d7579b1ade" data-id="b7a4b5ddf1794f7c88ab44d7579b1ade"><span><div id="b7a4b5ddf1794f7c88ab44d7579b1ade" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b7a4b5ddf1794f7c88ab44d7579b1ade" title="7.2.1.2.2 UefiBootContinue"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.1.2.2 <b>UefiBootContinue</b></span></span></h4><div class="notion-text notion-block-6d669c1983dc458a9fdf549e0ddf7d33">DisplayEarlyInfo() 显示模块早期初始化</div><div class="notion-text notion-block-52309fe98a64498f9e320675fb39075f">在 DisplayEarlyInfo 中主要工作就是解析 UEFI version 版本号，然后根据版本号加载对应的镜像，接着打印系统启动的路径。</div><div class="notion-text notion-block-f5d07efb68b34fd3909a6d8933b1cfaa">主要流程为：</div><ol start="1" class="notion-list notion-list-numbered notion-block-8ceca55d64be4f128cc13dc55b5e7f28"><li>获取UefiPlatCfg.c中的UEFI CORE字段信息，PlatConfigFileName=&quot;uefiplatLA.cfg&quot;</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-6f4730a170cc4f63bf781fa980b0238e"><li>获取固件版本号，定义在boot_images\QcomPkg\Sdm660Pkg\LA\Sdm660Pkg_Core.dsc中</li></ol><div class="notion-text notion-block-4a513c0b31914a0294e20e8205f4d991">gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L&quot;4.2&quot;</div><ol start="1" class="notion-list notion-list-numbered notion-block-3664e8aaf132492083c55404cd07a478"><li>根据固件版本号查找对应的image镜像 Append Image version string component</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-bd881bcf88aa480498b304b2dd36fbb8"><li>打印UEFI固件版本号</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-ff723165ee9b406089f431d4cde79b6d"><li>选UEFI启动类型，判断顺序为 UFS &gt; EMMC &gt; SPI</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-31a80626bace4a7fb1a11ae683aaeae7" data-id="31a80626bace4a7fb1a11ae683aaeae7"><span><div id="31a80626bace4a7fb1a11ae683aaeae7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31a80626bace4a7fb1a11ae683aaeae7" title="7.2.2 DXE(驱动执行环境)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.2 DXE(驱动执行环境)</span></span></h4><div class="notion-text notion-block-07e766093d764e9abf7d140913ab7d03">从上一章分析后，代码将进入DXE继续执行，函数入口为 LoadDxeCoreFromFv()</div><div class="notion-text notion-block-45348db56a034f28babfccb72a77464e">先查找<code class="notion-inline-code">DXE_CORE</code>的文件地址，接着调用<code class="notion-inline-code">LoadDxeCoreFromFfsFile</code> 加载 <code class="notion-inline-code">EntryPoint</code>函数</div><div class="notion-text notion-block-d021be2c7e5b4ac0a26a5960b5edd3d1">之后CPU跳转到了ENTRY_POINT函数 DxeMain()中</div><div class="notion-text notion-block-42c9ed64861a4dde91ad449673d40e7c">代码路径：BOOT.XF.1.4/boot_images/MdeModulePkg/Core/Dxe/DxeMain.inf</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cd92111e089648269e802000bc68a2a3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F91f335c9-0671-4baf-920b-30460b2276a6%2FUntitled.png?table=block&amp;id=cd92111e-0896-4826-9e80-2000bc68a2a3&amp;t=cd92111e-0896-4826-9e80-2000bc68a2a3&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-cd26b8f55ec54ab1b79a2b9040ea3943">这段代码比较复杂，基本看不懂</div><div class="notion-text notion-block-7d8bea9b80844fde94e9be3b04a86cd9">主要工作流程如下：</div><ol start="1" class="notion-list notion-list-numbered notion-block-7fd555ef935f4eed97cc1d8fa9e99f70"><li>初始化CPU异常处理</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-105cb8e0796d49f98d01dbeb05057973"><li>初始化内存等，初始化UEFI代码基础环境</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-6ccdbb738d914ea3b5b53073ee8b7a5d"><li>初始化DXE调度器</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7805af84a1d24e909a3c06e0429069df" data-id="7805af84a1d24e909a3c06e0429069df"><span><div id="7805af84a1d24e909a3c06e0429069df" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7805af84a1d24e909a3c06e0429069df" title="7.2.3 BDS (启动设备选择)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.3 BDS (启动设备选择)</span></span></h4><div class="notion-text notion-block-690b2215d5dd4a51959dd8116f260b0d">代码路径：BOOT.XF.4.1/boot_images/QcomPkg/Drivers/BdsDxe/BdsDxe.inf</div><div class="notion-text notion-block-64d7d1c9181145069a917c939f1c0c7a">其主要工作为：</div><ol start="1" class="notion-list notion-list-numbered notion-block-a45a22ad3eb04accaf0c625802462277"><li>注册按键事件，按下按键后会回调到HotkeyEvent() 函数，最终调用到HotkeyCallback()函数中，解析其中的key scancode</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7911724e70984f468bbfa81ff12b9ccf"><li>平台BDS初始化</li></ol><div class="notion-text notion-block-7958d2b726e148f39d34c5ec98bb00c4">在其中会打印显示版本号，平台版本信息等等</div><div class="notion-text notion-block-0cbfd2450ec646479a56b63d03f6912e">调用LaunchDefaultBDSApps ()加载默认APP</div><div class="notion-text notion-block-358471d9e2e740a79f12b8e07cfa54c4">调用SetupPlatformSecurity()初始化secureboot安全环境</div><div class="notion-text notion-block-ae9fead5682544d9b36f58e2ade4a341">挂载efisp分区</div><div class="notion-text notion-block-4abbe03e81af4f1e9ae571bd0dcea40c">调用ReadAnyKey() 循环检测音量下键是否按下，从而更新对应的启动项</div><ol start="1" class="notion-list notion-list-numbered notion-block-9d9b6509d9cc4ae6a99719d5be347f4a"><li>初始化所有 DriverOptionList 上的 驱动协议。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-09d050f409f04afcbe85bee867b8e5b2"><li>根据选择的启动方式，启动对应的的系统</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-23ac3b3341d7457894939a4032b47558"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F16e1ab5b-ebe1-40b7-95dc-5fa34b43fdfc%2FUntitled.png?table=block&amp;id=23ac3b33-41d7-4578-9493-9a4032b47558&amp;t=23ac3b33-41d7-4578-9493-9a4032b47558&amp;width=707.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1ed28d4a82834755a9cfe1d9182b351c" data-id="1ed28d4a82834755a9cfe1d9182b351c"><span><div id="1ed28d4a82834755a9cfe1d9182b351c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1ed28d4a82834755a9cfe1d9182b351c" title="7.2.4 RT(Run Time)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2.4 RT(Run Time)</span></span></h4><div class="notion-text notion-block-345cfa173bf54e59972254df4d7e6bfe">代码位于BOOT.XF.4.1/boot_images/MdeModulePkg/Core/RuntimeDxe/Runtime</div><div class="notion-text notion-block-9298bfb681f44fbf972c7257d3c648eb">看不懂，和我们关系也不大</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-e209cb6b655d48128db7d71023290aef" data-id="e209cb6b655d48128db7d71023290aef"><span><div id="e209cb6b655d48128db7d71023290aef" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e209cb6b655d48128db7d71023290aef" title="7.3 如何创建 UEFI DXE_DRIVER 驱动及UEFI_APPLICATION 应用程序"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.3 如何创建 UEFI DXE_DRIVER 驱动及UEFI_APPLICATION 应用程序</span></span></h4><div class="notion-text notion-block-2fc9b3beb5e94dd58c44aa3771e8dd0b">本章可查看：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://opqqrjk1dc.feishu.cn/wiki/wikcnQuvn8YORvQJ0QcnEq1mFwe">第一个UEFI程序</a></div><div class="notion-text notion-block-fcaeefd383914663b040ca0857733de3">此篇文章以hello world的Dxe driver以及Application为例，在串口输出打印log</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d05e8a9e566c43c38edbf348985cec45" data-id="d05e8a9e566c43c38edbf348985cec45"><span><div id="d05e8a9e566c43c38edbf348985cec45" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d05e8a9e566c43c38edbf348985cec45" title="7.4 UEFI XBL QcomChargerApp充电流程代码分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.4 UEFI XBL QcomChargerApp充电流程代码分析</span></span></h4><div class="notion-text notion-block-12b5728dffe74f38abfb9fc94ea3be98">系统开机过程中，初始化 BDS 时，会调用LaunchDefaultBDSApps()函数，在该函数中，会实现对上述两个默认app 的调用。</div><ol start="1" class="notion-list notion-list-numbered notion-block-d12bec3be78142ff8b05db665744b5f6"><li>解析 uefiplat.cfg 中的 DefaultChargerApp，字符串保存在 DefaultApp 数组中。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-d6b5971626f34079b90af1eacac5c232"><li>加载 QcomCharger App 应用程序，传参gMainFvGuid 和 “DefaultChargerApp”</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-7a102309579740b79ec0b98889516872"><li>解析 uefiplat.cfg 中的 DefaultBDSBootApp，字符串保存在 DefaultApp 数组中</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-41d44b0e693f4c8a8dabd3bf27f8975d"><li>加载 DefaultBDSBootApp 应用程序，加载后不再返回</li></ol><div class="notion-text notion-block-9996c1e2273245daafa6a22bbeecc7c9">后续部分请查看文章<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://opqqrjk1dc.feishu.cn/wiki/wikcnw1vpD3FyRerRQB9yRF8RGf">QCOM UEFI QcomChargerApp充电流程代码分析</a></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-9b1036f04cdf4a43aacc0f4c97ebdb57" data-id="9b1036f04cdf4a43aacc0f4c97ebdb57"><span><div id="9b1036f04cdf4a43aacc0f4c97ebdb57" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9b1036f04cdf4a43aacc0f4c97ebdb57" title="八、UEFI之ABL"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">八、UEFI之ABL</span></span></h3><div class="notion-text notion-block-1a11489a48f04bbb8f5713a4102b2391">BOOT.XF.4.1/boot_images/QcomPkg/QcomToolsPkg/MenuApp/Uefi_Menu.cfg中可以定制相关的option</div><div class="notion-text notion-block-d50c573eb3ec4e5a9422f1a7831e6da3">在LaunchDefaultBDSApps函数中load uefiplat.cfg中定义的DefaultChargerApp和DefaultBDSBootApp</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-28716b6338eb4747bb49c75838d1875d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:701px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fd06ea15d-d745-4884-8269-d01cc0efab91%2FUntitled.png?table=block&amp;id=28716b63-38eb-4747-bb49-c75838d1875d&amp;t=28716b63-38eb-4747-bb49-c75838d1875d&amp;width=701&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-88aee543e1f945da85b544eb1b8038b9">而LinuxLoader是属于UEFI Application，这个代码是在ap侧的abl中</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[SWR0011671][Sensor][P2] 量产机型能够抓取子系统ramdump]]></title>
            <link>https://notion.iliuqi.com/article/miui_task_enable_ssr_ramdump</link>
            <guid>https://notion.iliuqi.com/article/miui_task_enable_ssr_ramdump</guid>
            <pubDate>Thu, 07 Nov 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[机器硬件损坏会触发子系统重启，一直产生ramdump文件，最终占满手机内存，严重影响用户使用；
本地需要多次手动重启子系统，查看对应目录下是否有ramdump文件疯狂增长的情况；]]></description>
            <content:encoded><![CDATA[机器硬件损坏会触发子系统重启，一直产生ramdump文件，最终占满手机内存，严重影响用户使用；
本地需要多次手动重启子系统，查看对应目录下是否有ramdump文件疯狂增长的情况；]]></content:encoded>
        </item>
    </channel>
</rss>