]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c
MdeModulePkg Variable: Enhance the code logic about VariableLock
[mirror_edk2.git] / MdeModulePkg / Universal / FvSimpleFileSystemDxe / FvSimpleFileSystemEntryPoint.c
CommitLineData
9da91aea
BJ
1/** @file\r
2 This driver uses the EFI_FIRMWARE_VOLUME2_PROTOCOL to expose files in firmware\r
3 volumes via the the EFI_SIMPLE_FILESYSTEM_PROTOCOL and EFI_FILE_PROTOCOL.\r
4\r
5 It will expose a single directory, containing one file for each file in the firmware\r
6 volume. If a file has a UI section, its contents will be used as a filename.\r
7 Otherwise, a string representation of the GUID will be used.\r
8 Files of an executable type (That is PEIM, DRIVER, COMBINED_PEIM_DRIVER and APPLICATION)\r
9 will have ".efi" added to their filename.\r
10\r
11 Its primary intended use is to be able to start EFI applications embedded in FVs\r
12 from the UEFI shell. It is entirely read-only.\r
13\r
14Copyright (c) 2014, ARM Limited. All rights reserved.\r
15Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
16\r
17This program and the accompanying materials\r
18are licensed and made available under the terms and conditions of the BSD License\r
19which accompanies this distribution. The full text of the license may be found at\r
20http://opensource.org/licenses/bsd-license.php\r
21\r
22THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
23WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
24\r
25**/\r
26\r
27#include "FvSimpleFileSystemInternal.h"\r
28\r
29EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollation = NULL;\r
30\r
31//\r
32// A Guid string is 32 hex characters with 4 hyphens and a NULL-terminated char: 37 characters total\r
33//\r
34#define GUID_STRING_SIZE (37 * sizeof (CHAR16))\r
35\r
36#define FVFS_VOLUME_LABEL_PREFIX L"Firmware Volume: "\r
37#define FVFS_VOLUME_LABEL_SIZE (sizeof (FVFS_VOLUME_LABEL_PREFIX) + GUID_STRING_SIZE - sizeof (CHAR16))\r
38#define FVFS_FALLBACK_VOLUME_LABEL L"Firmware Volume"\r
39\r
40//\r
41// Template for EFI_SIMPLE_FILE_SYSTEM_PROTOCOL data structure.\r
42//\r
43EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mSimpleFsTemplate = {\r
44 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,\r
45 FvSimpleFileSystemOpenVolume\r
46};\r
47\r
48//\r
49// Template for EFI_DRIVER_BINDING_PROTOCOL data structure.\r
50//\r
51EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {\r
52 FvSimpleFileSystemDriverSupported,\r
53 FvSimpleFileSystemDriverStart,\r
54 FvSimpleFileSystemDriverStop,\r
55 0,\r
56 NULL,\r
57 NULL\r
58};\r
59\r
60/**\r
61 Open the root directory on a volume.\r
62\r
63 @param This A pointer to the volume to open the root directory.\r
64 @param RootFile A pointer to the location to return the opened file handle for the\r
65 root directory.\r
66\r
67 @retval EFI_SUCCESS The device was opened.\r
68 @retval EFI_UNSUPPORTED This volume does not support the requested file system type.\r
69 @retval EFI_NO_MEDIA The device has no medium.\r
70 @retval EFI_DEVICE_ERROR The device reported an error.\r
71 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
72 @retval EFI_ACCESS_DENIED The service denied access to the file.\r
73 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r
74 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no\r
75 longer supported. Any existing file handles for this volume are\r
76 no longer valid. To access the files on the new medium, the\r
77 volume must be reopened with OpenVolume().\r
78\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82FvSimpleFileSystemOpenVolume (\r
83 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
84 OUT EFI_FILE_PROTOCOL **RootFile\r
85 )\r
86{\r
87 EFI_STATUS Status;\r
88 FV_FILESYSTEM_FILE *Root;\r
89 CHAR16 *UiSection;\r
90 EFI_GUID NameGuid;\r
91 EFI_FV_FILE_ATTRIBUTES Attributes;\r
92 UINT32 Authentication;\r
93 UINTN Key;\r
94 EFI_FV_FILETYPE FileType;\r
95 UINTN Size;\r
96 FV_FILESYSTEM_INSTANCE *Instance;\r
97 FV_FILESYSTEM_FILE_INFO *FvFileInfo;\r
98 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;\r
99 CHAR16 *Name;\r
100 UINTN NameLen;\r
101 UINTN NumChars;\r
102 UINTN DestMax;\r
103\r
104 Instance = FVFS_INSTANCE_FROM_SIMPLE_FS_THIS (This);\r
105 Status = EFI_SUCCESS;\r
106\r
107 if (Instance->Root == NULL) {\r
108 //\r
109 // Allocate file structure for root file\r
110 //\r
111 Root = AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE));\r
112 if (Root == NULL) {\r
113 return EFI_OUT_OF_RESOURCES;\r
114 }\r
115\r
116 Instance->Root = Root;\r
117 Root->Instance = Instance;\r
118 Root->Signature = FVFS_FILE_SIGNATURE;\r
119 CopyMem (&Root->FileProtocol, &mFileSystemTemplate, sizeof (mFileSystemTemplate));\r
120 Root->FvFileInfo = AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE_INFO));\r
121 if (Root->FvFileInfo == NULL) {\r
122 return EFI_OUT_OF_RESOURCES;\r
123 }\r
124 Root->FvFileInfo->FileInfo.Size = sizeof (EFI_FILE_INFO);\r
125 Root->FvFileInfo->FileInfo.Attribute = EFI_FILE_DIRECTORY | EFI_FILE_READ_ONLY;\r
126\r
127 //\r
128 // Populate the instance's list of files. We consider anything a file that\r
129 // has a UI_SECTION, which we consider to be its filename.\r
130 //\r
131 FvProtocol = Instance->FvProtocol;\r
132 //\r
133 // Allocate Key\r
134 //\r
135 Key = 0;\r
136\r
137 do {\r
138 FileType = EFI_FV_FILETYPE_ALL;\r
139\r
140 Status = FvProtocol->GetNextFile (\r
141 FvProtocol,\r
142 &Key,\r
143 &FileType,\r
144 &NameGuid,\r
145 &Attributes,\r
146 &Size\r
147 );\r
148 if (EFI_ERROR (Status)) {\r
149 ASSERT (Status == EFI_NOT_FOUND);\r
150 break;\r
151 }\r
152\r
153 //\r
154 // Get a file's name: If it has a UI section, use that, otherwise use\r
155 // its NameGuid.\r
156 //\r
157 UiSection = NULL;\r
158 Status = FvProtocol->ReadSection (\r
159 FvProtocol,\r
160 &NameGuid,\r
161 EFI_SECTION_USER_INTERFACE,\r
162 0,\r
163 (VOID **)&UiSection,\r
164 &Size,\r
165 &Authentication\r
166 );\r
167 if (!EFI_ERROR (Status)) {\r
168 Name = UiSection;\r
169 } else {\r
170 Name = AllocateZeroPool (GUID_STRING_SIZE);\r
171 if (Name == NULL) {\r
172 return EFI_OUT_OF_RESOURCES;\r
173 }\r
174 NumChars = UnicodeSPrint (Name, GUID_STRING_SIZE, L"%g", &NameGuid);\r
175 ASSERT ((NumChars + 1) * sizeof (CHAR16) == GUID_STRING_SIZE);\r
176 }\r
177\r
178 //\r
179 // Found a file.\r
180 // Allocate a file structure and populate it.\r
181 //\r
182 NameLen = StrSize (Name);\r
183 if (FV_FILETYPE_IS_EXECUTABLE (FileType)) {\r
184 NameLen += StrSize (L".efi") - sizeof (CHAR16);\r
185 }\r
186\r
187 FvFileInfo = AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE_INFO) + NameLen - sizeof (CHAR16));\r
188 if (FvFileInfo == NULL) {\r
189 return EFI_OUT_OF_RESOURCES;\r
190 }\r
191\r
192 FvFileInfo->Signature = FVFS_FILE_INFO_SIGNATURE;\r
193 InitializeListHead (&FvFileInfo->Link);\r
194 CopyMem (&FvFileInfo->NameGuid, &NameGuid, sizeof (EFI_GUID));\r
195 FvFileInfo->Type = FileType;\r
196\r
197 //\r
198 // Add ".efi" to filenames of drivers and applications.\r
199 //\r
200 DestMax = NameLen / sizeof (CHAR16);\r
201 Status = StrnCpyS (&FvFileInfo->FileInfo.FileName[0], DestMax, Name, StrLen (Name));\r
202 ASSERT_EFI_ERROR (Status);\r
203\r
204 if (FV_FILETYPE_IS_EXECUTABLE (FileType)) {\r
205 Status = StrnCatS (&FvFileInfo->FileInfo.FileName[0], DestMax, L".efi", StrLen (L".efi"));\r
206 ASSERT_EFI_ERROR (Status);\r
207 }\r
208\r
209 FvFileInfo->FileInfo.Size = sizeof (EFI_FILE_INFO) + NameLen - sizeof (CHAR16);\r
210 Status = FvFsGetFileSize (FvProtocol, FvFileInfo);\r
211 ASSERT_EFI_ERROR (Status);\r
212 FvFileInfo->FileInfo.PhysicalSize = FvFileInfo->FileInfo.FileSize;\r
213 FvFileInfo->FileInfo.Attribute = EFI_FILE_READ_ONLY;\r
214\r
215 InsertHeadList (&Instance->FileInfoHead, &FvFileInfo->Link);\r
216\r
217 FreePool (Name);\r
218\r
219 } while (TRUE);\r
220\r
221 if (Status == EFI_NOT_FOUND) {\r
222 Status = EFI_SUCCESS;\r
223 }\r
224 }\r
225\r
226 Instance->Root->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);\r
227 *RootFile = &Instance->Root->FileProtocol;\r
228 return Status;\r
229}\r
230\r
231/**\r
232 Worker function to initialize Unicode Collation support.\r
233\r
234 It tries to locate Unicode Collation (2) protocol and matches it with current\r
235 platform language code.\r
236\r
237 @param AgentHandle The handle used to open Unicode Collation (2) protocol.\r
238 @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.\r
239 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.\r
240 @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.\r
241\r
242 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.\r
243 @retval Others The Unicode Collation (2) protocol has not been located.\r
244\r
245**/\r
246EFI_STATUS\r
247InitializeUnicodeCollationSupportWorker (\r
248 IN EFI_HANDLE AgentHandle,\r
249 IN EFI_GUID *ProtocolGuid,\r
250 IN CONST CHAR16 *VariableName,\r
251 IN CONST CHAR8 *DefaultLanguage\r
252 )\r
253{\r
254 EFI_STATUS ReturnStatus;\r
255 EFI_STATUS Status;\r
256 UINTN NumHandles;\r
257 UINTN Index;\r
258 EFI_HANDLE *Handles;\r
259 EFI_UNICODE_COLLATION_PROTOCOL *Uci;\r
260 BOOLEAN Iso639Language;\r
261 CHAR8 *Language;\r
262 CHAR8 *BestLanguage;\r
263\r
264 Status = gBS->LocateHandleBuffer (\r
265 ByProtocol,\r
266 ProtocolGuid,\r
267 NULL,\r
268 &NumHandles,\r
269 &Handles\r
270 );\r
271 if (EFI_ERROR (Status)) {\r
272 return Status;\r
273 }\r
274\r
275 Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);\r
276 GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL);\r
277\r
278 ReturnStatus = EFI_UNSUPPORTED;\r
279 for (Index = 0; Index < NumHandles; Index++) {\r
280 //\r
281 // Open Unicode Collation Protocol\r
282 //\r
283 Status = gBS->OpenProtocol (\r
284 Handles[Index],\r
285 ProtocolGuid,\r
286 (VOID **) &Uci,\r
287 AgentHandle,\r
288 NULL,\r
289 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
290 );\r
291 if (EFI_ERROR (Status)) {\r
292 continue;\r
293 }\r
294\r
295 //\r
296 // Find the best matching matching language from the supported languages\r
297 // of Unicode Collation (2) protocol.\r
298 //\r
299 BestLanguage = GetBestLanguage (\r
300 Uci->SupportedLanguages,\r
301 Iso639Language,\r
302 (Language == NULL) ? "" : Language,\r
303 DefaultLanguage,\r
304 NULL\r
305 );\r
306 if (BestLanguage != NULL) {\r
307 FreePool (BestLanguage);\r
308 mUnicodeCollation = Uci;\r
309 ReturnStatus = EFI_SUCCESS;\r
310 break;\r
311 }\r
312 }\r
313\r
314 if (Language != NULL) {\r
315 FreePool (Language);\r
316 }\r
317\r
318 FreePool (Handles);\r
319\r
320 return ReturnStatus;\r
321}\r
322\r
323/**\r
324 Initialize Unicode Collation support.\r
325\r
326 It tries to locate Unicode Collation 2 protocol and matches it with current\r
327 platform language code. If for any reason the first attempt fails, it then tries to\r
328 use Unicode Collation Protocol.\r
329\r
330 @param AgentHandle The handle used to open Unicode Collation (2) protocol.\r
331\r
332 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.\r
333 @retval Others The Unicode Collation (2) protocol has not been located.\r
334\r
335**/\r
336EFI_STATUS\r
337InitializeUnicodeCollationSupport (\r
338 IN EFI_HANDLE AgentHandle\r
339 )\r
340{\r
341\r
342 EFI_STATUS Status;\r
343\r
344 Status = EFI_UNSUPPORTED;\r
345\r
346 //\r
347 // First try to use RFC 4646 Unicode Collation 2 Protocol.\r
348 //\r
349 Status = InitializeUnicodeCollationSupportWorker (\r
350 AgentHandle,\r
351 &gEfiUnicodeCollation2ProtocolGuid,\r
352 L"PlatformLang",\r
353 (CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)\r
354 );\r
355 //\r
356 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back\r
357 // on the ISO 639-2 Unicode Collation Protocol.\r
358 //\r
359 if (EFI_ERROR (Status)) {\r
360 Status = InitializeUnicodeCollationSupportWorker (\r
361 AgentHandle,\r
362 &gEfiUnicodeCollationProtocolGuid,\r
363 L"Lang",\r
364 (CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang)\r
365 );\r
366 }\r
367\r
368 return Status;\r
369}\r
370\r
371/**\r
372 Test to see if this driver supports ControllerHandle.\r
373\r
374 @param DriverBinding Protocol instance pointer.\r
375 @param ControllerHandle Handle of device to test\r
376 @param RemainingDevicePath Optional parameter use to pick a specific child\r
377 device to start.\r
378\r
379 @retval EFI_SUCCESS This driver supports this device\r
380 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
381 @retval other This driver does not support this device\r
382\r
383**/\r
384EFI_STATUS\r
385EFIAPI\r
386FvSimpleFileSystemDriverSupported (\r
387 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,\r
388 IN EFI_HANDLE ControllerHandle,\r
389 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
390 )\r
391{\r
392 return gBS->OpenProtocol (\r
393 ControllerHandle,\r
394 &gEfiFirmwareVolume2ProtocolGuid,\r
395 NULL,\r
396 gImageHandle,\r
397 ControllerHandle,\r
398 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
399 );\r
400}\r
401\r
402/**\r
403 Start this driver on ControllerHandle by opening a FV protocol and\r
404 installing a SimpleFileSystem protocol on ControllerHandle.\r
405\r
406 @param DriverBinding Protocol instance pointer.\r
407 @param ControllerHandle Handle of device to bind driver to\r
408 @param RemainingDevicePath Optional parameter use to pick a specific child\r
409 device to start.\r
410\r
411 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
412 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
413 @retval other This driver does not support this device\r
414\r
415**/\r
416EFI_STATUS\r
417EFIAPI\r
418FvSimpleFileSystemDriverStart (\r
419 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,\r
420 IN EFI_HANDLE ControllerHandle,\r
421 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
422 )\r
423{\r
424 EFI_STATUS Status;\r
425 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;\r
426 FV_FILESYSTEM_INSTANCE *Instance;\r
427 EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r
428 EFI_GUID *FvGuid;\r
429 UINTN NumChars;\r
430\r
431 Status = InitializeUnicodeCollationSupport (DriverBinding->DriverBindingHandle);\r
432 if (EFI_ERROR (Status)) {\r
433 return Status;\r
434 }\r
435\r
436 //\r
437 // Open FV protocol\r
438 //\r
439 Status = gBS->OpenProtocol (\r
440 ControllerHandle,\r
441 &gEfiFirmwareVolume2ProtocolGuid,\r
442 (VOID **) &FvProtocol,\r
443 gImageHandle,\r
444 ControllerHandle,\r
445 EFI_OPEN_PROTOCOL_BY_DRIVER\r
446 );\r
447 if (EFI_ERROR (Status)) {\r
448 return Status;\r
449 }\r
450\r
451 //\r
452 // Create an instance\r
453 //\r
454 Instance = AllocateZeroPool (sizeof (FV_FILESYSTEM_INSTANCE));\r
455 if (Instance == NULL) {\r
456 return EFI_OUT_OF_RESOURCES;\r
457 }\r
458\r
459 Instance->Root = NULL;\r
460 Instance->FvProtocol = FvProtocol;\r
461 Instance->Signature = FVFS_INSTANCE_SIGNATURE;\r
462 InitializeListHead (&Instance->FileInfoHead);\r
463 InitializeListHead (&Instance->FileHead);\r
464 CopyMem (&Instance->SimpleFs, &mSimpleFsTemplate, sizeof (mSimpleFsTemplate));\r
465\r
466 Status = gBS->InstallProtocolInterface(\r
467 &ControllerHandle,\r
468 &gEfiSimpleFileSystemProtocolGuid,\r
469 EFI_NATIVE_INTERFACE,\r
470 &Instance->SimpleFs\r
471 );\r
472\r
473 //\r
474 // Decide on a filesystem volume label, which will include the FV's guid.\r
475 // Get the device path to find the FV's GUID\r
476 //\r
477 Instance->VolumeLabel = NULL;\r
478 Status = gBS->OpenProtocol (\r
479 ControllerHandle,\r
480 &gEfiDevicePathProtocolGuid,\r
481 (VOID **) &FvDevicePath,\r
482 gImageHandle,\r
483 ControllerHandle,\r
484 EFI_OPEN_PROTOCOL_BY_DRIVER\r
485 );\r
486 if (!EFI_ERROR (Status)) {\r
487 //\r
488 // Iterate over device path until we find a firmware volume node\r
489 //\r
490 while (!IsDevicePathEndType (FvDevicePath)) {\r
491 if (DevicePathType (FvDevicePath) == MEDIA_DEVICE_PATH &&\r
492 DevicePathSubType (FvDevicePath) == MEDIA_PIWG_FW_VOL_DP) {\r
493 //\r
494 // Allocate the volume label\r
495 //\r
496 Instance->VolumeLabel = AllocateZeroPool (FVFS_VOLUME_LABEL_SIZE);\r
497 //\r
498 // Check the allocation was successful\r
499 //\r
500 if (Instance->VolumeLabel != NULL) {\r
501 //\r
502 // Extract the FV's guid\r
503 //\r
504 FvGuid = &((MEDIA_FW_VOL_DEVICE_PATH *) FvDevicePath)->FvName;\r
505 //\r
506 // Build the volume label string\r
507 //\r
508 NumChars = UnicodeSPrint (\r
509 Instance->VolumeLabel,\r
510 FVFS_VOLUME_LABEL_SIZE,\r
511 FVFS_VOLUME_LABEL_PREFIX L"%g",\r
512 FvGuid\r
513 );\r
514 ASSERT ((NumChars + 1) * sizeof (CHAR16) == FVFS_VOLUME_LABEL_SIZE);\r
515 }\r
516 break;\r
517 }\r
518 FvDevicePath = NextDevicePathNode (FvDevicePath);\r
519 }\r
520 }\r
521 //\r
522 // If we didn't decide on a volume label, set a fallback one\r
523 //\r
524 if (Instance->VolumeLabel == NULL) {\r
525 Instance->VolumeLabel = AllocateCopyPool (\r
526 sizeof (FVFS_FALLBACK_VOLUME_LABEL),\r
527 FVFS_FALLBACK_VOLUME_LABEL\r
528 );\r
529 }\r
530\r
531 return Status;\r
532}\r
533\r
534/**\r
535 Stop this driver on ControllerHandle by removing SimpleFileSystem protocol and closing\r
536 the FV protocol on ControllerHandle.\r
537\r
538 @param DriverBinding Protocol instance pointer.\r
539 @param ControllerHandle Handle of device to stop driver on\r
540 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
541 children is zero stop the entire bus driver.\r
542 @param ChildHandleBuffer List of Child Handles to Stop.\r
543\r
544 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
545 @retval other This driver was not removed from this device\r
546\r
547**/\r
548EFI_STATUS\r
549EFIAPI\r
550FvSimpleFileSystemDriverStop (\r
551 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,\r
552 IN EFI_HANDLE ControllerHandle,\r
553 IN UINTN NumberOfChildren,\r
554 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
555 )\r
556{\r
557 EFI_STATUS Status;\r
558 FV_FILESYSTEM_INSTANCE *Instance;\r
559 FV_FILESYSTEM_FILE_INFO *FvFileInfo;\r
560 LIST_ENTRY *Entry;\r
561 LIST_ENTRY *DelEntry;\r
562 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFile;\r
563\r
564 Status = gBS->OpenProtocol (\r
565 ControllerHandle,\r
566 &gEfiSimpleFileSystemProtocolGuid,\r
567 (VOID **) &SimpleFile,\r
568 DriverBinding->DriverBindingHandle,\r
569 ControllerHandle,\r
570 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
571 );\r
572 if (EFI_ERROR (Status)) {\r
573 return Status;\r
574 }\r
575\r
576 Instance = FVFS_INSTANCE_FROM_SIMPLE_FS_THIS (SimpleFile);\r
577\r
578 if (IsListEmpty (&Instance->FileHead) == FALSE) {\r
579 //\r
580 // Not all opened files are closed\r
581 //\r
582 return EFI_DEVICE_ERROR;\r
583 }\r
584\r
585 //\r
586 // Close and uninstall protocols.\r
587 //\r
588 Status = gBS->CloseProtocol (\r
589 ControllerHandle,\r
590 &gEfiFirmwareVolume2ProtocolGuid,\r
591 gImageHandle,\r
592 ControllerHandle\r
593 );\r
594 ASSERT_EFI_ERROR (Status);\r
595\r
596 Status = gBS->UninstallProtocolInterface (\r
597 ControllerHandle,\r
598 &gEfiSimpleFileSystemProtocolGuid,\r
599 &Instance->SimpleFs\r
600 );\r
601 ASSERT_EFI_ERROR (Status);\r
602\r
603 //\r
604 // Free file structures\r
605 //\r
606 if (!IsListEmpty (&Instance->FileInfoHead)) {\r
607 //\r
608 // Free the Subtask list.\r
609 //\r
610 for(Entry = Instance->FileInfoHead.ForwardLink;\r
611 Entry != (&Instance->FileInfoHead);\r
612 ) {\r
613 DelEntry = Entry;\r
614 Entry = Entry->ForwardLink;\r
615 FvFileInfo = FVFS_FILE_INFO_FROM_LINK (DelEntry);\r
616\r
617 RemoveEntryList (DelEntry);\r
618 FreePool (FvFileInfo);\r
619 }\r
620 }\r
621\r
622 if (Instance->Root != NULL) {\r
623 //\r
624 // Root->Name is statically allocated, no need to free.\r
625 //\r
626 if (Instance->Root->FvFileInfo != NULL) {\r
627 FreePool (Instance->Root->FvFileInfo);\r
628 }\r
629 FreePool (Instance->Root);\r
630 }\r
631\r
632 //\r
633 // Free Instance\r
634 //\r
635 if (Instance->VolumeLabel != NULL) {\r
636 FreePool (Instance->VolumeLabel);\r
637 }\r
638 FreePool (Instance);\r
639\r
640 return EFI_SUCCESS;\r
641}\r
642\r
643/**\r
644 The user Entry Point for module FvSimpleFileSystem. The user code starts with this function.\r
645\r
646 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
647 @param[in] SystemTable A pointer to the EFI System Table.\r
648\r
649 @retval EFI_SUCCESS The entry point is executed successfully.\r
650 @retval other Some error occurs when executing this entry point.\r
651\r
652**/\r
653EFI_STATUS\r
654EFIAPI\r
655FvSimpleFileSystemEntryPoint (\r
656 IN EFI_HANDLE ImageHandle,\r
657 IN EFI_SYSTEM_TABLE *SystemTable\r
658 )\r
659{\r
660 EFI_STATUS Status;\r
661\r
662 //\r
663 // Install driver model protocol(s).\r
664 //\r
665 Status = EfiLibInstallDriverBindingComponentName2 (\r
666 ImageHandle,\r
667 SystemTable,\r
668 &mDriverBinding,\r
669 ImageHandle,\r
670 &gFvSimpleFileSystemComponentName,\r
671 &gFvSimpleFileSystemComponentName2\r
672 );\r
673 ASSERT_EFI_ERROR (Status);\r
674\r
675 return Status;\r
676}\r