嵌入式 Linux - 引导阶段
我想系统化我的 U-Boot/linux 知识。每个嵌入式平台是否都需要至少 2 个引导加载程序阶段?或者以下流程可能会有所不同?
第一阶段引导加载程序(可以是 U-Boot)存储在处理器内部的 ROM 中,无法更新。它将从内部高速缓存运行。这个U-Boot需要(至少):初始化RAM,初始化外部闪存,初始化串行控制台,读取并运行第二阶段引导加载程序。
第二阶段引导加载程序(可以是 U-Boot)存储在 RW 闪存中。它将处理以太网、闪存RW功能等。该U-Boot可以定制和覆盖。主要任务是将Linux内核加载到RAM中并运行。
Linux 内核启动。
第一阶段引导加载程序始终是只读的吗?
I would like to systematize my U-Boot/linux knowledge. Is it true that minimum 2 bootloader phases are needed in each embedded platform? Or can following process vary?
1st-stage bootloader (can be U-Boot) is stored in internal the processor's ROM and can't be updated. It will run from internal cache memory. This U-Boot needs to (at least): initialize RAM, initialize external flash, initialize serial console, read and run 2nd-stage bootloader.
2nd-stage bootloader (can be U-Boot) is stored in RW flash memory. It will handle ethernet, flash RW functions, etc. This U-Boot can be customized and overwritten. Main task is to load linux kernel into RAM and run it.
linux kernel startup.
Is 1st-stage bootloader always Read-Only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个引导加载程序在哪里、如何在很大程度上取决于系统。您可能有某种 USB 可启动设备,它可以枚举并下载固件以将所有硬件存储到内存中,然后处理器从该内存中启动。
通常情况下,第一次启动是某种闪存。最好让第一个引导加载程序超级简单,基本上 100% 无错误,耐用且可靠,可能通过串行或其他方式进入,以便您可以使用它来替换第二个/真正的引导加载程序。
理想情况下,第二个引导加载程序也希望是闪存,第二个引导加载程序需要完成大部分工作,初始化 ddr、设置以太网(如果它想要进行某种基于以太网的调试或文件传输、bootp 等)。它的体积要大得多,也更复杂,预计会存在错误,并且需要比主引导加载程序更频繁地升级。希望主引导加载程序不会被覆盖,这样您就可以轻松地替换第二引导加载程序,而不会导致系统变砖。
所有系统都使用上述内容吗?不,一些/许多可能只使用单个引导加载程序,可能很早就有暂停,以便串行端口上的击键可以中断引导加载程序,将您带到可以重新加载引导加载程序的位置。允许引导加载程序开发,减少变砖的机会,但如果您之前搞砸了第一部分(包括击键和串行闪存加载程序),那么仍然有机会。同样,串行加载程序并不总是存在,只是为引导加载程序开发人员提供便利。通常,后备将是jtag,或可移动的prom或其他一些系统方式,以便在您砖砌它时进入并重新编程prom(而且,有时与生产板时在系统中第一次对其进行编程的方式相同,某些设计可砖化以节省成本并在制造过程中使用预编程闪存,以便第一次启动即可工作)。
Linux引导加载程序不需要任何/所有这些,一个非常非常小的设置RAM,准备命令行或标签或其他什么,然后分支到Linux。
这是一个沉重的问题,因为答案很大程度上取决于您的系统、处理器、设计工程师(包括您)。传统上,处理器从闪存启动,引导加载程序获取内存和其他一些东西,以便下一段代码可以运行。接下来的代码可以来自很多地方,USB、磁盘、闪存/ROM、以太网/bootp/tftp、pcie、mdio、spi、i2c 等。并且在开机重置和 linux 启动之间可以有尽可能多的层设计的愿望或要求。
Where, how that first bootloader is is heavily system dependent. You might have some sort of usb bootable device that enumerates and downloads firmware to ram all in hardware then the processor boots from that ram.
Normally yes the first boot is some sort of flash. It is a good idea to have that first bootloader uber simple, essentially 100% bug free and durable and reliable with perhaps a serial or other way to get in so that you can use it to replace the second/real bootloader.
Ideally the second bootloader wants to be flash as well, the second bootloader would want to do the bulk of the work, initializing ddr, setting up ethernet if it wants to have some sort of ethernet based debugging or transferring of files, bootp, etc. Being significantly larger and more complicated it is expected to both have bugs and need to be upgraded more often than the primary bootloader. The primary is hopefully protected from being overwritten, so that you can comfortably replace the second bootloader without bricking the system.
Do all systems use the above? No, some/many may only use a single bootloader, with there perhaps being a pause very early so that a keystroke on a serial port can interrupt the bootloader taking you to a place where you can re-load the bootloader. Allowing for bootloader development with fewer chances at bricking but still a chance if you mess up that first bit before and including the keystroke and serial flash loader thing. Here again that serial loader thing is not always present, just a convenience for the bootloader developers. Often the fallback will be jtag, or a removable prom or some other system way to get in and reprogram the prom when you brick it (also, sometimes the same way you program it the first time in system when the board is produced, some designs are brickable to save on cost and use pre-programmed flashes during manufacturing so the first boot works).
A linux bootloader does not require any/all of this, a very very minimal, setup ram, prep the command line or atags or whatever and branch to linux.
It is a loaded question as the answer is heavily dependent on your system, processor, design engineers (including you). Traditionally processors boot from flash and the bootloader gets memory and some other things up so the next bit of code can run. That next bit of code can come from many places, usb, disk, flash/rom, ethernet/bootp/tftp, pcie, mdio, spi, i2c, etc. And there can be as many layers between power on reset and linux starting as the design desires or requires.
第一阶段引导加载程序不一定是只读的,但是将只读引导加载程序放入带有某种恢复模式的 ROM 中会很有帮助,以防您损坏闪存的读写部分;否则,您需要将编程器物理连接到闪存芯片才能恢复。
The first-stage bootloader doesn't have to be read-only - but putting a read-only bootloader in ROM with some recovery mode is helpful in case you corrupt the read-write parts of flash; otherwise you'll need to physically attach a programmer to the flash chip in order to recover.
如果您使用 U-Boot,可以跳过第二阶段引导加载程序以加快引导时间。换句话说,第一阶段引导加载程序(SPL)将直接加载Linux内核,跳过第二阶段引导加载程序(u-boot)。在 U-Boot 中,这称为 猎鹰模式。
If you are using U-Boot, the 2nd stage bootloader can be skipped to speed up the boot time. In other words, the first stage bootloader (SPL) will load the Linux kernel directly, skipping the second stage bootloader (u-boot). In U-Boot, this is called the Falcon Mode.