]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
1, Fix EDKT141
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 3aff06f9569303bc3c56946ec39210d1e33ad11e..a8ec270355146dd8693d376a193171900050f649 100644 (file)
 \r
 package org.tianocore.build.autogen;\r
 \r
-import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.Spd;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.id.ModuleIdentification;\r
-import org.tianocore.build.id.PackageIdentification;\r
-import org.tianocore.GuidsDocument;\r
-import org.tianocore.LibraryClassDocument.LibraryClass;\r
-import org.tianocore.PPIsDocument;\r
-import org.tianocore.ProtocolsDocument;\r
-import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
-import org.tianocore.build.exception.*;\r
-import org.tianocore.logger.EdkLog;\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.xmlbeans.XmlObject;\r
-\r
 import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
 import java.util.ArrayList;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
+import java.util.LinkedHashSet;\r
 import java.util.LinkedList;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 \r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.GuidsDocument;\r
+import org.tianocore.LibraryClassDocument.LibraryClass;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.ProtocolsDocument;\r
+import org.tianocore.build.exception.*;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.Spd;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
+import org.tianocore.logger.EdkLog;\r
+\r
 /**\r
  * This class is to generate Autogen.h and Autogen.c according to module surface\r
  * area or library surface area.\r
@@ -52,7 +55,10 @@ public class AutoGen {
        // / The output path of Autogen.h and Autogen.c\r
        // /\r
        private String outputPath;\r
-\r
+    /// \r
+    /// The name of FV directory \r
+    /// \r
+    private String fvDir;\r
        // /\r
        // / The base name of module or library.\r
        // /\r
@@ -104,10 +110,11 @@ public class AutoGen {
         * @param arch\r
         *            Target architecture.\r
         */\r
-       public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
+       public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch) {\r
                this.outputPath = outputPath;\r
                this.moduleId = moduleId;\r
                this.arch = arch;\r
+        this.fvDir = fvDir;\r
 \r
        }\r
 \r
@@ -316,7 +323,17 @@ public class AutoGen {
                }\r
                fileBuffer.append("\r\n");\r
 \r
-               //\r
+        //\r
+        //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to \r
+        // {DEST_DIR_DRBUG}/FlashMap.h\r
+        // \r
+        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.include);\r
+            fileBuffer.append("  <");\r
+            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            copyFlashMapHToDebugDir();\r
+        }\r
+\r
                // Write PCD autogen information to AutoGen.h.\r
                //\r
                if (this.myPcdAutogen != null) {\r
@@ -439,25 +456,18 @@ public class AutoGen {
                GuidGuidToAutogenC(fileBuffer);\r
 \r
                //\r
-               // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
-               // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
-               // PCD information has been collected in FPDParser task by\r
-               // CollectPCDAction.\r
-               // Note : when PCD image tool ready,\r
-               // isPCDEmulatedDriver parameter will be removed.\r
-               //\r
-                try {\r
-//              this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),\r
-//              moduleId.getGuid(), moduleId.getPackage().getName(), moduleId.getPackage().getGuid(),this.arch,moduleId.getVersion(),false, null);\r
-         this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),null,null,null, this.arch,null,false, null);\r
-                this.myPcdAutogen.execute();\r
-                } catch (Exception e) {\r
-                throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
-                }\r
+               // Call pcd autogen. \r
+               //\r
+                this.myPcdAutogen = new PCDAutoGenAction(moduleId, this.arch, false, null);\r
+                try {\r
+                    this.myPcdAutogen.execute();\r
+                } catch (Exception exp) {\r
+                    throw new BuildException (exp.getMessage());\r
+                }\r
                \r
                if (this.myPcdAutogen != null) {\r
-            fileBuffer.append("\r\n");\r
-                       fileBuffer.append(this.myPcdAutogen.OutputC());\r
+                    fileBuffer.append("\r\n");\r
+                    fileBuffer.append(this.myPcdAutogen.OutputC());\r
                }\r
 \r
                if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
@@ -544,6 +554,17 @@ public class AutoGen {
                }\r
                fileBuffer.append("\r\n");\r
 \r
+        //\r
+        //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to \r
+        // {DEST_DIR_DRBUG}/FlashMap.h\r
+        // \r
+        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.include);\r
+            fileBuffer.append("  <");\r
+            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            copyFlashMapHToDebugDir();\r
+        }\r
+\r
                //\r
                // Write PCD information to library AutoGen.h.\r
                //\r
