2/22/2021

[轉][整理] SEC->PEI->DXE->BDS | GoMCU

 


出處:http://william30101.blogspot.tw/

UEFI – SEC Phase

SEC Phase Security

Why??

1. 需要用Assembly 完成C無法處理的工作,像是CPU 的 特殊Register (MSR , MTRR , CPX)
2. C 需要Memory當作Stack處理Local Variable,但是剛Boot的時後,Memory還沒被Initialize 所以無法使用,這時後需要 Cache As Ram。
3. 使CPU進入 Protected Mode (Flat Mode)。

Task

1. 系統Boot / Restart 的Entry point,負責處理所有Platform的Restart Events
2. Create 一個暫時的Region,在Memory Initialize 之前使用
3. 因為Boot的時後,整個code最開始是在 SEC Phase,所以Platform Designer 在Call PEI Foundation前可在SEC Phase Verify PEI Foundation的Security,所以SEC Phase是System Trust root。
4. 傳Handoff message到PEI Foundation(SEC Phase最終目地),這個Message包括:
a. Platform Status
b. BFV (Boot Firmware Volume)的Address 和 Size
c. 暫時RAM的Address 和 Size
d. Stack Address 和 Size
Data Structure 為:EFI_PEI_STARTUP_DESCRIPTOR
typedef struct {
UINTN BootFirmwareVolume;UINTN SizeOfCacheAsRam;EFI_PEI_PPI_DESCRIPTOR *DispatchTable;} EFI_PEI_STARTUP_DESCRIPTOR;
還有另外一個PPI:FORM_INFORMATION_PPI 也可傳送Handoff Message
在SEC_PLATFORM_INFORMATION_PPI.PlatformInformation() Define 一個 EFI_HEALTH_FLAGS,
包含了Processor,Hardware 以及Itanium Process的 PLA(Processor Abstract Layer),code中有關於Process Reset的Status。
下圖為 SEC Phase 執行的Flow

UEFI – PEI Phase

PEI PhasePre-EFI Initialization Environment
Why??
1. 因為所有Code都沒經過Compress,會有Rom size 的問題
2. Memory 還沒Initialize
3. Chipset 還沒Initialize
Task
1. CPU Cache Translation
a. 切換Stack到真正的Cache (Disable Cache As Ram And Enable L1 L2 Cache)
2. Chipset Initialization
a. Platform Chipset Initialization
b. Memory Initialization
3. Board Initialization
a. Clock Initialization
b. GPIO Initialization
4. BIOS Recovery
5. S3 Resume
6. 啟動DEXIPL (DXE Initial Program Loader)
Component
1. PEI Foundation (exist in BFV)
a. Dispatching PEIM
b. Maintaining the boot mode
c. Initialize permanent memory
d. Invoking DXEIPL
2. PEIM Service
PEI foundation建立一個system table叫做PEI service table,是可以被所有的PEIMs所存取的。因為記憶體的空間只有在PEI最後的階段才可以使用
a. PPI Service:管理PPI並在必要時,從temporary ROM裡頭的database呼叫他。
b. Boot Mode Services: 管理系統的boot mode( s3, s5, normal boot, diagnostic, etc.)
c. HOB Service: 創造一個HOB的資料結構,並傳到下一個DXE階段。
d. Firmware Volume Service:走訪FV的FFS(Firmware File System)去找出PEIMs,並找出位在Flash device的Firmware file。
e. PEI memory Service:提供記憶體管理的服務在初始化記憶體以前,或是以後。
f. Status Code Service:提供錯誤回報的服務,例如:port 80h。
g. Reset Service:提供cold or warm系統的重啟動。
h.
3. PEIMS (Exist in FVs)
Executable Binaries – Process , Chipset , Device or other Platform 指定的function
4. PEIM to PEIM interface (PPI) => Data Structer EFI_PEI_PPI_DESCRIPTOR:由GUID和一個Pointer 組成,PEIM 彼此Communicate 的Structure
5. PEI Dispatcher
這是在PEI foundation裡頭的一個state machine,他會衡量每個FV裡頭的PEIMS之間的相依性。決定哪些PEIMS應該要先Dispatch。而他們之間的相依性
是由PPIs所決定,PPIs裡頭敘述了PEIMs之間的相依性。
再一開始的時候PEI dispatcher會去PEI foundation裡頭的PPI Database檢查哪些PPI已經被install如果已經被install,他PEIM的dependency expression會被評估成true,代表所屬的PEIMs已經可以被dispatch。在PEI dispatcher評估過全部FV裡頭所有PEIM的dependency expression發現全部都是FALSE以後,代表已經沒有PEIM可以被dispatch,PEI dispatcher結束,在來PEI foundation把control foward給DXE IPL PPI,進入DXE phase。

