3 The API to create the binary.
5 Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "BinaryCreate.h"
12 #define GENSEC_RAW "GenSec -s %s \"%s\" -o \"%s\" > NUL"
14 #define GENSEC_RAW "GenSec -s %s \"%s\" -o \"%s\" > /dev/null"
18 // The guid is to for FFS of BFV.
20 EFI_GUID gEfiFfsBfvForMultiPlatformGuid
= EFI_FFS_BFV_FOR_MULTIPLATFORM_GUID
;
21 EFI_GUID gEfiFfsBfvForMultiPlatformGuid2
= EFI_FFS_BFV_FOR_MULTIPLATFORM_GUID2
;
24 Convert a GUID to a string.
26 @param[in] Guid Pointer to GUID to print.
28 @return The string after convert.
44 Buffer
= (CHAR8
*) malloc (36 + 1);
49 memset (Buffer
, '\0', 36 + 1);
53 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
71 Create the Ras section in FFS
73 @param[in] InputFilePath .efi file, it's optional unless process PE/TE section.
74 @param[in] OutputFilePath .te or .pe file
81 IN CHAR8
* InputFilePath
,
82 IN CHAR8
* OutputFilePath
89 SystemCommand
= malloc (
91 strlen ("EFI_SECTION_RAW") +
92 strlen (InputFilePath
) +
93 strlen (OutputFilePath
) +
96 if (NULL
== SystemCommand
) {
97 return EFI_OUT_OF_RESOURCES
;
106 ReturnValue
= system (SystemCommand
);
109 if (ReturnValue
!= 0) {
110 printf ("Error. Call GenSec failed.\n");
117 Create the Ras type of FFS
119 @param[in] InputFilePath .efi file, it's optional unless process PE/TE section.
120 @param[in] OutputFilePath .te or .pe file
127 IN CHAR8
** InputFilePaths
,
128 IN CHAR8
* OutputFilePath
,
129 IN BOOLEAN SizeOptimized
133 CHAR8
* SystemCommandFormatString
;
134 CHAR8
* SystemCommand
;
136 CHAR8
* FilePathFormatStr
;
142 SystemCommand
= NULL
;
147 FilePathFormatStr
= " -i \"";
149 for (Index
= 0; InputFilePaths
[Index
] != NULL
; Index
++) {
150 Size
= strlen (FilePathFormatStr
) + strlen (InputFilePaths
[Index
]) + 2; // 2 menas "" "
151 if (FilePathStr
== NULL
) {
152 FilePathStr
= malloc (Size
);
153 if (NULL
== FilePathStr
) {
154 return EFI_OUT_OF_RESOURCES
;
157 FilePathStr
= realloc (FilePathStr
, StrLen
+ Size
);
158 if (NULL
== FilePathStr
) {
159 return EFI_OUT_OF_RESOURCES
;
162 memset (FilePathStr
+ StrLen
, ' ', Size
);
163 memcpy (FilePathStr
+ StrLen
, FilePathFormatStr
, strlen(FilePathFormatStr
));
164 memcpy(FilePathStr
+ StrLen
+ strlen(FilePathFormatStr
), InputFilePaths
[Index
], strlen(InputFilePaths
[Index
]));
166 *(FilePathStr
+ StrLen
- 2) = '\"';
168 if (FilePathStr
== NULL
) {
171 *(FilePathStr
+ StrLen
- 1)= '\0';
175 GuidStr
= LibBfmGuidToStr(&gEfiFfsBfvForMultiPlatformGuid2
);
177 GuidStr
= LibBfmGuidToStr(&gEfiFfsBfvForMultiPlatformGuid
);
179 if (NULL
== GuidStr
) {
181 return EFI_OUT_OF_RESOURCES
;
183 SystemCommandFormatString
= "GenFfs -t %s %s -g %s -o \"%s\"";
184 SystemCommand
= malloc (
185 strlen (SystemCommandFormatString
) +
186 strlen ("EFI_FV_FILETYPE_FREEFORM") +
187 strlen (FilePathStr
) +
189 strlen (OutputFilePath
) +
192 if (NULL
== SystemCommand
) {
195 return EFI_OUT_OF_RESOURCES
;
199 "GenFfs -t %s %s -g %s -o \"%s\"",
200 "EFI_FV_FILETYPE_FREEFORM",// -t
205 ReturnValue
= system (SystemCommand
);
210 if (ReturnValue
!= 0) {
211 printf ("Error. Call GenFfs failed.\n");