diff options
-rwxr-xr-x | chromiumos_image_diff.py | 38 | ||||
-rwxr-xr-x | image_chromeos.py | 36 |
2 files changed, 41 insertions, 33 deletions
diff --git a/chromiumos_image_diff.py b/chromiumos_image_diff.py index 82e4e17d..74906d32 100755 --- a/chromiumos_image_diff.py +++ b/chromiumos_image_diff.py @@ -1,4 +1,10 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Diff 2 chromiumos images by comparing each elf file. The script diffs every *ELF* files by dissembling every *executable* @@ -66,8 +72,8 @@ class CrosImage(object): self.image, self.rootfs, self.stateful)) ## First of all creating an unmount image self.CreateUnmountScript() - command = image_chromeos.GetImageMountCommand( - self.chromeos_root, self.image, self.rootfs, self.stateful) + command = image_chromeos.GetImageMountCommand(self.image, self.rootfs, + self.stateful) rv = self._ce.RunCommand(command, print_to_console=True) self.mounted = (rv == 0) if not self.mounted: @@ -85,8 +91,8 @@ class CrosImage(object): f.close() self._ce.RunCommand( 'chmod +x {}'.format(self.unmount_script), print_to_console=False) - self.logger.LogOutput( - 'Created an unmount script - "{0}"'.format(self.unmount_script)) + self.logger.LogOutput('Created an unmount script - "{0}"'.format( + self.unmount_script)) def UnmountImage(self): """Unmount the image and delete mount point.""" @@ -115,8 +121,8 @@ class CrosImage(object): Always true """ - self.logger.LogOutput( - 'Finding all elf files in "{0}" ...'.format(self.rootfs)) + self.logger.LogOutput('Finding all elf files in "{0}" ...'.format( + self.rootfs)) # Note '\;' must be prefixed by 'r'. command = ('find "{0}" -type f -exec ' 'bash -c \'file -b "{{}}" | grep -q "ELF"\'' @@ -125,8 +131,8 @@ class CrosImage(object): self.logger.LogCmd(command) _, out, _ = self._ce.RunCommandWOutput(command, print_to_console=False) self.elf_files = out.splitlines() - self.logger.LogOutput( - 'Total {0} elf files found.'.format(len(self.elf_files))) + self.logger.LogOutput('Total {0} elf files found.'.format( + len(self.elf_files))) return True @@ -142,10 +148,10 @@ class ImageComparator(object): def Cleanup(self): if self.tempf1 and self.tempf2: - command_executer.GetCommandExecuter().RunCommand( - 'rm {0} {1}'.format(self.tempf1, self.tempf2)) - logger.GetLogger( - 'Removed "{0}" and "{1}".'.format(self.tempf1, self.tempf2)) + command_executer.GetCommandExecuter().RunCommand('rm {0} {1}'.format( + self.tempf1, self.tempf2)) + logger.GetLogger('Removed "{0}" and "{1}".'.format( + self.tempf1, self.tempf2)) def CheckElfFileSetEquality(self): """Checking whether images have exactly number of elf files.""" @@ -185,8 +191,8 @@ class ImageComparator(object): match_count = 0 i1 = self.images[0] i2 = self.images[1] - self.logger.LogOutput( - 'Start comparing {0} elf file by file ...'.format(len(i1.elf_files))) + self.logger.LogOutput('Start comparing {0} elf file by file ...'.format( + len(i1.elf_files))) ## Note - i1.elf_files and i2.elf_files have exactly the same entries here. ## Create 2 temp files to be used for all disassembed files. @@ -222,8 +228,8 @@ class ImageComparator(object): tempf2=self.tempf2) ret = cmde.RunCommand(command, print_to_console=False) if ret != 0: - self.logger.LogOutput( - '*** Not match - "{0}" "{1}"'.format(full_path1, full_path2)) + self.logger.LogOutput('*** Not match - "{0}" "{1}"'.format( + full_path1, full_path2)) mismatch_list.append(f1) if self.diff_file: command = ('echo "Diffs of disassemble of \"{f1}\" and \"{f2}\"" ' diff --git a/image_chromeos.py b/image_chromeos.py index aa8824b6..bea6fe57 100755 --- a/image_chromeos.py +++ b/image_chromeos.py @@ -1,6 +1,10 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- # -# Copyright 2011 Google Inc. All Rights Reserved. +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Script to image a ChromeOS device. This script images a remote ChromeOS device with a specific image." @@ -238,11 +242,6 @@ def DoImage(argv): cmd_executer.CrosRunCommand( command, chromeos_root=options.chromeos_root, machine=options.remote) - real_src_dir = os.path.join( - os.path.realpath(options.chromeos_root), 'src') - real_chroot_dir = os.path.join( - os.path.realpath(options.chromeos_root), 'chroot') - # Check to see if cros flash will work for the remote machine. CheckForCrosFlash(options.chromeos_root, options.remote, log_level) @@ -289,7 +288,7 @@ def DoImage(argv): # If this is a non-local image, then the ret returned from # EnsureMachineUp is the one that will be returned by this function; # in that case, make sure the value in 'ret' is appropriate. - if not local_image and ret == True: + if not local_image and ret is True: ret = 0 else: ret = 1 @@ -312,12 +311,18 @@ def DoImage(argv): TryRemountPartitionAsRW(options.chromeos_root, options.remote, log_level) - if found == False: + if found is False: temp_dir = os.path.dirname(located_image) l.LogOutput('Deleting temp image dir: %s' % temp_dir) shutil.rmtree(temp_dir) else: - l.LogOutput('Checksums match. Skipping reimage') + l.LogOutput('Checksums match. Skipping reimage, doing a reboot.') + command = 'reboot && exit' + _ = cmd_executer.CrosRunCommand( + command, chromeos_root=options.chromeos_root, machine=options.remote) + # Wait 30s after reboot. + time.sleep(30) + return ret finally: if should_unlock: @@ -338,8 +343,8 @@ def LocateOrCopyImage(chromeos_root, image, board=None): return [True, image] # First search within the existing build dirs for any matching files. - images_glob = ('%s/src/build/images/%s/*/*.bin' % (chromeos_root_realpath, - board_glob)) + images_glob = ( + '%s/src/build/images/%s/*/*.bin' % (chromeos_root_realpath, board_glob)) images_list = glob.glob(images_glob) for potential_image in images_list: if filecmp.cmp(potential_image, image): @@ -359,7 +364,7 @@ def LocateOrCopyImage(chromeos_root, image, board=None): return [False, new_image] -def GetImageMountCommand(chromeos_root, image, rootfs_mp, stateful_mp): +def GetImageMountCommand(image, rootfs_mp, stateful_mp): image_dir = os.path.dirname(image) image_file = os.path.basename(image) mount_command = ('cd ~/trunk/src/scripts &&' @@ -379,7 +384,7 @@ def MountImage(chromeos_root, unmount=False, extra_commands=''): cmd_executer = command_executer.GetCommandExecuter(log_level=log_level) - command = GetImageMountCommand(chromeos_root, image, rootfs_mp, stateful_mp) + command = GetImageMountCommand(image, rootfs_mp, stateful_mp) if unmount: command = '%s --unmount' % command if extra_commands: @@ -440,10 +445,7 @@ def VerifyChromeChecksum(chromeos_root, image, remote, log_level): [_, o, _] = cmd_executer.CrosRunCommandWOutput( command, chromeos_root=chromeos_root, machine=remote) device_chrome_checksum = o.split()[0] - if image_chrome_checksum.strip() == device_chrome_checksum.strip(): - return True - else: - return False + return image_chrome_checksum.strip() == device_chrome_checksum.strip() # Remount partition as writable. |