]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
EDKT96.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 3147a245389169fe68761915beac6b1d9a5c3b07..e36945501b5a7806fb335424910843e9d408b8f3 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
@@ -43,6 +30,21 @@ import java.util.List;
 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 +54,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 +109,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
@@ -251,10 +257,8 @@ public class AutoGen {
                // Add #ifndef ${BaseName}_AUTOGENH\r
                // #def ${BseeName}_AUTOGENH\r
                //\r
-               fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
-                               + "_AUTOGENH\r\n");\r
-               fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
-                               + "_AUTOGENH\r\n\r\n");\r
+               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n");\r
+               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n");\r
 \r
                //\r
                // Write the specification version and release version at the begine\r
@@ -264,29 +268,6 @@ public class AutoGen {
                // moduleType.\r
                //\r
                moduleType = SurfaceAreaQuery.getModuleType();\r
-//             switch (CommonDefinition.getModuleType(moduleType)) {\r
-//             case CommonDefinition.ModuleTypeDxeCore:\r
-//             case CommonDefinition.ModuleTypeDxeDriver:\r
-//             case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-//             case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-//             case CommonDefinition.ModuleTypeDxeSalDriver:\r
-//             case CommonDefinition.ModuleTypeUefiDriver:\r
-//             case CommonDefinition.ModuleTypeUefiApplication:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-//                     break;\r
-//             default:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHVersionDefault);\r
-//                     break;\r
-//             }\r
-//             switch (CommonDefinition.getModuleType(moduleType)) {\r
-//             case CommonDefinition.ModuleTypeUefiDriver:\r
-//             case CommonDefinition.ModuleTypeUefiApplication:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHReleaseDefault);\r
-//                     break;\r
-//             default:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHLine2);\r
-//                     break;\r
-//             }\r
 \r
                //\r
                // Add "extern int __make_me_compile_correctly;" at begin of\r
@@ -308,7 +289,7 @@ public class AutoGen {
                // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
                // .getDependencePkg(this.arch);\r
                PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-                               .getDependencePkg(null);\r
+                               .getDependencePkg(this.arch);\r
                if (consumedPkgIdList != null) {\r
                        headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
                        item = headerFileList.iterator();\r
@@ -321,7 +302,7 @@ public class AutoGen {
                // Write library class's related *.h file to autogen.h.\r
                //\r
                String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -331,7 +312,7 @@ public class AutoGen {
                }\r
 \r
                libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -341,7 +322,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
@@ -516,10 +507,8 @@ public class AutoGen {
                // Add #ifndef ${BaseName}_AUTOGENH\r
                // #def ${BseeName}_AUTOGENH\r
                //\r
-               fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
-                               + "_AUTOGENH\r\n");\r
-               fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
-                               + "_AUTOGENH\r\n\r\n");\r
+               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n");\r
+               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n");\r
 \r
                //\r
                // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
@@ -551,7 +540,7 @@ public class AutoGen {
                // Write library class's related *.h file to autogen.h\r
                //\r
                String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -561,7 +550,7 @@ public class AutoGen {
                }\r
 \r
                libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -571,6 +560,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
@@ -891,21 +891,17 @@ public class AutoGen {
                                fileBuffer.append("{\r\n");\r
                                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
                                fileBuffer.append("}\r\n\r\n");\r
-                               break;\r
+\r
                        } else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("EFI_STATUS\r\n");\r
-                        fileBuffer.append("EFIAPI\r\n");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (\r\n");\r
-                        fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                        fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                        entryPointCount++;\r
-                    } else {\r
-                        break;\r
-                    }\r
+                    fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (\r\n");\r
+                    fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
                 }\r
                 fileBuffer\r
                         .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
@@ -962,27 +958,24 @@ public class AutoGen {
             entryPointList = CommonDefinition.remDupString(entryPointList);\r
                        entryPointCount = 0;\r
 \r
-                       fileBuffer\r
-                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-                       fileBuffer.append(Integer.toString(entryPointCount));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-\r
                        if (entryPointList != null) {\r
                                for (int i = 0; i < entryPointList.length; i++) {\r
-                                       if (!entryPointList[i].equals("")) {\r
-                                               fileBuffer.append("EFI_STATUS\r\n");\r
-                                               fileBuffer.append("EFIAPI\r\n");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append(" (\r\n");\r
-                                               fileBuffer\r
-                                                               .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
-                               }\r
+                    fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (\r\n");\r
+                    fileBuffer\r
+                            .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
+                }\r
                        }\r
 \r
+            fileBuffer\r
+                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+                       fileBuffer.append(Integer.toString(entryPointCount));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+\r
                        fileBuffer.append("EFI_STATUS\r\n");\r
                        fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
@@ -1135,18 +1128,14 @@ public class AutoGen {
                        entryPointCount = 0;\r
                        if (entryPointList != null) {\r
                                for (int i = 0; i < entryPointList.length; i++) {\r
-                                       if (!entryPointList[i].equals("")) {\r
-                                               fileBuffer.append("EFI_STATUS\r\n");\r
-                                               fileBuffer.append("EFIAPI\r\n");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append(" (\r\n");\r
-                                               fileBuffer\r
-                                                               .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                               entryPointCount++;\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
+                    fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (\r\n");\r
+                    fileBuffer\r
+                            .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
                                }\r
                        }\r
 \r
@@ -1155,22 +1144,6 @@ public class AutoGen {
                        fileBuffer.append(Integer.toString(entryPointCount));\r
                        fileBuffer.append(";\r\n\r\n");\r
 \r
-                       if (entryPointList != null) {\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
-                                       if (!entryPointList[i].equals("")) {\r
-                                               fileBuffer.append("EFI_STATUS\r\n");\r
-                                               fileBuffer.append("EFIAPI\r\n");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append(" (\r\n");\r
-                                               fileBuffer\r
-                                                               .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
                        fileBuffer.append("EFI_STATUS\n");\r
                        fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
@@ -1822,7 +1795,7 @@ public class AutoGen {
                if (compDiagList != null && compDiagList.length != 0) {\r
                        if (drvBindList.length != compDiagList.length) {\r
                                throw new BuildException(\r
-                                               "Different number of Driver Binding and Driver Configuration protocols!");\r
+                                               "Different number of Driver Binding and Driver Diagnosis protocols!");\r
                        }\r
 \r
                        BitMask |= 0x04;\r
@@ -2083,4 +2056,27 @@ 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
+        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
+\r
 }
\ No newline at end of file