EFI_STATUS BdsLoadOptionMemMapUpdateDevicePath ( IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath ) { EFI_STATUS Status; CHAR16 StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX]; CHAR16 StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX]; MEMMAP_DEVICE_PATH* EndingDevicePath; EFI_DEVICE_PATH* DevicePath; DevicePath = DuplicateDevicePath (OldDevicePath); EndingDevicePath = (MEMMAP_DEVICE_PATH*)GetLastDevicePathNode (DevicePath); Print(L"Starting Address of the %s: ", FileName); UnicodeSPrint (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->StartingAddress); Status = EditHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { //return EFI_ABORTED; goto Exit; } Print(L"Ending Address of the %s: ", FileName); UnicodeSPrint (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->EndingAddress); Status = EditHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { goto Exit; //return EFI_ABORTED; } EndingDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress); EndingDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress); Exit: if (EFI_ERROR(Status)) { FreePool(DevicePath); } else { *NewDevicePath = DevicePath; } return Status; }
/** Function try to convert a string to GUID format. @param[in] String The string will be converted. @param[out] Guid Save the result convert from string. @retval EFI_SUCCESS The string was successfully converted to a GUID. @retval EFI_UNSUPPORTED The input string is not in registry format. **/ EFI_STATUS ConvertStrToGuid( IN CONST CHAR16 *String, OUT GUID *Guid ) { CONST CHAR16 *Walker; UINT8 TempValue; UINTN Index; if (String == NULL || !IsValidGuidString (String)) { return EFI_UNSUPPORTED; } Index = 0; Walker = String; Guid->Data1 = (UINT32)StrHexToUint64 (Walker); Walker += 9; Guid->Data2 = (UINT16)StrHexToUint64 (Walker); Walker += 5; Guid->Data3 = (UINT16)StrHexToUint64 (Walker); Walker += 5; while (Walker != NULL && *Walker != CHAR_NULL) { if (*Walker == L'-') { Walker++; } else { TempValue = (UINT8)HexCharToDecimal (*Walker); TempValue = (UINT8)LShiftU64 (TempValue, 4); Walker++; TempValue += (UINT8)HexCharToDecimal (*Walker); Walker++; Guid->Data4[Index] = TempValue; Index++; } } return EFI_SUCCESS; }
EFI_STATUS BdsLoadOptionMemMapCreateDevicePath ( IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { EFI_STATUS Status; MEMMAP_DEVICE_PATH *MemMapDevicePath; CHAR16 StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX]; CHAR16 StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX]; Print(L"Starting Address of the %s: ", FileName); Status = GetHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { return EFI_ABORTED; } Print(L"Ending Address of the %s: ", FileName); Status = GetHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { return EFI_ABORTED; } // Create the MemMap Device Path Node MemMapDevicePath = (MEMMAP_DEVICE_PATH*)AllocatePool (sizeof(MEMMAP_DEVICE_PATH) + END_DEVICE_PATH_LENGTH); if (NULL == MemMapDevicePath) { return EFI_OUT_OF_RESOURCES; } MemMapDevicePath->Header.Type = HARDWARE_DEVICE_PATH; MemMapDevicePath->Header.SubType = HW_MEMMAP_DP; SetDevicePathNodeLength (MemMapDevicePath, sizeof(MEMMAP_DEVICE_PATH)); MemMapDevicePath->MemoryType = EfiBootServicesData; MemMapDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress); MemMapDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress); // Set a Device Path End Node after the Memory Map Device Path Node SetDevicePathEndNode (MemMapDevicePath + 1); *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath; return Status; }