Skip to content

Commit

Permalink
Revert "Migrate python2 scripts to python3"
Browse files Browse the repository at this point in the history
This reverts commit ead4c1f.

Reverting this patch since boot issue is seen on MBL Fab-B board.

Tracked-On: OAM-122801
Signed-off-by: Salini Venate <salini.venate@intel.com>
  • Loading branch information
SaliniVenate committed Jul 29, 2024
1 parent ead4c1f commit c2da550
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 74 deletions.
8 changes: 4 additions & 4 deletions bootloader_from_zip
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def main(argv):
sys.exit(1)

if not OPTIONS.zipfile:
print ("--zipfile is required")
print "--zipfile is required"
common.Usage(__doc__)
sys.exit(1)

tf = tempfile.NamedTemporaryFile()
tf.write(b"foo")
tf.write("foo")
tf.flush()

extra_files = OPTIONS.bootimage
Expand All @@ -106,9 +106,9 @@ if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except (common.ExternalError,e):
except common.ExternalError, e:
print
print (" ERROR: %s" % (e,))
print " ERROR: %s" % (e,)
print
sys.exit(1)

37 changes: 18 additions & 19 deletions create_gpt_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Script to create a GPT/UEFI image or to show information it contains.
"""

from sys import version_info, exit
from sys import version_info

if version_info < (2, 7, 3):
exit('Python version must be 2.7.3 or higher')
Expand All @@ -35,7 +35,7 @@
if version_info < (3, 0, 1):
from ConfigParser import SafeConfigParser, ParsingError, NoOptionError, NoSectionError
else:
from configparser import ConfigParser, ParsingError, NoOptionError, NoSectionError
from configparser import SafeConfigParser, ParsingError, NoOptionError, NoSectionError
from math import floor, log


Expand Down Expand Up @@ -135,8 +135,8 @@ def write(self, img_file, offset=0):
Used to write MBR in an image file
"""
self.raw = pack(MBRInfos._FMT, self.boot, self.os_type,
self.lba_start, self.lba_size, b'',
MBRInfos._PART_ENTRY.encode('utf-8'), b'', self.sign.encode('utf-8'))
self.lba_start, self.lba_size, '',
MBRInfos._PART_ENTRY, '', self.sign)
img_file.seek(offset)
img_file.write(self.raw)

