eac41ed9bf81a7b8910b9a95ea679efc0ec818b8
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
1 ## @file
2 # Routines for generating AutoGen.h and AutoGen.c
3 #
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ## Import Modules
15 #
16 import string
17 import collections
18 import struct
19 from Common import EdkLogger
20
21 from Common.BuildToolError import *
22 from Common.DataType import *
23 from Common.Misc import *
24 from Common.StringUtils import StringToArray
25 from StrGather import *
26 from GenPcdDb import CreatePcdDatabaseCode
27 from IdfClassObject import *
28
29 ## PCD type string
30 gItemTypeStringDatabase = {
31 TAB_PCDS_FEATURE_FLAG : TAB_PCDS_FIXED_AT_BUILD,
32 TAB_PCDS_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD,
33 TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch',
34 TAB_PCDS_DYNAMIC : '',
35 TAB_PCDS_DYNAMIC_DEFAULT : '',
36 TAB_PCDS_DYNAMIC_VPD : '',
37 TAB_PCDS_DYNAMIC_HII : '',
38 TAB_PCDS_DYNAMIC_EX : '',
39 TAB_PCDS_DYNAMIC_EX_DEFAULT : '',
40 TAB_PCDS_DYNAMIC_EX_VPD : '',
41 TAB_PCDS_DYNAMIC_EX_HII : '',
42 }
43
44
45 ## Datum size
46 gDatumSizeStringDatabase = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOLEAN',TAB_VOID:'8'}
47 gDatumSizeStringDatabaseH = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOL',TAB_VOID:'PTR'}
48 gDatumSizeStringDatabaseLib = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'Bool',TAB_VOID:'Ptr'}
49
50 ## AutoGen File Header Templates
51 gAutoGenHeaderString = TemplateString("""\
52 /**
53 DO NOT EDIT
54 FILE auto-generated
55 Module name:
56 ${FileName}
57 Abstract: Auto-generated ${FileName} for building module or library.
58 **/
59 """)
60
61 gAutoGenHPrologueString = TemplateString("""
62 #ifndef _${File}_${Guid}
63 #define _${File}_${Guid}
64
65 """)
66
67 gAutoGenHCppPrologueString = """\
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 """
73
74 gAutoGenHEpilogueString = """
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif
81 """
82
83 ## PEI Core Entry Point Templates
84 gPeiCoreEntryPointPrototype = TemplateString("""
85 ${BEGIN}
86 VOID
87 EFIAPI
88 ${Function} (
89 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
90 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
91 IN VOID *Context
92 );
93 ${END}
94 """)
95
96 gPeiCoreEntryPointString = TemplateString("""
97 ${BEGIN}
98 VOID
99 EFIAPI
100 ProcessModuleEntryPointList (
101 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
102 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
103 IN VOID *Context
104 )
105
106 {
107 ${Function} (SecCoreData, PpiList, Context);
108 }
109 ${END}
110 """)
111
112
113 ## DXE Core Entry Point Templates
114 gDxeCoreEntryPointPrototype = TemplateString("""
115 ${BEGIN}
116 VOID
117 EFIAPI
118 ${Function} (
119 IN VOID *HobStart
120 );
121 ${END}
122 """)
123
124 gDxeCoreEntryPointString = TemplateString("""
125 ${BEGIN}
126 VOID
127 EFIAPI
128 ProcessModuleEntryPointList (
129 IN VOID *HobStart
130 )
131
132 {
133 ${Function} (HobStart);
134 }
135 ${END}
136 """)
137
138 ## PEIM Entry Point Templates
139 gPeimEntryPointPrototype = TemplateString("""
140 ${BEGIN}
141 EFI_STATUS
142 EFIAPI
143 ${Function} (
144 IN EFI_PEI_FILE_HANDLE FileHandle,
145 IN CONST EFI_PEI_SERVICES **PeiServices
146 );
147 ${END}
148 """)
149
150 gPeimEntryPointString = [
151 TemplateString("""
152 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
153
154 EFI_STATUS
155 EFIAPI
156 ProcessModuleEntryPointList (
157 IN EFI_PEI_FILE_HANDLE FileHandle,
158 IN CONST EFI_PEI_SERVICES **PeiServices
159 )
160
161 {
162 return EFI_SUCCESS;
163 }
164 """),
165 TemplateString("""
166 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
167 ${BEGIN}
168 EFI_STATUS
169 EFIAPI
170 ProcessModuleEntryPointList (
171 IN EFI_PEI_FILE_HANDLE FileHandle,
172 IN CONST EFI_PEI_SERVICES **PeiServices
173 )
174
175 {
176 return ${Function} (FileHandle, PeiServices);
177 }
178 ${END}
179 """),
180 TemplateString("""
181 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
182
183 EFI_STATUS
184 EFIAPI
185 ProcessModuleEntryPointList (
186 IN EFI_PEI_FILE_HANDLE FileHandle,
187 IN CONST EFI_PEI_SERVICES **PeiServices
188 )
189
190 {
191 EFI_STATUS Status;
192 EFI_STATUS CombinedStatus;
193
194 CombinedStatus = EFI_LOAD_ERROR;
195 ${BEGIN}
196 Status = ${Function} (FileHandle, PeiServices);
197 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
198 CombinedStatus = Status;
199 }
200 ${END}
201 return CombinedStatus;
202 }
203 """)
204 ]
205
206 ## SMM_CORE Entry Point Templates
207 gSmmCoreEntryPointPrototype = TemplateString("""
208 ${BEGIN}
209 EFI_STATUS
210 EFIAPI
211 ${Function} (
212 IN EFI_HANDLE ImageHandle,
213 IN EFI_SYSTEM_TABLE *SystemTable
214 );
215 ${END}
216 """)
217
218 gSmmCoreEntryPointString = TemplateString("""
219 ${BEGIN}
220 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
221 const UINT32 _gDxeRevision = ${PiSpecVersion};
222
223 EFI_STATUS
224 EFIAPI
225 ProcessModuleEntryPointList (
226 IN EFI_HANDLE ImageHandle,
227 IN EFI_SYSTEM_TABLE *SystemTable
228 )
229 {
230 return ${Function} (ImageHandle, SystemTable);
231 }
232 ${END}
233 """)
234
235 ## MM_CORE_STANDALONE Entry Point Templates
236 gMmCoreStandaloneEntryPointPrototype = TemplateString("""
237 ${BEGIN}
238 EFI_STATUS
239 EFIAPI
240 ${Function} (
241 IN VOID *HobStart
242 );
243 ${END}
244 """)
245
246 gMmCoreStandaloneEntryPointString = TemplateString("""
247 ${BEGIN}
248 const UINT32 _gMmRevision = ${PiSpecVersion};
249
250 VOID
251 EFIAPI
252 ProcessModuleEntryPointList (
253 IN VOID *HobStart
254 )
255 {
256 ${Function} (HobStart);
257 }
258 ${END}
259 """)
260
261 ## MM_STANDALONE Entry Point Templates
262 gMmStandaloneEntryPointPrototype = TemplateString("""
263 ${BEGIN}
264 EFI_STATUS
265 EFIAPI
266 ${Function} (
267 IN EFI_HANDLE ImageHandle,
268 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
269 );
270 ${END}
271 """)
272
273 gMmStandaloneEntryPointString = [
274 TemplateString("""
275 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
276
277 EFI_STATUS
278 EFIAPI
279 ProcessModuleEntryPointList (
280 IN EFI_HANDLE ImageHandle,
281 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
282 )
283
284 {
285 return EFI_SUCCESS;
286 }
287 """),
288 TemplateString("""
289 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
290 ${BEGIN}
291 EFI_STATUS
292 EFIAPI
293 ProcessModuleEntryPointList (
294 IN EFI_HANDLE ImageHandle,
295 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
296 )
297
298 {
299 return ${Function} (ImageHandle, MmSystemTable);
300 }
301 ${END}
302 """),
303 TemplateString("""
304 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
305
306 EFI_STATUS
307 EFIAPI
308 ProcessModuleEntryPointList (
309 IN EFI_HANDLE ImageHandle,
310 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
311 )
312
313 {
314 EFI_STATUS Status;
315 EFI_STATUS CombinedStatus;
316
317 CombinedStatus = EFI_LOAD_ERROR;
318 ${BEGIN}
319 Status = ${Function} (ImageHandle, MmSystemTable);
320 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
321 CombinedStatus = Status;
322 }
323 ${END}
324 return CombinedStatus;
325 }
326 """)
327 ]
328
329 ## DXE SMM Entry Point Templates
330 gDxeSmmEntryPointPrototype = TemplateString("""
331 ${BEGIN}
332 EFI_STATUS
333 EFIAPI
334 ${Function} (
335 IN EFI_HANDLE ImageHandle,
336 IN EFI_SYSTEM_TABLE *SystemTable
337 );
338 ${END}
339 """)
340
341 gDxeSmmEntryPointString = [
342 TemplateString("""
343 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
344 const UINT32 _gDxeRevision = ${PiSpecVersion};
345
346 EFI_STATUS
347 EFIAPI
348 ProcessModuleEntryPointList (
349 IN EFI_HANDLE ImageHandle,
350 IN EFI_SYSTEM_TABLE *SystemTable
351 )
352
353 {
354 return EFI_SUCCESS;
355 }
356 """),
357 TemplateString("""
358 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
359 const UINT32 _gDxeRevision = ${PiSpecVersion};
360
361 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
362 static EFI_STATUS mDriverEntryPointStatus;
363
364 VOID
365 EFIAPI
366 ExitDriver (
367 IN EFI_STATUS Status
368 )
369 {
370 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
371 mDriverEntryPointStatus = Status;
372 }
373 LongJump (&mJumpContext, (UINTN)-1);
374 ASSERT (FALSE);
375 }
376
377 EFI_STATUS
378 EFIAPI
379 ProcessModuleEntryPointList (
380 IN EFI_HANDLE ImageHandle,
381 IN EFI_SYSTEM_TABLE *SystemTable
382 )
383 {
384 mDriverEntryPointStatus = EFI_LOAD_ERROR;
385
386 ${BEGIN}
387 if (SetJump (&mJumpContext) == 0) {
388 ExitDriver (${Function} (ImageHandle, SystemTable));
389 ASSERT (FALSE);
390 }
391 ${END}
392
393 return mDriverEntryPointStatus;
394 }
395 """)
396 ]
397
398 ## UEFI Driver Entry Point Templates
399 gUefiDriverEntryPointPrototype = TemplateString("""
400 ${BEGIN}
401 EFI_STATUS
402 EFIAPI
403 ${Function} (
404 IN EFI_HANDLE ImageHandle,
405 IN EFI_SYSTEM_TABLE *SystemTable
406 );
407 ${END}
408 """)
409
410 gUefiDriverEntryPointString = [
411 TemplateString("""
412 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
413 const UINT32 _gDxeRevision = ${PiSpecVersion};
414
415 EFI_STATUS
416 EFIAPI
417 ProcessModuleEntryPointList (
418 IN EFI_HANDLE ImageHandle,
419 IN EFI_SYSTEM_TABLE *SystemTable
420 )
421 {
422 return EFI_SUCCESS;
423 }
424 """),
425 TemplateString("""
426 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
427 const UINT32 _gDxeRevision = ${PiSpecVersion};
428
429 ${BEGIN}
430 EFI_STATUS
431 EFIAPI
432 ProcessModuleEntryPointList (
433 IN EFI_HANDLE ImageHandle,
434 IN EFI_SYSTEM_TABLE *SystemTable
435 )
436
437 {
438 return ${Function} (ImageHandle, SystemTable);
439 }
440 ${END}
441 VOID
442 EFIAPI
443 ExitDriver (
444 IN EFI_STATUS Status
445 )
446 {
447 if (EFI_ERROR (Status)) {
448 ProcessLibraryDestructorList (gImageHandle, gST);
449 }
450 gBS->Exit (gImageHandle, Status, 0, NULL);
451 }
452 """),
453 TemplateString("""
454 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
455 const UINT32 _gDxeRevision = ${PiSpecVersion};
456
457 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
458 static EFI_STATUS mDriverEntryPointStatus;
459
460 EFI_STATUS
461 EFIAPI
462 ProcessModuleEntryPointList (
463 IN EFI_HANDLE ImageHandle,
464 IN EFI_SYSTEM_TABLE *SystemTable
465 )
466 {
467 mDriverEntryPointStatus = EFI_LOAD_ERROR;
468 ${BEGIN}
469 if (SetJump (&mJumpContext) == 0) {
470 ExitDriver (${Function} (ImageHandle, SystemTable));
471 ASSERT (FALSE);
472 }
473 ${END}
474 return mDriverEntryPointStatus;
475 }
476
477 VOID
478 EFIAPI
479 ExitDriver (
480 IN EFI_STATUS Status
481 )
482 {
483 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
484 mDriverEntryPointStatus = Status;
485 }
486 LongJump (&mJumpContext, (UINTN)-1);
487 ASSERT (FALSE);
488 }
489 """)
490 ]
491
492
493 ## UEFI Application Entry Point Templates
494 gUefiApplicationEntryPointPrototype = TemplateString("""
495 ${BEGIN}
496 EFI_STATUS
497 EFIAPI
498 ${Function} (
499 IN EFI_HANDLE ImageHandle,
500 IN EFI_SYSTEM_TABLE *SystemTable
501 );
502 ${END}
503 """)
504
505 gUefiApplicationEntryPointString = [
506 TemplateString("""
507 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
508
509 EFI_STATUS
510 EFIAPI
511 ProcessModuleEntryPointList (
512 IN EFI_HANDLE ImageHandle,
513 IN EFI_SYSTEM_TABLE *SystemTable
514 )
515 {
516 return EFI_SUCCESS;
517 }
518 """),
519 TemplateString("""
520 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
521
522 ${BEGIN}
523 EFI_STATUS
524 EFIAPI
525 ProcessModuleEntryPointList (
526 IN EFI_HANDLE ImageHandle,
527 IN EFI_SYSTEM_TABLE *SystemTable
528 )
529
530 {
531 return ${Function} (ImageHandle, SystemTable);
532 }
533 ${END}
534 VOID
535 EFIAPI
536 ExitDriver (
537 IN EFI_STATUS Status
538 )
539 {
540 if (EFI_ERROR (Status)) {
541 ProcessLibraryDestructorList (gImageHandle, gST);
542 }
543 gBS->Exit (gImageHandle, Status, 0, NULL);
544 }
545 """),
546 TemplateString("""
547 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
548
549 EFI_STATUS
550 EFIAPI
551 ProcessModuleEntryPointList (
552 IN EFI_HANDLE ImageHandle,
553 IN EFI_SYSTEM_TABLE *SystemTable
554 )
555
556 {
557 ${BEGIN}
558 if (SetJump (&mJumpContext) == 0) {
559 ExitDriver (${Function} (ImageHandle, SystemTable));
560 ASSERT (FALSE);
561 }
562 ${END}
563 return mDriverEntryPointStatus;
564 }
565
566 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
567 static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
568
569 VOID
570 EFIAPI
571 ExitDriver (
572 IN EFI_STATUS Status
573 )
574 {
575 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
576 mDriverEntryPointStatus = Status;
577 }
578 LongJump (&mJumpContext, (UINTN)-1);
579 ASSERT (FALSE);
580 }
581 """)
582 ]
583
584 ## UEFI Unload Image Templates
585 gUefiUnloadImagePrototype = TemplateString("""
586 ${BEGIN}
587 EFI_STATUS
588 EFIAPI
589 ${Function} (
590 IN EFI_HANDLE ImageHandle
591 );
592 ${END}
593 """)
594
595 gUefiUnloadImageString = [
596 TemplateString("""
597 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
598
599 EFI_STATUS
600 EFIAPI
601 ProcessModuleUnloadList (
602 IN EFI_HANDLE ImageHandle
603 )
604 {
605 return EFI_SUCCESS;
606 }
607 """),
608 TemplateString("""
609 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
610
611 ${BEGIN}
612 EFI_STATUS
613 EFIAPI
614 ProcessModuleUnloadList (
615 IN EFI_HANDLE ImageHandle
616 )
617 {
618 return ${Function} (ImageHandle);
619 }
620 ${END}
621 """),
622 TemplateString("""
623 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
624
625 EFI_STATUS
626 EFIAPI
627 ProcessModuleUnloadList (
628 IN EFI_HANDLE ImageHandle
629 )
630 {
631 EFI_STATUS Status;
632
633 Status = EFI_SUCCESS;
634 ${BEGIN}
635 if (EFI_ERROR (Status)) {
636 ${Function} (ImageHandle);
637 } else {
638 Status = ${Function} (ImageHandle);
639 }
640 ${END}
641 return Status;
642 }
643 """)
644 ]
645
646 gLibraryStructorPrototype = {
647 SUP_MODULE_BASE : TemplateString("""${BEGIN}
648 RETURN_STATUS
649 EFIAPI
650 ${Function} (
651 VOID
652 );${END}
653 """),
654
655 'PEI' : TemplateString("""${BEGIN}
656 EFI_STATUS
657 EFIAPI
658 ${Function} (
659 IN EFI_PEI_FILE_HANDLE FileHandle,
660 IN CONST EFI_PEI_SERVICES **PeiServices
661 );${END}
662 """),
663
664 'DXE' : TemplateString("""${BEGIN}
665 EFI_STATUS
666 EFIAPI
667 ${Function} (
668 IN EFI_HANDLE ImageHandle,
669 IN EFI_SYSTEM_TABLE *SystemTable
670 );${END}
671 """),
672
673 'MM' : TemplateString("""${BEGIN}
674 EFI_STATUS
675 EFIAPI
676 ${Function} (
677 IN EFI_HANDLE ImageHandle,
678 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
679 );${END}
680 """),
681 }
682
683 gLibraryStructorCall = {
684 SUP_MODULE_BASE : TemplateString("""${BEGIN}
685 Status = ${Function} ();
686 ASSERT_EFI_ERROR (Status);${END}
687 """),
688
689 'PEI' : TemplateString("""${BEGIN}
690 Status = ${Function} (FileHandle, PeiServices);
691 ASSERT_EFI_ERROR (Status);${END}
692 """),
693
694 'DXE' : TemplateString("""${BEGIN}
695 Status = ${Function} (ImageHandle, SystemTable);
696 ASSERT_EFI_ERROR (Status);${END}
697 """),
698
699 'MM' : TemplateString("""${BEGIN}
700 Status = ${Function} (ImageHandle, MmSystemTable);
701 ASSERT_EFI_ERROR (Status);${END}
702 """),
703 }
704
705 ## Library Constructor and Destructor Templates
706 gLibraryString = {
707 SUP_MODULE_BASE : TemplateString("""
708 ${BEGIN}${FunctionPrototype}${END}
709
710 VOID
711 EFIAPI
712 ProcessLibrary${Type}List (
713 VOID
714 )
715 {
716 ${BEGIN} EFI_STATUS Status;
717 ${FunctionCall}${END}
718 }
719 """),
720
721 'PEI' : TemplateString("""
722 ${BEGIN}${FunctionPrototype}${END}
723
724 VOID
725 EFIAPI
726 ProcessLibrary${Type}List (
727 IN EFI_PEI_FILE_HANDLE FileHandle,
728 IN CONST EFI_PEI_SERVICES **PeiServices
729 )
730 {
731 ${BEGIN} EFI_STATUS Status;
732 ${FunctionCall}${END}
733 }
734 """),
735
736 'DXE' : TemplateString("""
737 ${BEGIN}${FunctionPrototype}${END}
738
739 VOID
740 EFIAPI
741 ProcessLibrary${Type}List (
742 IN EFI_HANDLE ImageHandle,
743 IN EFI_SYSTEM_TABLE *SystemTable
744 )
745 {
746 ${BEGIN} EFI_STATUS Status;
747 ${FunctionCall}${END}
748 }
749 """),
750
751 'MM' : TemplateString("""
752 ${BEGIN}${FunctionPrototype}${END}
753
754 VOID
755 EFIAPI
756 ProcessLibrary${Type}List (
757 IN EFI_HANDLE ImageHandle,
758 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
759 )
760 {
761 ${BEGIN} EFI_STATUS Status;
762 ${FunctionCall}${END}
763 }
764 """),
765 }
766
767 gBasicHeaderFile = "Base.h"
768
769 gModuleTypeHeaderFile = {
770 SUP_MODULE_BASE : [gBasicHeaderFile],
771 SUP_MODULE_SEC : ["PiPei.h", "Library/DebugLib.h"],
772 SUP_MODULE_PEI_CORE : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],
773 SUP_MODULE_PEIM : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],
774 SUP_MODULE_DXE_CORE : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],
775 SUP_MODULE_DXE_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
776 SUP_MODULE_DXE_SMM_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
777 SUP_MODULE_DXE_RUNTIME_DRIVER: ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
778 SUP_MODULE_DXE_SAL_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
779 SUP_MODULE_UEFI_DRIVER : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
780 SUP_MODULE_UEFI_APPLICATION : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],
781 SUP_MODULE_SMM_CORE : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],
782 SUP_MODULE_MM_STANDALONE : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],
783 SUP_MODULE_MM_CORE_STANDALONE : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],
784 SUP_MODULE_USER_DEFINED : [gBasicHeaderFile]
785 }
786
787 ## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
788 # the TokenName and Guid comparison to avoid define name collisions.
789 #
790 # @param Info The ModuleAutoGen object
791 # @param AutoGenH The TemplateString object for header file
792 #
793 #
794 def DynExPcdTokenNumberMapping(Info, AutoGenH):
795 ExTokenCNameList = []
796 PcdExList = []
797 # Even it is the Library, the PCD is saved in the ModulePcdList
798 PcdList = Info.ModulePcdList
799 for Pcd in PcdList:
800 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
801 ExTokenCNameList.append(Pcd.TokenCName)
802 PcdExList.append(Pcd)
803 if len(ExTokenCNameList) == 0:
804 return
805 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')
806 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
807 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
808 # Use the Guid pointer to see if it matches any of the token space GUIDs.
809 TokenCNameList = set()
810 for TokenCName in ExTokenCNameList:
811 if TokenCName in TokenCNameList:
812 continue
813 Index = 0
814 Count = ExTokenCNameList.count(TokenCName)
815 for Pcd in PcdExList:
816 RealTokenCName = Pcd.TokenCName
817 for PcdItem in GlobalData.MixedPcd:
818 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
819 RealTokenCName = PcdItem[0]
820 break
821 if Pcd.TokenCName == TokenCName:
822 Index = Index + 1
823 if Index == 1:
824 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName))
825 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
826 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))
827 else:
828 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
829 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))
830 if Index == Count:
831 AutoGenH.Append('0 \\\n )\n')
832 TokenCNameList.add(TokenCName)
833
834 TokenCNameList = set()
835 for TokenCName in ExTokenCNameList:
836 if TokenCName in TokenCNameList:
837 continue
838 Index = 0
839 Count = ExTokenCNameList.count(TokenCName)
840 for Pcd in PcdExList:
841 RealTokenCName = Pcd.TokenCName
842 for PcdItem in GlobalData.MixedPcd:
843 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
844 RealTokenCName = PcdItem[0]
845 break
846 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == TokenCName:
847 Index = Index + 1
848 if Index == 1:
849 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName))
850 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')
851 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
852 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))
853 else:
854 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
855 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))
856 if Index == Count:
857 AutoGenH.Append('0 \\\n )\n')
858 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
859 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
860 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
861 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
862 AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'
863 % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))
864 TokenCNameList.add(TokenCName)
865
866 ## Create code for module PCDs
867 #
868 # @param Info The ModuleAutoGen object
869 # @param AutoGenC The TemplateString object for C code
870 # @param AutoGenH The TemplateString object for header file
871 # @param Pcd The PCD object
872 #
873 def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
874 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]
875 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
876 #
877 # Write PCDs
878 #
879 TokenCName = Pcd.TokenCName
880 for PcdItem in GlobalData.MixedPcd:
881 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
882 TokenCName = PcdItem[0]
883 break
884 PcdTokenName = '_PCD_TOKEN_' + TokenCName
885 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'
886 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName
887 PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName
888 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName
889 FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName
890
891 if Pcd.PcdValueFromComm:
892 Pcd.DefaultValue = Pcd.PcdValueFromComm
893
894 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
895 TokenNumber = int(Pcd.TokenValue, 0)
896 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
897 # different Guids but same TokenCName
898 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName
899 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
900 else:
901 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
902 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
903 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
904 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
905 # report warning message notify the PI that they are attempting to build a module
906 # that must be included in a flash image in order to be functional. These Dynamic PCD
907 # will not be added into the Database unless it is used by other modules that are
908 # included in the FDF file.
909 # In this case, just assign an invalid token number to make it pass build.
910 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:
911 TokenNumber = 0
912 else:
913 EdkLogger.error("build", AUTOGEN_ERROR,
914 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),
915 ExtraData="[%s]" % str(Info))
916 else:
917 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
918 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))
919
920 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)
921 if Pcd.Type not in gItemTypeStringDatabase:
922 EdkLogger.error("build", AUTOGEN_ERROR,
923 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),
924 ExtraData="[%s]" % str(Info))
925
926 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]
927 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]
928 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
929 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
930 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName
931 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
932
933 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
934 if Info.IsLibrary:
935 PcdList = Info.LibraryPcdList
936 else:
937 PcdList = Info.ModulePcdList
938 PcdExCNameTest = 0
939 for PcdModule in PcdList:
940 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
941 PcdExCNameTest += 1
942 # get out early once we found > 1...
943 if PcdExCNameTest > 1:
944 break
945 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
946 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
947 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
948 if PcdExCNameTest > 1:
949 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')
950 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
951 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
952 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
953 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
954 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
955 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
956 else:
957 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
958 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
959 else:
960 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
961 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
962 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
963 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
964 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
965 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
966 else:
967 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
968 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
969 elif Pcd.Type in PCD_DYNAMIC_TYPE_SET:
970 PcdCNameTest = 0
971 for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:
972 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
973 PcdCNameTest += 1
974 # get out early once we found > 1...
975 if PcdCNameTest > 1:
976 break
977 if PcdCNameTest > 1:
978 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))
979 else:
980 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
981 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))
982 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
983 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
984 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
985 else:
986 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
987 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
988 else:
989 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName
990 Const = 'const'
991 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
992 Const = ''
993 Type = ''
994 Array = ''
995 Value = Pcd.DefaultValue
996 Unicode = False
997 ValueNumber = 0
998
999 if Pcd.DatumType == 'BOOLEAN':
1000 BoolValue = Value.upper()
1001 if BoolValue == 'TRUE' or BoolValue == '1':
1002 Value = '1U'
1003 elif BoolValue == 'FALSE' or BoolValue == '0':
1004 Value = '0U'
1005
1006 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:
1007 try:
1008 if Value.upper().endswith('L'):
1009 Value = Value[:-1]
1010 ValueNumber = int (Value, 0)
1011 except:
1012 EdkLogger.error("build", AUTOGEN_ERROR,
1013 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1014 ExtraData="[%s]" % str(Info))
1015 if Pcd.DatumType == TAB_UINT64:
1016 if ValueNumber < 0:
1017 EdkLogger.error("build", AUTOGEN_ERROR,
1018 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1019 ExtraData="[%s]" % str(Info))
1020 elif ValueNumber >= 0x10000000000000000:
1021 EdkLogger.error("build", AUTOGEN_ERROR,
1022 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1023 ExtraData="[%s]" % str(Info))
1024 if not Value.endswith('ULL'):
1025 Value += 'ULL'
1026 elif Pcd.DatumType == TAB_UINT32:
1027 if ValueNumber < 0:
1028 EdkLogger.error("build", AUTOGEN_ERROR,
1029 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1030 ExtraData="[%s]" % str(Info))
1031 elif ValueNumber >= 0x100000000:
1032 EdkLogger.error("build", AUTOGEN_ERROR,
1033 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1034 ExtraData="[%s]" % str(Info))
1035 if not Value.endswith('U'):
1036 Value += 'U'
1037 elif Pcd.DatumType == TAB_UINT16:
1038 if ValueNumber < 0:
1039 EdkLogger.error("build", AUTOGEN_ERROR,
1040 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1041 ExtraData="[%s]" % str(Info))
1042 elif ValueNumber >= 0x10000:
1043 EdkLogger.error("build", AUTOGEN_ERROR,
1044 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1045 ExtraData="[%s]" % str(Info))
1046 if not Value.endswith('U'):
1047 Value += 'U'
1048 elif Pcd.DatumType == TAB_UINT8:
1049 if ValueNumber < 0:
1050 EdkLogger.error("build", AUTOGEN_ERROR,
1051 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1052 ExtraData="[%s]" % str(Info))
1053 elif ValueNumber >= 0x100:
1054 EdkLogger.error("build", AUTOGEN_ERROR,
1055 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1056 ExtraData="[%s]" % str(Info))
1057 if not Value.endswith('U'):
1058 Value += 'U'
1059 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1060 if not Pcd.MaxDatumSize:
1061 EdkLogger.error("build", AUTOGEN_ERROR,
1062 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),
1063 ExtraData="[%s]" % str(Info))
1064
1065 ArraySize = int(Pcd.MaxDatumSize, 0)
1066 if Value[0] == '{':
1067 Type = '(VOID *)'
1068 ValueSize = len(Value.split(','))
1069 else:
1070 if Value[0] == 'L':
1071 Unicode = True
1072 Value = Value.lstrip('L') #.strip('"')
1073 Value = eval(Value) # translate escape character
1074 ValueSize = len(Value) + 1
1075 NewValue = '{'
1076 for Index in range(0, len(Value)):
1077 if Unicode:
1078 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
1079 else:
1080 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
1081 if Unicode:
1082 ArraySize = ArraySize / 2
1083 Value = NewValue + '0 }'
1084 if ArraySize < ValueSize:
1085 if Pcd.MaxSizeUserSet:
1086 EdkLogger.error("build", AUTOGEN_ERROR,
1087 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
1088 ExtraData="[%s]" % str(Info))
1089 else:
1090 ArraySize = Pcd.GetPcdSize()
1091 if Unicode:
1092 ArraySize = ArraySize / 2
1093 Array = '[%d]' % ArraySize
1094 #
1095 # skip casting for fixed at build since it breaks ARM assembly.
1096 # Long term we need PCD macros that work in assembly
1097 #
1098 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD and Pcd.DatumType in TAB_PCD_NUMERIC_TYPES_VOID:
1099 Value = "((%s)%s)" % (Pcd.DatumType, Value)
1100
1101 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1102 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName
1103 else:
1104 PcdValueName = '_PCD_VALUE_' + TokenCName
1105
1106 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1107 #
1108 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1109 #
1110 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))
1111 if Unicode:
1112 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
1113 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))
1114 else:
1115 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
1116 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))
1117 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))
1118
1119 PcdDataSize = Pcd.GetPcdSize()
1120 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:
1121 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1122 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))
1123 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName, PcdDataSize))
1124 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1125 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))
1126 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))
1127 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1128 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))
1129 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable, Pcd.MaxDatumSize))
1130 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1131 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
1132 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
1133 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
1134 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
1135
1136 PcdDataSize = Pcd.GetPcdSize()
1137 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))
1138
1139 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))
1140 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1141 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))
1142 else:
1143 PcdDataSize = Pcd.GetPcdSize()
1144 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1145 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))
1146
1147 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
1148 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
1149 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
1150 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
1151
1152 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1153 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1154 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))
1155 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))
1156 else:
1157 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
1158 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))
1159 else:
1160 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
1161
1162 ## Create code for library module PCDs
1163 #
1164 # @param Info The ModuleAutoGen object
1165 # @param AutoGenC The TemplateString object for C code
1166 # @param AutoGenH The TemplateString object for header file
1167 # @param Pcd The PCD object
1168 #
1169 def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
1170 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
1171 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
1172 TokenCName = Pcd.TokenCName
1173 for PcdItem in GlobalData.MixedPcd:
1174 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
1175 TokenCName = PcdItem[0]
1176 break
1177 PcdTokenName = '_PCD_TOKEN_' + TokenCName
1178 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName
1179 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'
1180 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName
1181 PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName
1182 FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName
1183
1184 if Pcd.PcdValueFromComm:
1185 Pcd.DefaultValue = Pcd.PcdValueFromComm
1186 #
1187 # Write PCDs
1188 #
1189 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
1190 TokenNumber = int(Pcd.TokenValue, 0)
1191 else:
1192 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
1193 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1194 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1195 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1196 # report warning message notify the PI that they are attempting to build a module
1197 # that must be included in a flash image in order to be functional. These Dynamic PCD
1198 # will not be added into the Database unless it is used by other modules that are
1199 # included in the FDF file.
1200 # In this case, just assign an invalid token number to make it pass build.
1201 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:
1202 TokenNumber = 0
1203 else:
1204 EdkLogger.error("build", AUTOGEN_ERROR,
1205 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),
1206 ExtraData="[%s]" % str(Info))
1207 else:
1208 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
1209
1210 if Pcd.Type not in gItemTypeStringDatabase:
1211 EdkLogger.error("build", AUTOGEN_ERROR,
1212 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),
1213 ExtraData="[%s]" % str(Info))
1214
1215 DatumType = Pcd.DatumType
1216 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]
1217 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]
1218 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
1219 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
1220 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName
1221 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1222
1223 Type = ''
1224 Array = ''
1225 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1226 if Pcd.DefaultValue[0]== '{':
1227 Type = '(VOID *)'
1228 Array = '[]'
1229 PcdItemType = Pcd.Type
1230 if PcdItemType in PCD_DYNAMIC_EX_TYPE_SET:
1231 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName
1232 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
1233
1234 if Info.IsLibrary:
1235 PcdList = Info.LibraryPcdList
1236 else:
1237 PcdList = Info.ModulePcdList
1238 PcdExCNameTest = 0
1239 for PcdModule in PcdList:
1240 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
1241 PcdExCNameTest += 1
1242 # get out early once we found > 1...
1243 if PcdExCNameTest > 1:
1244 break
1245 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1246 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1247 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1248 if PcdExCNameTest > 1:
1249 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')
1250 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
1251 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1252 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
1253 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1254 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1255 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1256 else:
1257 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1258 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1259 else:
1260 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
1261 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1262 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
1263 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1264 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1265 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1266 else:
1267 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1268 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1269 else:
1270 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))
1271 if PcdItemType in PCD_DYNAMIC_TYPE_SET:
1272 PcdList = []
1273 PcdCNameList = []
1274 PcdList.extend(Info.LibraryPcdList)
1275 PcdList.extend(Info.ModulePcdList)
1276 for PcdModule in PcdList:
1277 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET:
1278 PcdCNameList.append(PcdModule.TokenCName)
1279 if PcdCNameList.count(Pcd.TokenCName) > 1:
1280 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName.They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))
1281 else:
1282 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
1283 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))
1284 if DatumType not in TAB_PCD_NUMERIC_TYPES:
1285 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
1286 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1287 else:
1288 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
1289 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1290 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:
1291 GetModeMaxSizeName = '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName
1292 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName
1293 if DatumType not in TAB_PCD_NUMERIC_TYPES:
1294 if DatumType == TAB_VOID and Array == '[]':
1295 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']
1296 else:
1297 DatumType = TAB_UINT8
1298 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))
1299 else:
1300 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))
1301 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))
1302 PcdDataSize = Pcd.GetPcdSize()
1303 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1304 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
1305 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
1306 AutoGenH.Append('#define %s %s\n' % (GetModeMaxSizeName, PatchPcdMaxSizeVariable))
1307 AutoGenH.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable)
1308 else:
1309 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
1310 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))
1311 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))
1312
1313 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, PatchPcdSizeVariableName))
1314 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1315
1316 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:
1317 key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
1318 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName
1319 if DatumType == TAB_VOID and Array == '[]':
1320 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']
1321 if DatumType not in TAB_PCD_NUMERIC_TYPES_VOID:
1322 DatumType = TAB_UINT8
1323 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))
1324 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))
1325 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
1326
1327 ConstFixedPcd = False
1328 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):
1329 ConstFixedPcd = True
1330 if key in Info.ConstPcd:
1331 Pcd.DefaultValue = Info.ConstPcd[key]
1332 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1333 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))
1334 else:
1335 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))
1336 PcdDataSize = Pcd.GetPcdSize()
1337 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:
1338 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1339 if ConstFixedPcd:
1340 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1341 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))
1342 else:
1343 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixedPcdSizeVariableName))
1344 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, FixedPcdSizeVariableName))
1345 AutoGenH.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName)
1346 else:
1347 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1348 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))
1349
1350 ## Create code for library constructor
1351 #
1352 # @param Info The ModuleAutoGen object
1353 # @param AutoGenC The TemplateString object for C code
1354 # @param AutoGenH The TemplateString object for header file
1355 #
1356 def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
1357 #
1358 # Library Constructors
1359 #
1360 ConstructorPrototypeString = TemplateString()
1361 ConstructorCallingString = TemplateString()
1362 if Info.IsLibrary:
1363 DependentLibraryList = [Info.Module]
1364 else:
1365 DependentLibraryList = Info.DependentLibraryList
1366 for Lib in DependentLibraryList:
1367 if len(Lib.ConstructorList) <= 0:
1368 continue
1369 Dict = {'Function':Lib.ConstructorList}
1370 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1371 ConstructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))
1372 ConstructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))
1373 elif Lib.ModuleType in SUP_MODULE_SET_PEI:
1374 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1375 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1376 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1377 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1378 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1379 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1380 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1381 ConstructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))
1382 ConstructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))
1383
1384 if str(ConstructorPrototypeString) == '':
1385 ConstructorPrototypeList = []
1386 else:
1387 ConstructorPrototypeList = [str(ConstructorPrototypeString)]
1388 if str(ConstructorCallingString) == '':
1389 ConstructorCallingList = []
1390 else:
1391 ConstructorCallingList = [str(ConstructorCallingString)]
1392
1393 Dict = {
1394 'Type' : 'Constructor',
1395 'FunctionPrototype' : ConstructorPrototypeList,
1396 'FunctionCall' : ConstructorCallingList
1397 }
1398 if Info.IsLibrary:
1399 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1400 else:
1401 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1402 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
1403 elif Info.ModuleType in SUP_MODULE_SET_PEI:
1404 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1405 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1406 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1407 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1408 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1409 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))
1410
1411 ## Create code for library destructor
1412 #
1413 # @param Info The ModuleAutoGen object
1414 # @param AutoGenC The TemplateString object for C code
1415 # @param AutoGenH The TemplateString object for header file
1416 #
1417 def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
1418 #
1419 # Library Destructors
1420 #
1421 DestructorPrototypeString = TemplateString()
1422 DestructorCallingString = TemplateString()
1423 if Info.IsLibrary:
1424 DependentLibraryList = [Info.Module]
1425 else:
1426 DependentLibraryList = Info.DependentLibraryList
1427 for Index in range(len(DependentLibraryList)-1, -1, -1):
1428 Lib = DependentLibraryList[Index]
1429 if len(Lib.DestructorList) <= 0:
1430 continue
1431 Dict = {'Function':Lib.DestructorList}
1432 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1433 DestructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))
1434 DestructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))
1435 elif Lib.ModuleType in SUP_MODULE_SET_PEI:
1436 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1437 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1438 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1439 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1440 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1441 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1442 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1443 DestructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))
1444 DestructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))
1445
1446 if str(DestructorPrototypeString) == '':
1447 DestructorPrototypeList = []
1448 else:
1449 DestructorPrototypeList = [str(DestructorPrototypeString)]
1450 if str(DestructorCallingString) == '':
1451 DestructorCallingList = []
1452 else:
1453 DestructorCallingList = [str(DestructorCallingString)]
1454
1455 Dict = {
1456 'Type' : 'Destructor',
1457 'FunctionPrototype' : DestructorPrototypeList,
1458 'FunctionCall' : DestructorCallingList
1459 }
1460 if Info.IsLibrary:
1461 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1462 else:
1463 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1464 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
1465 elif Info.ModuleType in SUP_MODULE_SET_PEI:
1466 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1467 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1468 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1469 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1470 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1471 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))
1472
1473
1474 ## Create code for ModuleEntryPoint
1475 #
1476 # @param Info The ModuleAutoGen object
1477 # @param AutoGenC The TemplateString object for C code
1478 # @param AutoGenH The TemplateString object for header file
1479 #
1480 def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
1481 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:
1482 return
1483 #
1484 # Module Entry Points
1485 #
1486 NumEntryPoints = len(Info.Module.ModuleEntryPointList)
1487 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:
1488 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']
1489 else:
1490 PiSpecVersion = '0x00000000'
1491 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:
1492 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']
1493 else:
1494 UefiSpecVersion = '0x00000000'
1495 Dict = {
1496 'Function' : Info.Module.ModuleEntryPointList,
1497 'PiSpecVersion' : PiSpecVersion + 'U',
1498 'UefiSpecVersion': UefiSpecVersion + 'U'
1499 }
1500
1501 if Info.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_DXE_CORE, SUP_MODULE_SMM_CORE, SUP_MODULE_MM_CORE_STANDALONE]:
1502 if Info.SourceFileList:
1503 if NumEntryPoints != 1:
1504 EdkLogger.error(
1505 "build",
1506 AUTOGEN_ERROR,
1507 '%s must have exactly one entry point' % Info.ModuleType,
1508 File=str(Info),
1509 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)
1510 )
1511 if Info.ModuleType == SUP_MODULE_PEI_CORE:
1512 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))
1513 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))
1514 elif Info.ModuleType == SUP_MODULE_DXE_CORE:
1515 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))
1516 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))
1517 elif Info.ModuleType == SUP_MODULE_SMM_CORE:
1518 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))
1519 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))
1520 elif Info.ModuleType == SUP_MODULE_MM_CORE_STANDALONE:
1521 AutoGenC.Append(gMmCoreStandaloneEntryPointString.Replace(Dict))
1522 AutoGenH.Append(gMmCoreStandaloneEntryPointPrototype.Replace(Dict))
1523 elif Info.ModuleType == SUP_MODULE_PEIM:
1524 if NumEntryPoints < 2:
1525 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))
1526 else:
1527 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))
1528 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))
1529 elif Info.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:
1530 if NumEntryPoints < 2:
1531 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))
1532 else:
1533 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))
1534 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))
1535 elif Info.ModuleType == SUP_MODULE_DXE_SMM_DRIVER:
1536 if NumEntryPoints == 0:
1537 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))
1538 else:
1539 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))
1540 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))
1541 elif Info.ModuleType == SUP_MODULE_MM_STANDALONE:
1542 if NumEntryPoints < 2:
1543 AutoGenC.Append(gMmStandaloneEntryPointString[NumEntryPoints].Replace(Dict))
1544 else:
1545 AutoGenC.Append(gMmStandaloneEntryPointString[2].Replace(Dict))
1546 AutoGenH.Append(gMmStandaloneEntryPointPrototype.Replace(Dict))
1547 elif Info.ModuleType == SUP_MODULE_UEFI_APPLICATION:
1548 if NumEntryPoints < 2:
1549 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))
1550 else:
1551 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))
1552 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))
1553
1554 ## Create code for ModuleUnloadImage
1555 #
1556 # @param Info The ModuleAutoGen object
1557 # @param AutoGenC The TemplateString object for C code
1558 # @param AutoGenH The TemplateString object for header file
1559 #
1560 def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):
1561 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:
1562 return
1563 #
1564 # Unload Image Handlers
1565 #
1566 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)
1567 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}
1568 if NumUnloadImage < 2:
1569 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))
1570 else:
1571 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))
1572 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))
1573
1574 ## Create code for GUID
1575 #
1576 # @param Info The ModuleAutoGen object
1577 # @param AutoGenC The TemplateString object for C code
1578 # @param AutoGenH The TemplateString object for header file
1579 #
1580 def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):
1581 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1582 GuidType = TAB_GUID
1583 else:
1584 GuidType = "EFI_GUID"
1585
1586 if Info.GuidList:
1587 if not Info.IsLibrary:
1588 AutoGenC.Append("\n// Guids\n")
1589 AutoGenH.Append("\n// Guids\n")
1590 #
1591 # GUIDs
1592 #
1593 for Key in Info.GuidList:
1594 if not Info.IsLibrary:
1595 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))
1596 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1597
1598 ## Create code for protocol
1599 #
1600 # @param Info The ModuleAutoGen object
1601 # @param AutoGenC The TemplateString object for C code
1602 # @param AutoGenH The TemplateString object for header file
1603 #
1604 def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):
1605 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1606 GuidType = TAB_GUID
1607 else:
1608 GuidType = "EFI_GUID"
1609
1610 if Info.ProtocolList:
1611 if not Info.IsLibrary:
1612 AutoGenC.Append("\n// Protocols\n")
1613 AutoGenH.Append("\n// Protocols\n")
1614 #
1615 # Protocol GUIDs
1616 #
1617 for Key in Info.ProtocolList:
1618 if not Info.IsLibrary:
1619 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))
1620 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1621
1622 ## Create code for PPI
1623 #
1624 # @param Info The ModuleAutoGen object
1625 # @param AutoGenC The TemplateString object for C code
1626 # @param AutoGenH The TemplateString object for header file
1627 #
1628 def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):
1629 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1630 GuidType = TAB_GUID
1631 else:
1632 GuidType = "EFI_GUID"
1633
1634 if Info.PpiList:
1635 if not Info.IsLibrary:
1636 AutoGenC.Append("\n// PPIs\n")
1637 AutoGenH.Append("\n// PPIs\n")
1638 #
1639 # PPI GUIDs
1640 #
1641 for Key in Info.PpiList:
1642 if not Info.IsLibrary:
1643 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))
1644 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1645
1646 ## Create code for PCD
1647 #
1648 # @param Info The ModuleAutoGen object
1649 # @param AutoGenC The TemplateString object for C code
1650 # @param AutoGenH The TemplateString object for header file
1651 #
1652 def CreatePcdCode(Info, AutoGenC, AutoGenH):
1653
1654 # Collect Token Space GUIDs used by DynamicEc PCDs
1655 TokenSpaceList = []
1656 for Pcd in Info.ModulePcdList:
1657 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenSpaceGuidCName not in TokenSpaceList:
1658 TokenSpaceList.append(Pcd.TokenSpaceGuidCName)
1659
1660 SkuMgr = Info.Workspace.Platform.SkuIdMgr
1661 AutoGenH.Append("\n// Definition of SkuId Array\n")
1662 AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
1663 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1664 if TokenSpaceList:
1665 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1666 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1667 GuidType = TAB_GUID
1668 else:
1669 GuidType = "EFI_GUID"
1670 for Item in TokenSpaceList:
1671 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))
1672
1673 if Info.IsLibrary:
1674 if Info.ModulePcdList:
1675 AutoGenH.Append("\n// PCD definitions\n")
1676 for Pcd in Info.ModulePcdList:
1677 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)
1678 DynExPcdTokenNumberMapping (Info, AutoGenH)
1679 else:
1680 AutoGenC.Append("\n// Definition of SkuId Array\n")
1681 AutoGenC.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr.DumpSkuIdArrary())
1682 if Info.ModulePcdList:
1683 AutoGenH.Append("\n// Definition of PCDs used in this module\n")
1684 AutoGenC.Append("\n// Definition of PCDs used in this module\n")
1685 for Pcd in Info.ModulePcdList:
1686 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)
1687 DynExPcdTokenNumberMapping (Info, AutoGenH)
1688 if Info.LibraryPcdList:
1689 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1690 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")
1691 for Pcd in Info.LibraryPcdList:
1692 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)
1693 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)
1694
1695 ## Create code for unicode string definition
1696 #
1697 # @param Info The ModuleAutoGen object
1698 # @param AutoGenC The TemplateString object for C code
1699 # @param AutoGenH The TemplateString object for header file
1700 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1701 # @param UniGenBinBuffer Buffer to store uni string package data
1702 #
1703 def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):
1704 WorkingDir = os.getcwd()
1705 os.chdir(Info.WorkspaceDir)
1706
1707 IncList = [Info.MetaFile.Dir]
1708 # Get all files under [Sources] section in inf file for EDK-II module
1709 EDK2Module = True
1710 SrcList = [F for F in Info.SourceFileList]
1711 if Info.AutoGenVersion < 0x00010005:
1712 EDK2Module = False
1713 # Get all files under the module directory for EDK-I module
1714 Cwd = os.getcwd()
1715 os.chdir(Info.MetaFile.Dir)
1716 for Root, Dirs, Files in os.walk("."):
1717 if 'CVS' in Dirs:
1718 Dirs.remove('CVS')
1719 if '.svn' in Dirs:
1720 Dirs.remove('.svn')
1721 for File in Files:
1722 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)
1723 if File in SrcList:
1724 continue
1725 SrcList.append(File)
1726 os.chdir(Cwd)
1727
1728 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:
1729 CompatibleMode = True
1730 else:
1731 CompatibleMode = False
1732
1733 #
1734 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1735 #
1736 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:
1737 if CompatibleMode:
1738 EdkLogger.error("build", AUTOGEN_ERROR,
1739 "-c and -s build options should be used exclusively",
1740 ExtraData="[%s]" % str(Info))
1741 ShellMode = True
1742 else:
1743 ShellMode = False
1744
1745 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1746 if EDK2Module:
1747 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]
1748 else:
1749 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]
1750 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)
1751 if CompatibleMode or UniGenCFlag:
1752 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")
1753 AutoGenC.Append(Code)
1754 AutoGenC.Append("\n")
1755 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")
1756 AutoGenH.Append(Header)
1757 if CompatibleMode or UniGenCFlag:
1758 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)
1759 os.chdir(WorkingDir)
1760
1761 def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):
1762 if len(Info.IdfFileList) > 0:
1763 ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList))
1764 if ImageFiles.ImageFilesDict:
1765 Index = 1
1766 PaletteIndex = 1
1767 IncList = [Info.MetaFile.Dir]
1768 SrcList = [F for F in Info.SourceFileList]
1769 SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf']
1770 FileList = GetFileList(SrcList, IncList, SkipList)
1771 ValueStartPtr = 60
1772 StringH.Append("\n//\n//Image ID\n//\n")
1773 ImageInfoOffset = 0
1774 PaletteInfoOffset = 0
1775 ImageBuffer = pack('x')
1776 PaletteBuffer = pack('x')
1777 BufferStr = ''
1778 PaletteStr = ''
1779 FileDict = {}
1780 for Idf in ImageFiles.ImageFilesDict:
1781 if ImageFiles.ImageFilesDict[Idf]:
1782 for FileObj in ImageFiles.ImageFilesDict[Idf]:
1783 for sourcefile in Info.SourceFileList:
1784 if FileObj.FileName == sourcefile.File:
1785 if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']:
1786 EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info))
1787 FileObj.File = sourcefile
1788 break
1789 else:
1790 EdkLogger.error("build", AUTOGEN_ERROR, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj.FileName, Idf), ExtraData="[%s]" % str(Info))
1791
1792 for FileObj in ImageFiles.ImageFilesDict[Idf]:
1793 ID = FileObj.ImageID
1794 File = FileObj.File
1795 if not os.path.exists(File.Path) or not os.path.isfile(File.Path):
1796 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path)
1797 SearchImageID (FileObj, FileList)
1798 if FileObj.Referenced:
1799 if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0:
1800 Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n'
1801 else:
1802 Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n'
1803
1804 if File not in FileDict:
1805 FileDict[File] = Index
1806 else:
1807 DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE)
1808 DuplicateBlock += pack('H', FileDict[File])
1809 ImageBuffer += DuplicateBlock
1810 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))
1811 TempBufferList = AscToHexList(DuplicateBlock)
1812 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')
1813 StringH.Append(Line)
1814 Index += 1
1815 continue
1816
1817 TmpFile = open(File.Path, 'rb')
1818 Buffer = TmpFile.read()
1819 TmpFile.close()
1820 if File.Ext.upper() == '.PNG':
1821 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG)
1822 TempBuffer += pack('I', len(Buffer))
1823 TempBuffer += Buffer
1824 elif File.Ext.upper() == '.JPG':
1825 ImageType, = struct.unpack('4s', Buffer[6:10])
1826 if ImageType != 'JFIF':
1827 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path)
1828 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG)
1829 TempBuffer += pack('I', len(Buffer))
1830 TempBuffer += Buffer
1831 elif File.Ext.upper() == '.BMP':
1832 TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent)
1833 if len(TempPalette) > 1:
1834 PaletteIndex += 1
1835 NewPalette = pack('H', len(TempPalette))
1836 NewPalette += TempPalette
1837 PaletteBuffer += NewPalette
1838 PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4)))
1839 TempPaletteList = AscToHexList(NewPalette)
1840 PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n')
1841 ImageBuffer += TempBuffer
1842 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))
1843 TempBufferList = AscToHexList(TempBuffer)
1844 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')
1845
1846 StringH.Append(Line)
1847 Index += 1
1848
1849 BufferStr = WriteLine(BufferStr, '// End of the Image Info')
1850 BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n')
1851 ImageEnd = pack('B', EFI_HII_IIBT_END)
1852 ImageBuffer += ImageEnd
1853
1854 if len(ImageBuffer) > 1:
1855 ImageInfoOffset = 12
1856 if len(PaletteBuffer) > 1:
1857 PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer
1858
1859 IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset)
1860 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
1861 if len(PaletteBuffer) > 1:
1862 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1
1863 else:
1864 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1
1865 if PaletteIndex > 1:
1866 PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1)
1867 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
1868 Hex_Length = '%06X' % PACKAGE_HEADER_Length
1869 if PACKAGE_HEADER_Length > 0xFFFFFF:
1870 EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info))
1871 PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES)
1872
1873 IdfGenBinBuffer.write(PACKAGE_HEADER)
1874 IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR)
1875 if len(ImageBuffer) > 1 :
1876 IdfGenBinBuffer.write(ImageBuffer[1:])
1877 if PaletteIndex > 1:
1878 IdfGenBinBuffer.write(PALETTE_INFO_HEADER)
1879 if len(PaletteBuffer) > 1:
1880 IdfGenBinBuffer.write(PaletteBuffer[1:])
1881
1882 if IdfGenCFlag:
1883 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length
1884 AutoGenC.Append("\n//\n//Image Pack Definition\n//\n")
1885 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n')
1886 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')
1887 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')
1888 AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n')
1889 IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER)
1890 IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR)
1891 AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n')
1892 AllStr = WriteLine(AllStr, '// Image DATA\n')
1893 if BufferStr:
1894 AllStr = WriteLine(AllStr, BufferStr)
1895 if PaletteStr:
1896 AllStr = WriteLine(AllStr, '// Palette Header\n')
1897 PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER)
1898 AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n')
1899 AllStr = WriteLine(AllStr, '// Palette Data\n')
1900 AllStr = WriteLine(AllStr, PaletteStr)
1901 AllStr = WriteLine(AllStr, '};')
1902 AutoGenC.Append(AllStr)
1903 AutoGenC.Append("\n")
1904 StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n')
1905 StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName)
1906
1907 # typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
1908 # EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
1909 # UINT32 ImageInfoOffset;
1910 # UINT32 PaletteInfoOffset;
1911 # } EFI_HII_IMAGE_PACKAGE_HDR;
1912
1913 # typedef struct {
1914 # UINT32 Length:24;
1915 # UINT32 Type:8;
1916 # UINT8 Data[];
1917 # } EFI_HII_PACKAGE_HEADER;
1918
1919 # typedef struct _EFI_HII_IMAGE_BLOCK {
1920 # UINT8 BlockType;
1921 # UINT8 BlockBody[];
1922 # } EFI_HII_IMAGE_BLOCK;
1923
1924 def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):
1925 ImageType, = struct.unpack('2s', Buffer[0:2])
1926 if ImageType!= 'BM': # BMP file type is 'BM'
1927 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)
1928 BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize', 'bfReserved1', 'bfReserved2', 'bfOffBits', 'biSize', 'biWidth', 'biHeight', 'biPlanes', 'biBitCount', 'biCompression', 'biSizeImage', 'biXPelsPerMeter', 'biYPelsPerMeter', 'biClrUsed', 'biClrImportant'])
1929 BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')
1930 BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))
1931 #
1932 # Doesn't support compress.
1933 #
1934 if BmpHeader.biCompression != 0:
1935 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path)
1936
1937 # The Width and Height is UINT16 type in Image Package
1938 if BmpHeader.biWidth > 0xFFFF:
1939 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path)
1940 if BmpHeader.biHeight > 0xFFFF:
1941 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path)
1942
1943 PaletteBuffer = pack('x')
1944 if BmpHeader.biBitCount == 1:
1945 if TransParent:
1946 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)
1947 else:
1948 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)
1949 ImageBuffer += pack('B', PaletteIndex)
1950 Width = (BmpHeader.biWidth + 7)/8
1951 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1952 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1953 elif BmpHeader.biBitCount == 4:
1954 if TransParent:
1955 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)
1956 else:
1957 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)
1958 ImageBuffer += pack('B', PaletteIndex)
1959 Width = (BmpHeader.biWidth + 1)/2
1960 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1961 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1962 elif BmpHeader.biBitCount == 8:
1963 if TransParent:
1964 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)
1965 else:
1966 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT)
1967 ImageBuffer += pack('B', PaletteIndex)
1968 Width = BmpHeader.biWidth
1969 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1970 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1971 elif BmpHeader.biBitCount == 24:
1972 if TransParent:
1973 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS)
1974 else:
1975 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT)
1976 Width = BmpHeader.biWidth * 3
1977 else:
1978 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path))
1979
1980 ImageBuffer += pack('H', BmpHeader.biWidth)
1981 ImageBuffer += pack('H', BmpHeader.biHeight)
1982 Start = BmpHeader.bfOffBits
1983 End = BmpHeader.bfSize - 1
1984 for Height in range(0, BmpHeader.biHeight):
1985 if Width % 4 != 0:
1986 Start = End + (Width % 4) - 4 - Width
1987 else:
1988 Start = End - Width
1989 ImageBuffer += Buffer[Start + 1 : Start + Width + 1]
1990 End = Start
1991
1992 # handle the Palette info, BMP use 4 bytes for R, G, B and Reserved info while EFI_HII_RGB_PIXEL only have the R, G, B info
1993 if PaletteBuffer and len(PaletteBuffer) > 1:
1994 PaletteTemp = pack('x')
1995 for Index in range(0, len(PaletteBuffer)):
1996 if Index % 4 == 3:
1997 continue
1998 PaletteTemp += PaletteBuffer[Index]
1999 PaletteBuffer = PaletteTemp[1:]
2000 return ImageBuffer, PaletteBuffer
2001
2002 ## Create common code
2003 #
2004 # @param Info The ModuleAutoGen object
2005 # @param AutoGenC The TemplateString object for C code
2006 # @param AutoGenH The TemplateString object for header file
2007 #
2008 def CreateHeaderCode(Info, AutoGenC, AutoGenH):
2009 # file header
2010 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))
2011 # header file Prologue
2012 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-', '_')}))
2013 AutoGenH.Append(gAutoGenHCppPrologueString)
2014 if Info.AutoGenVersion >= 0x00010005:
2015 # header files includes
2016 if Info.ModuleType in gModuleTypeHeaderFile:
2017 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])
2018 #
2019 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
2020 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
2021 #
2022 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:
2023 AutoGenH.Append("#include <Library/PcdLib.h>\n")
2024
2025 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')
2026 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
2027
2028 if Info.IsLibrary:
2029 return
2030
2031 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))
2032
2033 if Info.IsLibrary:
2034 return
2035 # C file header
2036 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))
2037 if Info.AutoGenVersion >= 0x00010005:
2038 # C file header files includes
2039 if Info.ModuleType in gModuleTypeHeaderFile:
2040 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:
2041 AutoGenC.Append("#include <%s>\n" % Inc)
2042 else:
2043 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)
2044
2045 #
2046 # Publish the CallerId Guid
2047 #
2048 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))
2049 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)
2050
2051 ## Create common code for header file
2052 #
2053 # @param Info The ModuleAutoGen object
2054 # @param AutoGenC The TemplateString object for C code
2055 # @param AutoGenH The TemplateString object for header file
2056 #
2057 def CreateFooterCode(Info, AutoGenC, AutoGenH):
2058 AutoGenH.Append(gAutoGenHEpilogueString)
2059
2060 ## Create code for a module
2061 #
2062 # @param Info The ModuleAutoGen object
2063 # @param AutoGenC The TemplateString object for C code
2064 # @param AutoGenH The TemplateString object for header file
2065 # @param StringH The TemplateString object for header file
2066 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
2067 # @param UniGenBinBuffer Buffer to store uni string package data
2068 # @param StringIdf The TemplateString object for header file
2069 # @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
2070 # @param IdfGenBinBuffer Buffer to store Idf string package data
2071 #
2072 def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):
2073 CreateHeaderCode(Info, AutoGenC, AutoGenH)
2074
2075 if Info.AutoGenVersion >= 0x00010005:
2076 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)
2077 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)
2078 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)
2079 CreatePcdCode(Info, AutoGenC, AutoGenH)
2080 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)
2081 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)
2082 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)
2083 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)
2084
2085 if Info.UnicodeFileList:
2086 FileName = "%sStrDefs.h" % Info.Name
2087 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))
2088 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-', '_')}))
2089 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)
2090
2091 GuidMacros = []
2092 for Guid in Info.Module.Guids:
2093 if Guid in Info.Module.GetGuidsUsedByPcd():
2094 continue
2095 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))
2096 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():
2097 GuidMacros.append('#define %s %s' % (Guid, Value))
2098 # supports FixedAtBuild and FeaturePcd usage in VFR file
2099 if Info.VfrFileList and Info.ModulePcdList:
2100 GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))
2101 GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))
2102 GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))
2103 GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))
2104 GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))
2105 GuidMacros.append('#define %s %s' % ('FeaturePcdGet(TokenName)', '_PCD_VALUE_##TokenName'))
2106 for Pcd in Info.ModulePcdList:
2107 if Pcd.Type in [TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_FEATURE_FLAG]:
2108 TokenCName = Pcd.TokenCName
2109 Value = Pcd.DefaultValue
2110 if Pcd.DatumType == 'BOOLEAN':
2111 BoolValue = Value.upper()
2112 if BoolValue == 'TRUE':
2113 Value = '1'
2114 elif BoolValue == 'FALSE':
2115 Value = '0'
2116 for PcdItem in GlobalData.MixedPcd:
2117 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
2118 TokenCName = PcdItem[0]
2119 break
2120 GuidMacros.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName, Value))
2121
2122 if Info.IdfFileList:
2123 GuidMacros.append('#include "%sImgDefs.h"' % Info.Name)
2124
2125 if GuidMacros:
2126 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))
2127
2128 StringH.Append("\n#endif\n")
2129 AutoGenH.Append('#include "%s"\n' % FileName)
2130
2131 if Info.IdfFileList:
2132 FileName = "%sImgDefs.h" % Info.Name
2133 StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))
2134 StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-', '_')}))
2135 CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)
2136
2137 StringIdf.Append("\n#endif\n")
2138 AutoGenH.Append('#include "%s"\n' % FileName)
2139
2140 CreateFooterCode(Info, AutoGenC, AutoGenH)
2141
2142 # no generation of AutoGen.c for Edk modules without unicode file
2143 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:
2144 AutoGenC.String = ''
2145
2146 ## Create the code file
2147 #
2148 # @param FilePath The path of code file
2149 # @param Content The content of code file
2150 # @param IsBinaryFile The flag indicating if the file is binary file or not
2151 #
2152 # @retval True If file content is changed or file doesn't exist
2153 # @retval False If the file exists and the content is not changed
2154 #
2155 def Generate(FilePath, Content, IsBinaryFile):
2156 return SaveFileOnChange(FilePath, Content, IsBinaryFile)
2157