UEFI – DXE Phase

DXE PhaseDriver Execution Environment
Why??
System Initialize 的地方大部份都在這。
Task
Component
1. DXE Core (DXE Foundation)
產生一組Boot Services , Runtime Services , DXE Services。由Boot Service code 組合而成。
Boot 到 OS之後就不存在。
2. DXE Dispatcher
Discovery 及以正確的順序Execute DXE Drivers
3. DXE Drivers
Initialize CPU ,chipset 及 System Compoment 以及為了System Services等等做的事
DXE Driver Type

1. Early DXE Driver–Platform initialization Drivers
a. 在DXE Phase 最早執行的Driver
b. 包括Dependency Expression Syntax(DEPEX) 描述Dispatch的順序
c. 包含的型式有
i. Basic Services
ii. Processor Initialization Code
iii. Chipset Initialization Code
iv. Platform Initialization Code
d. 產生Architectural Protocols
2. EFI Drivers that follow EFI Driver Model
a. Initialize 過程不會涉及到Hardware
b. Follow EFI Driver Model
c. 提供對 Console Devices 跟 Boot Devices 的訪問
d. 抽像化 Bus Controller
e. 只有 Boot OS 所需要的Driver 才能被初始化
f. DXE Dispatcher 完成的時後才被呼叫
g. 像Driver的方式一樣被呼叫
h. 需要建立控制台 ( Keyboard , Video) 和處理 EFI Boot Option的時後要連結 EFI Drivers

UEFI – BDS Phase

BDS PhaseBoot Device Select
Why??

BDS通過系統中存在的 Boot Option Variable 來找到並啟動 OS Loader 或 UEFI Application。
Task

1. Initialize console devices base on the ConIn, ConOut and StdErr environment variables.
(初始化根據環境變數Conln 、ConOut 以及 StdErr 的 Console Devices)

