]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
Added stringToInt method to handle hex integer for FFS_ATTRIB_DATA_ALIGNMENT
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFfsFileTask.java
index 3c7ebed362e0419d1a2dad10cf40a2aaf331c944..2c46f09d659d7a449a91775043a48d9843c00bba 100644 (file)
@@ -85,11 +85,11 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
     ///\r
     boolean ffsAttribRecovery        = false;\r
     ///\r
-    /// ffsAligenment value is used to set the corresponding bit in the output \r
+    /// ffsAttribDataAlignment value is used to set the corresponding bit in the output \r
     /// FFS file header.The specified FFS alignment must be a value between 0 \r
     /// and 7 inclusive\r
     ///\r
-    int     ffsAlignment       = 0;\r
+    int     ffsAttribDataAlignment       = 0;\r
     ///\r
     /// ffsAttribChecksum value is used to set the corresponding bit in the \r
     /// output FFS file header\r
@@ -490,8 +490,8 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
       This function is to get the ffsAligment\r
       @return  The value of ffsAligment.\r
     **/\r
-    public int getFfsAligment() {\r
-        return this.ffsAlignment;\r
+    public int getFfsAttribDataAlignment() {\r
+        return this.ffsAttribDataAlignment;\r
     }\r
 \r
     /**\r
@@ -500,12 +500,12 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
       This function is to set ffsAligment \r
       @param  ffsAligment     The value of ffsAligment.\r
     **/\r
-    public void setFfsAligment(int ffsAligment) {\r
-        this.ffsAlignment = ffsAligment;\r
-        if (this.ffsAlignment > 7) {\r
-            throw new BuildException ("FFS_ALIGMENT Scope is 0-7");\r
+    public void setFfsAttribDataAlignment(String ffsAligment) {\r
+        this.ffsAttribDataAlignment = stringToInt(ffsAligment.replaceAll(" ", "").toLowerCase());\r
+        if (this.ffsAttribDataAlignment < 0 || this.ffsAttribDataAlignment > 7) {\r
+            throw new BuildException ("FFS_ATTRIB_DATA_ALIGMENT must be 0-7");\r
         } else {\r
-            attributes |= (((byte)this.ffsAlignment) << 3);\r
+            attributes |= (((byte)this.ffsAttribDataAlignment) << 3);\r
         }\r
     }\r
 \r
@@ -948,4 +948,36 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
     public void setModuleType(String moduleType) {\r
         this.moduleType = moduleType;\r
     }\r
+\r
+    /**\r
+     Convert a string to a integer.\r
+     \r
+     @param     intString   The string representing a integer\r
+     \r
+     @retval    int     The value of integer represented by the\r
+                        given string; -1 is returned if the format\r
+                        of the string is wrong.\r
+     **/\r
+    private int stringToInt(String intString) {\r
+        int value;\r
+        int hexPrefixPos = intString.indexOf("0x");\r
+        int radix = 10;\r
+        String intStringNoPrefix;\r
+\r
+        if (hexPrefixPos >= 0) {\r
+            radix = 16;\r
+            intStringNoPrefix = intString.substring(hexPrefixPos + 2, intString.length());\r
+        } else {\r
+            intStringNoPrefix = intString;\r
+        }\r
+\r
+        try {\r
+            value = Integer.parseInt(intStringNoPrefix, radix);\r
+        } catch (NumberFormatException e) {\r
+            log("Incorrect format of int (" + intString + "). -1 is assumed");\r
+            return -1;\r
+        }\r
+\r
+        return value;\r
+    }\r
 }\r