搜尋此網誌

顯示具有 EFI/UEFI Shell 指令集 標籤的文章。 顯示所有文章
顯示具有 EFI/UEFI Shell 指令集 標籤的文章。 顯示所有文章

2017年3月8日 星期三

Check Legacy BIOS Image from UEFi Shell

//The program is for searching and dumping Legacy BIOS Image between 0 to 1M system Memory.
EFI_STATUS
EFIAPI
InitializeUIApplication (
    IN EFI_HANDLE           ImageHandle,
    IN EFI_SYSTEM_TABLE     *SystemTable
) {
    EFI_STATUS Status = EFI_SUCCESS;
    EFI_SHELL_APP_INIT (ImageHandle, SystemTable);
    {
        UINT64 addr, offset;
        UINT16 count = 0, i;
        Print(L"Detecting....\n");
        //for (addr = 0xC0000; addr < 0xE0000; addr += 0x200)
        for (addr = 0x0000; addr < 0x100000; addr += 0x200)
{
    //Print(L"address=0x%x\n", addr);
            if (
                ((*(UINT16 *)(addr + 0x00)) == 0xAA55) &&
                ((*(UINT16 *)(addr + 0x20)) == 0x8086) && //Vendor ID
                //((*(UINT16 *)(addr + 0x22)) == 0x27D8) && //Device ID
                (1)) {
                    Print(L"Legacy BIOS is at:0x%08x\n", (UINT32)(UINT64)addr);
                    for (offset = 0; offset < 4; offset ++){
                        Print(L"%08x: ", (UINT32)(addr + offset * 0x10));
                        for (i = 0; i < 16; i ++) {
                            Print(L"%02x ", (UINT8)*((UINT8 *)addr + offset * 0x10 + i));
                        }
                        for (i = 0; i < 16; i ++) {
                            if (((UINT8)*((UINT8 *)(addr + offset * 0x10 +  i)) >= 0x20)
                                && ((UINT8)*((UINT8 *)(addr + offset * 0x10 +  i)) < 0x80))
                                Print(L"%c", (UINT8)*((UINT8 *)addr + offset * 0x10 + i));
                            else
                                Print(L".");
                        }
                        Print(L"\n");
                    }
                    count ++;
            }
        }
        if (count == 0)
            Print(L"No found any BIOS image.\n");
    }
    {
         Print(L"System BIOS remaining memory[0040h:0013h]=0x%x(%d KBytes)\n", *(UINT16 *)0x413, *(UINT16 *)0x413);
         Print(L"Length of EBDA[0040h:000Eh]=%xh:0000h=%dk\n", *(UINT16 *)0x40e, *(UINT8 *)((UINT32)*(UINT16 *)0x40e << 4));
    }
    return Status;
}

2014年12月1日 星期一

How to reset SATA Devices(with AHCI architecture) by UEFI shell mm command?

How to get Bar5 address first?

fs0:\test〉 pci
   Seg  Bus  Dev  Func
   ---  ---  ---  ----
    00   04   00    00 ==〉 Mass Storage Controller - UNDEFINED
             Vendor 1B4B Device 9230 Prog Interface 1

