162306a36Sopenharmony_ciChinese translated version of Documentation/arch/arm64/booting.rst 262306a36Sopenharmony_ci 362306a36Sopenharmony_ciIf you have any comment or update to the content, please contact the 462306a36Sopenharmony_cioriginal document maintainer directly. However, if you have a problem 562306a36Sopenharmony_cicommunicating in English you can also ask the Chinese maintainer for 662306a36Sopenharmony_cihelp. Contact the Chinese maintainer if this translation is outdated 762306a36Sopenharmony_cior if there is a problem with the translation. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciM: Will Deacon <will.deacon@arm.com> 1062306a36Sopenharmony_cizh_CN: Fu Wei <wefu@redhat.com> 1162306a36Sopenharmony_ciC: 55f058e7574c3615dea4615573a19bdb258696c6 1262306a36Sopenharmony_ci--------------------------------------------------------------------- 1362306a36Sopenharmony_ciDocumentation/arch/arm64/booting.rst 的中文翻译 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文 1662306a36Sopenharmony_ci交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻 1762306a36Sopenharmony_ci译存在问题,请联系中文版维护者。 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci英文版维护者: Will Deacon <will.deacon@arm.com> 2062306a36Sopenharmony_ci中文版维护者: 傅炜 Fu Wei <wefu@redhat.com> 2162306a36Sopenharmony_ci中文版翻译者: 傅炜 Fu Wei <wefu@redhat.com> 2262306a36Sopenharmony_ci中文版校译者: 傅炜 Fu Wei <wefu@redhat.com> 2362306a36Sopenharmony_ci本文翻译提交时的 Git 检出点为: 55f058e7574c3615dea4615573a19bdb258696c6 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci以下为正文 2662306a36Sopenharmony_ci--------------------------------------------------------------------- 2762306a36Sopenharmony_ci 启动 AArch64 Linux 2862306a36Sopenharmony_ci ================== 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci作者: Will Deacon <will.deacon@arm.com> 3162306a36Sopenharmony_ci日期: 2012 年 09 月 07 日 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci本文档基于 Russell King 的 ARM 启动文档,且适用于所有公开发布的 3462306a36Sopenharmony_ciAArch64 Linux 内核代码。 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciAArch64 异常模型由多个异常级(EL0 - EL3)组成,对于 EL0 和 EL1 异常级 3762306a36Sopenharmony_ci有对应的安全和非安全模式。EL2 是系统管理级,且仅存在于非安全模式下。 3862306a36Sopenharmony_ciEL3 是最高特权级,且仅存在于安全模式下。 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci基于本文档的目的,我们将简单地使用‘引导装载程序’(‘boot loader’) 4162306a36Sopenharmony_ci这个术语来定义在将控制权交给 Linux 内核前 CPU 上执行的所有软件。 4262306a36Sopenharmony_ci这可能包含安全监控和系统管理代码,或者它可能只是一些用于准备最小启动 4362306a36Sopenharmony_ci环境的指令。 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci基本上,引导装载程序(至少)应实现以下操作: 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci1、设置和初始化 RAM 4862306a36Sopenharmony_ci2、设置设备树数据 4962306a36Sopenharmony_ci3、解压内核映像 5062306a36Sopenharmony_ci4、调用内核映像 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci1、设置和初始化 RAM 5462306a36Sopenharmony_ci----------------- 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci必要性: 强制 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci引导装载程序应该找到并初始化系统中所有内核用于保持系统变量数据的 RAM。 5962306a36Sopenharmony_ci这个操作的执行方式因设备而异。(它可能使用内部算法来自动定位和计算所有 6062306a36Sopenharmony_ciRAM,或可能使用对这个设备已知的 RAM 信息,还可能是引导装载程序设计者 6162306a36Sopenharmony_ci想到的任何合适的方法。) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci2、设置设备树数据 6562306a36Sopenharmony_ci--------------- 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci必要性: 强制 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci设备树数据块(dtb)必须 8 字节对齐,且大小不能超过 2MB。由于设备树 7062306a36Sopenharmony_ci数据块将在使能缓存的情况下以 2MB 粒度被映射,故其不能被置于必须以特定 7162306a36Sopenharmony_ci属性映射的2M区域内。 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci注: v4.2 之前的版本同时要求设备树数据块被置于从内核映像以下 7462306a36Sopenharmony_citext_offset 字节处算起第一个 512MB 内。 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci3、解压内核映像 7762306a36Sopenharmony_ci------------- 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci必要性: 可选 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciAArch64 内核当前没有提供自解压代码,因此如果使用了压缩内核映像文件 8262306a36Sopenharmony_ci(比如 Image.gz),则需要通过引导装载程序(使用 gzip 等)来进行解压。 8362306a36Sopenharmony_ci若引导装载程序没有实现这个功能,就要使用非压缩内核映像文件。 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci4、调用内核映像 8762306a36Sopenharmony_ci------------- 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci必要性: 强制 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci已解压的内核映像包含一个 64 字节的头,内容如下: 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci u32 code0; /* 可执行代码 */ 9462306a36Sopenharmony_ci u32 code1; /* 可执行代码 */ 9562306a36Sopenharmony_ci u64 text_offset; /* 映像装载偏移,小端模式 */ 9662306a36Sopenharmony_ci u64 image_size; /* 映像实际大小, 小端模式 */ 9762306a36Sopenharmony_ci u64 flags; /* 内核旗标, 小端模式 * 9862306a36Sopenharmony_ci u64 res2 = 0; /* 保留 */ 9962306a36Sopenharmony_ci u64 res3 = 0; /* 保留 */ 10062306a36Sopenharmony_ci u64 res4 = 0; /* 保留 */ 10162306a36Sopenharmony_ci u32 magic = 0x644d5241; /* 魔数, 小端, "ARM\x64" */ 10262306a36Sopenharmony_ci u32 res5; /* 保留 (用于 PE COFF 偏移) */ 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci映像头注释: 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci- 自 v3.17 起,除非另有说明,所有域都是小端模式。 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci- code0/code1 负责跳转到 stext. 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci- 当通过 EFI 启动时, 最初 code0/code1 被跳过。 11262306a36Sopenharmony_ci res5 是到 PE 文件头的偏移,而 PE 文件头含有 EFI 的启动入口点 11362306a36Sopenharmony_ci (efi_stub_entry)。当 stub 代码完成了它的使命,它会跳转到 code0 11462306a36Sopenharmony_ci 继续正常的启动流程。 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci- v3.17 之前,未明确指定 text_offset 的字节序。此时,image_size 为零, 11762306a36Sopenharmony_ci 且 text_offset 依照内核字节序为 0x80000。 11862306a36Sopenharmony_ci 当 image_size 非零,text_offset 为小端模式且是有效值,应被引导加载 11962306a36Sopenharmony_ci 程序使用。当 image_size 为零,text_offset 可假定为 0x80000。 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci- flags 域 (v3.17 引入) 为 64 位小端模式,其编码如下: 12262306a36Sopenharmony_ci 位 0: 内核字节序。 1 表示大端模式,0 表示小端模式。 12362306a36Sopenharmony_ci 位 1-2: 内核页大小。 12462306a36Sopenharmony_ci 0 - 未指定。 12562306a36Sopenharmony_ci 1 - 4K 12662306a36Sopenharmony_ci 2 - 16K 12762306a36Sopenharmony_ci 3 - 64K 12862306a36Sopenharmony_ci 位 3: 内核物理位置 12962306a36Sopenharmony_ci 0 - 2MB 对齐基址应尽量靠近内存起始处,因为 13062306a36Sopenharmony_ci 其基址以下的内存无法通过线性映射访问 13162306a36Sopenharmony_ci 1 - 2MB 对齐基址可以在物理内存的任意位置 13262306a36Sopenharmony_ci 位 4-63: 保留。 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci- 当 image_size 为零时,引导装载程序应试图在内核映像末尾之后尽可能 13562306a36Sopenharmony_ci 多地保留空闲内存供内核直接使用。对内存空间的需求量因所选定的内核 13662306a36Sopenharmony_ci 特性而异, 并无实际限制。 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci内核映像必须被放置在任意一个可用系统内存 2MB 对齐基址的 text_offset 13962306a36Sopenharmony_ci字节处,并从该处被调用。2MB 对齐基址和内核映像起始地址之间的区域对于 14062306a36Sopenharmony_ci内核来说没有特殊意义,且可能被用于其他目的。 14162306a36Sopenharmony_ci从映像起始地址算起,最少必须准备 image_size 字节的空闲内存供内核使用。 14262306a36Sopenharmony_ci注: v4.6 之前的版本无法使用内核映像物理偏移以下的内存,所以当时建议 14362306a36Sopenharmony_ci将映像尽量放置在靠近系统内存起始的地方。 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci任何提供给内核的内存(甚至在映像起始地址之前),若未从内核中标记为保留 14662306a36Sopenharmony_ci(如在设备树(dtb)的 memreserve 区域),都将被认为对内核是可用。 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci在跳转入内核前,必须符合以下状态: 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci- 停止所有 DMA 设备,这样内存数据就不会因为虚假网络包或磁盘数据而 15162306a36Sopenharmony_ci 被破坏。这可能可以节省你许多的调试时间。 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci- 主 CPU 通用寄存器设置 15462306a36Sopenharmony_ci x0 = 系统 RAM 中设备树数据块(dtb)的物理地址。 15562306a36Sopenharmony_ci x1 = 0 (保留,将来可能使用) 15662306a36Sopenharmony_ci x2 = 0 (保留,将来可能使用) 15762306a36Sopenharmony_ci x3 = 0 (保留,将来可能使用) 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci- CPU 模式 16062306a36Sopenharmony_ci 所有形式的中断必须在 PSTATE.DAIF 中被屏蔽(Debug、SError、IRQ 16162306a36Sopenharmony_ci 和 FIQ)。 16262306a36Sopenharmony_ci CPU 必须处于 EL2(推荐,可访问虚拟化扩展)或非安全 EL1 模式下。 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci- 高速缓存、MMU 16562306a36Sopenharmony_ci MMU 必须关闭。 16662306a36Sopenharmony_ci 指令缓存开启或关闭皆可。 16762306a36Sopenharmony_ci 已载入的内核映像的相应内存区必须被清理,以达到缓存一致性点(PoC)。 16862306a36Sopenharmony_ci 当存在系统缓存或其他使能缓存的一致性主控器时,通常需使用虚拟地址 16962306a36Sopenharmony_ci 维护其缓存,而非 set/way 操作。 17062306a36Sopenharmony_ci 遵从通过虚拟地址操作维护构架缓存的系统缓存必须被配置,并可以被使能。 17162306a36Sopenharmony_ci 而不通过虚拟地址操作维护构架缓存的系统缓存(不推荐),必须被配置且 17262306a36Sopenharmony_ci 禁用。 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci *译者注:对于 PoC 以及缓存相关内容,请参考 ARMv8 构架参考手册 17562306a36Sopenharmony_ci ARM DDI 0487A 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci- 架构计时器 17862306a36Sopenharmony_ci CNTFRQ 必须设定为计时器的频率,且 CNTVOFF 必须设定为对所有 CPU 17962306a36Sopenharmony_ci 都一致的值。如果在 EL1 模式下进入内核,则 CNTHCTL_EL2 中的 18062306a36Sopenharmony_ci EL1PCTEN (bit 0) 必须置位。 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci- 一致性 18362306a36Sopenharmony_ci 通过内核启动的所有 CPU 在内核入口地址上必须处于相同的一致性域中。 18462306a36Sopenharmony_ci 这可能要根据具体实现来定义初始化过程,以使能每个CPU上对维护操作的 18562306a36Sopenharmony_ci 接收。 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci- 系统寄存器 18862306a36Sopenharmony_ci 在进入内核映像的异常级中,所有构架中可写的系统寄存器必须通过软件 18962306a36Sopenharmony_ci 在一个更高的异常级别下初始化,以防止在 未知 状态下运行。 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci 对于拥有 GICv3 中断控制器并以 v3 模式运行的系统: 19262306a36Sopenharmony_ci - 如果 EL3 存在: 19362306a36Sopenharmony_ci ICC_SRE_EL3.Enable (位 3) 必须初始化为 0b1。 19462306a36Sopenharmony_ci ICC_SRE_EL3.SRE (位 0) 必须初始化为 0b1。 19562306a36Sopenharmony_ci - 若内核运行在 EL1: 19662306a36Sopenharmony_ci ICC_SRE_EL2.Enable (位 3) 必须初始化为 0b1。 19762306a36Sopenharmony_ci ICC_SRE_EL2.SRE (位 0) 必须初始化为 0b1。 19862306a36Sopenharmony_ci - 设备树(DT)或 ACPI 表必须描述一个 GICv3 中断控制器。 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci 对于拥有 GICv3 中断控制器并以兼容(v2)模式运行的系统: 20162306a36Sopenharmony_ci - 如果 EL3 存在: 20262306a36Sopenharmony_ci ICC_SRE_EL3.SRE (位 0) 必须初始化为 0b0。 20362306a36Sopenharmony_ci - 若内核运行在 EL1: 20462306a36Sopenharmony_ci ICC_SRE_EL2.SRE (位 0) 必须初始化为 0b0。 20562306a36Sopenharmony_ci - 设备树(DT)或 ACPI 表必须描述一个 GICv2 中断控制器。 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci以上对于 CPU 模式、高速缓存、MMU、架构计时器、一致性、系统寄存器的 20862306a36Sopenharmony_ci必要条件描述适用于所有 CPU。所有 CPU 必须在同一异常级别跳入内核。 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci引导装载程序必须在每个 CPU 处于以下状态时跳入内核入口: 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci- 主 CPU 必须直接跳入内核映像的第一条指令。通过此 CPU 传递的设备树 21362306a36Sopenharmony_ci 数据块必须在每个 CPU 节点中包含一个 ‘enable-method’ 属性,所 21462306a36Sopenharmony_ci 支持的 enable-method 请见下文。 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci 引导装载程序必须生成这些设备树属性,并在跳入内核入口之前将其插入 21762306a36Sopenharmony_ci 数据块。 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci- enable-method 为 “spin-table” 的 CPU 必须在它们的 CPU 22062306a36Sopenharmony_ci 节点中包含一个 ‘cpu-release-addr’ 属性。这个属性标识了一个 22162306a36Sopenharmony_ci 64 位自然对齐且初始化为零的内存位置。 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci 这些 CPU 必须在内存保留区(通过设备树中的 /memreserve/ 域传递 22462306a36Sopenharmony_ci 给内核)中自旋于内核之外,轮询它们的 cpu-release-addr 位置(必须 22562306a36Sopenharmony_ci 包含在保留区中)。可通过插入 wfe 指令来降低忙循环开销,而主 CPU 将 22662306a36Sopenharmony_ci 发出 sev 指令。当对 cpu-release-addr 所指位置的读取操作返回非零值 22762306a36Sopenharmony_ci 时,CPU 必须跳入此值所指向的地址。此值为一个单独的 64 位小端值, 22862306a36Sopenharmony_ci 因此 CPU 须在跳转前将所读取的值转换为其本身的端模式。 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci- enable-method 为 “psci” 的 CPU 保持在内核外(比如,在 23162306a36Sopenharmony_ci memory 节点中描述为内核空间的内存区外,或在通过设备树 /memreserve/ 23262306a36Sopenharmony_ci 域中描述为内核保留区的空间中)。内核将会发起在 ARM 文档(编号 23362306a36Sopenharmony_ci ARM DEN 0022A:用于 ARM 上的电源状态协调接口系统软件)中描述的 23462306a36Sopenharmony_ci CPU_ON 调用来将 CPU 带入内核。 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci *译者注: ARM DEN 0022A 已更新到 ARM DEN 0022C。 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci 设备树必须包含一个 ‘psci’ 节点,请参考以下文档: 23962306a36Sopenharmony_ci Documentation/devicetree/bindings/arm/psci.yaml 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci- 辅助 CPU 通用寄存器设置 24362306a36Sopenharmony_ci x0 = 0 (保留,将来可能使用) 24462306a36Sopenharmony_ci x1 = 0 (保留,将来可能使用) 24562306a36Sopenharmony_ci x2 = 0 (保留,将来可能使用) 24662306a36Sopenharmony_ci x3 = 0 (保留,将来可能使用) 247