@@ -145,7 +145,7 @@ def PrintBigError(sz):
145145 device_log (sz )
146146 device_log ("\n msp.py failed - Log is log_msp.txt\n \n " )
147147 sys .exit (1 )
148-
148+
149149def PrettyPrintArray (bytes_read ):
150150 Bytes = struct .unpack ("%dB" % len (bytes_read ),bytes_read )
151151
@@ -154,9 +154,9 @@ def PrettyPrintArray(bytes_read):
154154 for j in range (32 ):
155155 for i in range (16 ):
156156 sys .stdout .write ("%.2X " % Bytes [i + j * 16 ])
157-
157+
158158 sys .stdout .write ("\t " )
159-
159+
160160 for i in range (16 ):
161161 sys .stdout .write ("%c" % Bytes [i + j * 16 ])
162162 print (" " )
@@ -187,22 +187,21 @@ def external_call(command, capture_output=True):
187187 device_log ("Process stderr: %s" % errors )
188188 return output
189189
190-
191190def HandleNUM_DISK_SECTORS (field ):
192191 if type (field ) is not str :
193192 #print "returning since this is not a string"
194193 return field
195-
194+
196195 m = re .search (r'NUM_DISK_SECTORS-(\d+)' , field )
197196 if type (m ) is not NoneType :
198197 if DiskSizeInBytes > 0 :
199198 field = int ((DiskSizeInBytes / SECTOR_SIZE )- int (m .group (1 ))) # here I know DiskSizeInBytes
200199 else :
201200 field = int ((EMMCBLD_MAX_DISK_SIZE_IN_BYTES / SECTOR_SIZE )+ int (m .group (1 ))) # I make this a gigantic number for sorting (PLUS not MINUS here)
202-
201+
203202 if type (field ) is not str :
204203 return field
205-
204+
206205 m = re .search ("NUM_DISK_SECTORS" , field )
207206 if type (m ) is not NoneType :
208207 if DiskSizeInBytes > 0 :
@@ -214,10 +213,9 @@ def HandleNUM_DISK_SECTORS(field):
214213 return field
215214
216215 field = int (field )
217-
216+
218217 return field
219-
220-
218+
221219def ReturnParsedValues (element ):
222220 global SECTOR_SIZE
223221 MyDict = { 'filename' :'' ,'file_sector_offset' :'0' ,'label' :'' ,'num_partition_sectors' :'0' ,
@@ -230,12 +228,12 @@ def ReturnParsedValues(element):
230228
231229 if 'SECTOR_SIZE_IN_BYTES' in MyDict :
232230 SECTOR_SIZE = int (MyDict ['SECTOR_SIZE_IN_BYTES' ])
233-
231+
234232 if 'num_sectors' in MyDict : ## Legacy name used in original partition.xml
235233 MyDict ['num_partition_sectors' ] = MyDict ['num_sectors' ]
236234 if 'offset' in MyDict : ## Legacy name used in original partition.xml
237235 MyDict ['file_sector_offset' ] = MyDict ['offset' ]
238-
236+
239237 MyDict ['num_partition_sectors' ] = HandleNUM_DISK_SECTORS (MyDict ['num_partition_sectors' ]) # Means field can have 'NUM_DISK_SECTORS-5.' type of contents
240238 MyDict ['start_sector' ] = HandleNUM_DISK_SECTORS (MyDict ['start_sector' ]) # Means field can have 'NUM_DISK_SECTORS-5.' type of contents
241239 MyDict ['file_sector_offset' ] = HandleNUM_DISK_SECTORS (MyDict ['file_sector_offset' ]) # Means field can have 'NUM_DISK_SECTORS-5.' type of contents
@@ -261,9 +259,9 @@ def ReturnParsedValues(element):
261259 MyDict ['arg1' ] = int (float (m .group (2 ))) # len_in_bytes
262260
263261 MyDict ['value' ] = HandleNUM_DISK_SECTORS (MyDict ['value' ]) # Means field can have 'NUM_DISK_SECTORS-5.' type of contents
264-
262+
265263 return MyDict
266-
264+
267265def ParseXML (xml_filename ): ## this function updates all the global arrays
268266 global WriteArray ,PatchArray ,ReadArray ,MinDiskSizeInSectors
269267
@@ -287,7 +285,7 @@ def ParseXML(xml_filename): ## this function updates all the global arrays
287285 else :
288286 print ("ERROR: Your <program> tag is not formed correctly\n " )
289287 sys .exit (1 )
290-
288+
291289 elif element .tag == "patch" :
292290 if list (element .keys ()):
293291 PatchArray .append ( ReturnParsedValues (element ) )
@@ -306,7 +304,7 @@ def ParseXML(xml_filename): ## this function updates all the global arrays
306304 #for Patch in PatchArray:
307305 # print Patch
308306 #print "------------------------------------------------\n\n\n"
309-
307+
310308
311309def ReturnArrayFromCommaSeparatedList (sz ):
312310 temp = re .sub (r'\s+|\n' ," " ,sz )
@@ -345,11 +343,11 @@ def DoubleCheckDiskSize():
345343
346344 if sys .platform .startswith ("win" ):
347345 device_log ("\n \n Testing of OS detected disk size correctly...\n " )
348-
346+
349347 Size = AvailablePartitions [Filename ]
350-
348+
351349 TrueSize = Size
352-
350+
353351 count = 0
354352 # Windows workaround to get the correct number of sectors
355353 fp = open (Filename , 'rb' )
@@ -366,7 +364,7 @@ def DoubleCheckDiskSize():
366364 except Exception as x :
367365 TrueSize = fp .tell ()
368366 fp .close ()
369-
367+
370368 if TrueSize != Size and Size <= (64 * 1024 * 1024 * 1024 ):
371369 PrintBigWarning (" " )
372370 device_log ("NOTE: This OS has *not* detected the correct size of the disk" )
@@ -376,7 +374,7 @@ def DoubleCheckDiskSize():
376374 device_log ("\n NOTE: This program *can't* write to the end of the disk, OS limitation" )
377375 else :
378376 device_log ("\n \n All is well\n " )
379-
377+
380378
381379
382380def PerformRead ():
@@ -514,14 +512,14 @@ def PerformRead():
514512
515513
516514 device_log ("\n Done Reading Files\n " )
517-
515+
518516
519517
520518def PerformWrite ():
521519 global WriteSorted , LoadSubsetOfFiles , search_paths , interactive , Filename
522520
523521 ThereWereWarnings = 0
524-
522+
525523 device_log ("\t _ " )
526524 device_log ("\t (_) " )
527525 device_log ("\t _ __ _ __ ___ __ _ _ __ __ _ _ __ ___ _ __ ___ _ _ __ __ _ " )
@@ -641,7 +639,7 @@ def PerformWrite():
641639 ##device_log("\tsize of \"%s\" is %i bytes" % (Write['filename'],size))
642640 ##device_log("\tsize of partition listed in in \"%s\" is %i bytes" % (rawprogram_filename,Write['num_partition_sectors']*SECTOR_SIZE))
643641
644- ## This below happens on files like partition0.bin, where they hold the entire partition table,
642+ ## This below happens on files like partition0.bin, where they hold the entire partition table,
645643 ## but, only MBR is meant to be written, thus partition0.bin is 9 sectors but MBR is only 1 sector
646644
647645 if size > (Write ['num_partition_sectors' ]* SECTOR_SIZE ):
@@ -716,7 +714,7 @@ def PerformWrite():
716714 device_log ("REASON: %s" % (x ))
717715
718716 if sys .platform .startswith ("linux" ):
719- print ("\t _ ___" )
717+ print ("\t _ ___" )
720718 print ("\t | | |__ \\ " )
721719 print ("\t ___ _ _ __| | ___ ) |" )
722720 print ("\t / __| | | |/ _` |/ _ \\ / /" )
@@ -771,7 +769,7 @@ def PerformWrite():
771769 ##device_log("MAX_FILE_SIZE_BEFORE_SPLIT=",MAX_FILE_SIZE_BEFORE_SPLIT)
772770
773771 CurrentSector += (size / SECTOR_SIZE )
774-
772+
775773 if size < MAX_FILE_SIZE_BEFORE_SPLIT :
776774 device_log ("\t File can be written completely." )
777775 device_log ("\t Calling opfile.write(bytes_read)" )
@@ -816,7 +814,7 @@ def PerformWrite():
816814
817815 TempSize += MAX_FILE_SIZE_BEFORE_SPLIT
818816 ##device_log("Out of loop")
819- a += 1
817+ a += 1
820818
821819 if Remainder == 1 :
822820 # Need to PAD the file to be a multiple of SECTOR_SIZE bytes too
@@ -859,7 +857,7 @@ def PerformWrite():
859857 device_log ("\t SingleImageSize %i bytes (%i sectors)" % (CurrentSector * SECTOR_SIZE ,CurrentSector ))
860858 device_log ("\t CurrentSector=%i" % CurrentSector )
861859 device_log ("\t DiskSize=%i sectors" % int (DiskSizeInBytes / SECTOR_SIZE ))
862-
860+
863861
864862 #device_log("\tWrote %d bytes at sector %d on %s" % (len(bytes_read),Write['start_sector'],Filename))
865863
@@ -894,7 +892,7 @@ def PerformWrite():
894892 device_log ("\n Done Writing Files\n " )
895893
896894 return ThereWereWarnings
897-
895+
898896def GetPartitions ():
899897 global Devices ,AvailablePartitions
900898 if sys .platform .startswith ("linux" ):
@@ -917,7 +915,7 @@ def GetPartitions():
917915 Size = int (m .group (1 ))
918916 Device = "/dev/" + m .group (2 )
919917 #device_log("%s\tSize=%d,%.1fMB (%.2fGB) (%iKB)" % (Device,Size,int(Size)/1024.0,int(Size)/(1024.0*1024.0),int(Size))
920- AvailablePartitions [Device ] = Size * 1024.0 # linux reports in terms of 1024,
918+ AvailablePartitions [Device ] = Size * 1024.0 # linux reports in terms of 1024,
921919
922920
923921 else :
@@ -976,7 +974,7 @@ def PerformPatching():
976974 device_log ("\t | .__/ \\ __,_|\\ __|\\ ___|_| |_|_|_| |_|\\ __, |" )
977975 device_log ("\t | | __/ |" )
978976 device_log ("\t |_| |___/ " )
979-
977+
980978 var = 'Y'
981979 if Patching == "DISK" :
982980 var = 'N' ## user must authorize this
@@ -1000,7 +998,7 @@ def PerformPatching():
1000998 continue ## want to patch FILES, but this was a DISK, so skip it
1001999 else :
10021000 pass ## this was filename, so let's patch it
1003-
1001+
10041002 device_log ("\n " + "-" * 78 )
10051003 device_log ("PATCH: (%s) %s" % (Patch ['filename' ],Patch ['what' ]))
10061004
@@ -1069,7 +1067,7 @@ def PerformPatching():
10691067 elif temp == 'Y' or temp == 'y' or temp == '' :
10701068 search_paths .append (temppath )
10711069 device_log ("\n " )
1072-
1070+
10731071 try :
10741072 opfile = open (FileWithPath , "r+b" )
10751073 device_log ("Opened %s, cwd=%s" % (FileWithPath ,os .getcwd () ))
@@ -1205,7 +1203,7 @@ def PerformPatching():
12051203 #import pdb; pdb.set_trace()
12061204 sys .stdout .write ("%.2X " % (int (Patch ['value' ]>> (j * 8 )) & 0xFF ))
12071205
1208-
1206+
12091207 #for b in ValueList:
12101208 # sys.stdout.write("%.2X "%b)
12111209
@@ -1243,7 +1241,7 @@ def PerformPatching():
12431241 except Exception as x :
12441242 device_log ("\t WARNING: Could not close %s" % FileWithPath )
12451243 device_log ("REASON: %s" % (x ))
1246-
1244+
12471245 device_log ("CLOSED '%s'" % FileWithPath )
12481246
12491247 if sys .platform .startswith ("linux" ):
@@ -1425,9 +1423,9 @@ def CalculateMinDiskSize():
14251423 if OldMinDiskSizeInSectors != MinDiskSizeInSectors :
14261424 device_log ("MinDiskSizeInSectors=%i sectors (%.2fMB)" % (MinDiskSizeInSectors ,MinDiskSizeInSectors * SECTOR_SIZE / (1024 * 1024.0 )))
14271425 OldMinDiskSizeInSectors = MinDiskSizeInSectors
1428-
1426+
14291427 return MinDiskSizeInSectors
1430-
1428+
14311429## ==============================================================================================
14321430## ==============================================================================================
14331431## ==============================================================================================
@@ -1500,7 +1498,7 @@ def CalculateMinDiskSize():
15001498 elif o in ("-p" , "--patch" ):
15011499 patch_filename = a
15021500 Operation |= OPERATION_PATCH
1503-
1501+
15041502 elif o in ("-d" , "--dest" ):
15051503 disk_name = a
15061504
@@ -1590,7 +1588,7 @@ def CalculateMinDiskSize():
15901588 device_log ("Don't foreget to specify your drive, EX '-d \\ .\PHYSICALDRIVE1' OR '-d 0' to create a singleimage" );
15911589
15921590 PrintBigError ("You must specify a DISK, option -d" )
1593-
1591+
15941592if (Operation & OPERATION_PROGRAM ) > 0 :
15951593 if rawprogram_filename is None :
15961594 PrintBigError ("You must specify an \" rawprogram\" XML file for option -r" )
@@ -1622,9 +1620,9 @@ def CalculateMinDiskSize():
16221620 Operation |= OPERATION_PROGRAM
16231621if len (ReadArray )> 0 :
16241622 Operation |= OPERATION_READ
1625-
1623+
16261624if DiskSizeInBytes > 0 :
1627- if DiskSizeInBytes < int (MinDiskSizeInSectors )* SECTOR_SIZE :
1625+ if DiskSizeInBytes < int (MinDiskSizeInSectors )* SECTOR_SIZE :
16281626 PrintBigError ("" )
16291627 device_log ("\n ERROR: Current eMMC/SD card is too small to program these partitions" )
16301628 device_log (" Need at least %s" % ReturnSizeString (int (MinDiskSizeInSectors )))
@@ -1673,7 +1671,7 @@ def CalculateMinDiskSize():
16731671 #device_log("---------------- with start_sector = %i and PartitionStartSector[%i]=%i" % (Write["start_sector"],Count,PartitionStartSector[Count]))
16741672 if Write ['filename' ]== "" :
16751673 continue
1676-
1674+
16771675 if Write ["start_sector" ] == PartitionStartSector [Count ]:
16781676 ##device_log("FOUND, len(PartitionStartSector)=%d and len(WriteSorted)=%d" % (len(PartitionStartSector),len(WriteSorted)))
16791677 # To be here means I found the *next* start_sector in order, i.e. 0,100,200 etc
@@ -1703,7 +1701,7 @@ def CalculateMinDiskSize():
17031701 sys .exit ()
17041702 device_log ("\n DiskSizeInBytes was set to 0, DiskSizeInBytes will be %s (%d sectors)" % (ReturnSizeString (DiskSizeInBytes ),int (DiskSizeInBytes / SECTOR_SIZE )))
17051703
1706-
1704+
17071705if patch_filename is not None :
17081706 Operation |= OPERATION_PATCH
17091707 ParseXML (patch_filename )
@@ -1756,22 +1754,22 @@ def CalculateMinDiskSize():
17561754
17571755
17581756ThereWereWarnings = 0
1759-
1757+
17601758if (Operation & OPERATION_PROGRAM ) > 0 and (Operation & OPERATION_PATCH ) > 0 :
17611759 ## Have info to do both write and patch
17621760
1763-
1761+
17641762 if Filename == "singleimage.bin" :
17651763 # it's a singleimage, so do patching first
17661764 PerformPatching ()
1767-
1765+
17681766 ThereWereWarnings = PerformWrite ()
1769-
1767+
17701768 if (Operation & OPERATION_READ ) > 0 :
17711769 PerformRead ()
17721770 if verbose is True :
17731771 DoubleCheckDiskSize ()
1774-
1772+
17751773 else :
17761774 ThereWereWarnings = PerformWrite ()
17771775 PerformPatching ()
@@ -1781,9 +1779,9 @@ def CalculateMinDiskSize():
17811779 DoubleCheckDiskSize ()
17821780
17831781elif (Operation & OPERATION_PROGRAM ) > 0 :
1784- ThereWereWarnings = PerformWrite ()
1782+ ThereWereWarnings = PerformWrite ()
17851783 if (Operation & OPERATION_READ ) > 0 :
1786- PerformRead ()
1784+ PerformRead ()
17871785 device_log ("\n " + "-" * 78 )
17881786 device_log ("If you wrote any partition table information (MBR0.bin, gpt_main0.bin, etc)" )
17891787 device_log (" " )
@@ -1818,27 +1816,25 @@ def CalculateMinDiskSize():
18181816 DoubleCheckDiskSize ()
18191817
18201818elif (Operation & OPERATION_PATCH ) > 0 :
1821- PerformPatching ()
1819+ PerformPatching ()
18221820 if verbose is True :
18231821 DoubleCheckDiskSize ()
1824-
1822+
18251823if (Operation & OPERATION_PROGRAM ) > 0 :
1826-
1827- if os .path .basename (Filename )== "singleimage.bin" :
1824+
1825+ if os .path .basename (Filename )== "singleimage.bin" :
18281826 device_log ("\n NOTE: This program does *not* pad the last partition, therefore" )
18291827 device_log (" singleimage.bin might be smaller than %d sectors (%.2f MB)" % (int (DiskSizeInBytes / SECTOR_SIZE ),DiskSizeInBytes / (1048576.0 )))
18301828
18311829 device_log ("\n \n SUCCESS - %s created" % Filename )
18321830 device_log ("SUCCESS - %s created" % Filename )
18331831 device_log ("SUCCESS - %s created\n " % Filename )
1834-
1832+
18351833 if FileNotFoundShowWarning == 1 :
18361834 device_log ("\n WARNING: 1 or more files were *not* found, your singleimage.bin is *NOT* complete" )
18371835 device_log ("\n WARNING: 1 or more files were *not* found, your singleimage.bin is *NOT* complete" )
18381836 device_log ("\n WARNING: 1 or more files were *not* found, your singleimage.bin is *NOT* complete\n \n " )
18391837
1840-
1841-
18421838device_log ("\n msp.py exiting SUCCESSFULLY- Log is log_msp.txt\n \n " )
18431839
18441840if ThereWereWarnings == 1 :
0 commit comments