Ejemplo n.º 1
0
 def testSimple(self):
     """Test that USB case works, and strips boot."""
     imagefile.SignImage('USB', 'infile', 'outfile', 2, '/keydir')
     self.android_mock.assert_called_once()
     rootfs_dir, keyset = self.android_mock.call_args[0]
     self.fw_mock.assert_called_once_with('outfile', keyset)
     expected_rc = [
         mock.call(['cp', '--sparse=always', 'infile', 'outfile'], ),
         mock.call(['sudo', '--', 'dump_kernel_config', '/dev/loop9999p2'],
                   capture_output=True,
                   print_cmd=False,
                   check=True,
                   encoding='utf-8'),
         mock.call(
             ['strip_boot_from_image.sh', '--image', '/dev/loop9999p3'],
             extra_env={'PATH': 'path'}),
     ]
     self.assertEqual(expected_rc, self.rc.call_args_list)
     self.assertTrue(rootfs_dir.startswith(self.tempdir + '/'))
     self.assertTrue(rootfs_dir.endswith('/dir-3'))
     self.assertEqual('/keydir', keyset.key_dir)
     self.uefi_mock.assert_called_once_with(self.image,
                                            rootfs_dir,
                                            keyset,
                                            vboot_path=None)
Ejemplo n.º 2
0
def main(argv):
  parser = commandline.ArgumentParser(description=__doc__)
  parser.add_argument('-t', '--type', required=True, dest='image_type',
                      choices=list(ValidImageTypes), help='Type of image')
  parser.add_argument('-i', '--input', required=True, dest='input_image',
                      type='path', help='Path to input image file')
  parser.add_argument('-k', '--keyset-dir', required=True, dest='key_dir',
                      help='Path to keyset directory')
  parser.add_argument('-o', '--output', required=True, dest='output_image',
                      help='Path to output image file')

  options = parser.parse_args(argv)
  options.Freeze()

  # See what kind of image this is.
  call_args = SignImageArgs.get(options.image_type, None)
  if call_args:
    imagefile.SignImage(
        call_args.image_type, options.input_image, options.output_image,
        call_args.kernel_id, options.key_dir, call_args.keyA_prefix)
    return 0

  # TODO(lamontjones): implement signing for the other supported image types:
  # firmware, kernel, recovery_kernel, update_payload,
  # accessory_usbpd, accessory_rwsig.
  logging.error('Unimplemented --type %s', options.image_type)
  return 2
Ejemplo n.º 3
0
 def testNoStripOnNonFactrory(self):
     """Verify that strip is not called on factory installs."""
     imagefile.SignImage('factory_install', 'infile', 'outfile', 2,
                         '/keydir')
     self.assertNotIn(
         mock.call(
             ['strip_boot_from_image.sh', '--image', '/dev/loop9999p3'],
             extra_env={'PATH': 'path'}), self.rc.call_args_list)
Ejemplo n.º 4
0
 def testNoStripOnEFI(self):
     """Verify that strip is not called for EFI."""
     self.rc.AddCmdResult(
         ['sudo', '--', 'dump_kernel_config', '/dev/loop9999p2'],
         output=' cros_efi ')
     imagefile.SignImage('USB', 'infile', 'outfile', 2, '/keydir')
     self.assertNotIn(
         mock.call(
             ['strip_boot_from_image.sh', '--image', '/dev/loop9999p3'],
             extra_env={'PATH': 'path'}), self.rc.call_args_list)