RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Conf.c
Go to the documentation of this file.
1 
13 #include "EfiScannerHeaders.h"
14 
23 VOID ParseConfiguration(CHAR8 *ConfData, UINTN ConfDataSize)
24 {
25  UINTN i;
26  ULONG32 Cmd;
27  CHAR8 *p;
28 
29  CHAR8 AddrAscii[17], AddrAscii2[17];
30  UINT64 Addr, Addr2;
31 
32  AddrAscii[16] = 0;
33  AddrAscii2[16] = 0;
34 
35  i = 0;
36  while (1)
37  {
38  p = (CHAR8*)(ConfData + i);
39  Cmd = *(ULONG32*)p;
40 
41  switch (Cmd)
42  {
43  // unknown command
44  default:
45  break;
46 
47  // dump command
48  //case 'pmud':
49  // break;
50 
51  // badd <addr_start> <addr_end>
52  case 'ddab':
53  p += sizeof(ULONG32);
54 
55  MemCopy(AddrAscii, (p + 1), 16);
56  MemCopy(AddrAscii2, (p + 1 + 16 + 1), 16);
57  Addr = AsciiStrHexToUint64(AddrAscii);
58  Addr2 = AsciiStrHexToUint64(AddrAscii2);
59 
60 #if DEBUG_ON == 1
61  LogFullAscii("%a: badd command at i = %08x bad_index=%d addr1=%a(%lx) addr2=%a(%lx)\r\n",
62  __FUNCTION__, i, gEfiScannerPolicy.NumOfBadAddrs, AddrAscii, Addr, AddrAscii2, Addr2);
63 #endif
64 
66  {
70  }
71  break;
72  }
73 
74  // scan until new line is found or end of file
75  while (ConfData[i] != '\n')
76  {
77  if (i >= ConfDataSize)
78  return;
79  i++;
80  }
81 
82  i++;
83  }
84 }
85 
86 
87 
88 
102 EFI_STATUS ReadConfiguration(CHAR16 *ConfPath)
103 {
104  EFI_STATUS Status;
105  EFI_FILE_PROTOCOL *File;
106  UINTN ConfSize;
107 
108  CHAR8 *ConfData;
109 #define MAX_CONF_DATA 512*10
110 
111 
112  // read the configuration file
113  Status = OpenFile(ConfPath, EFI_FILE_MODE_READ, &File);
114 
115  if (EFI_ERROR(Status))
116  {
117 
118 #if DEBUG_ON == 1
119  LogFullAscii("%a: unable to open configuration file, status = %08x\r\n",
120  __FUNCTION__, Status);
121 #endif
122 
123  return Status;
124  }
125 
126  ConfData = (CHAR8*)MemAllocate(MAX_CONF_DATA + 32);
127  if (!ConfData)
128  {
129  LogFileAscii("%a: MemAllocate returned error!\r\n", __FUNCTION__);
130  File->Close(File);
131  return EFI_NOT_FOUND;
132  }
133 
134  ConfSize = MAX_CONF_DATA;
135  Status = File->Read(File, &ConfSize, ConfData);
136  File->Close(File);
137 
138  ParseConfiguration(ConfData, ConfSize);
139 
140  MemFree(ConfData);
141  return EFI_SUCCESS;
142 }