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