搜尋此網誌

2012年6月21日 星期四

在UEFI系統下,如何撰寫一個批次檔(nsh)


  1. edit建立一個test.nsh的測試檔案。
  2. 指令請參考  EFI/UEFI Shell 指令集 
  3. 例如:
## 註解==========================================
##Example 1
echo -off 
for %a in 1 2 3 
echo %a 
endfor 
echo -on
## 註解==========================================
##Example 2
echo -off 
for %a run (1 3)
echo %a
endfor

echo -on
## 註解==========================================

##這結果將呈現相同結果,列印如下:
FS0:\ test.nsh
FS0:\ echo -off
1
2
3
FS0:\




2012年6月11日 星期一

How to debug in UEFI - EDK2

如何Debug在UEFI下
UEFI有2種debug方式;

  1. 在虛擬環境Nt32Pkg中debug,在需要測試的程式碼前面加入"_asm int 3;" ,編譯然後再執行虛擬環境(Nt32Pkg),當模擬器執行到"_asm int 3;"這個指令時,就會彈出對話框,此時程式碼將會被中斷。
  2. 另一種是通過Serial Port(RS232)輸出,在 UEFI 真實環境中的運作。可將變數透過 Serial Port(RS232)輸出到終端機上。

UEFI會為每個Disk(HD or SSD)建立一個對應的裝置(Device),也會為每一個磁區建立一個對應的裝置。 透通"DiskIO Protocol"安裝OS到裝置上,也可以透過此協定去讀寫每一個磁區。
每個裝置上都有"DevicePath Protocol", 可透過DevicePath去判斷此裝置是一個磁區 ,或是一個Disk(HD or SSD)。磁區中的DevicePath的最後一個有效Node是HD(SPEC 9.3.6.1)。
當你得到了GPT HD或SSD的DiskIo後,可利用DiskIo讀取第一個磁區(第0個磁區是MBR或者是Protective MBR)取得GPT header,在第2~33磁區中存放的是EFI_PARTITION_ENTRY。 GPT用到的資料結構,在MdePkg/Include/Uefi/UefiGpt.h中可以查閱到,其GPT的格式可以參考UEFI SPEC 第5章。

如何製作UEFI去創造一個USB虛擬環境 - EDK2(UDK2010)

如何製作UEFI USB Boot Disk
分成兩種狀況,如果平台是UEFI,請按照下列步驟:
1.Format USB DISK 為FAT(或FAT16, FAT32)格式。
2.在 USB DISK 上建立目錄 efi\boot。
3.將UEFI的應用程式copy到efi\boot 目錄,並改名為bootx64.efi 或者bootia32.efi。
      因為UEFI的啟動檔案是FAT檔案系統下的efi\boot目錄裡的bootx64.efi 或bootia32.UEFI與Legacy BIOS需要MBR描述來載入不同的OS。
如果目標平台是Legacy BIOIS, 需要在USB DISK中製作MBR和載入描述檔, 請按照下列步驟:
1.編譯duet package
      build -a IA32 -p DuetPkg\DuetPkgIa32.dsc
      or
      build -a X64 -p DuetPkg\DuetPkgX64.dsc
2.產生出的檔案會被放置在DuetPkg
      cd DuetPkg
      PostBuild.bat Ia32 或者 PostBuild.bat X64
3.置入USB DISK,假如USB DISK是G:,在執行程式後,USB DISK將會被寫入新的MBR。
      createbootdisk usb G: FAT32 IA32 或者createbootdisk usb G: FAT32 X64
      createbootdisk usb G: FAT16 IA32 或者createbootdisk usb G: FAT16 X64
4.移除並重新置入此USB DISK,複製UEFI的檔案到USB DISK。
      createbootdisk usb G: FAT32 IA32 step2 或者createbootdisk usb G: FAT32 X64 step2
      createbootdisk usb G: FAT16 IA32 step2 或者createbootdisk usb G: FAT16 X64 step2
      此命令複製efildr20到USB DISK的根目錄, 該檔案用於載入系統進入UEFI環境,並向efi\boot目錄copy了載入檔案bootia32.efi或bootx64.efi,接下來就可以使用 USB DISK來執行UEFI。

祝你使用成功!!!

安裝與編譯UEFI EDK2


如何安裝開發環境
1. 取得Windows VC and DDK,並安裝,請參照[How To Build EDK II(EFI Developer Kit II) on Windows]。
2. Download EDK2.[Download EDK2]
3. 打開Visual Studio 2008 Command Prompt.
    cd MyWorkSpace
    edksetup.bat
4. Edit Conf\taget.txt, 更改編譯工具程式"TOOL_CHAIN​​_TAG"成為
From
   TOOL_CHAIN​​_TAG = MYTOOLS
To
   TOOL_CHAIN​​_TAG = VS2008
5. 編譯指令
    build的參數,-a 是用來選擇平台(IA32, X64, ...), -p是用來選擇package的路徑,系統預設值是Nt32Pkg,所以build -a IA32 -p Nt32Pkg\Nt32Pkg.dsc是用來編譯UEFI虛擬環境 。
