TianoCore EDK2 master
Loading...
Searching...
No Matches
FitLib.c
Go to the documentation of this file.
1
7#include "FitLib.h"
8
9PROPERTY_DATA PropertyData32List[] = {
10 { "data-offset", PAYLOAD_ENTRY_OFFSET_OFFSET },
11 { "data-size", PAYLOAD_ENTRY_SIZE_OFFSET },
12 { "reloc-start", RELOCATE_TABLE_OFFSET_OFFSET }
13};
14
15PROPERTY_DATA PropertyData64List[] = {
16 { "entry-start", PAYLOAD_ENTRY_POINT_OFFSET },
17 { "load", PAYLOAD_LOAD_ADDR_OFFSET }
18};
19
29EFIAPI
31 IN VOID *Fdt,
32 IN CHAR8 *Firmware,
33 OUT FIT_IMAGE_CONTEXT *Context
34 )
35{
36 CONST FDT_PROPERTY *PropertyPtr;
37 INT32 ImageNode;
38 INT32 TianoNode;
39 INT32 TempLen;
40 UINT32 *Data32;
41 UINT64 *Data64;
42 UINT32 *ContextOffset32;
43 UINT64 *ContextOffset64;
44 INT32 Index;
45
46 ImageNode = FdtSubnodeOffsetNameLen (Fdt, 0, "images", (INT32)AsciiStrLen ("images"));
47 if (ImageNode <= 0) {
48 return EFI_NOT_FOUND;
49 }
50
51 TianoNode = FdtSubnodeOffsetNameLen (Fdt, ImageNode, Firmware, (INT32)AsciiStrLen (Firmware));
52 if (TianoNode <= 0) {
53 return EFI_NOT_FOUND;
54 }
55
56 for (Index = 0; Index < sizeof (PropertyData32List) / sizeof (PROPERTY_DATA); Index++) {
57 PropertyPtr = FdtGetProperty (Fdt, TianoNode, PropertyData32List[Index].Name, &TempLen);
58 Data32 = (UINT32 *)(PropertyPtr->Data);
59 ContextOffset32 = (UINT32 *)((UINTN)Context + PropertyData32List[Index].Offset);
60 *ContextOffset32 = Fdt32ToCpu (*Data32);
61 }
62
63 for (Index = 0; Index < sizeof (PropertyData64List)/sizeof (PROPERTY_DATA); Index++) {
64 PropertyPtr = FdtGetProperty (Fdt, TianoNode, PropertyData64List[Index].Name, &TempLen);
65 Data64 = (UINT64 *)(PropertyPtr->Data);
66 ContextOffset64 = (UINT64 *)((UINTN)Context + PropertyData64List[Index].Offset);
67 *ContextOffset64 = Fdt64ToCpu (*Data64);
68 }
69
70 return EFI_SUCCESS;
71}
72
81EFIAPI
83 IN VOID *ImageBase,
84 OUT FIT_IMAGE_CONTEXT *Context
85 )
86{
87 VOID *Fdt;
88 INT32 ConfigNode;
89 INT32 Config1Node;
90 CONST FDT_PROPERTY *PropertyPtr;
91 INT32 TempLen;
92 UINT32 *Data32;
93 UINT64 Value;
94 EFI_STATUS Status;
95 UINTN UplSize;
96 CHAR8 *Firmware;
97
98 Status = FdtCheckHeader (ImageBase);
99 if (EFI_ERROR (Status)) {
100 return EFI_UNSUPPORTED;
101 }
102
103 Fdt = ImageBase;
104 PropertyPtr = FdtGetProperty (Fdt, 0, "size", &TempLen);
105 Data32 = (UINT32 *)(PropertyPtr->Data);
106 UplSize = Value = Fdt32ToCpu (*Data32);
107 ConfigNode = FdtSubnodeOffsetNameLen (Fdt, 0, "configurations", (INT32)AsciiStrLen ("configurations"));
108 if (ConfigNode <= 0) {
109 return EFI_NOT_FOUND;
110 }
111
112 Config1Node = FdtSubnodeOffsetNameLen (Fdt, ConfigNode, "conf-1", (INT32)AsciiStrLen ("conf-1"));
113 if (Config1Node <= 0) {
114 return EFI_NOT_FOUND;
115 }
116
117 PropertyPtr = FdtGetProperty (Fdt, Config1Node, "firmware", &TempLen);
118 Firmware = (CHAR8 *)(PropertyPtr->Data);
119
120 FitParseFirmwarePropertyData (Fdt, Firmware, Context);
121
122 Context->ImageBase = (EFI_PHYSICAL_ADDRESS)ImageBase;
123 Context->PayloadSize = UplSize;
124 Context->RelocateTableCount = (Context->PayloadEntrySize - (Context->RelocateTableOffset - Context->PayloadEntryOffset)) / sizeof (FIT_RELOCATE_ITEM);
125
126 return EFI_SUCCESS;
127}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
CONST FDT_PROPERTY *EFIAPI FdtGetProperty(IN CONST VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN INT32 *Length)
Definition: FdtLib.c:446
UINT64 EFIAPI Fdt64ToCpu(IN UINT64 Value)
Definition: FdtLib.c:91
INT32 EFIAPI FdtSubnodeOffsetNameLen(IN CONST VOID *Fdt, IN INT32 ParentOffset, IN CONST CHAR8 *Name, IN INT32 NameLength)
Definition: FdtLib.c:320
INT32 EFIAPI FdtCheckHeader(IN CONST VOID *Fdt)
Definition: FdtLib.c:125
UINT32 EFIAPI Fdt32ToCpu(IN UINT32 Value)
Definition: FdtLib.c:57
EFI_STATUS EFIAPI FitParseFirmwarePropertyData(IN VOID *Fdt, IN CHAR8 *Firmware, OUT FIT_IMAGE_CONTEXT *Context)
Definition: FitLib.c:30
EFI_STATUS EFIAPI ParseFitImage(IN VOID *ImageBase, OUT FIT_IMAGE_CONTEXT *Context)
Definition: FitLib.c:82
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112