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