]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process data section generation\r | |
3 | #\r | |
8bb63e37 | 4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
30fdf114 | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30fdf114 LG |
7 | #\r |
8 | \r | |
9 | ##\r | |
10 | # Import Modules\r | |
11 | #\r | |
1ccc4d89 | 12 | from __future__ import absolute_import\r |
bfa65b61 GL |
13 | from . import Section\r |
14 | from .GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
30fdf114 | 15 | import subprocess\r |
9e47e6f9 | 16 | from .Ffs import SectionSuffix\r |
1be2ed90 | 17 | import Common.LongFilePathOs as os\r |
30fdf114 | 18 | from CommonDataClass.FdfClass import DataSectionClassObject\r |
9053bc51 | 19 | from Common.Misc import PeImageClass\r |
1be2ed90 | 20 | from Common.LongFilePathSupport import CopyLongFilePath\r |
8bb63e37 | 21 | from Common.DataType import *\r |
30fdf114 LG |
22 | \r |
23 | ## generate data section\r | |
24 | #\r | |
25 | #\r | |
26 | class DataSection (DataSectionClassObject):\r | |
27 | ## The constructor\r | |
28 | #\r | |
29 | # @param self The object pointer\r | |
30 | #\r | |
31 | def __init__(self):\r | |
32 | DataSectionClassObject.__init__(self)\r | |
33 | \r | |
34 | ## GenSection() method\r | |
35 | #\r | |
36 | # Generate compressed section\r | |
37 | #\r | |
38 | # @param self The object pointer\r | |
39 | # @param OutputPath Where to place output file\r | |
40 | # @param ModuleName Which module this section belongs to\r | |
41 | # @param SecNum Index of section\r | |
42 | # @param KeyStringList Filter for inputs of section generation\r | |
43 | # @param FfsInf FfsInfStatement object that contains this section data\r | |
44 | # @param Dict dictionary contains macro and its value\r | |
45 | # @retval tuple (Generated file name list, section alignment)\r | |
46 | #\r | |
e32f7bc9 | 47 | def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):\r |
30fdf114 LG |
48 | #\r |
49 | # Prepare the parameter of GenSection\r | |
50 | #\r | |
e32f7bc9 FZ |
51 | if Dict is None:\r |
52 | Dict = {}\r | |
4231a819 | 53 | if FfsFile is not None:\r |
30fdf114 LG |
54 | self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r |
55 | self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r | |
56 | else:\r | |
57 | self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r | |
58 | self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r | |
59 | \r | |
60 | """Check Section file exist or not !"""\r | |
61 | \r | |
62 | if not os.path.exists(self.SectFileName):\r | |
63 | self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r | |
64 | self.SectFileName)\r | |
65 | \r | |
66 | """Copy Map file to Ffs output"""\r | |
67 | Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)\r | |
68 | if Filename[(len(Filename)-4):] == '.efi':\r | |
69 | MapFile = Filename.replace('.efi', '.map')\r | |
37de70b7 YZ |
70 | CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r |
71 | if IsMakefile:\r | |
72 | if GenFdsGlobalVariable.CopyList == []:\r | |
73 | GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r | |
74 | else:\r | |
75 | GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r | |
76 | else:\r | |
77 | if os.path.exists(MapFile):\r | |
78 | if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r | |
79 | CopyLongFilePath(MapFile, CopyMapFile)\r | |
30fdf114 | 80 | \r |
9053bc51 | 81 | #Get PE Section alignment when align is set to AUTO\r |
91fa33ee | 82 | if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r |
d8be0107 | 83 | self.Alignment = "0"\r |
30fdf114 | 84 | NoStrip = True\r |
91fa33ee | 85 | if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r |
4231a819 | 86 | if self.KeepReloc is not None:\r |
30fdf114 LG |
87 | NoStrip = self.KeepReloc\r |
88 | \r | |
89 | if not NoStrip:\r | |
90 | FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r | |
91 | if not os.path.exists(FileBeforeStrip) or \\r | |
92 | (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r | |
1be2ed90 | 93 | CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r |
30fdf114 LG |
94 | StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r |
95 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
37de70b7 YZ |
96 | StrippedFile,\r |
97 | [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r | |
98 | Strip=True,\r | |
99 | IsMakefile = IsMakefile\r | |
100 | )\r | |
30fdf114 LG |
101 | self.SectFileName = StrippedFile\r |
102 | \r | |
91fa33ee | 103 | if self.SecType == BINARY_FILE_TYPE_TE:\r |
30fdf114 LG |
104 | TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r |
105 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
37de70b7 YZ |
106 | TeFile,\r |
107 | [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r | |
108 | Type='te',\r | |
109 | IsMakefile = IsMakefile\r | |
110 | )\r | |
30fdf114 LG |
111 | self.SectFileName = TeFile\r |
112 | \r | |
9e47e6f9 | 113 | OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get(self.SecType))\r |
30fdf114 | 114 | OutputFile = os.path.normpath(OutputFile)\r |
37de70b7 | 115 | GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r |
30fdf114 LG |
116 | FileList = [OutputFile]\r |
117 | return FileList, self.Alignment\r |