]> git.proxmox.com Git - mirror_edk2.git/blob - BeagleBoardPkg/Bds/FirmwareVolume.c
Adding support for BeagleBoard.
[mirror_edk2.git] / BeagleBoardPkg / Bds / FirmwareVolume.c
1 /** @file
2 The entry of the embedded BDS. This BDS does not follow the Boot Manager requirements
3 of the UEFI specification as it is designed to implement an embedded systmes
4 propriatary boot scheme.
5
6 This template assume a DXE driver produces a SerialIo protocol not using the EFI
7 driver module and it will attempt to connect a console on top of this.
8
9
10 Copyright (c) 2009 Apple, Inc. All rights reserved.
11 Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
12
13
14 This document is the property of Apple, Inc.
15 It is considered confidential and proprietary.
16
17 This document may not be reproduced or transmitted in any form,
18 in whole or in part, without the express written permission of
19 Apple, Inc.
20
21 **/
22
23 #include "BdsEntry.h"
24
25
26 EFI_STATUS
27 FindApplicationMatchingUiSection (
28 IN CHAR16 *UiString,
29 OUT EFI_HANDLE *FvHandle,
30 OUT EFI_GUID *NameGuid
31 )
32 {
33 EFI_STATUS Status;
34 EFI_STATUS NextStatus;
35 UINTN NoHandles;
36 EFI_HANDLE *Buffer;
37 UINTN Index;
38 EFI_FV_FILETYPE FileType;
39 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
40 VOID *Key;
41 EFI_FV_FILE_ATTRIBUTES Attributes;
42 UINTN Size;
43 UINTN UiStringLen;
44 CHAR16 *UiSection;
45 UINT32 Authentication;
46
47
48 UiStringLen = 0;
49 if (UiString != NULL) {
50 DEBUG ((DEBUG_ERROR, "UiString %s\n", UiString));
51 UiStringLen = StrLen (UiString);
52 }
53
54 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Buffer);
55 if (!EFI_ERROR (Status)) {
56 for (Index = 0; Index < NoHandles; Index++) {
57 Status = gBS->HandleProtocol (Buffer[Index], &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);
58 if (!EFI_ERROR (Status)) {
59 Key = AllocatePool (Fv->KeySize);
60 ASSERT (Key != NULL);
61 ZeroMem (Key, Fv->KeySize);
62
63 FileType = EFI_FV_FILETYPE_APPLICATION;
64
65 do {
66 NextStatus = Fv->GetNextFile (Fv, Key, &FileType, NameGuid, &Attributes, &Size);
67 if (!EFI_ERROR (NextStatus)) {
68 if (UiString == NULL) {
69 //
70 // If UiString is NULL match first application we find.
71 //
72 *FvHandle = Buffer[Index];
73 FreePool (Key);
74 return Status;
75 }
76
77 UiSection = NULL;
78 Status = Fv->ReadSection (
79 Fv,
80 NameGuid,
81 EFI_SECTION_USER_INTERFACE,
82 0,
83 (VOID **)&UiSection,
84 &Size,
85 &Authentication
86 );
87 if (!EFI_ERROR (Status)) {
88 if (StrnCmp (UiString, UiSection, UiStringLen) == 0) {
89 //
90 // We found a UiString match.
91 //
92 *FvHandle = Buffer[Index];
93 FreePool (Key);
94 FreePool (UiSection);
95 return Status;
96 }
97 FreePool (UiSection);
98 }
99 }
100 } while (!EFI_ERROR (NextStatus));
101
102 FreePool (Key);
103 }
104 }
105
106 FreePool (Buffer);
107 }
108
109 return EFI_NOT_FOUND;
110 }
111
112
113 EFI_DEVICE_PATH *
114 FvFileDevicePath (
115 IN EFI_HANDLE FvHandle,
116 IN EFI_GUID *NameGuid
117 )
118 {
119 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
120 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;
121
122 DevicePath = DevicePathFromHandle (FvHandle);
123
124 EfiInitializeFwVolDevicepathNode (&NewNode, NameGuid);
125
126 return AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);
127 }
128
129
130
131 EFI_STATUS
132 LoadPeCoffSectionFromFv (
133 IN EFI_HANDLE FvHandle,
134 IN EFI_GUID *NameGuid
135 )
136 {
137 EFI_STATUS Status;
138 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
139 EFI_HANDLE ImageHandle;
140
141 DevicePath = FvFileDevicePath (FvHandle, NameGuid);
142
143 Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);
144 if (!EFI_ERROR (Status)) {
145 Status = gBS->StartImage (ImageHandle, NULL, NULL);
146 }
147
148 return Status;
149 }
150