6. 編譯與執行虛擬環境指令
    與build -a IA32 -p Nt32Pkg\Nt32Pkg.dsc run 命令等同,是用來執行UEFI虛擬環境。

2012年6月9日 星期六

How to add UEFI_Shell_2.0 into EDK2?

DOWNLOAD
UEFI_Shell_2.0 Package
Shell 2.0 Documentation

OVERVIEW
The UEFI 2.0 shell provides a standard pre-boot command line processor.
It is similar to the EDK EFI Shell or a *nix command line parser.

HOW TO INCORPORATE THIS SHELL INTO NT32
The instructions below are included as a sample and template on how a
developer may integrate this code into an existing platform:

1. Add this shell build to the build:
   Add the shell.inf to the [components] section as it is in the ShellPkg.dsc.
   EXAMPLE: to add the shell to Nt32 emulation, edit file "Nt32Pkg.dsc" add the following .inf 
                to the [Components...] section and before the [BuildOptions] Section
_______
  ShellPkg/Application/Shell/Shell.inf {
   
      DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
      ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
      NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
      NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
      HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
      FileHandleLib|ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
      ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
      SortLib|ShellPkg/Library/UefiSortLib/UefiSortLib.inf
      PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf


   
      gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
      gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
      gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000
  }
_________

2. Update system PCDs in the .dsc file  to support this new module
   Update the PCD as follows using the Shell's PCD:
   EXAMPLE: to add the shell to Nt32 emulation, edit file "Nt32Pkg.dsc" add the following to the [PcdsFixedAtBuild] section
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }

3. Remove the old shell from the Firmware list .fdf file.
   Remove the FILE APPLICATION section for the old shell.
   EXAMPLE: to add the shell to Nt32 emulation, edit file "Nt32Pkg.fdf" and comment out the following:
     #FILE APPLICATION = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile) {
     #    SECTION PE32 = EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi
     #  }

4. Add this shell to the .fdf firmware list
   Add the Shell.INF to the end of the list of DXE modules.
   EXAMPLE: to add the shell to Nt32 emulation, edit file "Nt32Pkg.fdf" add the following at the end of the DXE modules:

    INF  ShellPkg/Application/Shell/Shell.inf

5. Build -p Nt32Pkg\Nt32Pkg.dsc

KNOWN LIMITATIONS
1. RM can delete current working directory via other map name.
2. DrvCfg is not functional.
3. ifConfig permanent settings are under investigation (may not function correctly)
4. Shell documentation is in development and forthcoming.

2012年6月6日 星期三

SMART EXECUTE OFF-LINE IMMEDIATE - B0h/D4h, Non-data


Inputs:
Register
7
6
5
4
3
2
1
0
Features
D4h
Sector Count
na
LBA Low
Subcommand specific
LBA Mid
4Fh
LBA High
C2h
Device
obs
na
obs
DEV
na
na
na
na
Command
B0h
Device register -
DEV shall specify the selected device.

SMART EXECUTE OFF-LINE IMMEDIATE LBA Low register values

Value
Description of subcommand to be executed
0
Execute SMART off-line routine immediately in off-line mode
1
Execute SMART Short self-test routine immediately in off-line mode
2
Execute SMART Extended self-test routine immediately in off-line mode
3
Execute SMART Conveyance self-test routine immediately in off-line mode
4
Execute SMART Selective self-test routine immediately in off-line mode
5-63
Reserved
64-126
Vendor specific
127
Abort off-line mode self-test routine
128
Reserved
129
Execute SMART Short self-test routine immediately in captive mode
130
Execute SMART Extended self-test routine immediately in captive mode
131
Execute SMART Conveyance self-test routine immediately in captive mode
132
Execute SMART Selective self-test routine immediately in captive mode
133-191
Reserved
192-255
Vendor specific



Normal Outputs:
Register
7
6
5
4
3
2
1
0
Error
na
Sector Count
na
LBA Low
na
LBA Mid
na or 4Fh
LBA High
na or C2h
Device
obs
na
obs
DEV
na
na
na
na
Status
BSY
DRDY
DF
na
DRQ
na
na
ERR
LBA Mid -
na when the subcommand specified an off-line routine including an off-line self-test routine. 4Fh when the subcommand specified a captive self-test routine that has executed without failure.
LBA High -
na when the subcommand specified an off-line routine including an off-line self-test routine. C2h when the subcommand specified a captive self-test routine that has executed without failure.
Device register –
DEV shall indicate the selected device.
Status register -
BSY shall be cleared to zero indicating command completion.
DRDY shall be set to one.
DF (Device Fault) shall be cleared to zero.
DRQ shall be cleared to zero.
ERR shall be cleared to zero.

