From 6878e7a7be6a29da75fca61ba42681fc64a3fdf3 Mon Sep 17 00:00:00 2001 From: jcarsey Date: Tue, 12 Apr 2011 21:55:07 +0000 Subject: update Bcfg to correctly remove by option index not variable name and add driver order items properly. update connect and reconnect to account for ignoring the child handle in the connect operation. update disconnect to output correctly. hexedit corrected to properly display status bar and title bar and refresh when required. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11525 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c | 189 ++++++++++++++++----- .../UefiShellDebug1CommandsLib/EditStatusBar.c | 25 ++- .../HexEdit/MainHexEditor.c | 34 +++- .../Library/UefiShellDriver1CommandsLib/Connect.c | 32 ++-- .../UefiShellDriver1CommandsLib/Disconnect.c | 2 +- .../UefiShellDriver1CommandsLib/Reconnect.c | 5 + .../UefiShellDriver1CommandsLib.c | 2 + .../UefiShellDriver1CommandsLib.h | 1 + .../Library/UefiShellInstall1CommandsLib/Bcfg.c | 189 ++++++++++++++++----- 9 files changed, 358 insertions(+), 121 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index e6884a2d59..c2b14d7ee7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -47,6 +47,63 @@ typedef struct { CONST CHAR16 *OptData; } BGFG_OPERATION; +/** + This function will populate the device path protocol parameter based on TheHandle. + + @param[in,out] DevPath On a sucessful return the device path to the handle. + + @retval EFI_SUCCESS The device path was sucessfully returned. + @retval other A error from gBS->HandleProtocol. + + @sa HandleProtocol +**/ +EFI_STATUS +EFIAPI +GetDevicePathForDriverHandleDebug1 ( + IN EFI_HANDLE TheHandle, + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath + ) +{ + EFI_STATUS Status; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiLoadedImageProtocolGuid, + (VOID**)&LoadedImage, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Status = gBS->OpenProtocol ( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&ImageDevicePath, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { +// *DevPath = DuplicateDevicePath (ImageDevicePath); +// *FilePath = DuplicateDevicePath (LoadedImage->FilePath); + *FilePath = AppendDevicePath(ImageDevicePath,LoadedImage->FilePath); + gBS->CloseProtocol( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + gImageHandle, + NULL); + } + gBS->CloseProtocol( + TheHandle, + &gEfiLoadedImageProtocolGuid, + gImageHandle, + NULL); + } + return (Status); +} + /** Function to add a option. @@ -81,9 +138,9 @@ BcfgAddDebug1( EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_DEVICE_PATH_PROTOCOL *FileNode; - EFI_DEVICE_PATH_PROTOCOL *DevPath; +// EFI_DEVICE_PATH_PROTOCOL *DevPath; CHAR16 *Str; - CONST CHAR16 *StringWalker; +// CONST CHAR16 *StringWalker; UINT8 *TempByteBuffer; UINT8 *TempByteStart; EFI_SHELL_FILE_INFO *Arg; @@ -100,7 +157,6 @@ BcfgAddDebug1( UINTN ChildControllerHandleCount; SHELL_STATUS ShellStatus; UINT16 *NewOrder; - UINT64 Intermediate; if (!UseHandle) { if (File == NULL || Desc == NULL) { @@ -125,42 +181,79 @@ BcfgAddDebug1( TargetLocation = 0xFFFF; if (UseHandle) { - Status = ShellConvertStringToUint64(File, &Intermediate, TRUE, FALSE); - CurHandle = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (CurHandle == NULL || EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, File); + CurHandle = ConvertHandleIndexToHandle(HandleNumber); + if (CurHandle == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Handle Number"); ShellStatus = SHELL_INVALID_PARAMETER; } else { - // - //Make sure that the handle should point to a real controller - // - Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( - CurHandle, - &DriverBindingHandleCount, - NULL); - - Status = PARSE_HANDLE_DATABASE_PARENTS ( - CurHandle, - &ParentControllerHandleCount, - NULL); - - Status = ParseHandleDatabaseForChildControllers ( - CurHandle, - &ChildControllerHandleCount, - NULL); - - if (DriverBindingHandleCount > 0 - || ParentControllerHandleCount > 0 - || ChildControllerHandleCount > 0) { - FilePath = NULL; + if (Target == BcfgTargetBootOrder) { + // + //Make sure that the handle should point to a real controller + // + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( + CurHandle, + &DriverBindingHandleCount, + NULL); + + Status = PARSE_HANDLE_DATABASE_PARENTS ( + CurHandle, + &ParentControllerHandleCount, + NULL); + + Status = ParseHandleDatabaseForChildControllers ( + CurHandle, + &ChildControllerHandleCount, + NULL); + + if (DriverBindingHandleCount > 0 + || ParentControllerHandleCount > 0 + || ChildControllerHandleCount > 0) { + FilePath = NULL; + Status = gBS->HandleProtocol ( + CurHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&FilePath); + } + if (EFI_ERROR (Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellDebug1HiiHandle, HandleNumber); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + // + //Make sure that the handle should point to driver, not a controller. + // + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( + CurHandle, + &DriverBindingHandleCount, + NULL); + + Status = PARSE_HANDLE_DATABASE_PARENTS ( + CurHandle, + &ParentControllerHandleCount, + NULL); + + Status = ParseHandleDatabaseForChildControllers ( + CurHandle, + &ChildControllerHandleCount, + NULL); + Status = gBS->HandleProtocol ( CurHandle, &gEfiDevicePathProtocolGuid, (VOID**)&FilePath); - } - if (EFI_ERROR (Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellDebug1HiiHandle, Intermediate); - ShellStatus = SHELL_INVALID_PARAMETER; + + if (DriverBindingHandleCount > 0 + || ParentControllerHandleCount > 0 + || ChildControllerHandleCount > 0 + || !EFI_ERROR(Status) ) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Handle Number"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // Get the DevicePath from the loaded image information. + // + Status = GetDevicePathForDriverHandleDebug1(CurHandle, &FilePath); + } } } } else { @@ -199,6 +292,7 @@ BcfgAddDebug1( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellDebug1HiiHandle, Arg->FullName); ShellStatus = SHELL_UNSUPPORTED; } else { +/* if (UsePath) { DevPath = DevicePath; while (!IsDevicePathEnd(DevPath)) { @@ -221,9 +315,11 @@ BcfgAddDebug1( FilePath = AppendDevicePath(DevicePath, FileNode); FreePool(FileNode); } else { +*/ FilePath = DuplicateDevicePath(DevicePath); +/* } - +*/ FreePool(DevicePath); } } @@ -364,16 +460,15 @@ BcfgRemoveDebug1( IN CONST BCFG_OPERATION_TARGET Target, IN CONST UINT16 *CurrentOrder, IN CONST UINTN OrderCount, - IN CONST UINT16 Location + IN CONST UINT16 Location ) { CHAR16 VariableName[12]; UINT16 *NewOrder; EFI_STATUS Status; - UINTN LoopVar; UINTN NewCount; - UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", Location); + UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", CurrentOrder[Location]); Status = gRT->SetVariable( VariableName, (EFI_GUID*)&gEfiGlobalVariableGuid, @@ -388,12 +483,9 @@ BcfgRemoveDebug1( if (NewOrder != NULL) { NewCount = OrderCount; CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0])); - for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){ - if (NewOrder[LoopVar] == Location) { - CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0])); - NewCount--; - } - } + CopyMem(NewOrder+Location, NewOrder+Location+1, (OrderCount - Location - 1)*sizeof(CurrentOrder[0])); + NewCount--; + Status = gRT->SetVariable( Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", (EFI_GUID*)&gEfiGlobalVariableGuid, @@ -542,9 +634,14 @@ BcfgDisplayDumpDebug1( return (SHELL_INVALID_PARAMETER); } - DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); - CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); - DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE); + if ((*(UINT16*)(Buffer+4)) != 0) { + DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); + CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); + DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE); + } else { + DevPath = NULL; + DevPathString = NULL; + } ShellPrintHiiEx( -1, -1, diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c index 3fd604d818..ff3f465ad7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c @@ -125,14 +125,23 @@ StatusBarRefresh ( // // print row, column fields // - ShellPrintEx ( - 0, - (INT32)(LastRow) - 4, - L" Row: %d Col: %d %s", - FileRow, - FileCol, - StatusString - ); + if (FileRow != (UINTN)(-1) && FileCol != (UINTN)(-1)) { + ShellPrintEx ( + 0, + (INT32)(LastRow) - 4, + L" Row: %d Col: %d %s", + FileRow, + FileCol, + StatusString + ); + } else { + ShellPrintEx ( + 0, + (INT32)(LastRow) - 4, + L" %s", + StatusString + ); + } // // print insert mode field diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c index ccd73a9882..83b31992d2 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c @@ -1704,12 +1704,28 @@ HMainEditorRefresh ( NameChange = FALSE; ReadChange = FALSE; - if ( HMainEditor.BufferImage->FileImage != NULL && - HMainEditor.BufferImage->FileImage->FileName != NULL && - HBufferImageBackupVar.FileImage != NULL && - HBufferImageBackupVar.FileImage->FileName != NULL && - StrCmp (HMainEditor.BufferImage->FileImage->FileName, HBufferImageBackupVar.FileImage->FileName) != 0 ) { - NameChange = TRUE; + if (HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer) { + if (HMainEditor.BufferImage->DiskImage != NULL && + HBufferImageBackupVar.DiskImage != NULL && + (HMainEditor.BufferImage->DiskImage->Offset != HBufferImageBackupVar.DiskImage->Offset || + HMainEditor.BufferImage->DiskImage->Size != HBufferImageBackupVar.DiskImage->Size) ){ + NameChange = TRUE; + } + } else if (HMainEditor.BufferImage->BufferType == FileTypeMemBuffer) { + if (HMainEditor.BufferImage->MemImage != NULL && + HBufferImageBackupVar.MemImage != NULL && + (HMainEditor.BufferImage->MemImage->Offset != HBufferImageBackupVar.MemImage->Offset || + HMainEditor.BufferImage->MemImage->Size != HBufferImageBackupVar.MemImage->Size) ){ + NameChange = TRUE; + } + } else if (HMainEditor.BufferImage->BufferType == FileTypeFileBuffer) { + if ( HMainEditor.BufferImage->FileImage != NULL && + HMainEditor.BufferImage->FileImage->FileName != NULL && + HBufferImageBackupVar.FileImage != NULL && + HBufferImageBackupVar.FileImage->FileName != NULL && + StrCmp (HMainEditor.BufferImage->FileImage->FileName, HBufferImageBackupVar.FileImage->FileName) != 0 ) { + NameChange = TRUE; + } } if ( HMainEditor.BufferImage->FileImage != NULL && HBufferImageBackupVar.FileImage != NULL && @@ -1753,9 +1769,9 @@ HMainEditorRefresh ( HEditorFirst, HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column, - 0, - 0, - TRUE + (UINTN)(-1), + (UINTN)(-1), + FALSE ); HBufferImageRefresh (); } diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c index e4e780a437..429964d8c8 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c @@ -277,7 +277,8 @@ ShellCommandRunConnect ( // // if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters // - if ((ShellCommandLineGetCount(Package) > 3) + Count = (gInReconnect?0x4:0x3); + if ((ShellCommandLineGetCount(Package) > Count) ||((ShellCommandLineGetFlag(Package, L"-r") || ShellCommandLineGetFlag(Package, L"-c")) && ShellCommandLineGetCount(Package)>1) ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetFlag(Package, L"-c") ) ){ @@ -328,17 +329,26 @@ ShellCommandRunConnect ( Param2 = ShellCommandLineGetRawValue(Package, 2); Count = ShellCommandLineGetCount(Package); - Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); - Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); - ShellStatus = SHELL_INVALID_PARAMETER; + if (Param1 != NULL) { + Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); + Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle1 = NULL; } - Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE); - Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); - ShellStatus = SHELL_INVALID_PARAMETER; + + if (Param2 != NULL) { + Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE); + Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle2 = NULL; } if (ShellStatus == SHELL_SUCCESS) { diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c index 3a19304b66..96233f9b53 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c @@ -174,7 +174,7 @@ ShellCommandRunDisconnect ( } else { ASSERT(Param1 != NULL); Status = gBS->DisconnectController(Handle1, Handle2, Handle3); - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", Intermediate1, Intermediate2, Intermediate3, Status); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, Status); } } } diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c index 0a8e1b2be8..e6a0fba20d 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c @@ -29,9 +29,14 @@ ShellCommandRunReconnect ( { SHELL_STATUS ShellStatus; + gInReconnect = TRUE; + ShellStatus = ShellCommandRunDisconnect(ImageHandle, SystemTable); if (ShellStatus == SHELL_SUCCESS) { ShellStatus = ShellCommandRunConnect(ImageHandle, SystemTable); } + + gInReconnect = FALSE; + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c index 1673d56880..d802a5d7d4 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c @@ -16,6 +16,8 @@ STATIC CONST CHAR16 mFileName[] = L"Driver1Commands"; EFI_HANDLE gShellDriver1HiiHandle = NULL; +BOOLEAN gInReconnect = FALSE; + CONST EFI_GUID gShellDriver1HiiGuid = \ { \ 0xaf0b742, 0x63ec, 0x45bd, {0x8d, 0xb6, 0x71, 0xad, 0x7f, 0x2f, 0xe8, 0xe8} \ diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h index 699053f2d8..61754a5477 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h @@ -58,6 +58,7 @@ extern EFI_HANDLE gShellDriver1HiiHandle; extern CONST EFI_GUID gShellDriver1HiiGuid; +extern BOOLEAN gInReconnect; /** Function for 'connect' command. diff --git a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c index aeb3fcd10e..f7126e32b7 100644 --- a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c @@ -47,6 +47,63 @@ typedef struct { CONST CHAR16 *OptData; } BGFG_OPERATION; +/** + This function will populate the device path protocol parameter based on TheHandle. + + @param[in,out] DevPath On a sucessful return the device path to the handle. + + @retval EFI_SUCCESS The device path was sucessfully returned. + @retval other A error from gBS->HandleProtocol. + + @sa HandleProtocol +**/ +EFI_STATUS +EFIAPI +GetDevicePathForDriverHandleInstall1 ( + IN EFI_HANDLE TheHandle, + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath + ) +{ + EFI_STATUS Status; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiLoadedImageProtocolGuid, + (VOID**)&LoadedImage, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Status = gBS->OpenProtocol ( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&ImageDevicePath, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { +// *DevPath = DuplicateDevicePath (ImageDevicePath); +// *FilePath = DuplicateDevicePath (LoadedImage->FilePath); + *FilePath = AppendDevicePath(ImageDevicePath,LoadedImage->FilePath); + gBS->CloseProtocol( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + gImageHandle, + NULL); + } + gBS->CloseProtocol( + TheHandle, + &gEfiLoadedImageProtocolGuid, + gImageHandle, + NULL); + } + return (Status); +} + /** Function to add a option. @@ -81,9 +138,9 @@ BcfgAddInstall1( EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_DEVICE_PATH_PROTOCOL *FileNode; - EFI_DEVICE_PATH_PROTOCOL *DevPath; +// EFI_DEVICE_PATH_PROTOCOL *DevPath; CHAR16 *Str; - CONST CHAR16 *StringWalker; +// CONST CHAR16 *StringWalker; UINT8 *TempByteBuffer; UINT8 *TempByteStart; EFI_SHELL_FILE_INFO *Arg; @@ -100,7 +157,6 @@ BcfgAddInstall1( UINTN ChildControllerHandleCount; SHELL_STATUS ShellStatus; UINT16 *NewOrder; - UINT64 Intermediate; if (!UseHandle) { if (File == NULL || Desc == NULL) { @@ -125,42 +181,79 @@ BcfgAddInstall1( TargetLocation = 0xFFFF; if (UseHandle) { - Status = ShellConvertStringToUint64(File, &Intermediate, TRUE, FALSE); - CurHandle = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (CurHandle == NULL || EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, File); + CurHandle = ConvertHandleIndexToHandle(HandleNumber); + if (CurHandle == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, L"Handle Number"); ShellStatus = SHELL_INVALID_PARAMETER; } else { - // - //Make sure that the handle should point to a real controller - // - Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( - CurHandle, - &DriverBindingHandleCount, - NULL); - - Status = PARSE_HANDLE_DATABASE_PARENTS ( - CurHandle, - &ParentControllerHandleCount, - NULL); - - Status = ParseHandleDatabaseForChildControllers ( - CurHandle, - &ChildControllerHandleCount, - NULL); - - if (DriverBindingHandleCount > 0 - || ParentControllerHandleCount > 0 - || ChildControllerHandleCount > 0) { - FilePath = NULL; + if (Target == BcfgTargetBootOrder) { + // + //Make sure that the handle should point to a real controller + // + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( + CurHandle, + &DriverBindingHandleCount, + NULL); + + Status = PARSE_HANDLE_DATABASE_PARENTS ( + CurHandle, + &ParentControllerHandleCount, + NULL); + + Status = ParseHandleDatabaseForChildControllers ( + CurHandle, + &ChildControllerHandleCount, + NULL); + + if (DriverBindingHandleCount > 0 + || ParentControllerHandleCount > 0 + || ChildControllerHandleCount > 0) { + FilePath = NULL; + Status = gBS->HandleProtocol ( + CurHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&FilePath); + } + if (EFI_ERROR (Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellInstall1HiiHandle, HandleNumber); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + // + //Make sure that the handle should point to driver, not a controller. + // + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( + CurHandle, + &DriverBindingHandleCount, + NULL); + + Status = PARSE_HANDLE_DATABASE_PARENTS ( + CurHandle, + &ParentControllerHandleCount, + NULL); + + Status = ParseHandleDatabaseForChildControllers ( + CurHandle, + &ChildControllerHandleCount, + NULL); + Status = gBS->HandleProtocol ( CurHandle, &gEfiDevicePathProtocolGuid, (VOID**)&FilePath); - } - if (EFI_ERROR (Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellInstall1HiiHandle, Intermediate); - ShellStatus = SHELL_INVALID_PARAMETER; + + if (DriverBindingHandleCount > 0 + || ParentControllerHandleCount > 0 + || ChildControllerHandleCount > 0 + || !EFI_ERROR(Status) ) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, L"Handle Number"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // Get the DevicePath from the loaded image information. + // + Status = GetDevicePathForDriverHandleInstall1(CurHandle, &FilePath); + } } } } else { @@ -199,6 +292,7 @@ BcfgAddInstall1( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellInstall1HiiHandle, Arg->FullName); ShellStatus = SHELL_UNSUPPORTED; } else { +/* if (UsePath) { DevPath = DevicePath; while (!IsDevicePathEnd(DevPath)) { @@ -221,9 +315,11 @@ BcfgAddInstall1( FilePath = AppendDevicePath(DevicePath, FileNode); FreePool(FileNode); } else { +*/ FilePath = DuplicateDevicePath(DevicePath); +/* } - +*/ FreePool(DevicePath); } } @@ -364,16 +460,15 @@ BcfgRemoveInstall1( IN CONST BCFG_OPERATION_TARGET Target, IN CONST UINT16 *CurrentOrder, IN CONST UINTN OrderCount, - IN CONST UINT16 Location + IN CONST UINT16 Location ) { CHAR16 VariableName[12]; UINT16 *NewOrder; EFI_STATUS Status; - UINTN LoopVar; UINTN NewCount; - UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", Location); + UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", CurrentOrder[Location]); Status = gRT->SetVariable( VariableName, (EFI_GUID*)&gEfiGlobalVariableGuid, @@ -388,12 +483,9 @@ BcfgRemoveInstall1( if (NewOrder != NULL) { NewCount = OrderCount; CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0])); - for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){ - if (NewOrder[LoopVar] == Location) { - CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0])); - NewCount--; - } - } + CopyMem(NewOrder+Location, NewOrder+Location+1, (OrderCount - Location - 1)*sizeof(CurrentOrder[0])); + NewCount--; + Status = gRT->SetVariable( Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", (EFI_GUID*)&gEfiGlobalVariableGuid, @@ -542,9 +634,14 @@ BcfgDisplayDumpInstall1( return (SHELL_INVALID_PARAMETER); } - DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); - CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); - DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE); + if ((*(UINT16*)(Buffer+4)) != 0) { + DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); + CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); + DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE); + } else { + DevPath = NULL; + DevPathString = NULL; + } ShellPrintHiiEx( -1, -1, -- cgit v1.2.3