###### tags: `The Linux Foundation Youtube`
# Tutorial: Introduction to the Embedded Boot Loader U-boot
我是看完了這個影片才發覺Youtube上面這個頻道真的是個學習Linux的好地方,另一方面也覺得不做一點summary記錄下來很是可惜。這篇的講者Behan Webster講得很清楚,同時不會像有的講者嗯嗯啊啊的贅詞一堆口音還很難懂,最後又有workshop帶你一步一步實做,算是有照顧到我這種動手派的需求了。
一般開機的順序為:First stage bootloader -> User bootloader -> Linux kernel -> Userspace。第一步的First stage bootloader在BootROM裡面,你改也改不到,進到第二步User bootloader才有第一個使用者可以修改的地方,這裡又可以拆解成U-boot SPL (secondary program loader)和U-boot,有時甚至有U-boot SPL, U-boot TPL (tertiary program loader), 和U-boot。
走到U-boot就有U-boot shell可以停下來,user可以在這裡觀察一些hardware informaion或是下boot argument去帶接下來的Linux kernel,或是可以在這裡修改device tree,另外有一些林林總總的memory access指令,gpio指令,i2c指令等等,總之U-boot的使命就是把接下來的Linux kernel image叫起來,我的理解這裡做出一個shell,可以執行一些比較複雜的for while loop,是一個方便debug的中繼站。
這個演講的youtube連結在[這裡](https://www.youtube.com/watch?v=INWghYZH3hI),投影片在[這裡](https://ossna2020.sched.com/event/c47M/tutorial-introduction-to-the-embedded-boot-loader-u-boot-behan-webster-converse-in-code),大致的章節如下:
Basic U-boot commands
U-boot memory access commands
U-boot environment and scripting commands
U-boot shell conditional expressions and loops
U-boot data loading commands
Booting the kernel
Miscellaneous U-boot commands
Compiling U-boot from source
Labs
我覺得一張一張貼slide上來還不如自己上去抓原本的投影片,強烈建議看一下youtube,很淺顯易懂的!
最後是一個Q&A,我把一些重要的問題記錄下來:
1. How to boot very fast (within 1 second)?
這個問題是說怎麼把Linux boot弄的超級快,他知道有些機器可以快到一秒鐘以下,這是怎麼辦到的?我們都知道這問題沒什麼標準答案,端看你的系統多複雜,不過他還是給出了一些重要的hint,有時候hard coding或者是讓他「看起來好像跑起來了」就可以了,比如在一秒之內先帶一下screen,出一個開機logo就可以了。
"Some hard coding and sometimes "cheating" (some devices may not be full functional), and sometimes "pretened to be running" in 1 second."
2. Are there ways to access encrypted file systems in Uboot?
據他的經驗是沒有碰過這情形,另外他指出一個點,U-boot的GPL license不允許放有版權的東西,我對這東西不大清楚,似乎是在說有patent的encryption不能做。
"I've never done that before and to my knowledge I'm not aware of possible ways to do. Uboot has a strict policy on GPL only code and non-patented things only."
3. Does Uboot supoort USB?
"Yes. Some beaglebone boards can use USB boot."
4. What is bootloader linker script?
聽他的解釋這東西聽起來很像之前在ARM改過的scatter file,不過主講者也說了這個一般是不會去改動他的。
"Linker script describes what goes where in memory so things can be loaded appropriately. Users usually don't care and leave as it is."
5. Talk about driver porting and Uboot
再次說明有版權的東西不應該放在U-boot code裡面,所以寫一些device相關的code在裡面會變得很奇怪,因為抓下來的人會需要再去拿掉這些code。
"Uboot is GPLv2 and if you need to put code in, you need to upstream it. If it is upstream it will be dragged along and hopefully there is no porting to be done."
6. Is there difference between Uboot and kernel device trees?
"In theory the same, in practice they may change inside Uboot and kernel."
7. Can we have a live process after bootloader during kernel boot?
我猜測他的意圖應該是說,可以在bootz/i/m command帶入kernel image的同時,開一個process去監測系統帶入kernel image的行為嗎?常規上來說應該是不行,真的要做的話應該也是可以,但可能會需要其他的software幫助(其實我不是很懂,但應該是說最好別硬幹的意思吧)
"In general no. In practice there are other ways of spliiting cores to run other operating systems. If you were to bring up let's say a hypervisor and starting kernel at the same time, but without other software you cannot."