X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FBcfg.c;h=73831d267e1cbf249ef9760e94351ee90c01d6b7;hp=d278ee60e6696d7d717670a1fb99cb53a089821f;hb=e3df6949e7e2a4578660d4079988487a147c91b7;hpb=33c031ee2092282a069ce07d30202082ceaf61fe diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index d278ee60e6..73831d267e 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -1,7 +1,7 @@ /** @file Main file for bcfg shell Debug1 function. - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -47,6 +47,219 @@ typedef struct { CONST CHAR16 *OptData; } BGFG_OPERATION; +/** + Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3. + + @param KeyOption Pointer to the EFI_KEY_OPTION structure. + + @return Actual number of entries in EFI_KEY_OPTION.Keys. +**/ +#define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) \ + (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK)) + +/** + Update the optional data for a boot or driver option. + + If optional data exists it will be changed. + + @param[in] Index The boot or driver option index update. + @param[in] DataSize The size in bytes of Data. + @param[in] Data The buffer for the optioanl data. + @param[in] Target The target of the operation. + + @retval EFI_SUCCESS The data was sucessfully updated. + @retval other A error occured. +**/ +EFI_STATUS +EFIAPI +UpdateOptionalDataDebug1( + UINT16 Index, + UINTN DataSize, + UINT8 *Data, + IN CONST BCFG_OPERATION_TARGET Target + ) +{ + EFI_STATUS Status; + CHAR16 VariableName[12]; + UINTN OriginalSize; + UINT8 *OriginalData; + UINTN NewSize; + UINT8 *NewData; + UINTN OriginalOptionDataSize; + + UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", Index); + + OriginalSize = 0; + OriginalData = NULL; + NewData = NULL; + NewSize = 0; + + Status = gRT->GetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + NULL, + &OriginalSize, + OriginalData); + if (Status == EFI_BUFFER_TOO_SMALL) { + OriginalData = AllocateZeroPool(OriginalSize); + if (OriginalData == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + Status = gRT->GetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + NULL, + &OriginalSize, + OriginalData); + } + + if (!EFI_ERROR(Status)) { + // + // Allocate new struct and discard old optional data. + // + ASSERT (OriginalData != NULL); + OriginalOptionDataSize = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16)))); + OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32))); + OriginalOptionDataSize -= OriginalSize; + NewSize = OriginalSize - OriginalOptionDataSize + DataSize; + NewData = AllocateCopyPool(NewSize, OriginalData); + if (NewData == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + CopyMem(NewData + OriginalSize - OriginalOptionDataSize, Data, DataSize); + } + } + + if (!EFI_ERROR(Status)) { + // + // put the data back under the variable + // + Status = gRT->SetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS, + NewSize, + NewData); + } + + SHELL_FREE_NON_NULL(OriginalData); + SHELL_FREE_NON_NULL(NewData); + return (Status); +} + +/** + This function will get a CRC for a boot option. + + @param[in, out] Crc The CRC value to return. + @param[in] BootIndex The boot option index to CRC. + + @retval EFI_SUCCESS The CRC was sucessfully returned. + @retval other A error occured. +**/ +EFI_STATUS +EFIAPI +GetBootOptionCrcDebug1( + UINT32 *Crc, + UINT16 BootIndex + ) +{ + CHAR16 VariableName[12]; + EFI_STATUS Status; + UINT8 *Buffer; + UINTN BufferSize; + + Buffer = NULL; + BufferSize = 0; + + // + // Get the data Buffer + // + UnicodeSPrint(VariableName, sizeof(VariableName), L"%Boot%04x", BootIndex); + Status = gRT->GetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + NULL, + &BufferSize, + NULL); + if (Status == EFI_BUFFER_TOO_SMALL) { + Buffer = AllocateZeroPool(BufferSize); + Status = gRT->GetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + NULL, + &BufferSize, + Buffer); + } + + // + // Get the CRC computed + // + if (!EFI_ERROR(Status)) { + Status = gBS->CalculateCrc32 (Buffer, BufferSize, Crc); + } + + SHELL_FREE_NON_NULL(Buffer); + return EFI_SUCCESS; +} + +/** + This function will populate the device path protocol parameter based on TheHandle. + + @param[in] TheHandle Driver handle. + @param[in, out] FilePath 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. @@ -80,10 +293,8 @@ BcfgAddDebug1( EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *FilePath; - EFI_DEVICE_PATH_PROTOCOL *FileNode; - EFI_DEVICE_PATH_PROTOCOL *DevPath; + /* EFI_DEVICE_PATH_PROTOCOL *FileNode; */ CHAR16 *Str; - CONST CHAR16 *StringWalker; UINT8 *TempByteBuffer; UINT8 *TempByteStart; EFI_SHELL_FILE_INFO *Arg; @@ -100,7 +311,6 @@ BcfgAddDebug1( UINTN ChildControllerHandleCount; SHELL_STATUS ShellStatus; UINT16 *NewOrder; - UINT64 Intermediate; if (!UseHandle) { if (File == NULL || Desc == NULL) { @@ -118,49 +328,86 @@ BcfgAddDebug1( Str = NULL; FilePath = NULL; - FileNode = NULL; + /* FileNode = NULL; */ FileList = NULL; Handles = NULL; ShellStatus = SHELL_SUCCESS; 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 { @@ -194,11 +441,12 @@ BcfgAddDebug1( // // get the device path // - DevicePath = mEfiShellProtocol->GetDevicePathFromFilePath(Arg->FullName); + DevicePath = gEfiShellProtocol->GetDevicePathFromFilePath(Arg->FullName); if (DevicePath == NULL) { 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 +469,11 @@ BcfgAddDebug1( FilePath = AppendDevicePath(DevicePath, FileNode); FreePool(FileNode); } else { +*/ FilePath = DuplicateDevicePath(DevicePath); +/* } - +*/ FreePool(DevicePath); } } @@ -275,6 +525,7 @@ BcfgAddDebug1( CopyMem (TempByteBuffer, Desc, DescSize); TempByteBuffer += DescSize; + ASSERT (FilePath != NULL); CopyMem (TempByteBuffer, FilePath, FilePathSize); UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation); @@ -324,14 +575,10 @@ BcfgAddDebug1( } } } - if (FileNode != NULL) { - FreePool (FileNode); - } // //If always Free FilePath, will free devicepath in system when use "addh" // - if (FilePath!=NULL && !UseHandle) { FreePool (FilePath); } @@ -368,16 +615,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, @@ -392,12 +638,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, @@ -467,15 +710,284 @@ BcfgMoveDebug1( return (SHELL_SUCCESS); } +/** + Function to add optional data to an option. + + @param[in] OptData The optional data to add. + @param[in] CurrentOrder The pointer to the current order of items. + @param[in] OrderCount The number if items in CurrentOrder. + @param[in] Target The target of the operation. + + @retval SHELL_SUCCESS The operation was succesful. +**/ SHELL_STATUS EFIAPI BcfgAddOptDebug1( IN CONST CHAR16 *OptData, + IN CONST UINT16 *CurrentOrder, + IN CONST UINTN OrderCount, IN CONST BCFG_OPERATION_TARGET Target ) { - ASSERT(OptData != NULL); - return SHELL_SUCCESS; + EFI_KEY_OPTION NewKeyOption; + EFI_KEY_OPTION *KeyOptionBuffer; + SHELL_STATUS ShellStatus; + EFI_STATUS Status; + UINT16 OptionIndex; + UINT16 LoopCounter; + UINT64 Intermediate; + CONST CHAR16 *Temp; + CONST CHAR16 *Walker; + CHAR16 *FileName; + CHAR16 *Temp2; + CHAR16 *Data; + UINT16 KeyIndex; + CHAR16 VariableName[12]; + + SHELL_FILE_HANDLE FileHandle; + + Status = EFI_SUCCESS; + ShellStatus = SHELL_SUCCESS; + Walker = OptData; + FileName = NULL; + Data = NULL; + KeyOptionBuffer = NULL; + + ZeroMem(&NewKeyOption, sizeof(EFI_KEY_OPTION)); + + while(Walker[0] == L' ') { + Walker++; + } + + // + // Get the index of the variable we are changing. + // + Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE); + if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL || ((UINT16)Intermediate) > ((UINT16)OrderCount)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Option Index"); + ShellStatus = SHELL_INVALID_PARAMETER; + return (ShellStatus); + } + OptionIndex = (UINT16)Intermediate; + + Temp = StrStr(Walker, L" "); + if (Temp != NULL) { + Walker = Temp; + } + while(Walker[0] == L' ') { + Walker++; + } + + // + // determine whether we have file with data, quote delimited information, or a hot-key + // + if (Walker[0] == L'\"') { + // + // quoted filename or quoted information. + // + Temp = StrStr(Walker+1, L"\""); + if (Temp == NULL || StrLen(Temp) != 1) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0); + if (FileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + return (ShellStatus); + } + Temp2 = StrStr(FileName, L"\""); + ASSERT(Temp2 != NULL); + Temp2[0] = CHAR_NULL; + Temp2++; + if (StrLen(Temp2)>0) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } + if (EFI_ERROR(ShellFileExists(Walker))) { + // + // Not a file. must be misc information. + // + Data = FileName; + FileName = NULL; + } else { + FileName = StrnCatGrow(&FileName, NULL, Walker, 0); + } + } + } else { + // + // filename or hot key information. + // + if (StrStr(Walker, L" ") == NULL) { + // + // filename + // + if (EFI_ERROR(ShellFileExists(Walker))) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + FileName = StrnCatGrow(&FileName, NULL, Walker, 0); + } + } else { + if (Target != BcfgTargetBootOrder) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_BOOT_ONLY), gShellDebug1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus == SHELL_SUCCESS) { + // + // Get hot key information + // + Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE); + if (EFI_ERROR(Status) || (((UINT32)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } + NewKeyOption.KeyData = (UINT32)Intermediate; + Temp = StrStr(Walker, L" "); + if (Temp != NULL) { + Walker = Temp; + } + while(Walker[0] == L' ') { + Walker++; + } + } + + if (ShellStatus == SHELL_SUCCESS) { + // + // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct. + // Re-allocate with the added information. + // + KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)), &NewKeyOption); + if (KeyOptionBuffer == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + } + } + for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption); LoopCounter++) { + // + // ScanCode + // + Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE); + if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } + ((EFI_INPUT_KEY*)(((UINT8*)KeyOptionBuffer) + sizeof(EFI_KEY_OPTION)))[LoopCounter].ScanCode = (UINT16)Intermediate; + Temp = StrStr(Walker, L" "); + if (Temp != NULL) { + Walker = Temp; + } + while(Walker[0] == L' ') { + Walker++; + } + + // + // UnicodeChar + // + Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE); + if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); + ShellStatus = SHELL_INVALID_PARAMETER; + } + ((EFI_INPUT_KEY*)(((UINT8*)KeyOptionBuffer) + sizeof(EFI_KEY_OPTION)))[LoopCounter].UnicodeChar = (UINT16)Intermediate; + Temp = StrStr(Walker, L" "); + if (Temp != NULL) { + Walker = Temp; + } + while(Walker[0] == L' ') { + Walker++; + } + } + + if (ShellStatus == SHELL_SUCCESS) { + // + // Now do the BootOption / BootOptionCrc + // + ASSERT (OptionIndex <= OrderCount); + KeyOptionBuffer->BootOption = CurrentOrder[OptionIndex]; + Status = GetBootOptionCrcDebug1(&(KeyOptionBuffer->BootOptionCrc), KeyOptionBuffer->BootOption); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Option Index"); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + + if (ShellStatus == SHELL_SUCCESS) { + for (Temp2 = NULL, KeyIndex = 0 ; KeyIndex < 0xFFFF ; KeyIndex++) { + UnicodeSPrint(VariableName, sizeof(VariableName), L"Key%04x", KeyIndex); + Status = gRT->GetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + NULL, + (UINTN*)&Intermediate, + NULL); + if (Status == EFI_NOT_FOUND) { + break; + } + } + Status = gRT->SetVariable( + VariableName, + (EFI_GUID*)&gEfiGlobalVariableGuid, + EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)), + KeyOptionBuffer); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); + ShellStatus = SHELL_INVALID_PARAMETER; + } + ASSERT(FileName == NULL && Data == NULL); + } + } + } + + // + // Shouldn't be possible to have have both. Neither is ok though. + // + ASSERT(FileName == NULL || Data == NULL); + + if (ShellStatus == SHELL_SUCCESS && (FileName != NULL || Data != NULL)) { + if (FileName != NULL) { + // + // Open the file and populate the data buffer. + // + Status = ShellOpenFileByName( + FileName, + &FileHandle, + EFI_FILE_MODE_READ, + 0); + if (!EFI_ERROR(Status)) { + Status = ShellGetFileSize(FileHandle, &Intermediate); + } + Data = AllocateZeroPool((UINTN)Intermediate); + if (Data == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + } + if (!EFI_ERROR(Status)) { + Status = ShellReadFile(FileHandle, (UINTN *)&Intermediate, Data); + } + } else { + Intermediate = StrSize(Data); + } + + if (!EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS && Data != NULL) { + Status = UpdateOptionalDataDebug1(CurrentOrder[OptionIndex], (UINTN)Intermediate, (UINT8*)Data, Target); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + + SHELL_FREE_NON_NULL(Data); + SHELL_FREE_NON_NULL(KeyOptionBuffer); + SHELL_FREE_NON_NULL(FileName); + return ShellStatus; } /** @@ -538,9 +1050,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 = ConvertDevicePathToText(DevPath, TRUE, FALSE); + } else { + DevPath = NULL; + DevPathString = NULL; + } ShellPrintHiiEx( -1, -1, @@ -696,7 +1213,7 @@ ShellCommandRunBcfg ( // // Read in the boot or driver order environment variable (not needed for opt) // - if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type != BcfgTypeOpt) { + if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax) { Length = 0; Status = gRT->GetVariable( CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", @@ -876,7 +1393,7 @@ ShellCommandRunBcfg ( ShellStatus = BcfgAddDebug1( CurrentOperation.Number1, CurrentOperation.FileName, - CurrentOperation.Description, + CurrentOperation.Description==NULL?L"":CurrentOperation.Description, CurrentOperation.Order, Length / sizeof(CurrentOperation.Order[0]), CurrentOperation.Target, @@ -887,6 +1404,8 @@ ShellCommandRunBcfg ( case BcfgTypeOpt: ShellStatus = BcfgAddOptDebug1( CurrentOperation.OptData, + CurrentOperation.Order, + Length / sizeof(CurrentOperation.Order[0]), CurrentOperation.Target); break; default: