18c2ecf20Sopenharmony_ciChinese translated version of Documentation/arm/booting.rst
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciIf you have any comment or update to the content, please contact the
48c2ecf20Sopenharmony_cioriginal document maintainer directly.  However, if you have a problem
58c2ecf20Sopenharmony_cicommunicating in English you can also ask the Chinese maintainer for
68c2ecf20Sopenharmony_cihelp.  Contact the Chinese maintainer if this translation is outdated
78c2ecf20Sopenharmony_cior if there is a problem with the translation.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciMaintainer: Russell King <linux@arm.linux.org.uk>
108c2ecf20Sopenharmony_ciChinese maintainer: Fu Wei <tekkamanninja@gmail.com>
118c2ecf20Sopenharmony_ci---------------------------------------------------------------------
128c2ecf20Sopenharmony_ciDocumentation/arm/booting.rst 的中文翻译
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
158c2ecf20Sopenharmony_ci交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
168c2ecf20Sopenharmony_ci译存在问题,请联系中文版维护者。
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci英文版维护者: Russell King <linux@arm.linux.org.uk>
198c2ecf20Sopenharmony_ci中文版维护者: 傅炜  Fu Wei <tekkamanninja@gmail.com>
208c2ecf20Sopenharmony_ci中文版翻译者: 傅炜  Fu Wei <tekkamanninja@gmail.com>
218c2ecf20Sopenharmony_ci中文版校译者: 傅炜  Fu Wei <tekkamanninja@gmail.com>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci以下为正文
248c2ecf20Sopenharmony_ci---------------------------------------------------------------------
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci			启动 ARM Linux
278c2ecf20Sopenharmony_ci			==============
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci作者:Russell King
308c2ecf20Sopenharmony_ci日期:2002年5月18日
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci以下文档适用于 2.4.18-rmk6 及以上版本。
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci为了启动 ARM Linux,你需要一个引导装载程序(boot loader),
358c2ecf20Sopenharmony_ci它是一个在主内核启动前运行的一个小程序。引导装载程序需要初始化各种
368c2ecf20Sopenharmony_ci设备,并最终调用 Linux 内核,将信息传递给内核。
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci从本质上讲,引导装载程序应提供(至少)以下功能:
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci1、设置和初始化 RAM。
418c2ecf20Sopenharmony_ci2、初始化一个串口。
428c2ecf20Sopenharmony_ci3、检测机器的类型(machine type)。
438c2ecf20Sopenharmony_ci4、设置内核标签列表(tagged list)。
448c2ecf20Sopenharmony_ci5、调用内核映像。
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci1、设置和初始化 RAM
488c2ecf20Sopenharmony_ci-------------------
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci现有的引导加载程序:		强制
518c2ecf20Sopenharmony_ci新开发的引导加载程序:		强制
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci引导装载程序应该找到并初始化系统中所有内核用于保持系统变量数据的 RAM。
548c2ecf20Sopenharmony_ci这个操作的执行是设备依赖的。(它可能使用内部算法来自动定位和计算所有
558c2ecf20Sopenharmony_ciRAM,或可能使用对这个设备已知的 RAM 信息,还可能使用任何引导装载程序
568c2ecf20Sopenharmony_ci设计者想到的匹配方法。)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci2、初始化一个串口
608c2ecf20Sopenharmony_ci-----------------------------
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci现有的引导加载程序:		可选、建议
638c2ecf20Sopenharmony_ci新开发的引导加载程序:		可选、建议
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci引导加载程序应该初始化并使能一个目标板上的串口。这允许内核串口驱动
668c2ecf20Sopenharmony_ci自动检测哪个串口用于内核控制台。(一般用于调试或与目标板通信。)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci作为替代方案,引导加载程序也可以通过标签列表传递相关的'console='
698c2ecf20Sopenharmony_ci选项给内核以指定某个串口,而串口数据格式的选项在以下文档中描述:
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci       Documentation/admin-guide/kernel-parameters.rst728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci3、检测机器类型
758c2ecf20Sopenharmony_ci--------------------------
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci现有的引导加载程序:		可选
788c2ecf20Sopenharmony_ci新开发的引导加载程序:		强制
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci引导加载程序应该通过某些方式检测自身所处的机器类型。这是一个硬件
818c2ecf20Sopenharmony_ci代码或通过查看所连接的硬件用某些算法得到,这些超出了本文档的范围。
828c2ecf20Sopenharmony_ci引导加载程序最终必须能提供一个 MACH_TYPE_xxx 值给内核。
838c2ecf20Sopenharmony_ci(详见 linux/arch/arm/tools/mach-types )。
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci4、设置启动数据
868c2ecf20Sopenharmony_ci------------------
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci现有的引导加载程序:		可选、强烈建议
898c2ecf20Sopenharmony_ci新开发的引导加载程序:		强制
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci引导加载程序必须提供标签列表或者 dtb 映像以传递配置数据给内核。启动
928c2ecf20Sopenharmony_ci数据的物理地址通过寄存器 r2 传递给内核。
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci4a、设置内核标签列表
958c2ecf20Sopenharmony_ci--------------------------------
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cibootloader 必须创建和初始化内核标签列表。一个有效的标签列表以
988c2ecf20Sopenharmony_ciATAG_CORE 标签开始,并以 ATAG_NONE 标签结束。ATAG_CORE 标签可以是
998c2ecf20Sopenharmony_ci空的,也可以是非空。一个空 ATAG_CORE 标签其 size 域设置为
1008c2ecf20Sopenharmony_ci‘2’(0x00000002)。ATAG_NONE 标签的 size 域必须设置为零。
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci在列表中可以保存任意数量的标签。对于一个重复的标签是追加到之前标签
1038c2ecf20Sopenharmony_ci所携带的信息之后,还是会覆盖原来的信息,是未定义的。某些标签的行为
1048c2ecf20Sopenharmony_ci是前者,其他是后者。
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cibootloader 必须传递一个系统内存的位置和最小值,以及根文件系统位置。
1078c2ecf20Sopenharmony_ci因此,最小的标签列表如下所示:
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci		+-----------+
1108c2ecf20Sopenharmony_ci基地址 ->	| ATAG_CORE |  |
1118c2ecf20Sopenharmony_ci		+-----------+  |
1128c2ecf20Sopenharmony_ci		| ATAG_MEM  |  | 地址增长方向
1138c2ecf20Sopenharmony_ci		+-----------+  |
1148c2ecf20Sopenharmony_ci		| ATAG_NONE |  |
1158c2ecf20Sopenharmony_ci		+-----------+  v
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci标签列表应该保存在系统的 RAM 中。
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci标签列表必须置于内核自解压和 initrd'bootp' 程序都不会覆盖的内存区。
1208c2ecf20Sopenharmony_ci建议放在 RAM 的头 16KiB 中。
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci4b、设置设备树
1238c2ecf20Sopenharmony_ci-------------------------
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cibootloader 必须以 64bit 地址对齐的形式加载一个设备树映像(dtb)到系统
1268c2ecf20Sopenharmony_ciRAM 中,并用启动数据初始化它。dtb 格式在文档
1278c2ecf20Sopenharmony_ciDocumentation/devicetree/booting-without-of.rst 中。内核将会在
1288c2ecf20Sopenharmony_cidtb 物理地址处查找 dtb 魔数值(0xd00dfeed),以确定 dtb 是否已经代替
1298c2ecf20Sopenharmony_ci标签列表被传递进来。
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cibootloader 必须传递一个系统内存的位置和最小值,以及根文件系统位置。
1328c2ecf20Sopenharmony_cidtb 必须置于内核自解压不会覆盖的内存区。建议将其放置于 RAM 的头 16KiB
1338c2ecf20Sopenharmony_ci中。但是不可将其放置于“0”物理地址处,因为内核认为:r2 中为 0,意味着
1348c2ecf20Sopenharmony_ci没有标签列表和 dtb 传递过来。
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci5、调用内核映像
1378c2ecf20Sopenharmony_ci---------------------------
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci现有的引导加载程序:		强制
1408c2ecf20Sopenharmony_ci新开发的引导加载程序:		强制
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci调用内核映像 zImage 有两个选择。如果 zImge 保存在 flash 中,且是为了
1438c2ecf20Sopenharmony_ci在 flash 中直接运行而被正确链接的。这样引导加载程序就可以在 flash 中
1448c2ecf20Sopenharmony_ci直接调用 zImage。
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cizImage 也可以被放在系统 RAM(任意位置)中被调用。注意:内核使用映像
1478c2ecf20Sopenharmony_ci基地址的前 16KB RAM 空间来保存页表。建议将映像置于 RAM 的 32KB 处。
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci对于以上任意一种情况,都必须符合以下启动状态:
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci- 停止所有 DMA 设备,这样内存数据就不会因为虚假网络包或磁盘数据而被破坏。
1528c2ecf20Sopenharmony_ci  这可能可以节省你许多的调试时间。
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci- CPU 寄存器配置
1558c2ecf20Sopenharmony_ci  r0 = 0,
1568c2ecf20Sopenharmony_ci  r1 = (在上面 3 中获取的)机器类型码。
1578c2ecf20Sopenharmony_ci  r2 = 标签列表在系统 RAM 中的物理地址,或
1588c2ecf20Sopenharmony_ci       设备树块(dtb)在系统 RAM 中的物理地址
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci- CPU 模式
1618c2ecf20Sopenharmony_ci  所有形式的中断必须被禁止 (IRQs 和 FIQs)
1628c2ecf20Sopenharmony_ci  CPU 必须处于 SVC 模式。(对于 Angel 调试有特例存在)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci- 缓存,MMUs
1658c2ecf20Sopenharmony_ci  MMU 必须关闭。
1668c2ecf20Sopenharmony_ci  指令缓存开启或关闭都可以。
1678c2ecf20Sopenharmony_ci  数据缓存必须关闭。
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci- 引导加载程序应该通过直接跳转到内核映像的第一条指令来调用内核映像。
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci  对于支持 ARM 指令集的 CPU,跳入内核入口时必须处在 ARM 状态,即使
1728c2ecf20Sopenharmony_ci  对于 Thumb-2 内核也是如此。
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci  对于仅支持 Thumb 指令集的 CPU,比如 Cortex-M 系列的 CPU,跳入
1758c2ecf20Sopenharmony_ci  内核入口时必须处于 Thumb 状态。
176