summaryrefslogtreecommitdiffstats
path: root/memtestEDK
diff options
context:
space:
mode:
authorRegina König2020-08-21 12:13:13 +0200
committerRegina König2020-08-21 12:13:13 +0200
commitd71b67c551f6f3a280afe9c6af56e44c0fc270fb (patch)
treeea2d533b24f231e9680c4a53f532157ead3c77a1 /memtestEDK
parentmodified ProtocolInformation.c (diff)
downloadmemtest86-d71b67c551f6f3a280afe9c6af56e44c0fc270fb.tar.gz
memtest86-d71b67c551f6f3a280afe9c6af56e44c0fc270fb.tar.xz
memtest86-d71b67c551f6f3a280afe9c6af56e44c0fc270fb.zip
created Logger.c. It's structure should be the final version for use in memtest
Diffstat (limited to 'memtestEDK')
-rw-r--r--memtestEDK/MdeModulePkg.dsc1
-rw-r--r--memtestEDK/Memtest/ProtocolInformation/Logger.c249
-rw-r--r--memtestEDK/Memtest/ProtocolInformation/Logger.inf32
3 files changed, 282 insertions, 0 deletions
diff --git a/memtestEDK/MdeModulePkg.dsc b/memtestEDK/MdeModulePkg.dsc
index 09bc5a1..34210e1 100644
--- a/memtestEDK/MdeModulePkg.dsc
+++ b/memtestEDK/MdeModulePkg.dsc
@@ -210,6 +210,7 @@
# Memtest/GraphicsOutput/GraphicsOutputProtocol.inf
Memtest/GraphicsOutput/TextOutput.inf
Memtest/Test1/doTest1.inf
+ Memtest/ProtocolInformation/Logger.inf
# MdeModulePkg/Application/HelloWorld/HelloWorld.inf
# MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf
diff --git a/memtestEDK/Memtest/ProtocolInformation/Logger.c b/memtestEDK/Memtest/ProtocolInformation/Logger.c
new file mode 100644
index 0000000..8f448c5
--- /dev/null
+++ b/memtestEDK/Memtest/ProtocolInformation/Logger.c
@@ -0,0 +1,249 @@
+/*
+TODO Description
+
+
+*/
+
+#include <stdio.h>
+
+#include <Uefi.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiApplicationEntryPoint.h>
+#include <Include/Guid/FileSystemInfo.h>
+
+
+EFI_STATUS efiStatus;
+EFI_BOOT_SERVICES* bs;
+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console;
+
+EFI_GUID sfspGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+
+EFI_HANDLE* handleBuffer = NULL;
+EFI_HANDLE* handleBuffer2 = NULL; // TODO remove
+UINTN handleCount = 0;
+UINTN handleCount2 = 0;
+UINTN handleIndex;
+
+EFI_GUID **ProtocolGuidArray;
+UINTN ArrayCount;
+UINTN ProtocolIndex;
+
+EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
+UINTN OpenInfoIndex;
+UINTN OpenInfoCount;
+
+void printFileSystemInfo(EFI_FILE_SYSTEM_INFO* fileSystemInfo) {
+
+ Print(L"fileSystemInfo pointer %p\n", fileSystemInfo);
+
+ CHAR16* volumeLabel = fileSystemInfo->VolumeLabel;
+ Print(L"VolumeLabel: %a\n", volumeLabel);
+ Print(L"Size of volume Label: %d\n", sizeof(fileSystemInfo->VolumeLabel));
+ Print(L"Size: %d\n", fileSystemInfo->Size);
+ Print(L"ReadOnly: %d\n", fileSystemInfo->ReadOnly);
+ Print(L"VolumeSize: %d\n", fileSystemInfo->VolumeSize);
+ Print(L"FreeSpace: %d\n", fileSystemInfo->FreeSpace);
+ Print(L"BlockSize: %d\n", fileSystemInfo->BlockSize);
+}
+
+void printFileContent(UINTN fileSize, CHAR16* fileBuffer) {
+ Print(L"File Size: %d\n", fileSize);
+ Print(L"File Content: %a\n", fileBuffer);
+}
+
+void checkStatus(EFI_STATUS es, char *msg) {
+ if (es != EFI_SUCCESS) {
+ Print(L"Point of failure: %a\n", msg);
+ Print(L"Exit with status: %r\n", es);
+ Exit(1);
+ }
+}
+
+BOOLEAN compareGuids(EFI_GUID* sfspGuid, EFI_GUID* guid) {
+ if (guid->Data1 == sfspGuid->Data1 && guid->Data2 == sfspGuid->Data2 && guid->Data3 == sfspGuid->Data3
+ && guid->Data4[0] == sfspGuid->Data4[0] && guid->Data4[1] == sfspGuid->Data4[1]
+ && guid->Data4[2] == sfspGuid->Data4[2] && guid->Data4[3] == sfspGuid->Data4[3]
+ && guid->Data4[4] == sfspGuid->Data4[4] && guid->Data4[5] == sfspGuid->Data4[5]
+ && guid->Data4[6] == sfspGuid->Data4[6] && guid->Data4[7] == sfspGuid->Data4[7]) {
+
+ Print(L"GUID: %x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x\n",
+ guid->Data1, guid->Data2, guid->Data3,
+ guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
+ guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ bs = SystemTable->BootServices;
+ Console = SystemTable->ConOut;
+
+ //
+ // Get all Handles
+ //
+ efiStatus = bs->LocateHandleBuffer (
+ AllHandles,
+ NULL,
+ NULL,
+ &handleCount,
+ &handleBuffer
+ );
+ checkStatus(efiStatus, "LocateHandleBuffer");
+
+ for (handleIndex = 0; handleIndex < handleCount; handleIndex++) {
+ //
+ // Retrieve the list of all the protocols on each handle
+ //
+ efiStatus = bs->ProtocolsPerHandle (
+ handleBuffer[handleIndex],
+ &ProtocolGuidArray,
+ &ArrayCount
+ );
+ checkStatus(efiStatus, "ProtocolsPerHandle");
+
+ //
+ // Search for protocol with EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
+ //
+ for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
+
+ EFI_GUID *guid = ProtocolGuidArray[ProtocolIndex];
+
+ if (compareGuids(&sfspGuid, guid)) {
+
+ //
+ // Retrieve the protocol instance for each protocol
+ //
+ efiStatus = bs->OpenProtocol (
+ handleBuffer[handleIndex],
+ ProtocolGuidArray[ProtocolIndex],
+ NULL,
+ ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+ );
+ checkStatus(efiStatus, "OpenProtocol");
+
+ //
+ // Retrieve the list of agents that have opened each protocol
+ //
+ efiStatus = bs->OpenProtocolInformation (
+ handleBuffer[handleIndex],
+ ProtocolGuidArray[ProtocolIndex],
+ &OpenInfo,
+ &OpenInfoCount // Number of agents that have opened the protocol
+ );
+ checkStatus(efiStatus, "OpenProtocolInformation");
+
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs = NULL;
+
+ efiStatus = bs->HandleProtocol( // TODO Should use OpenProtocol() in new implementations
+ handleBuffer[handleIndex],
+ &sfspGuid,
+ (void**)&fs
+ );
+ checkStatus(efiStatus, "HandleProtocol");
+
+ EFI_FILE_PROTOCOL* root = NULL;
+ efiStatus = fs->OpenVolume(fs, &root);
+ checkStatus(efiStatus, "OpenVolume");
+
+ EFI_GUID fsiGuid = EFI_FILE_SYSTEM_INFO_ID;
+ UINTN bufSize = 0;
+ EFI_FILE_SYSTEM_INFO* fileSystemInfo = NULL;
+ // First time it is expected to fail
+ efiStatus = root->GetInfo(
+ root,
+ &fsiGuid,
+ &bufSize,
+ &fileSystemInfo);
+
+ efiStatus = bs->AllocatePool(EfiLoaderData, (UINTN) (bufSize) , (void **)&fileSystemInfo);
+ checkStatus(efiStatus, "AllocatePool"); // TODO Free pool
+
+ efiStatus = root->GetInfo(
+ root,
+ &fsiGuid,
+ &bufSize,
+ fileSystemInfo);
+ checkStatus(efiStatus, "GetInfo");
+ //printFileSystemInfo(fileSystemInfo);
+
+ // TODO first check if it is the right filesystem. If yes, leave the for loop
+
+ EFI_FILE_PROTOCOL* token = NULL;
+ efiStatus = root->Open(
+ root,
+ &token,
+ L"memtest_log",
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
+ 0);
+ checkStatus(efiStatus, "Open");
+
+ UINT64 currPos;
+ efiStatus = token->GetPosition(token, &currPos);
+ checkStatus(efiStatus, "GetPosition");
+ Print(L"Current File Position: %d\n", currPos);
+
+ UINTN fileSize = 500; // TODO get the actual size
+ CHAR16* fileBuffer = NULL;
+ efiStatus = bs->AllocatePool(EfiLoaderData, (UINTN) (fileSize) , (void **)&fileBuffer);
+ checkStatus(efiStatus, "AllocatePool for file");
+
+ efiStatus = token->Read(token, &fileSize, fileBuffer);
+ checkStatus(efiStatus, "Read");
+ printFileContent(fileSize, fileBuffer);
+
+ efiStatus = token->GetPosition(token, &currPos);
+ checkStatus(efiStatus, "GetPosition");
+ Print(L"Current File Position: %d\n", currPos);
+
+ char *message = "\nAdding a new line";
+ UINTN length = 19;
+ Print(L"Lengh: %d\n", length);
+
+ if (fileSize >=1) {
+ token->SetPosition(token, fileSize - 1);
+ }
+
+ efiStatus = token->Write(token, &length, message);
+ checkStatus(efiStatus, "Write");
+
+ fileSize += length;
+
+ token->SetPosition(token, 0);
+
+ efiStatus = token->Read(token, &fileSize, fileBuffer);
+ printFileContent(fileSize, fileBuffer);
+
+ if (fileBuffer != NULL) {
+ bs->FreePool(fileBuffer);
+ }
+
+ if (fileSystemInfo != NULL) {
+ bs->FreePool(fileSystemInfo);
+ }
+
+ } // end if (compareGuids(&sfspGuid, guid))
+ } // end for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
+ } // end "for (handleIndex = 0; handleIndex < handleCount; handleIndex++)"
+
+
+ efiStatus = bs->LocateHandleBuffer(ByProtocol,
+ &sfspGuid,
+ NULL,
+ &handleCount2,
+ &handleBuffer2);
+
+ Print(L"Handle count2: %d\n", handleCount2);
+
+
+ return EFI_SUCCESS;
+}
+
diff --git a/memtestEDK/Memtest/ProtocolInformation/Logger.inf b/memtestEDK/Memtest/ProtocolInformation/Logger.inf
new file mode 100644
index 0000000..dd19520
--- /dev/null
+++ b/memtestEDK/Memtest/ProtocolInformation/Logger.inf
@@ -0,0 +1,32 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = Logger
+ FILE_GUID = 51d8cae0-112a-674f-a8d9-8451dff0ebd0
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC Etc...
+#
+
+[Sources]
+ Logger.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Guids]
+
+[Ppis]
+
+[Protocols]
+
+[FeaturePcd]
+
+[Pcd]