blob: 7e0254cc89847fd5085fe1d0460afa69863c2df4 [file] [log] [blame]
Rajesh Chennad7511d42012-01-17 23:06:361#!/usr/bin/python
2
Gilad Arnoldabb352e2012-09-23 08:24:273# Copyright (c) 2009-2012 The Chromium OS Authors. All rights reserved.
Rajesh Chennad7511d42012-01-17 23:06:364# Use of this source code is governed by a BSD-style license that can be
Gilad Arnoldabb352e2012-09-23 08:24:275# found in the LICENSE file.
Rajesh Chennad7511d42012-01-17 23:06:366
7"""This script updates given firmware in shellball and puts in an image.
8
9This scripts mounts given image and copies chromeos-firmwareupdate file. Then
10extracts chromeos-firmwareupdater and replaces given bios.bin in
11chromeos-firmwareupdater, re-packs the file and enables firmare update.
12At the end it unmounts the image.
13
14This is useful for test team to test new firmware/coreboot.
15
16Syntax:
17 update_firmware_image.py --imagedir <path to image> --image <image name>
18 --bios <path to bios>
19 e.g. update_firmware_image.py --imagedir /home/$USER/src/images/
20 --image chromiumos_test_image.bin
21 --bios /home/$USER/src/bios/bios.bin
22"""
23
24#__author__ = '[email protected] (Rajesh Chenna)'
25
Gilad Arnoldabb352e2012-09-23 08:24:2726# TODO(garnold) deprecated module, switch to using subprocess.
Rajesh Chennad7511d42012-01-17 23:06:3627import commands
28import logging
29import optparse
30import os
31import re
32import sys
33
Gilad Arnoldabb352e2012-09-23 08:24:2734
Rajesh Chennad7511d42012-01-17 23:06:3635# Constants
36dev_keys = '$HOME/trunk/src/platform/vboot_reference/tests/devkeys'
37mount_gpt_image = '$HOME/trunk/src/scripts/mount_gpt_image.sh'
38image_signing_dir = ('$HOME/trunk/src/platform/vboot_reference/scripts/'
39 'image_signing')
40
41def main():
42
43 parser = optparse.OptionParser()
44 parser.add_option('-b', '--bios', help='bios name including path')
45 parser.add_option('-d', '--imagedir', help='image directory')
46 parser.add_option('-i', '--image', help='image name')
47
48 (options, args) = parser.parse_args()
49 # Checking whether running inside chroot or not.
50 if not os.path.exists('/etc/debian_chroot'):
51 logging.fatal("Make sure you are inside chroot")
52 sys.exit(0)
53 # Conditions to check all arguments.
54 if not all([options.bios,
55 options.imagedir,
56 options.image]):
57 logging.fatal('Missing arguments.')
58 logging.fatal('Please provide bios, imagedir and image')
59 sys.exit(0)
60
61 # Verify bios.bin is passing.
62 #If not, copy the supplied bios to bios.bin.
63 if 'bios.bin' not in options.bios:
64 os.system('cp %s %s/bios.bin' %(options.bios,
65 options.bios[:options.bios.rfind('/')]))
66 # Step1: Mount the image.
67 os.system('sudo %s --from %s --image %s'
68 % (mount_gpt_image, options.imagedir,
69 options.image))
70
71 # Step2: copy shellball.
72 os.system('sudo cp /tmp/m/usr/sbin/chromeos-firmwareupdate /tmp/')
73 # Step3: Extract shellball.
74 extract = commands.getoutput('sudo /tmp/chromeos-firmwareupdate '
75 '--sb_extract')
76 extract_dir = re.match('Extracting to: (.+)', extract)
77 # Step4: copy bios.bin to extracted directory.
78 os.system('sudo cp %s/bios.bin %s/'
79 %(options.bios[:options.bios.rfind('/')], extract_dir.group(1)))
80 # Step5: repack shellball.
81 os.system('sudo /tmp/chromeos-firmwareupdate --sb_repack %s'
82 %(extract_dir.group(1)))
83 # Step6: copy shellball back to /tmp/m location.
84 os.system('sudo mv /tmp/chromeos-firmwareupdate /tmp/m/usr/sbin/')
85 # Step7: Unmount the image.
86 os.system('%s -u' %mount_gpt_image)
87 # Step 8: enable firmware update.
88 os.system('sudo %s/tag_image.sh --from=%s/%s --update_firmware=1'
89 %(image_signing_dir,
90 options.imagedir,
91 options.image))
92 # Step 9: Re-sign the image.
93 os.system('sudo %s/sign_official_build.sh usb %s/%s %s %s/resigned_%s'
94 %(image_signing_dir,
95 options.imagedir,
96 options.image,
97 dev_keys,
98 options.imagedir,
99 options.image))
100
101if __name__ == '__main__':
102 main()