Error Outputs:
Register
7
6
5
4
3
2
1
0
Error
na
na
na
IDNF
na
ABRT
na
na
Sector Count
na
LBA Low
na
LBA Mid
na or 4Fh or F4h
LBA High
na or C2h or 2Ch
Device
obs
na
obs
DEV
na
Status
BSY
DRDY
DF
na
DRQ
na
na
ERR
Error register –
IDNF shall be set to one if SMART data sector’s ID field could not be found.
ABRT shall be set to one if this command is not supported or if the input register values are invalid. ABRT may be set to one if the device is not able to complete the action requested by the command.
LBA Mid register –
na when the subcommand specified an off-line routine (including an off-line self-test routine).
4Fh when the subcommand specified a captive self-test routine and some error other than a self-test routine failure occurred (i.e., if the sub-command is not supported or register values are invalid)
F4h when the subcommand specified a captive self-test routine which has failed during execution.
LBA High register –
na when the subcommand specified an off-line routine (including an off-line self-test routine).
2Ch when the subcommand specified a captive self-test routine which has failed during execution.
C2h when the subcommand specified a captive self-test routine and some error other than a self-test routine failure occurred (i.e., if the sub-command is not supported or register values are invalid)
Device register -
DEV shall indicate the selected device.
Status register -
BSY shall be cleared to zero indicating command completion.
DRDY shall be set to one.
DF (Device Fault) shall be cleared to zero.
DRQ shall be cleared to zero.
ERR shall be cleared to zero.

SVN Tip - How to get the same revision on different path

I think this different caused older checked out version but with latest SVN external folder. There are the folders that as an external folder of source code of XXX1 driver on SVN for your reference.
cxxx svn://192.68.79.21/qqq/cxxx/trunk
rxxx svn://192.68.79.21/qqq/rxxx/trunk
mxxx svn://192.68.79.21 /qqq/mxxx/trunk
lxxx svn://192.68.79.21/qqq/lxxx/trunk
cxxx  svn://192.68.79.21/qqq/cxxx/trunk
ixxx svn://192.68.79.21/qqq/ixxx/trunk
wxxx svn://192.68.79.21/qqq/wxxx/trunk
hxxx svn://192.68.79.21/qqq/hxxx/trunk
in product folder:
xxx4 svn://192.68.79.21/qqq/product/xxx4/trunk
xxx3 svn://192.68.79.21/qqq/product/xxx3/trunk
xxx2 svn://192.68.79.21/qqq/product/xxx2/trunk
xxx1 svn://192.68.79.21/qqq/product/xxx1/trunk

Example: If you would like to check out version 48418, you need modified the SVN property to the example below.Otherwise it may cause build error or other crash issue.
cxxx -r 48418 svn://192.68.79.21/qqq/cxxx/trunk
rxxx -r 48418 svn://192.68.79.21/qqq/rxxx/trunk
mxxx -r 48418 svn://192.68.79.21/qqq/mxxx/trunk
lxxx -r 48418 svn://192.68.79.21/qqq/lxxx/trunk
cxxx -r 48418 svn://192.68.79.21/qqq/cxxx/trunk
ixxx -r 48418 svn://192.68.79.21/qqq/ixxx/trunk
wxxx -r 48418 svn://192.68.79.21/qqq/wxxx/trunk
hxxx -r 48418 svn://192.68.79.21/qqq/hxxx/trunk
in product folder:
xxx1 -r 48418 svn://192.68.79.21/product/chip/xxx1/trunk

SMART ENABLE OPERATIONS - B0h/D8h, Non-data


Inputs:
Register
7
6
5
4
3
2
1
0
Features
D8h
Sector Count
na
LBA Low
na
LBA Mid
4Fh
LBA High
C2h
Device
obs
na
obs
DEV
na
na
na
na
Command
B0h
Device register -
DEV shall specify the selected device.
Normal Outputs:
Register
7
6
5
4
3
2
1
0
Error
na
Sector Count
na
LBA Low
na
LBA Mid
na
LBA High
na
Device
obs
na
obs
DEV
na
na
na
na
Status
BSY
DRDY
DF
na
DRQ
na
na
ERR
Device register –
DEV shall indicate the selected device.
Status register -
BSY shall be cleared to zero indicating command completion.
DRDY shall be set to one.
DF (Device Fault) shall be cleared to zero.
DRQ shall be cleared to zero.
ERR shall be cleared to zero.

Error Outputs:
Register
7
6
5
4
3
2
1
0
Error
na
na
na
na
na
ABRT
na
na
Sector Count
na
LBA Low
na
LBA Mid
na
LBA High
na
Device
obs
na
obs
DEV
na
Status
BSY
DRDY
DF
na
DRQ
na
na
ERR
Error register -
ABRT shall be set to one if this command is not supported or if the input register values are invalid. ABRT may be set to one if the device is not able to complete the action requested by the command.
Device register -
DEV shall indicate the selected device.
Status register -
BSY shall be cleared to zero indicating command completion.
DRDY shall be set to one.
DF (Device Fault) shall be cleared to zero.
DRQ shall be cleared to zero.
ERR shall be cleared to zero.