@@ -585,33 +606,21 @@ public class AutoGen {
                fileBuffer.append("\r\n");\r
 \r
                //\r
-               // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
-               // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
-               // PCD information has been collected in FPDParser task by\r
-               // CollectPCDAction.\r
-               // Note : when PCD image tool ready,\r
-               // isPCDEmulatedDriver parameter will be removed.\r
+               // Call pcd autogen. \r
                //\r
+                this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,\r
+                                                         this.arch,\r
+                                                         true, \r
+                                                         SurfaceAreaQuery.getModulePcdEntryNameArray());\r
                try {\r
-//                      this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
-//                      this.moduleId.getGuid(),moduleId.getPackage().getName(),moduleId.getPackage().getGuid(), this.arch, moduleId.getVersion(),true, SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-            this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
-                                                     null,\r
-                                                     null,\r
-                                                     null,\r
-                                                     this.arch,\r
-                                                     null,\r
-                                                     true, \r
-                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-                     \r
-                       this.myPcdAutogen.execute();\r
+                    this.myPcdAutogen.execute();\r
                } catch (Exception e) {\r
-                       throw new BuildException(e.getMessage());\r
+                    throw new BuildException(e.getMessage());\r
                }\r
 \r
                if (this.myPcdAutogen != null) {\r
-            fileBuffer.append("\r\n");\r
-                       fileBuffer.append(this.myPcdAutogen.OutputC());\r
+                    fileBuffer.append("\r\n");\r
+                    fileBuffer.append(this.myPcdAutogen.OutputC());\r
                }\r
 \r
                if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
@@ -632,7 +641,7 @@ public class AutoGen {
         */\r
        Set<String> LibraryClassToAutogenH(String[] libClassList)\r
                        throws AutoGenException {\r
-               Set<String> includStrList = new HashSet<String>();\r
+               Set<String> includStrList = new LinkedHashSet<String>();\r
                String includerName[];\r
                String str = "";\r
 \r
@@ -1477,6 +1486,7 @@ public class AutoGen {
                        switch (CommonDefinition.getModuleType(moduleType)) {\r
                        case CommonDefinition.ModuleTypeBase:\r
                                fileBuffer.append("RETURN_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  VOID\r\n");\r
@@ -1486,6 +1496,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypePeiCore:\r
                        case CommonDefinition.ModuleTypePeim:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer\r
@@ -1503,6 +1514,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypeUefiDriver:\r
                        case CommonDefinition.ModuleTypeUefiApplication:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1516,6 +1528,7 @@ public class AutoGen {
                // Add ProcessLibraryConstructorList in AutoGen.c\r
                //\r
                fileBuffer.append("VOID\r\n");\r
+               fileBuffer.append("EFIAPI\r\n");\r
                fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
                switch (CommonDefinition.getModuleType(moduleType)) {\r
                case CommonDefinition.ModuleTypeBase:\r
@@ -1608,7 +1621,8 @@ public class AutoGen {
                for (int i = 0; i < libInstanceList.size(); i++) {\r
                        switch (CommonDefinition.getModuleType(moduleType)) {\r
                        case CommonDefinition.ModuleTypeBase:\r
-                               fileBuffer.append("RETURN_STATUS\n");\r
+                               fileBuffer.append("RETURN_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  VOID\r\n");\r
@@ -1617,6 +1631,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypePeiCore:\r
                        case CommonDefinition.ModuleTypePeim:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer\r
@@ -1633,6 +1648,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypeUefiDriver:\r
                        case CommonDefinition.ModuleTypeUefiApplication:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1658,6 +1674,7 @@ public class AutoGen {
                case CommonDefinition.ModuleTypeUefiDriver:\r
                case CommonDefinition.ModuleTypeUefiApplication:\r
                        fileBuffer.append("VOID\r\n");\r
+                       fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
                        fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
                        fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
@@ -1963,14 +1980,12 @@ public class AutoGen {
                        //\r
                        Count = 0;\r
                        if (exitBootList != null) {\r
-                               if (setVirtualList != null) {\r
-                                       for (i = 0; i < exitBootList.length; i++) {\r
-                                               if (exitBootList[i].equalsIgnoreCase("")) {\r
-                                                       break;\r
-                                               }\r
+                               for (i = 0; i < exitBootList.length; i++) {\r
+                                       if (exitBootList[i].equalsIgnoreCase("")) {\r
+                                               break;\r
                                        }\r
-                                       Count = i;\r
                                }\r
+                               Count = i;\r
                        }\r
                        fileBuffer.append(Integer.toString(Count));\r
                        fileBuffer.append(";\r\n\r\n");\r
@@ -2029,4 +2044,31 @@ public class AutoGen {
 \r
        }\r
 \r
+    private void copyFlashMapHToDebugDir() throws  AutoGenException{\r
+        \r
+        File inFile = new File(fvDir + File.separatorChar + CommonDefinition.flashMapH);\r
+        int size = (int)inFile.length();\r
+        byte[] buffer = new byte[size];\r
+        File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.tianoR8FlashMapH);\r
+               //\r
+               //  If TianoR8FlashMap.h existed and the flashMap.h don't change, \r
+               //  do nothing.\r
+               // \r
+        if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
+                   try{\r
+                if (inFile.exists()) {\r
+                    FileInputStream fis = new FileInputStream (inFile);\r
+                    fis.read(buffer);\r
+                    FileOutputStream fos = new FileOutputStream(outFile);\r
+                    fos.write(buffer);\r
+                    fis.close();\r
+                    fos.close();\r
+                }else {\r
+                    throw new AutoGenException("The flashMap.h file don't exist!!");\r
+                }\r
+            } catch (Exception e){\r
+                throw new AutoGenException(e.getMessage());\r
+            }\r
+               }\r
+    }\r
 }
\ No newline at end of file