fs0:\test〉 pci 4 0 0
pci 4 0 0

  PCI Segment 00 Bus 04 Device 00 Func 00 [EFI 0004000000]
  00000000: 4B 1B 30 92 07 00 10 00-11 01 06 01 08 00 00 00  *K.0.............*
  00000010: 01 EC 00 00 81 E8 00 00-01 E8 00 00 81 E4 00 00  *................*
  00000020: 01 E4 00 00 00 F8 BF FE-00 00 00 00 4B 1B 30 92  *............K.0.*
  00000030: 00 00 BE FE 40 00 00 00-00 00 00 00 0B 01 00 00  *....@...........*
  00000040: 01 50 03 40 00 00 00 00-00 00 00 00 00 00 00 00  *.P.@............*
  00000050: 05 70 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *.p..............*
  00000060: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
  00000070: 10 E0 12 00 02 87 28 00-10 20 09 00 22 3C 03 00  *......(.. .."<..*
  00000080: 40 00 21 10 00 00 00 00-00 00 00 00 00 00 00 00  *@.!.............*
  00000090: 00 00 00 00 10 00 00 00-00 00 00 00 00 00 00 00  *................*
  000000A0: 02 00 01 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
  000000B0: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
  000000C0: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
  000000D0: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
  000000E0: 12 00 00 00 48 00 00 00-00 00 00 00 00 00 00 00  *....H...........*
  000000F0: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*

Bar5=0xFEBFF800

[Reset SATA HDDs by shell mm commands]

edit file as below:

#####################################################################
mm febff800 4 ;MMIO -n
mm febff804 4 ;MMIO :0x80000000 -n # == Enable AHCI
mm febff804 4 ;MMIO -n
#pause
mm febff92c 4 ;MMIO :0x21 -n # == Reset Port0
stall 100000
mm febff92c 4 ;MMIO :0x20 -n
mm febff92c 4 ;MMIO -n
#pause
mm febff9ac 4 ;MMIO :0x21 -n # == Reset Port1
stall 100000
mm febff9ac 4 ;MMIO :0x20 -n
mm febff9ac 4 ;MMIO -n
#pause
mm febffa2c 4 ;MMIO :0x21 -n # == Reset Port2
stall 100000
mm febffa2c 4 ;MMIO :0x20 -n
mm febffa2c 4 ;MMIO -n
#pause
mm febffaac 4 ;MMIO :0x21 -n # == Reset Port3
stall 100000
mm febffaac 4 ;MMIO :0x20 -n
mm febffaac 4 ;MMIO -n
#pause


#####################################################################
fs0:\ test.nsh

2014年11月25日 星期二

EFI Shell Protocol Information Table

Protocol Symbol
UEFI Protocol
BlkIo
Block I/O Protocol
BusSpecificDriverOverride
Bus Specific Driver Override Protocol
ComponentName
Component Name Protocol
Configuration
Driver Configuration Protocol
ConIn
Console-in Device
ConOut
Console-out Device
DebugPort
Debugport Protocol
DebugSupport
Debug Support Protocol
Decompress
Decompress Protocol
DevIo
Device I/O Protocol
Diagnostics
Driver Diagnostics Protocol
DiskIo
Disk I/O Protocol
Dpath
Device Path Protocol
DriverBinding
Driver Binding Protocol
ErrOutSplit
Error-out Splitter Protocol
Fs
Simple File System Protocol
Image
Loaded Image Protocol
IsaAcpi
ISA ACPI Protocol
IsaIo
ISA I/O Protocol
LegacyBoot
Legacy Boot Protocol
Load
Load File Protocol
Net
Simple Network Protocol
Nii
Network Interface Identifier Protocol
PciIo
PCI I/O Protocol
PciRootBridgeIo
PCI Root Bridge I/O Protocol
Pxebc
PXE Base Code Protocol
ScsiIo
SCSI I/O Protocol
ScsiPassThru
SCSI Pass Thru Protocol
SerialIo
Serial I/O Protocol
SimplePointer
Simple Pointer Protocol
StdErr
Standard Error Device
Tcp
TCP Protocol
Txtin
Simple Text-in Protocol
TxtInSplit
Text-in Splitter Protocol
Txtout
Simple Text Output Protocol
TxtOutSplit
Text-out Splitter Protocol
UgaDraw
UGA Draw Protocol
UgaIo
UGA I/O Protocol
UnicodeCollation
Unicode Collation Protocol
UsbIo
USB I/O Protocol
VgaClass
VGA Class Driver Protocol

MS-DOS and Unix Equivalents for UEFI Shell Internal Commands

EFI Shell Command
MS-DOS 6.22 Equivalent
Linux Equivalent

alias
attrib
chmod
cd
cd
cls
clear


copy
cp
date
date
del
rm





lsmod

modinfo


echo
echo
exit
exit

help

insmod
dir
ls


mkdir
mkdir
move
mv


reset
reboot
set
set
time
time

touch
type
type

rmmod
ver

vol

2014年9月8日 星期一

EFI Shell commands -- PARSE(在一個標準格式裡,從記錄輸出擷取一個值)

Retrieves a value from a record output in a standard format.

parse filename tablename column [-i ] [-s ]
filename        Source file name
tablename       The name of the table being parsed.
column          The one-based column index to use to determine which value
                from a particular record to parse.
-i   Start parsing with the nth instance of specified tablename,                 after the specified instance of ShellCommand. If not present,
                then all instances will be returned.
-s   Start parsing with the nth instance of the ShellCommand table.                If not present, then 1 is assumed.
This command will enable the parsing of data from a file which contains data which has been output from a command having used the -sfo parameter. Since the standard formatted output has a well known means of parsing, this command is intended to be used as a simplified means of having scripts consume such constructed output files and use this retrieved data in logic of the scripts being written for the UEFI shell.
The following data is contained in a temporary file (temp.txt):
VolumeInfo, "MikesVolume","400000000","32000000","16000000"
FileInfo, "fs0:/efi/boot/winloader.efi","45670","arsh"
FileInfo, "fs0:/efi/boot/mikesfile.txt","1250","a"
FileInfo, "fs0:/efi/boot/readme.txt","795","a"
The following shows the parse command being used:
MikesVolume

Below is an example using the Index parameter:

fs0:\〉parse temp.txt FileInfo 3 -i 3

2012年9月6日 星期四

EFI/UEFI Shell commands list(指令集)

下列的指令集是依照不同的主機板廠商,提供不同的指令集:
?             - Displays the EFI Shell command list or verbose command help
alias         - Displays, creates, or deletes EFI Shell aliases
attrib        - Displays or changes the attributes of files or directories
cd            - Displays or changes the current directory
cls           - Clears standard output and optionally changes background color
comp          - Compares the contents of two files
connect       - Connects one or more EFI drivers to a device
cp            - Copies one or more files or directories to another location
date          - Displays or changes the current system date
dblk          - Displays one or more blocks from a block device
devices       - Displays the list of devices managed by EFI drivers
devtree       - Displays the EFI Driver Model compliant device tree
dh            - Displays EFI handle information
disconnect    - Disconnects one or more EFI drivers from a device
dmem          - Displays the contents of memory
dmpstore      - Displays all EFI NVRAM variables
drivers       - Displays the EFI driver list
drvcfg        - Invokes the Driver Configuration Protocol
drvdiag       - Invokes the Driver Diagnostics Protocol
echo          - Controls batch file command echoing or displays a message
edit          - Full screen editor for ASCII or UNICODE files
eficompress   - Compress a file
efidecompress - Decompress a file
err           - Displays or changes the error level
exit          - Exits the EFI Shell environment
for           - Executes commands for each item in a set of items
goto          - Forces batch file execution to jump to specified location
guid          - Displays all registered EFI GUIDs
help          - Displays the EFI Shell command list or verbose command help
hexedit       - Full screen hex editor
if            - Executes commands in specified conditions
ifconfig      - Modify the default IP address of UEFI network stack
ipconfig      - Displays or modifies the current IP configuration
load          - Loads and optionally connects one or more EFI drivers
loadpcirom    - Loads a PCI Option ROM
ls            - Displays a list of files and subdirectories in a directory
map           - Displays or defines mappings
mem           - Displays the contents of memory
memmap        - Displays the memory map
mkdir         - Creates one or more directories
mm            - Displays or modifies MEM/MMIO/IO/PCI/PCIE address space
mode          - Displays or changes the console output device mode
mount         - Mounts a file system on a block device
mv            - Moves one or more files or directories to another location
openinfo      - Displays the protocols and agents associated with a handle
pause         - Prints a message and waits for keyboard input
pci           - Displays PCI device list or PCI function configuration space
ping          - Ping a target machine with UEFI network stack
reconnect     - Reconnects one or more EFI drivers to a device
reset         - Resets the system
rm            - Deletes one or more files or directories
sermode       - Sets serial port attributes
set           - Displays or modifies EFI Shell environment variables
shift         - Shifts batch file input parameter positions
smbiosview    - Displays SMBIOS information
stall         - Stalls the processor for the specified number of microseconds
telnetmgmt    - Change terminal type
time          - Displays or changes the current system time
timezone      - Displays or sets time zone information
touch         - Updates filename timestamp with current system date and time
type          - Displays file contents
unload        - Unloads a EFI driver
ver           - Displays EFI Firmware version information
vol           - Displays or changes a file system volume label

Shell 2.0(UDK2010) 增加的指令
else      -Else identifies the portion of the code executed if the if was FALSE.
endif     -Ends the block of a script controlled by an 'if' statement.
endfor    -Ends a 'for' loop.
getmtc    -Gets the MTC from BootServices and displays it.
bcfg      -Manages the boot and driver options that are stored in NVRAM.
setsize   -Adjusts the size of a file.
setvar    -Changes the value of a UEFI variable.

UDK2014 增加的指令