BaseTools: Enable structure pcd in FDF file
[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 elif Pcd.PcdValueFromFdf:
894 Pcd.DefaultValue = Pcd.PcdValueFromFdf
895
896 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
897 TokenNumber = int(Pcd.TokenValue, 0)
898 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
899 # different Guids but same TokenCName
900 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName
901 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
902 else:
903 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
904 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
905 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
906 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
907 # report warning message notify the PI that they are attempting to build a module
908 # that must be included in a flash image in order to be functional. These Dynamic PCD
909 # will not be added into the Database unless it is used by other modules that are
910 # included in the FDF file.
911 # In this case, just assign an invalid token number to make it pass build.
912 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:
913 TokenNumber = 0
914 else:
915 EdkLogger.error("build", AUTOGEN_ERROR,
916 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),
917 ExtraData="[%s]" % str(Info))
918 else:
919 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
920 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))
921
922 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)
923 if Pcd.Type not in gItemTypeStringDatabase:
924 EdkLogger.error("build", AUTOGEN_ERROR,
925 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),
926 ExtraData="[%s]" % str(Info))
927
928 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]
929 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]
930 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
931 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
932 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName
933 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
934
935 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
936 if Info.IsLibrary:
937 PcdList = Info.LibraryPcdList
938 else:
939 PcdList = Info.ModulePcdList
940 PcdExCNameTest = 0
941 for PcdModule in PcdList:
942 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
943 PcdExCNameTest += 1
944 # get out early once we found > 1...
945 if PcdExCNameTest > 1:
946 break
947 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
948 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
949 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
950 if PcdExCNameTest > 1:
951 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')
952 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
953 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
954 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
955 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
956 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
957 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
958 else:
959 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
960 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
961 else:
962 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
963 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
964 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
965 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
966 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
967 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
968 else:
969 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
970 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
971 elif Pcd.Type in PCD_DYNAMIC_TYPE_SET:
972 PcdCNameTest = 0
973 for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:
974 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
975 PcdCNameTest += 1
976 # get out early once we found > 1...
977 if PcdCNameTest > 1:
978 break
979 if PcdCNameTest > 1:
980 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))
981 else:
982 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
983 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))
984 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
985 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
986 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
987 else:
988 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
989 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
990 else:
991 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName
992 Const = 'const'
993 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
994 Const = ''
995 Type = ''
996 Array = ''
997 Value = Pcd.DefaultValue
998 Unicode = False
999 ValueNumber = 0
1000
1001 if Pcd.DatumType == 'BOOLEAN':
1002 BoolValue = Value.upper()
1003 if BoolValue == 'TRUE' or BoolValue == '1':
1004 Value = '1U'
1005 elif BoolValue == 'FALSE' or BoolValue == '0':
1006 Value = '0U'
1007
1008 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:
1009 try:
1010 if Value.upper().endswith('L'):
1011 Value = Value[:-1]
1012 ValueNumber = int (Value, 0)
1013 except:
1014 EdkLogger.error("build", AUTOGEN_ERROR,
1015 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1016 ExtraData="[%s]" % str(Info))
1017 if Pcd.DatumType == TAB_UINT64:
1018 if ValueNumber < 0:
1019 EdkLogger.error("build", AUTOGEN_ERROR,
1020 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1021 ExtraData="[%s]" % str(Info))
1022 elif ValueNumber >= 0x10000000000000000:
1023 EdkLogger.error("build", AUTOGEN_ERROR,
1024 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1025 ExtraData="[%s]" % str(Info))
1026 if not Value.endswith('ULL'):
1027 Value += 'ULL'
1028 elif Pcd.DatumType == TAB_UINT32:
1029 if ValueNumber < 0:
1030 EdkLogger.error("build", AUTOGEN_ERROR,
1031 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1032 ExtraData="[%s]" % str(Info))
1033 elif ValueNumber >= 0x100000000:
1034 EdkLogger.error("build", AUTOGEN_ERROR,
1035 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1036 ExtraData="[%s]" % str(Info))
1037 if not Value.endswith('U'):
1038 Value += 'U'
1039 elif Pcd.DatumType == TAB_UINT16:
1040 if ValueNumber < 0:
1041 EdkLogger.error("build", AUTOGEN_ERROR,
1042 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1043 ExtraData="[%s]" % str(Info))
1044 elif ValueNumber >= 0x10000:
1045 EdkLogger.error("build", AUTOGEN_ERROR,
1046 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1047 ExtraData="[%s]" % str(Info))
1048 if not Value.endswith('U'):
1049 Value += 'U'
1050 elif Pcd.DatumType == TAB_UINT8:
1051 if ValueNumber < 0:
1052 EdkLogger.error("build", AUTOGEN_ERROR,
1053 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1054 ExtraData="[%s]" % str(Info))
1055 elif ValueNumber >= 0x100:
1056 EdkLogger.error("build", AUTOGEN_ERROR,
1057 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
1058 ExtraData="[%s]" % str(Info))
1059 if not Value.endswith('U'):
1060 Value += 'U'
1061 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1062 if not Pcd.MaxDatumSize:
1063 EdkLogger.error("build", AUTOGEN_ERROR,
1064 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),
1065 ExtraData="[%s]" % str(Info))
1066
1067 ArraySize = int(Pcd.MaxDatumSize, 0)
1068 if Value[0] == '{':
1069 Type = '(VOID *)'
1070 ValueSize = len(Value.split(','))
1071 else:
1072 if Value[0] == 'L':
1073 Unicode = True
1074 Value = Value.lstrip('L') #.strip('"')
1075 Value = eval(Value) # translate escape character
1076 ValueSize = len(Value) + 1
1077 NewValue = '{'
1078 for Index in range(0, len(Value)):
1079 if Unicode:
1080 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
1081 else:
1082 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
1083 if Unicode:
1084 ArraySize = ArraySize / 2
1085 Value = NewValue + '0 }'
1086 if ArraySize < ValueSize:
1087 if Pcd.MaxSizeUserSet:
1088 EdkLogger.error("build", AUTOGEN_ERROR,
1089 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
1090 ExtraData="[%s]" % str(Info))
1091 else:
1092 ArraySize = Pcd.GetPcdSize()
1093 if Unicode:
1094 ArraySize = ArraySize / 2
1095 Array = '[%d]' % ArraySize
1096 #
1097 # skip casting for fixed at build since it breaks ARM assembly.
1098 # Long term we need PCD macros that work in assembly
1099 #
1100 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD and Pcd.DatumType in TAB_PCD_NUMERIC_TYPES_VOID:
1101 Value = "((%s)%s)" % (Pcd.DatumType, Value)
1102
1103 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1104 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName
1105 else:
1106 PcdValueName = '_PCD_VALUE_' + TokenCName
1107
1108 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1109 #
1110 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1111 #
1112 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))
1113 if Unicode:
1114 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
1115 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))
1116 else:
1117 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
1118 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))
1119 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))
1120
1121 PcdDataSize = Pcd.GetPcdSize()
1122 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:
1123 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1124 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))
1125 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName, PcdDataSize))
1126 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1127 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))
1128 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))
1129 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1130 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))
1131 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable, Pcd.MaxDatumSize))
1132 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1133 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
1134 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
1135 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
1136 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
1137
1138 PcdDataSize = Pcd.GetPcdSize()
1139 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))
1140
1141 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))
1142 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1143 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))
1144 else:
1145 PcdDataSize = Pcd.GetPcdSize()
1146 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1147 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))
1148
1149 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
1150 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
1151 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
1152 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
1153
1154 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
1155 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1156 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))
1157 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))
1158 else:
1159 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
1160 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))
1161 else:
1162 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
1163
1164 ## Create code for library module PCDs
1165 #
1166 # @param Info The ModuleAutoGen object
1167 # @param AutoGenC The TemplateString object for C code
1168 # @param AutoGenH The TemplateString object for header file
1169 # @param Pcd The PCD object
1170 #
1171 def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
1172 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
1173 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
1174 TokenCName = Pcd.TokenCName
1175 for PcdItem in GlobalData.MixedPcd:
1176 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
1177 TokenCName = PcdItem[0]
1178 break
1179 PcdTokenName = '_PCD_TOKEN_' + TokenCName
1180 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName
1181 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'
1182 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName
1183 PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName
1184 FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName
1185
1186 if Pcd.PcdValueFromComm:
1187 Pcd.DefaultValue = Pcd.PcdValueFromComm
1188 elif Pcd.PcdValueFromFdf:
1189 Pcd.DefaultValue = Pcd.PcdValueFromFdf
1190 #
1191 # Write PCDs
1192 #
1193 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:
1194 TokenNumber = int(Pcd.TokenValue, 0)
1195 else:
1196 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
1197 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1198 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1199 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1200 # report warning message notify the PI that they are attempting to build a module
1201 # that must be included in a flash image in order to be functional. These Dynamic PCD
1202 # will not be added into the Database unless it is used by other modules that are
1203 # included in the FDF file.
1204 # In this case, just assign an invalid token number to make it pass build.
1205 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:
1206 TokenNumber = 0
1207 else:
1208 EdkLogger.error("build", AUTOGEN_ERROR,
1209 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),
1210 ExtraData="[%s]" % str(Info))
1211 else:
1212 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
1213
1214 if Pcd.Type not in gItemTypeStringDatabase:
1215 EdkLogger.error("build", AUTOGEN_ERROR,
1216 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),
1217 ExtraData="[%s]" % str(Info))
1218
1219 DatumType = Pcd.DatumType
1220 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]
1221 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]
1222 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
1223 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName
1224 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName
1225 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1226
1227 Type = ''
1228 Array = ''
1229 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1230 if Pcd.DefaultValue[0]== '{':
1231 Type = '(VOID *)'
1232 Array = '[]'
1233 PcdItemType = Pcd.Type
1234 if PcdItemType in PCD_DYNAMIC_EX_TYPE_SET:
1235 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName
1236 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
1237
1238 if Info.IsLibrary:
1239 PcdList = Info.LibraryPcdList
1240 else:
1241 PcdList = Info.ModulePcdList
1242 PcdExCNameTest = 0
1243 for PcdModule in PcdList:
1244 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:
1245 PcdExCNameTest += 1
1246 # get out early once we found > 1...
1247 if PcdExCNameTest > 1:
1248 break
1249 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1250 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1251 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1252 if PcdExCNameTest > 1:
1253 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')
1254 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
1255 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1256 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
1257 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1258 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1259 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1260 else:
1261 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1262 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1263 else:
1264 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
1265 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1266 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))
1267 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1268 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1269 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1270 else:
1271 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1272 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1273 else:
1274 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))
1275 if PcdItemType in PCD_DYNAMIC_TYPE_SET:
1276 PcdList = []
1277 PcdCNameList = []
1278 PcdList.extend(Info.LibraryPcdList)
1279 PcdList.extend(Info.ModulePcdList)
1280 for PcdModule in PcdList:
1281 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET:
1282 PcdCNameList.append(PcdModule.TokenCName)
1283 if PcdCNameList.count(Pcd.TokenCName) > 1:
1284 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))
1285 else:
1286 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
1287 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))
1288 if DatumType not in TAB_PCD_NUMERIC_TYPES:
1289 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
1290 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1291 else:
1292 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
1293 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1294 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:
1295 GetModeMaxSizeName = '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName
1296 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName
1297 if DatumType not in TAB_PCD_NUMERIC_TYPES:
1298 if DatumType == TAB_VOID and Array == '[]':
1299 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']
1300 else:
1301 DatumType = TAB_UINT8
1302 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))
1303 else:
1304 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))
1305 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))
1306 PcdDataSize = Pcd.GetPcdSize()
1307 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1308 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
1309 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
1310 AutoGenH.Append('#define %s %s\n' % (GetModeMaxSizeName, PatchPcdMaxSizeVariable))
1311 AutoGenH.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable)
1312 else:
1313 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
1314 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))
1315 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))
1316
1317 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, PatchPcdSizeVariableName))
1318 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
1319
1320 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:
1321 key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
1322 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName
1323 if DatumType == TAB_VOID and Array == '[]':
1324 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']
1325 if DatumType not in TAB_PCD_NUMERIC_TYPES_VOID:
1326 DatumType = TAB_UINT8
1327 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))
1328 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))
1329 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
1330
1331 ConstFixedPcd = False
1332 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):
1333 ConstFixedPcd = True
1334 if key in Info.ConstPcd:
1335 Pcd.DefaultValue = Info.ConstPcd[key]
1336 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1337 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))
1338 else:
1339 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))
1340 PcdDataSize = Pcd.GetPcdSize()
1341 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:
1342 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
1343 if ConstFixedPcd:
1344 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1345 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))
1346 else:
1347 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixedPcdSizeVariableName))
1348 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, FixedPcdSizeVariableName))
1349 AutoGenH.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName)
1350 else:
1351 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
1352 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))
1353
1354 ## Create code for library constructor
1355 #
1356 # @param Info The ModuleAutoGen object
1357 # @param AutoGenC The TemplateString object for C code
1358 # @param AutoGenH The TemplateString object for header file
1359 #
1360 def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
1361 #
1362 # Library Constructors
1363 #
1364 ConstructorPrototypeString = TemplateString()
1365 ConstructorCallingString = TemplateString()
1366 if Info.IsLibrary:
1367 DependentLibraryList = [Info.Module]
1368 else:
1369 DependentLibraryList = Info.DependentLibraryList
1370 for Lib in DependentLibraryList:
1371 if len(Lib.ConstructorList) <= 0:
1372 continue
1373 Dict = {'Function':Lib.ConstructorList}
1374 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1375 ConstructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))
1376 ConstructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))
1377 elif Lib.ModuleType in SUP_MODULE_SET_PEI:
1378 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1379 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1380 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1381 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1382 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1383 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1384 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1385 ConstructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))
1386 ConstructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))
1387
1388 if str(ConstructorPrototypeString) == '':
1389 ConstructorPrototypeList = []
1390 else:
1391 ConstructorPrototypeList = [str(ConstructorPrototypeString)]
1392 if str(ConstructorCallingString) == '':
1393 ConstructorCallingList = []
1394 else:
1395 ConstructorCallingList = [str(ConstructorCallingString)]
1396
1397 Dict = {
1398 'Type' : 'Constructor',
1399 'FunctionPrototype' : ConstructorPrototypeList,
1400 'FunctionCall' : ConstructorCallingList
1401 }
1402 if Info.IsLibrary:
1403 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1404 else:
1405 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1406 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
1407 elif Info.ModuleType in SUP_MODULE_SET_PEI:
1408 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1409 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1410 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1411 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1412 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1413 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))
1414
1415 ## Create code for library destructor
1416 #
1417 # @param Info The ModuleAutoGen object
1418 # @param AutoGenC The TemplateString object for C code
1419 # @param AutoGenH The TemplateString object for header file
1420 #
1421 def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
1422 #
1423 # Library Destructors
1424 #
1425 DestructorPrototypeString = TemplateString()
1426 DestructorCallingString = TemplateString()
1427 if Info.IsLibrary:
1428 DependentLibraryList = [Info.Module]
1429 else:
1430 DependentLibraryList = Info.DependentLibraryList
1431 for Index in range(len(DependentLibraryList)-1, -1, -1):
1432 Lib = DependentLibraryList[Index]
1433 if len(Lib.DestructorList) <= 0:
1434 continue
1435 Dict = {'Function':Lib.DestructorList}
1436 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1437 DestructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))
1438 DestructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))
1439 elif Lib.ModuleType in SUP_MODULE_SET_PEI:
1440 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1441 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1442 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1443 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1444 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1445 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1446 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1447 DestructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))
1448 DestructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))
1449
1450 if str(DestructorPrototypeString) == '':
1451 DestructorPrototypeList = []
1452 else:
1453 DestructorPrototypeList = [str(DestructorPrototypeString)]
1454 if str(DestructorCallingString) == '':
1455 DestructorCallingList = []
1456 else:
1457 DestructorCallingList = [str(DestructorCallingString)]
1458
1459 Dict = {
1460 'Type' : 'Destructor',
1461 'FunctionPrototype' : DestructorPrototypeList,
1462 'FunctionCall' : DestructorCallingList
1463 }
1464 if Info.IsLibrary:
1465 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1466 else:
1467 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:
1468 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
1469 elif Info.ModuleType in SUP_MODULE_SET_PEI:
1470 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1471 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
1472 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:
1473 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1474 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
1475 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))
1476
1477
1478 ## Create code for ModuleEntryPoint
1479 #
1480 # @param Info The ModuleAutoGen object
1481 # @param AutoGenC The TemplateString object for C code
1482 # @param AutoGenH The TemplateString object for header file
1483 #
1484 def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
1485 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:
1486 return
1487 #
1488 # Module Entry Points
1489 #
1490 NumEntryPoints = len(Info.Module.ModuleEntryPointList)
1491 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:
1492 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']
1493 else:
1494 PiSpecVersion = '0x00000000'
1495 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:
1496 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']
1497 else:
1498 UefiSpecVersion = '0x00000000'
1499 Dict = {
1500 'Function' : Info.Module.ModuleEntryPointList,
1501 'PiSpecVersion' : PiSpecVersion + 'U',
1502 'UefiSpecVersion': UefiSpecVersion + 'U'
1503 }
1504
1505 if Info.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_DXE_CORE, SUP_MODULE_SMM_CORE, SUP_MODULE_MM_CORE_STANDALONE]:
1506 if Info.SourceFileList:
1507 if NumEntryPoints != 1:
1508 EdkLogger.error(
1509 "build",
1510 AUTOGEN_ERROR,
1511 '%s must have exactly one entry point' % Info.ModuleType,
1512 File=str(Info),
1513 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)
1514 )
1515 if Info.ModuleType == SUP_MODULE_PEI_CORE:
1516 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))
1517 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))
1518 elif Info.ModuleType == SUP_MODULE_DXE_CORE:
1519 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))
1520 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))
1521 elif Info.ModuleType == SUP_MODULE_SMM_CORE:
1522 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))
1523 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))
1524 elif Info.ModuleType == SUP_MODULE_MM_CORE_STANDALONE:
1525 AutoGenC.Append(gMmCoreStandaloneEntryPointString.Replace(Dict))
1526 AutoGenH.Append(gMmCoreStandaloneEntryPointPrototype.Replace(Dict))
1527 elif Info.ModuleType == SUP_MODULE_PEIM:
1528 if NumEntryPoints < 2:
1529 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))
1530 else:
1531 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))
1532 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))
1533 elif Info.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:
1534 if NumEntryPoints < 2:
1535 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))
1536 else:
1537 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))
1538 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))
1539 elif Info.ModuleType == SUP_MODULE_DXE_SMM_DRIVER:
1540 if NumEntryPoints == 0:
1541 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))
1542 else:
1543 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))
1544 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))
1545 elif Info.ModuleType == SUP_MODULE_MM_STANDALONE:
1546 if NumEntryPoints < 2:
1547 AutoGenC.Append(gMmStandaloneEntryPointString[NumEntryPoints].Replace(Dict))
1548 else:
1549 AutoGenC.Append(gMmStandaloneEntryPointString[2].Replace(Dict))
1550 AutoGenH.Append(gMmStandaloneEntryPointPrototype.Replace(Dict))
1551 elif Info.ModuleType == SUP_MODULE_UEFI_APPLICATION:
1552 if NumEntryPoints < 2:
1553 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))
1554 else:
1555 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))
1556 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))
1557
1558 ## Create code for ModuleUnloadImage
1559 #
1560 # @param Info The ModuleAutoGen object
1561 # @param AutoGenC The TemplateString object for C code
1562 # @param AutoGenH The TemplateString object for header file
1563 #
1564 def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):
1565 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:
1566 return
1567 #
1568 # Unload Image Handlers
1569 #
1570 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)
1571 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}
1572 if NumUnloadImage < 2:
1573 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))
1574 else:
1575 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))
1576 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))
1577
1578 ## Create code for GUID
1579 #
1580 # @param Info The ModuleAutoGen object
1581 # @param AutoGenC The TemplateString object for C code
1582 # @param AutoGenH The TemplateString object for header file
1583 #
1584 def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):
1585 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1586 GuidType = TAB_GUID
1587 else:
1588 GuidType = "EFI_GUID"
1589
1590 if Info.GuidList:
1591 if not Info.IsLibrary:
1592 AutoGenC.Append("\n// Guids\n")
1593 AutoGenH.Append("\n// Guids\n")
1594 #
1595 # GUIDs
1596 #
1597 for Key in Info.GuidList:
1598 if not Info.IsLibrary:
1599 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))
1600 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1601
1602 ## Create code for protocol
1603 #
1604 # @param Info The ModuleAutoGen object
1605 # @param AutoGenC The TemplateString object for C code
1606 # @param AutoGenH The TemplateString object for header file
1607 #
1608 def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):
1609 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1610 GuidType = TAB_GUID
1611 else:
1612 GuidType = "EFI_GUID"
1613
1614 if Info.ProtocolList:
1615 if not Info.IsLibrary:
1616 AutoGenC.Append("\n// Protocols\n")
1617 AutoGenH.Append("\n// Protocols\n")
1618 #
1619 # Protocol GUIDs
1620 #
1621 for Key in Info.ProtocolList:
1622 if not Info.IsLibrary:
1623 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))
1624 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1625
1626 ## Create code for PPI
1627 #
1628 # @param Info The ModuleAutoGen object
1629 # @param AutoGenC The TemplateString object for C code
1630 # @param AutoGenH The TemplateString object for header file
1631 #
1632 def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):
1633 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1634 GuidType = TAB_GUID
1635 else:
1636 GuidType = "EFI_GUID"
1637
1638 if Info.PpiList:
1639 if not Info.IsLibrary:
1640 AutoGenC.Append("\n// PPIs\n")
1641 AutoGenH.Append("\n// PPIs\n")
1642 #
1643 # PPI GUIDs
1644 #
1645 for Key in Info.PpiList:
1646 if not Info.IsLibrary:
1647 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))
1648 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1649
1650 ## Create code for PCD
1651 #
1652 # @param Info The ModuleAutoGen object
1653 # @param AutoGenC The TemplateString object for C code
1654 # @param AutoGenH The TemplateString object for header file
1655 #
1656 def CreatePcdCode(Info, AutoGenC, AutoGenH):
1657
1658 # Collect Token Space GUIDs used by DynamicEc PCDs
1659 TokenSpaceList = []
1660 for Pcd in Info.ModulePcdList:
1661 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenSpaceGuidCName not in TokenSpaceList:
1662 TokenSpaceList.append(Pcd.TokenSpaceGuidCName)
1663
1664 SkuMgr = Info.Workspace.Platform.SkuIdMgr
1665 AutoGenH.Append("\n// Definition of SkuId Array\n")
1666 AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
1667 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1668 if TokenSpaceList:
1669 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1670 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:
1671 GuidType = TAB_GUID
1672 else:
1673 GuidType = "EFI_GUID"
1674 for Item in TokenSpaceList:
1675 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))
1676
1677 if Info.IsLibrary:
1678 if Info.ModulePcdList:
1679 AutoGenH.Append("\n// PCD definitions\n")
1680 for Pcd in Info.ModulePcdList:
1681 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)
1682 DynExPcdTokenNumberMapping (Info, AutoGenH)
1683 else:
1684 AutoGenC.Append("\n// Definition of SkuId Array\n")
1685 AutoGenC.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr.DumpSkuIdArrary())
1686 if Info.ModulePcdList:
1687 AutoGenH.Append("\n// Definition of PCDs used in this module\n")
1688 AutoGenC.Append("\n// Definition of PCDs used in this module\n")
1689 for Pcd in Info.ModulePcdList:
1690 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)
1691 DynExPcdTokenNumberMapping (Info, AutoGenH)
1692 if Info.LibraryPcdList:
1693 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1694 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")
1695 for Pcd in Info.LibraryPcdList:
1696 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)
1697 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)
1698
1699 ## Create code for unicode string definition
1700 #
1701 # @param Info The ModuleAutoGen object
1702 # @param AutoGenC The TemplateString object for C code
1703 # @param AutoGenH The TemplateString object for header file
1704 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1705 # @param UniGenBinBuffer Buffer to store uni string package data
1706 #
1707 def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):
1708 WorkingDir = os.getcwd()
1709 os.chdir(Info.WorkspaceDir)
1710
1711 IncList = [Info.MetaFile.Dir]
1712 # Get all files under [Sources] section in inf file for EDK-II module
1713 EDK2Module = True
1714 SrcList = [F for F in Info.SourceFileList]
1715 if Info.AutoGenVersion < 0x00010005:
1716 EDK2Module = False
1717 # Get all files under the module directory for EDK-I module
1718 Cwd = os.getcwd()
1719 os.chdir(Info.MetaFile.Dir)
1720 for Root, Dirs, Files in os.walk("."):
1721 if 'CVS' in Dirs:
1722 Dirs.remove('CVS')
1723 if '.svn' in Dirs:
1724 Dirs.remove('.svn')
1725 for File in Files:
1726 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)
1727 if File in SrcList:
1728 continue
1729 SrcList.append(File)
1730 os.chdir(Cwd)
1731
1732 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:
1733 CompatibleMode = True
1734 else:
1735 CompatibleMode = False
1736
1737 #
1738 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1739 #
1740 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:
1741 if CompatibleMode:
1742 EdkLogger.error("build", AUTOGEN_ERROR,
1743 "-c and -s build options should be used exclusively",
1744 ExtraData="[%s]" % str(Info))
1745 ShellMode = True
1746 else:
1747 ShellMode = False
1748
1749 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1750 if EDK2Module:
1751 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]
1752 else:
1753 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]
1754 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)
1755 if CompatibleMode or UniGenCFlag:
1756 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")
1757 AutoGenC.Append(Code)
1758 AutoGenC.Append("\n")
1759 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")
1760 AutoGenH.Append(Header)
1761 if CompatibleMode or UniGenCFlag:
1762 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)
1763 os.chdir(WorkingDir)
1764
1765 def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):
1766 if len(Info.IdfFileList) > 0:
1767 ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList))
1768 if ImageFiles.ImageFilesDict:
1769 Index = 1
1770 PaletteIndex = 1
1771 IncList = [Info.MetaFile.Dir]
1772 SrcList = [F for F in Info.SourceFileList]
1773 SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf']
1774 FileList = GetFileList(SrcList, IncList, SkipList)
1775 ValueStartPtr = 60
1776 StringH.Append("\n//\n//Image ID\n//\n")
1777 ImageInfoOffset = 0
1778 PaletteInfoOffset = 0
1779 ImageBuffer = pack('x')
1780 PaletteBuffer = pack('x')
1781 BufferStr = ''
1782 PaletteStr = ''
1783 FileDict = {}
1784 for Idf in ImageFiles.ImageFilesDict:
1785 if ImageFiles.ImageFilesDict[Idf]:
1786 for FileObj in ImageFiles.ImageFilesDict[Idf]:
1787 for sourcefile in Info.SourceFileList:
1788 if FileObj.FileName == sourcefile.File:
1789 if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']:
1790 EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info))
1791 FileObj.File = sourcefile
1792 break
1793 else:
1794 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))
1795
1796 for FileObj in ImageFiles.ImageFilesDict[Idf]:
1797 ID = FileObj.ImageID
1798 File = FileObj.File
1799 if not os.path.exists(File.Path) or not os.path.isfile(File.Path):
1800 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path)
1801 SearchImageID (FileObj, FileList)
1802 if FileObj.Referenced:
1803 if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0:
1804 Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n'
1805 else:
1806 Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n'
1807
1808 if File not in FileDict:
1809 FileDict[File] = Index
1810 else:
1811 DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE)
1812 DuplicateBlock += pack('H', FileDict[File])
1813 ImageBuffer += DuplicateBlock
1814 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))
1815 TempBufferList = AscToHexList(DuplicateBlock)
1816 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')
1817 StringH.Append(Line)
1818 Index += 1
1819 continue
1820
1821 TmpFile = open(File.Path, 'rb')
1822 Buffer = TmpFile.read()
1823 TmpFile.close()
1824 if File.Ext.upper() == '.PNG':
1825 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG)
1826 TempBuffer += pack('I', len(Buffer))
1827 TempBuffer += Buffer
1828 elif File.Ext.upper() == '.JPG':
1829 ImageType, = struct.unpack('4s', Buffer[6:10])
1830 if ImageType != 'JFIF':
1831 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path)
1832 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG)
1833 TempBuffer += pack('I', len(Buffer))
1834 TempBuffer += Buffer
1835 elif File.Ext.upper() == '.BMP':
1836 TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent)
1837 if len(TempPalette) > 1:
1838 PaletteIndex += 1
1839 NewPalette = pack('H', len(TempPalette))
1840 NewPalette += TempPalette
1841 PaletteBuffer += NewPalette
1842 PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4)))
1843 TempPaletteList = AscToHexList(NewPalette)
1844 PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n')
1845 ImageBuffer += TempBuffer
1846 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))
1847 TempBufferList = AscToHexList(TempBuffer)
1848 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')
1849
1850 StringH.Append(Line)
1851 Index += 1
1852
1853 BufferStr = WriteLine(BufferStr, '// End of the Image Info')
1854 BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n')
1855 ImageEnd = pack('B', EFI_HII_IIBT_END)
1856 ImageBuffer += ImageEnd
1857
1858 if len(ImageBuffer) > 1:
1859 ImageInfoOffset = 12
1860 if len(PaletteBuffer) > 1:
1861 PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer
1862
1863 IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset)
1864 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
1865 if len(PaletteBuffer) > 1:
1866 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1
1867 else:
1868 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1
1869 if PaletteIndex > 1:
1870 PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1)
1871 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
1872 Hex_Length = '%06X' % PACKAGE_HEADER_Length
1873 if PACKAGE_HEADER_Length > 0xFFFFFF:
1874 EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info))
1875 PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES)
1876
1877 IdfGenBinBuffer.write(PACKAGE_HEADER)
1878 IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR)
1879 if len(ImageBuffer) > 1 :
1880 IdfGenBinBuffer.write(ImageBuffer[1:])
1881 if PaletteIndex > 1:
1882 IdfGenBinBuffer.write(PALETTE_INFO_HEADER)
1883 if len(PaletteBuffer) > 1:
1884 IdfGenBinBuffer.write(PaletteBuffer[1:])
1885
1886 if IdfGenCFlag:
1887 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length
1888 AutoGenC.Append("\n//\n//Image Pack Definition\n//\n")
1889 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n')
1890 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')
1891 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')
1892 AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n')
1893 IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER)
1894 IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR)
1895 AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n')
1896 AllStr = WriteLine(AllStr, '// Image DATA\n')
1897 if BufferStr:
1898 AllStr = WriteLine(AllStr, BufferStr)
1899 if PaletteStr:
1900 AllStr = WriteLine(AllStr, '// Palette Header\n')
1901 PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER)
1902 AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n')
1903 AllStr = WriteLine(AllStr, '// Palette Data\n')
1904 AllStr = WriteLine(AllStr, PaletteStr)
1905 AllStr = WriteLine(AllStr, '};')
1906 AutoGenC.Append(AllStr)
1907 AutoGenC.Append("\n")
1908 StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n')
1909 StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName)
1910
1911 # typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
1912 # EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
1913 # UINT32 ImageInfoOffset;
1914 # UINT32 PaletteInfoOffset;
1915 # } EFI_HII_IMAGE_PACKAGE_HDR;
1916
1917 # typedef struct {
1918 # UINT32 Length:24;
1919 # UINT32 Type:8;
1920 # UINT8 Data[];
1921 # } EFI_HII_PACKAGE_HEADER;
1922
1923 # typedef struct _EFI_HII_IMAGE_BLOCK {
1924 # UINT8 BlockType;
1925 # UINT8 BlockBody[];
1926 # } EFI_HII_IMAGE_BLOCK;
1927
1928 def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):
1929 ImageType, = struct.unpack('2s', Buffer[0:2])
1930 if ImageType!= 'BM': # BMP file type is 'BM'
1931 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)
1932 BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize', 'bfReserved1', 'bfReserved2', 'bfOffBits', 'biSize', 'biWidth', 'biHeight', 'biPlanes', 'biBitCount', 'biCompression', 'biSizeImage', 'biXPelsPerMeter', 'biYPelsPerMeter', 'biClrUsed', 'biClrImportant'])
1933 BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')
1934 BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))
1935 #
1936 # Doesn't support compress.
1937 #
1938 if BmpHeader.biCompression != 0:
1939 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path)
1940
1941 # The Width and Height is UINT16 type in Image Package
1942 if BmpHeader.biWidth > 0xFFFF:
1943 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path)
1944 if BmpHeader.biHeight > 0xFFFF:
1945 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path)
1946
1947 PaletteBuffer = pack('x')
1948 if BmpHeader.biBitCount == 1:
1949 if TransParent:
1950 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)
1951 else:
1952 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)
1953 ImageBuffer += pack('B', PaletteIndex)
1954 Width = (BmpHeader.biWidth + 7)/8
1955 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1956 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1957 elif BmpHeader.biBitCount == 4:
1958 if TransParent:
1959 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)
1960 else:
1961 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)
1962 ImageBuffer += pack('B', PaletteIndex)
1963 Width = (BmpHeader.biWidth + 1)/2
1964 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1965 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1966 elif BmpHeader.biBitCount == 8:
1967 if TransParent:
1968 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)
1969 else:
1970 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT)
1971 ImageBuffer += pack('B', PaletteIndex)
1972 Width = BmpHeader.biWidth
1973 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
1974 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
1975 elif BmpHeader.biBitCount == 24:
1976 if TransParent:
1977 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS)
1978 else:
1979 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT)
1980 Width = BmpHeader.biWidth * 3
1981 else:
1982 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path))
1983
1984 ImageBuffer += pack('H', BmpHeader.biWidth)
1985 ImageBuffer += pack('H', BmpHeader.biHeight)
1986 Start = BmpHeader.bfOffBits
1987 End = BmpHeader.bfSize - 1
1988 for Height in range(0, BmpHeader.biHeight):
1989 if Width % 4 != 0:
1990 Start = End + (Width % 4) - 4 - Width
1991 else:
1992 Start = End - Width
1993 ImageBuffer += Buffer[Start + 1 : Start + Width + 1]
1994 End = Start
1995
1996 # 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
1997 if PaletteBuffer and len(PaletteBuffer) > 1:
1998 PaletteTemp = pack('x')
1999 for Index in range(0, len(PaletteBuffer)):
2000 if Index % 4 == 3:
2001 continue
2002 PaletteTemp += PaletteBuffer[Index]
2003 PaletteBuffer = PaletteTemp[1:]
2004 return ImageBuffer, PaletteBuffer
2005
2006 ## Create common code
2007 #
2008 # @param Info The ModuleAutoGen object
2009 # @param AutoGenC The TemplateString object for C code
2010 # @param AutoGenH The TemplateString object for header file
2011 #
2012 def CreateHeaderCode(Info, AutoGenC, AutoGenH):
2013 # file header
2014 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))
2015 # header file Prologue
2016 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-', '_')}))
2017 AutoGenH.Append(gAutoGenHCppPrologueString)
2018 if Info.AutoGenVersion >= 0x00010005:
2019 # header files includes
2020 if Info.ModuleType in gModuleTypeHeaderFile:
2021 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])
2022 #
2023 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
2024 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
2025 #
2026 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:
2027 AutoGenH.Append("#include <Library/PcdLib.h>\n")
2028
2029 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')
2030 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
2031
2032 if Info.IsLibrary:
2033 return
2034
2035 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))
2036
2037 if Info.IsLibrary:
2038 return
2039 # C file header
2040 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))
2041 if Info.AutoGenVersion >= 0x00010005:
2042 # C file header files includes
2043 if Info.ModuleType in gModuleTypeHeaderFile:
2044 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:
2045 AutoGenC.Append("#include <%s>\n" % Inc)
2046 else:
2047 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)
2048
2049 #
2050 # Publish the CallerId Guid
2051 #
2052 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))
2053 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)
2054
2055 ## Create common code for header file
2056 #
2057 # @param Info The ModuleAutoGen object
2058 # @param AutoGenC The TemplateString object for C code
2059 # @param AutoGenH The TemplateString object for header file
2060 #
2061 def CreateFooterCode(Info, AutoGenC, AutoGenH):
2062 AutoGenH.Append(gAutoGenHEpilogueString)
2063
2064 ## Create code for a module
2065 #
2066 # @param Info The ModuleAutoGen object
2067 # @param AutoGenC The TemplateString object for C code
2068 # @param AutoGenH The TemplateString object for header file
2069 # @param StringH The TemplateString object for header file
2070 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
2071 # @param UniGenBinBuffer Buffer to store uni string package data
2072 # @param StringIdf The TemplateString object for header file
2073 # @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
2074 # @param IdfGenBinBuffer Buffer to store Idf string package data
2075 #
2076 def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):
2077 CreateHeaderCode(Info, AutoGenC, AutoGenH)
2078
2079 if Info.AutoGenVersion >= 0x00010005:
2080 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)
2081 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)
2082 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)
2083 CreatePcdCode(Info, AutoGenC, AutoGenH)
2084 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)
2085 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)
2086 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)
2087 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)
2088
2089 if Info.UnicodeFileList:
2090 FileName = "%sStrDefs.h" % Info.Name
2091 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))
2092 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-', '_')}))
2093 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)
2094
2095 GuidMacros = []
2096 for Guid in Info.Module.Guids:
2097 if Guid in Info.Module.GetGuidsUsedByPcd():
2098 continue
2099 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))
2100 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():
2101 GuidMacros.append('#define %s %s' % (Guid, Value))
2102 # supports FixedAtBuild and FeaturePcd usage in VFR file
2103 if Info.VfrFileList and Info.ModulePcdList:
2104 GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))
2105 GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))
2106 GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))
2107 GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))
2108 GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))
2109 GuidMacros.append('#define %s %s' % ('FeaturePcdGet(TokenName)', '_PCD_VALUE_##TokenName'))
2110 for Pcd in Info.ModulePcdList:
2111 if Pcd.Type in [TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_FEATURE_FLAG]:
2112 TokenCName = Pcd.TokenCName
2113 Value = Pcd.DefaultValue
2114 if Pcd.DatumType == 'BOOLEAN':
2115 BoolValue = Value.upper()
2116 if BoolValue == 'TRUE':
2117 Value = '1'
2118 elif BoolValue == 'FALSE':
2119 Value = '0'
2120 for PcdItem in GlobalData.MixedPcd:
2121 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
2122 TokenCName = PcdItem[0]
2123 break
2124 GuidMacros.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName, Value))
2125
2126 if Info.IdfFileList:
2127 GuidMacros.append('#include "%sImgDefs.h"' % Info.Name)
2128
2129 if GuidMacros:
2130 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))
2131
2132 StringH.Append("\n#endif\n")
2133 AutoGenH.Append('#include "%s"\n' % FileName)
2134
2135 if Info.IdfFileList:
2136 FileName = "%sImgDefs.h" % Info.Name
2137 StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))
2138 StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-', '_')}))
2139 CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)
2140
2141 StringIdf.Append("\n#endif\n")
2142 AutoGenH.Append('#include "%s"\n' % FileName)
2143
2144 CreateFooterCode(Info, AutoGenC, AutoGenH)
2145
2146 # no generation of AutoGen.c for Edk modules without unicode file
2147 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:
2148 AutoGenC.String = ''
2149
2150 ## Create the code file
2151 #
2152 # @param FilePath The path of code file
2153 # @param Content The content of code file
2154 # @param IsBinaryFile The flag indicating if the file is binary file or not
2155 #
2156 # @retval True If file content is changed or file doesn't exist
2157 # @retval False If the file exists and the content is not changed
2158 #
2159 def Generate(FilePath, Content, IsBinaryFile):
2160 return SaveFileOnChange(FilePath, Content, IsBinaryFile)
2161