]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # process data section generation\r | |
3 | #\r | |
4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | #\r | |
6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | #\r | |
8 | \r | |
9 | ##\r | |
10 | # Import Modules\r | |
11 | #\r | |
12 | from __future__ import absolute_import\r | |
13 | from . import Section\r | |
14 | from .GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
15 | import subprocess\r | |
16 | from .Ffs import SectionSuffix\r | |
17 | import Common.LongFilePathOs as os\r | |
18 | from CommonDataClass.FdfClass import DataSectionClassObject\r | |
19 | from Common.Misc import PeImageClass\r | |
20 | from Common.LongFilePathSupport import CopyLongFilePath\r | |
21 | from Common.DataType import *\r | |
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 | |
47 | def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):\r | |
48 | #\r | |
49 | # Prepare the parameter of GenSection\r | |
50 | #\r | |
51 | if Dict is None:\r | |
52 | Dict = {}\r | |
53 | if FfsFile is not None:\r | |
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 | |
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 | |
80 | \r | |
81 | #Get PE Section alignment when align is set to AUTO\r | |
82 | if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r | |
83 | self.Alignment = "0"\r | |
84 | NoStrip = True\r | |
85 | if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r | |
86 | if self.KeepReloc is not None:\r | |
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 | |
93 | CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r | |
94 | StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r | |
95 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
96 | StrippedFile,\r | |
97 | [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r | |
98 | Strip=True,\r | |
99 | IsMakefile = IsMakefile\r | |
100 | )\r | |
101 | self.SectFileName = StrippedFile\r | |
102 | \r | |
103 | if self.SecType == BINARY_FILE_TYPE_TE:\r | |
104 | TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r | |
105 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
106 | TeFile,\r | |
107 | [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r | |
108 | Type='te',\r | |
109 | IsMakefile = IsMakefile\r | |
110 | )\r | |
111 | self.SectFileName = TeFile\r | |
112 | \r | |
113 | OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get(self.SecType))\r | |
114 | OutputFile = os.path.normpath(OutputFile)\r | |
115 | GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r | |
116 | FileList = [OutputFile]\r | |
117 | return FileList, self.Alignment\r |