2. Attempt to load all drivers listed in the Driver#### and DriverOrder environment variables.
(試著去Load 列在環境變數 Driver####及 DriverOrder上的Driver)

3. Attempt to boot Device from the boot selections list in the Boot#### and BootOrder environment variables.
(試著去Boot在環境變數Boot####以及BootOrder上的 Selections Device)
在這個時後使用者可以看見選單並選擇Boot Device

Console Device
Console Device 是從 Simple Test Output和Simple Input Protocol 抽象出來的。在UEFI中,能夠產生其中一種或兩種Protocol的Device都被當作是 Console Device
Console Device Type
1. VGA Adapters, produce Simple Text Output Protocol.
2. Video Adapters, produce Simple Text Output Protocol.
3.Serial Terminal, produce both Simple Text Output Protocol and Simple Input Protocol.
4.Telnet, produce both Simple Text Output Protocol and Simple Input Protocol.
5. Remote Graphical Displays(HTTP), produce both Simple Text Output Protocol and Simple Input Protocol.
Boot Device的幾種Type:
1.Devices that produce the Block I/O Protocol and are formatted with a FAT file system,  Disk Devices
2.Devices that directly produce the File System Protocol
3.Devices that directly produce the Load File Protocol 

.

3/20/2017

[Tab] missing separator, STOP.

missing separator. Stop.
missing separator (did you mean TAB instead of 8 spaces?). Stop.
不可識別的命令行,make在讀取Makefile過程中不能解析其中包含的內容。GNU make在讀取Makefile時根據各種分隔符號(:, =, [TAB]字元等)來識別Makefile的每一行內容。這些錯誤意味著make不能發現一個合法的分隔符號。

出現這些錯誤資訊的可能的原因是(或許是編輯器,絕大部分是ms-windows的編輯器)在Makefile中的命令之前使用了4個(或者8個)空格代替了[Tab]字元。這種情況,將產生上述的第二種形式產生錯誤資訊。且記,所有的命令行都應該是以[Tab]字元開始的。
      1. edit the .emacs.d/lisp/init-local.el
(require 'make-mode)
  
  (defconst makefile-nmake-statements
    `("!IF" "!ELSEIF" "!ELSE" "!ENDIF" "!MESSAGE" "!ERROR" "!INCLUDE" ,@makefile-statements)
    "List of keywords understood by nmake.")
  
  (defconst makefile-nmake-font-lock-keywords
    (makefile-make-font-lock-keywords
     makefile-var-use-regex
     makefile-nmake-statements
     t))
  
  (define-derived-mode makefile-nmake-mode makefile-mode "nMakefile"
    "An adapted `makefile-mode' that knows about nmake."
    (setq font-lock-defaults  `(makefile-nmake-font-lock-keywords ,@(cdr font-lock-defaults)))) 
          (setq auto-mode-alist(cons '("\\.mak\\'" . makefile-nmake-mode) auto-mode-alist))
2. https://www.emacswiki.org/emacs/MakefileMode

2/22/2017

Delete Chroot

  • Find the chrootname
        sudo edit-chroot -a
  • Delete the chroot
       sudo edit-chroot -d <chrootname>

2/21/2017

debug: No running instance of xfce4-panel was found

  1. clear the sessions in the cache folder
    • rm -r ~/.cache/sessions
    • save the sessions and logout
  2. alt-F2, run the xfce4-panel, and logout
  •  [False]
    • (emacs:1550): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
  • The Unable to locate theme engine in module_path: "pixmap" messages are a known bug.
    To fix it, install the gtk2-engines-pixbuf package

debug: solve the gibberish on website; cannot display Chinese

  • To install Chinese language support, run following commands:
# sudo apt-get install language-pack-zh* 
# sudo apt-get install chinese*
  • And finally, you will need to add additional fonts:
# sudo apt-get install fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho
# sudo apt-get install fonts-ipafont-gothic fonts-unfonts-core
----------------------------------------------------------------------------------------------------------------------------
  • List all the languages on this device
#locale -a
  • List settings on this device
#locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

LC_CTYPE 這會影響字元的分類和轉換,輸入中文設定
LC_TIME   日期和時間的顯示格式
LC_MONETARY 貨幣單位的符號和表示
LC_MESSAGES 系統訊息的顯示
LANG    這是預設
LC_ALL 這是強制全部使用這裡的設定
  • Generate the language file, edit the file 
$ sudo vim /var/lib/locales/supported.d/local
zh_TW.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
en_US.UTF-8 UTF-8
zh_TW BIG5
 $ sudo locale-gen
  •  Setting the User's enviroment
 $ vim ~/.bashrc
  •  Setting the Global Variables
$ sudo vim /etc/environment






1/25/2017

Change Git difftool and mergetool to 'Meld'

 Download:

sudo apt-get update
sudo apt-get install meld

Setting:

sudo  git  config  --global diff.tool=meld
sudo  git  config  --global  merge.tool=meld

Check:

sudo  git  config  -l

11/28/2016

解決 apt-get install 遇到404 Not Found的問題

Ubuntu 10.4版 要使用apt-get install 安裝套件的時候遇到了404 Not Found的問題,訊息大概如下:

Err http://archive.ubuntu.com quantal/main amd64 Packages
  404  Not Found [IP: 91.189.91.15 80]
Err http://archive.ubuntu.com quantal/restricted amd64 Packages
  404  Not Found [IP: 91.189.91.15 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/quantal-security/main/binary-amd64/Packages  404  Not Found [IP: 91.189.91.15 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/quantal-security/restricted/binary-amd64/Packages  404  Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/main amd64 Packages      
  404  Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/restricted amd64 Packages
  404  Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/universe amd64 Packages  
  404  Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/multiverse amd64 Packages
  404  Not Found [IP: 91.189.91.15 80]



找了一下原因與解決方法,原因大概是因為,舊版的LTS版本,ubuntu只支援5年的時間(如果不是LTS版本只支援9個月),五年後ubuntu就會把更新的Server從標準的Server "http://archive.ubuntu.com/ubuntu/dist/" (apt-get 會去找的地方),移到別的地方了。

所以解決無法apt-get install的方法有兩個:

1. 更新你的ubuntu版本,使用指令 sudo apt-get dist-upgrade 去做版本更新。

2. 另一個方法你可以不要更新,可以使用 sed command 去更改 /etc/apt/sources.list 這個檔案,我們要把source.list裡面的 "archive.ubuntu.com" 和 "security.ubuntu.com" 替換成 "old-releases.ubuntu.com",在使用替換的指令之前,請先備份一下source.list檔案,如果下面方法失敗還可以把source.list復原,接著就可以執行sed替換指令,兩個步驟(command)如下:

     一. cp /etc/apt/source.list /etc/apt/back_source.list
     二. sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com

當我們的source.list內容替換完成之後,請先執行update,update完成之後再作apt-get install 接下來應該就不會有404 Not Found的問題了! update的命令如下:

     sudo apt-get update

 source from: http://dannysun-unknown.blogspot.tw/2016_10_01_archive.html