change the 'r+b' to 'rb' for some file's open, since these files we only
read it and no need to write. It can fix the bug that the file's attribute
had been set to read-only.

Cc: Liming Gao <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <[email protected]>
---
 BaseTools/Source/Python/GenFds/FfsFileStatement.py | 2 +-
 BaseTools/Source/Python/GenFds/Fv.py               | 2 +-
 BaseTools/Source/Python/GenFds/FvImageSection.py   | 4 ++--
 BaseTools/Source/Python/GenFds/Region.py           | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py 
b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index 690826b..f76ddf4 100644
--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
@@ -99,11 +99,11 @@ class FileStatement (FileStatementClassObject) :
                     FileContent = ''
                     MaxAlignIndex = 0
                     MaxAlignValue = 1
                     for Index, File in enumerate(self.FileName):
                         try:
-                            f = open(File, 'r+b')
+                            f = open(File, 'rb')
                         except:
                             GenFdsGlobalVariable.ErrorLogger("Error opening 
RAW file %s." % (File))
                         Content = f.read()
                         f.close()
                         AlignValue = 1
diff --git a/BaseTools/Source/Python/GenFds/Fv.py 
b/BaseTools/Source/Python/GenFds/Fv.py
index 64d1709..ab3f8b2 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -180,11 +180,11 @@ class FV (FvClassObject):
 
         #
         # Write the Fv contents to Buffer
         #
         if os.path.isfile(FvOutputFile):
-            FvFileObj = open ( FvOutputFile,'r+b')
+            FvFileObj = open ( FvOutputFile,'rb')
 
             GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV 
Successfully" %self.UiFvName)
             GenFdsGlobalVariable.SharpCounter = 0
 
             Buffer.write(FvFileObj.read())
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py 
b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 748d02f..5989978 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -62,11 +62,11 @@ class FvImageSection(FvImageSectionClassObject):
 
             MaxFvAlignment = 0
             for FvFileName in FileList:
                 FvAlignmentValue = 0
                 if os.path.isfile(FvFileName):
-                    FvFileObj = open (FvFileName,'r+b')
+                    FvFileObj = open (FvFileName,'rb')
                     FvFileObj.seek(0)
                     # PI FvHeader is 0x48 byte
                     FvHeaderBuffer = FvFileObj.read(0x48)
                     # FV alignment position.
                     FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
@@ -107,11 +107,11 @@ class FvImageSection(FvImageSectionClassObject):
                             self.Alignment = Fv.FvAlignment
             else:
                 if self.FvFileName != None:
                     FvFileName = 
GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
                     if os.path.isfile(FvFileName):
-                        FvFileObj = open (FvFileName,'r+b')
+                        FvFileObj = open (FvFileName,'rb')
                         FvFileObj.seek(0)
                         # PI FvHeader is 0x48 byte
                         FvHeaderBuffer = FvFileObj.read(0x48)
                         # FV alignment position.
                         FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 
0x1F)
diff --git a/BaseTools/Source/Python/GenFds/Region.py 
b/BaseTools/Source/Python/GenFds/Region.py
index e393286..945c548 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -146,11 +146,11 @@ class Region(RegionClassObject):
                     FileLength = os.stat(FileName)[ST_SIZE]
                     if FileLength > Size:
                         EdkLogger.error("GenFds", GENFDS_ERROR,
                                         "Size of FV File (%s) is larger than 
Region Size 0x%X specified." \
                                         % (RegionData, Size))
-                    BinFile = open(FileName, 'r+b')
+                    BinFile = open(FileName, 'rb')
                     Buffer.write(BinFile.read())
                     BinFile.close()
                     Size = Size - FileLength
             #
             # Pad the left buffer
@@ -199,11 +199,11 @@ class Region(RegionClassObject):
                 FileLength = os.stat(FileName)[ST_SIZE]
                 if FileLength > Size:
                     EdkLogger.error("GenFds", GENFDS_ERROR,
                                     "Size 0x%X of Capsule File (%s) is larger 
than Region Size 0x%X specified." \
                                     % (FileLength, RegionData, Size))
-                BinFile = open(FileName, 'r+b')
+                BinFile = open(FileName, 'rb')
                 Buffer.write(BinFile.read())
                 BinFile.close()
                 Size = Size - FileLength
             #
             # Pad the left buffer
-- 
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to