-#define USE_DISKIO 1\r
-\r
-EFI_STATUS\r
-EblDiskIoCmd (\r
- IN UINTN Argc,\r
- IN CHAR8 **Argv\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN Offset;\r
- UINT8 *EndOffset;\r
- UINTN Length;\r
- UINTN Line;\r
- UINT8 *Buffer;\r
- UINT8 *BufferOffset;\r
- CHAR8 TextLine[0x11];\r
-#if USE_DISKIO\r
- EFI_DISK_IO_PROTOCOL *DiskIo;\r
-#else\r
- EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
- UINTN Lba;\r
-#endif \r
-\r
- if (AsciiStrCmp(Argv[1], "r") == 0)\r
- { \r
- Offset = AsciiStrHexToUintn(Argv[2]);\r
- Length = AsciiStrHexToUintn(Argv[3]);\r
-\r
-#if USE_DISKIO\r
- Status = gBS->LocateProtocol(&gEfiDiskIoProtocolGuid, NULL, (VOID **)&DiskIo);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("Did not locate DiskIO\n");\r
- return Status;\r
- }\r
-\r
- Buffer = AllocatePool(Length);\r
- BufferOffset = Buffer;\r
- \r
- Status = DiskIo->ReadDisk(DiskIo, SIGNATURE_32('f','l','s','h'), Offset, Length, Buffer);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("DiskIO read failed\n");\r
- gBS->FreePool(Buffer);\r
- return Status;\r
- } \r
-#else\r
- Status = gBS->LocateProtocol(&gEfiBlockIoProtocolGuid, NULL, (VOID **)&BlockIo);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("Did not locate BlockIo\n");\r
- return Status;\r
- }\r
- \r
- Length = BlockIo->Media->BlockSize;\r
- Buffer = AllocatePool(Length);\r
- BufferOffset = Buffer;\r
- Lba = Offset/BlockIo->Media->BlockSize;\r
- \r
- Status = BlockIo->ReadBlocks(BlockIo, BlockIo->Media->MediaId, Lba, Length, Buffer);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("BlockIo read failed\n");\r
- gBS->FreePool(Buffer);\r
- return Status;\r
- }\r
- \r
- // Whack offset to what we actually read from\r
- Offset = Lba * BlockIo->Media->BlockSize;\r
- \r
- Length = 0x100;\r
-#endif\r
-\r
- for (EndOffset = BufferOffset + Length; BufferOffset < EndOffset; Offset += 0x10)\r
- {\r
- AsciiPrint ("%08x: ", Offset);\r
- \r
- for (Line = 0; Line < 0x10; Line++)\r
- {\r
- AsciiPrint ("%02x ", *BufferOffset);\r
-\r
- if (*BufferOffset < ' ' || *BufferOffset > '~')\r
- TextLine[Line] = '.';\r
- else\r
- TextLine[Line] = *BufferOffset;\r
- \r
- BufferOffset++;\r
- }\r
-\r
- TextLine[Line] = '\0';\r
- AsciiPrint ("|%a|\n", TextLine);\r
- }\r
- \r
- gBS->FreePool(Buffer);\r
-\r
- return EFI_SUCCESS;\r
- }\r
- else if (AsciiStrCmp(Argv[1], "w") == 0)\r
- {\r
- Offset = AsciiStrHexToUintn(Argv[2]);\r
- Length = AsciiStrHexToUintn(Argv[3]);\r
- Buffer = (UINT8 *)AsciiStrHexToUintn(Argv[4]);\r
- \r
-#if USE_DISKIO\r
- Status = gBS->LocateProtocol(&gEfiDiskIoProtocolGuid, NULL, (VOID **)&DiskIo);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("Did not locate DiskIO\n");\r
- return Status;\r
- }\r
-\r
- Status = DiskIo->WriteDisk(DiskIo, SIGNATURE_32('f','l','s','h'), Offset, Length, Buffer);\r
- if (EFI_ERROR(Status))\r
- {\r
- AsciiPrint("DiskIO write failed\n");\r
- return Status;\r
- }\r
-\r
-#else\r
-#endif\r
-\r
- return EFI_SUCCESS;\r
- }\r
- else\r
- {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-}\r