Expand Down Expand Up @@ -284,30 +284,30 @@ def write(self, img_file, offset, block_size):
"""
Used to write GPT header and backup in an image file
"""
self.raw = pack(GPTHeaderInfos._FMT, self.sign.encode('utf-8'), self.rev.encode('utf-8'),
self.size, 0, 1, int(self.lba_backup),
int(self.lba_first), int(self.lba_last), self.uuid,
self.raw = pack(GPTHeaderInfos._FMT, self.sign, self.rev,
self.size, 0, 1, self.lba_backup,
self.lba_first, self.lba_last, self.uuid,
2, self.table_length, self.entry_size, 0)

backup_raw = pack(GPTHeaderInfos._FMT, self.sign.encode('utf-8'), self.rev.encode('utf-8'),
self.size, 0, int(self.lba_backup), 1,
int(self.lba_first), int(self.lba_last), self.uuid,
int(self.lba_start), self.table_length,
backup_raw = pack(GPTHeaderInfos._FMT, self.sign, self.rev,
self.size, 0, self.lba_backup, 1,
self.lba_first, self.lba_last, self.uuid,
self.lba_start, self.table_length,
self.entry_size, 0)

# writes a new GPT header
img_file.seek(offset)
img_file.write(self.raw)

# writes zero on unused blocks of GPT header
raw_stuffing = b'\x00' * (block_size - len(self.raw))
raw_stuffing = '\x00' * (block_size - len(self.raw))
img_file.write(raw_stuffing)

# saves the end of the GPT header
gpt_header_end = img_file.tell()

# writes a new GPT backup
backup_position = int(self.lba_backup) * block_size
backup_position = self.lba_backup * block_size
img_file.seek(backup_position)
img_file.write(backup_raw)

Expand Down Expand Up @@ -357,7 +357,6 @@ def write(self, img_file, offset, entry_size, tlb_infos, last_usable):
"""
# erases the partition table entries
self = []
offset=int(offset)

# writes all new partition entries in GPT header
current_offset = offset
Expand All @@ -372,7 +371,7 @@ def write(self, img_file, offset, entry_size, tlb_infos, last_usable):
img_file.seek(offset)
raw_entries_size = current_offset - offset
raw_entries = img_file.read(raw_entries_size)
img_file.seek(int(last_usable) + 1)
img_file.seek(last_usable + 1)
img_file.write(raw_entries)

img_file.seek(current_offset)
Expand Down Expand Up @@ -739,7 +738,7 @@ def _read_ini(self, block_size):
Used to read a INI TLB partition file
"""
# sets a parser to read the INI TLB partition file
cfg = ConfigParser(strict=False)
cfg = SafeConfigParser()
try:
cfg.read(self.path)

Expand Down Expand Up @@ -966,7 +965,7 @@ def _write_crc(self, img_file):
img_file.seek(2 * self.block_size)
raw_table = img_file.read(self.gpt_header.table_length *
self.gpt_header.entry_size)
img_file.seek((int(self.gpt_header.lba_backup) - 32) * self.block_size)
img_file.seek((self.gpt_header.lba_backup - 32) * self.block_size)
raw_backup_table = img_file.read(self.gpt_header.table_length *
self.gpt_header.entry_size)

Expand Down Expand Up @@ -1036,7 +1035,7 @@ def _write_partitions(self, img_file, tlb_infos, binaries_path):
# no binary file used to build the partition or slot_b case
label = tlb_part.label[0:]
if bin_path == 'none' or label[len(label)-2:] == '_b':
line = b'\0'
line = '\0'
img_file.seek(offset)
img_file.write(line)
bin_size = 0
Expand Down Expand Up @@ -1082,7 +1081,7 @@ def write(self, tlb_infos, binaries_path):

# fill output image header with 0x00: MBR size + GPT header size +
# (partition table length * entry size)
zero = b'\x00' * (2 * self.block_size +
zero = '\x00' * (2 * self.block_size +
self.gpt_header.table_length *
self.gpt_header.entry_size)
img_file.seek(0)
Expand Down
34 changes: 17 additions & 17 deletions generate_factory_images
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import os

_FLASHALL_FILENAME = "flash-all.sh"
# chmod (octal) -rwxr-x--x
_PERMS = 0o751
_PERMS = 0751
_FLASH_HEADER = """#!/bin/bash
# Copyright 2012 The Android Open Source Project
Expand Down Expand Up @@ -103,23 +103,23 @@ def ConvertToDOSFormat(filename):


def AddFlashScript(filename, tar, commands, windows):
print ("Archiving", filename)
print "Archiving", filename
tf = tempfile.NamedTemporaryFile(delete=False)
if (windows):
tf.write(_WIN_FLASH_HEADER.encode('utf-8'))
tf.write(_WIN_FLASH_HEADER)
else:
tf.write(_FLASH_HEADER.encode('utf-8'))
tf.write(_FLASH_HEADER)

for c in commands:
if windows:
tf.write(c.get_windows_command().encode('utf-8'))
tf.write(c.get_windows_command())
else:
tf.write(c.get_linux_command().encode('utf-8'))
tf.write(c.get_linux_command())

if (windows):
tf.write(_WIN_FLASH_FOOTER.encode('utf-8'))
tf.write(_WIN_FLASH_FOOTER)
else:
tf.write(_FLASH_FOOTER.encode('utf-8'))
tf.write(_FLASH_FOOTER)

tf.close()
if (windows):
Expand All @@ -146,8 +146,8 @@ class CommandlineParser(ArgumentParser):
self.description = __doc__

def error(self, message):
print ("ERROR: {}".format(message), file=sys.stderr)
print ("\n------\n", file=sys.stderr)
print >>stderr, "ERROR: {}".format(message)
print >>stderr, "\n------\n"
self.print_help()
exit(2)

Expand Down Expand Up @@ -230,31 +230,31 @@ def main():
archive_name = args.output

# Create Archive
print ("Creating archive: " + archive_name)
print "Creating archive: " + archive_name
tar = TarOpen(archive_name, "w:gz")

for src_path, dst_path in files:
print ("Archiving " + src_path)
print "Archiving " + src_path
RequireFile(src_path)
tar.add(src_path, arcname=dst_path)

# 'fastboot update' covers the additional AOSP pieces, add this to the
# command list now
commands.append(UpdateCommand(update_fn, True))
print ("Archiving " + args.update_archive)
print "Archiving " + args.update_archive
RequireFile(args.update_archive)
tar.add(args.update_archive, update_fn)
AddFlashScript(_FLASHALL_FILENAME, tar, commands, windows=False)
AddFlashScript(_WIN_FLASHALL_FILENAME, tar, commands, windows=True)

tar.close()

print ("Done.")
print "Done."

if __name__ == "__main__":
try:
exit(main())
except Usage as err:
print ("ERROR: {}".format(err.msg), file=sys.stderr)
print (" for help use --help", file=sys.stderr)
except Usage, err:
print >>stderr, "ERROR: {}".format(err.msg)
print >>stderr, " for help use --help"
exit(2)
4 changes: 2 additions & 2 deletions releasetools/bootloader_from_target_files
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(argv):
common.Usage(__doc__)
sys.exit(1)

print ("unzipping target-files...")
print "unzipping target-files..."
#OPTIONS.input_tmp = common.UnzipTemp(args[0])
OPTIONS.input_tmp = args[0]
#input_zip = zipfile.ZipFile(args[0], "r")
Expand Down Expand Up @@ -91,7 +91,7 @@ if __name__ == '__main__':
main(sys.argv[1:])
except common.ExternalError, e:
print
print (" ERROR: %s" % (e,))
print " ERROR: %s" % (e,)
print
sys.exit(1)
finally:
Expand Down
8 changes: 1 addition & 7 deletions releasetools/flash_cmd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,7 @@ def parse_config(ips, variant, platform):
results_list = []
for k,v in results.items():
results_list.append((k,v))
unique_files = []
for file in files:
# If the number is not already in the unique_numbers list, add it
if file not in unique_files:
unique_files.append(file)

flist = [f.rsplit(':', 1) for f in unique_files]
flist = [f.rsplit(':', 1) for f in set(files)]
return results_list, flist


Expand Down
Loading

0 comments on commit c2da550

Please sign in to comment.