OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Create and copy update image to target host. | 7 """Create and copy update image to target host. |
8 | 8 |
9 auto-update and devserver change out from beneath us often enough | 9 auto-update and devserver change out from beneath us often enough |
10 that despite having to duplicate a litte code, it seems that the | 10 that despite having to duplicate a litte code, it seems that the |
(...skipping 15 matching lines...) Expand all Loading... |
26 import traceback | 26 import traceback |
27 | 27 |
28 from xml.dom import minidom | 28 from xml.dom import minidom |
29 | 29 |
30 | 30 |
31 # This is the default filename within the image directory to load updates from | 31 # This is the default filename within the image directory to load updates from |
32 DEFAULT_IMAGE_NAME = 'chromiumos_image.bin' | 32 DEFAULT_IMAGE_NAME = 'chromiumos_image.bin' |
33 | 33 |
34 # The filenames we provide to clients to pull updates | 34 # The filenames we provide to clients to pull updates |
35 UPDATE_FILENAME = 'update.gz' | 35 UPDATE_FILENAME = 'update.gz' |
36 STATEFUL_FILENAME = 'stateful.image.gz' | 36 STATEFUL_FILENAME = 'stateful.tgz' |
37 | 37 |
38 # How long do we wait for the server to start before launching client | 38 # How long do we wait for the server to start before launching client |
39 SERVER_STARTUP_WAIT = 1 | 39 SERVER_STARTUP_WAIT = 1 |
40 | 40 |
41 | 41 |
42 class Command(object): | 42 class Command(object): |
43 """Shell command ease-ups for Python.""" | 43 """Shell command ease-ups for Python.""" |
44 | 44 |
45 def __init__(self, env): | 45 def __init__(self, env): |
46 self.env = env | 46 self.env = env |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return True | 185 return True |
186 | 186 |
187 if not self.cmd.Run(self.CrosUtilsPath('cros_generate_update_payload'), | 187 if not self.cmd.Run(self.CrosUtilsPath('cros_generate_update_payload'), |
188 '--image=%s' % src, '--output=%s' % dst, | 188 '--image=%s' % src, '--output=%s' % dst, |
189 '--patch_kernel'): | 189 '--patch_kernel'): |
190 self.Error('generate_payload failed') | 190 self.Error('generate_payload failed') |
191 return False | 191 return False |
192 | 192 |
193 return True | 193 return True |
194 | 194 |
195 def BuildStateful(self, src, dst): | 195 def BuildStateful(self, src, dst_dir, dst_file): |
196 """Create a stateful partition update image.""" | 196 """Create a stateful partition update image.""" |
197 | 197 |
198 if self.GetCached(src, dst): | 198 if self.GetCached(src, dst_file): |
199 self.Info('Using cached stateful %s' % dst) | 199 self.Info('Using cached stateful %s' % dst_file) |
200 return True | 200 return True |
201 | 201 |
202 cgpt = self.ChrootPath('/usr/bin/cgpt') | 202 return self.cmd.Run(self.CrosUtilsPath( |
203 offset = self.cmd.OutputOneLine(cgpt, 'show', '-b', '-i', '1', src) | 203 'cros_generate_stateful_update_payload'), |
204 size = self.cmd.OutputOneLine(cgpt, 'show', '-s', '-i', '1', src) | 204 '--image=%s' % src, '--output=%s' % dst_dir) |
205 if None in (size, offset): | |
206 self.Error('Unable to use cgpt to get image geometry') | |
207 return False | |
208 | |
209 return self.cmd.RunPipe([['dd', 'if=%s' % src, 'bs=512', | |
210 'skip=%s' % offset, 'count=%s' % size], | |
211 ['gzip', '-c']], outfile=dst) | |
212 | 205 |
213 def GetSize(self, filename): | 206 def GetSize(self, filename): |
214 return os.path.getsize(filename) | 207 return os.path.getsize(filename) |
215 | 208 |
216 def GetHash(self, filename): | 209 def GetHash(self, filename): |
217 return self.cmd.RunPipe([['openssl', 'sha1', '-binary'], | 210 return self.cmd.RunPipe([['openssl', 'sha1', '-binary'], |
218 ['openssl', 'base64']], | 211 ['openssl', 'base64']], |
219 infile=filename, | 212 infile=filename, |
220 capture=True, oneline=True) | 213 capture=True, oneline=True) |
221 | 214 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 cros_env.Fatal() | 600 cros_env.Fatal() |
608 | 601 |
609 elif not options.server_only: | 602 elif not options.server_only: |
610 parser.error('Either --server-only must be specified or ' | 603 parser.error('Either --server-only must be specified or ' |
611 '--remote=<client> needs to be given') | 604 '--remote=<client> needs to be given') |
612 | 605 |
613 update_file = os.path.join(image_directory, UPDATE_FILENAME) | 606 update_file = os.path.join(image_directory, UPDATE_FILENAME) |
614 stateful_file = os.path.join(image_directory, STATEFUL_FILENAME) | 607 stateful_file = os.path.join(image_directory, STATEFUL_FILENAME) |
615 | 608 |
616 if (not cros_env.GenerateUpdatePayload(image_file, update_file) or | 609 if (not cros_env.GenerateUpdatePayload(image_file, update_file) or |
617 not cros_env.BuildStateful(image_file, stateful_file)): | 610 not cros_env.BuildStateful(image_file, image_directory, stateful_file)): |
618 cros_env.Fatal() | 611 cros_env.Fatal() |
619 | 612 |
620 cros_env.CreateServer(options.port, update_file, stateful_file) | 613 cros_env.CreateServer(options.port, update_file, stateful_file) |
621 | 614 |
622 exit_status = 1 | 615 exit_status = 1 |
623 if options.server_only: | 616 if options.server_only: |
624 child = None | 617 child = None |
625 else: | 618 else: |
626 # Start an "image-to-live" instance that will pull bits from the server | 619 # Start an "image-to-live" instance that will pull bits from the server |
627 child = os.fork() | 620 child = os.fork() |
(...skipping 29 matching lines...) Expand all Loading... |
657 | 650 |
658 if child: | 651 if child: |
659 os.kill(child, 15) | 652 os.kill(child, 15) |
660 | 653 |
661 cros_env.Info('Server exiting with status %d' % exit_status) | 654 cros_env.Info('Server exiting with status %d' % exit_status) |
662 sys.exit(exit_status) | 655 sys.exit(exit_status) |
663 | 656 |
664 | 657 |
665 if __name__ == '__main__': | 658 if __name__ == '__main__': |
666 main(sys.argv) | 659 main(sys.argv) |
OLD | NEW |