Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(884)

Side by Side Diff: fixup_image_for_qemu.py

Issue 3027012: Changes to use the postinst --esp-part-file flag; postinst fixups removed (Closed) Base URL: ssh://gitrw.chromium.org/crosutils.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | image_to_vm.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env 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 """Makes changes to mounted Chromium OS image to allow it to run with VMs 7 """Makes changes to mounted Chromium OS image to allow it to run with VMs
8 8
9 This script changes two files within the Chromium OS image to let the image 9 This script changes two files within the Chromium OS image to let the image
10 work with VMs, particularly QEMU 10 work with VMs, particularly QEMU
11 11
12 Currently this script does the following, 12 Currently this script does the following,
13 1.) Modify the post install script to remove EFI fixup section; the VM's we 13 1.) Modify the post install script to remove EFI fixup section; the VM's we
14 support don't have EFI support anyway and this section of the script needs 14 support don't have EFI support anyway and this section of the script needs
15 access to the actual device drives 15 access to the actual device drives
16 16
17 2.) For QEMU/KVM, we change the xorg.conf to remove mouse support and instead 17 2.) For QEMU/KVM, we change the xorg.conf to remove mouse support and instead
18 change it to complete tablet support. This is done to provide better mouse 18 change it to complete tablet support. This is done to provide better mouse
19 response in the VM since tablets work of absolute coordinates while the mouse 19 response in the VM since tablets work of absolute coordinates while the mouse
20 works of relative. In a screen that doesn't support a mouse grab (e.g., VNC), 20 works of relative. In a screen that doesn't support a mouse grab (e.g., VNC),
21 relative coordinates can cause the mouse to be flaky 21 relative coordinates can cause the mouse to be flaky
22 22
23 """ 23 """
24 24
25 from optparse import OptionParser 25 from optparse import OptionParser
26 import os 26 import os
27 import stat 27 import stat
28 import sys 28 import sys
29 29
30 USAGE = "usage: %prog --mounted_dir=directory --for_qemu=[true]" 30 USAGE = "usage: %prog --mounted_dir=directory --enable_tablet=[true]"
31
32 POST_INST_IN_FILENAME = 'usr/sbin/chromeos-postinst'
33 POST_INST_OUT_FILENAME = 'postinst_vm'
34 XORG_CONF_FILENAME = os.path.join('etc', 'X11', 'xorg.conf')
35
36 EFI_CODE_MARKER_START = r'echo "Updating grub target for EFI BIOS"'
37 EFI_CODE_MARKER_END = \
38 r"""sh "${INSTALL_ROOT}"/usr/sbin/chromeos-firmwareupdate
39 fi
40 else"""
41 31
42 INPUT_SECTION_MARKER = r'Section "InputDevice"' 32 INPUT_SECTION_MARKER = r'Section "InputDevice"'
43 SECTION_END_MARKER = r'EndSection' 33 SECTION_END_MARKER = r'EndSection'
44 34
45 MOUSE_SECTION_IDENTIFIERS = [] 35 MOUSE_SECTION_IDENTIFIERS = []
46 MOUSE_SECTION_IDENTIFIERS += ['Identifier "Mouse'] 36 MOUSE_SECTION_IDENTIFIERS += ['Identifier "Mouse']
47 MOUSE_SECTION_IDENTIFIERS += ['Identifier "USBMouse'] 37 MOUSE_SECTION_IDENTIFIERS += ['Identifier "USBMouse']
48 38
49 REPLACE_USB_MOUSE_PAIR = ('InputDevice "USBMouse" "AlwaysCore"', 39 REPLACE_USB_MOUSE_PAIR = ('InputDevice "USBMouse" "AlwaysCore"', '')
50 '') 40 XORG_CONF_FILENAME = os.path.join('etc', 'X11', 'xorg.conf')
51 41
52 42
53 TABLET_DEVICE_CONFIG = """ 43 TABLET_DEVICE_CONFIG = """
54 Section "InputDevice" 44 Section "InputDevice"
55 Identifier "Mouse1" 45 Identifier "Mouse1"
56 Driver "evdev" 46 Driver "evdev"
57 Option "Device" "/dev/input/event2" 47 Option "Device" "/dev/input/event2"
58 Option "CorePointer" "true" 48 Option "CorePointer" "true"
59 EndSection 49 EndSection
60 """ 50 """
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 83
94 # Replace UsbMouse with Tablet. 84 # Replace UsbMouse with Tablet.
95 xorg_conf = xorg_conf.replace(REPLACE_USB_MOUSE_PAIR[0], 85 xorg_conf = xorg_conf.replace(REPLACE_USB_MOUSE_PAIR[0],
96 REPLACE_USB_MOUSE_PAIR[1]) 86 REPLACE_USB_MOUSE_PAIR[1])
97 87
98 # Write the file back out. 88 # Write the file back out.
99 f = open(xorg_conf_filename, 'w') 89 f = open(xorg_conf_filename, 'w')
100 f.write(xorg_conf) 90 f.write(xorg_conf)
101 f.close() 91 f.close()
102 92
103
104 # Remove the code that does EFI processing from the postinst script
105 def FixPostInst(mount_point):
106 postinst_in = os.path.join(mount_point, POST_INST_IN_FILENAME)
107 f = open(postinst_in, 'r')
108 postinst = f.read()
109 f.close()
110 m1 = postinst.find(EFI_CODE_MARKER_START)
111 m2 = postinst.find(EFI_CODE_MARKER_END)
112 if (m1 == -1) or (m2 == -1) or (m1 > m2):
113 # basic sanity check
114 return
115 m2 += len(EFI_CODE_MARKER_END)
116 postinst = postinst[0:m1] + postinst[m2:]
117
118 # Write the file back out.
119 postinst_out = os.path.join(mount_point, POST_INST_OUT_FILENAME)
120 f = open(postinst_out, 'w')
121 f.write(postinst)
122 f.close()
123
124 # Mark the file read/execute.
125 os.chmod(postinst_out, stat.S_IEXEC | stat.S_IREAD)
126
127
128 def main(): 93 def main():
129 parser = OptionParser(USAGE) 94 parser = OptionParser(USAGE)
130 parser.add_option('--mounted_dir', dest='mounted_dir', 95 parser.add_option('--mounted_dir', dest='mounted_dir',
131 help='directory where the Chromium OS image is mounted') 96 help='directory where the Chromium OS image is mounted')
132 parser.add_option('--for_qemu', dest='for_qemu', 97 parser.add_option('--enable_tablet', dest='enable_tablet',
133 default="true", 98 default="true",
134 help='fixup image for qemu') 99 help='fixup image for qemu')
135 (options, args) = parser.parse_args() 100 (options, args) = parser.parse_args()
136 101
137 if not options.mounted_dir: 102 if not options.mounted_dir:
138 parser.error("Please specify the mount point for the Chromium OS image"); 103 parser.error("Please specify the mount point for the Chromium OS image");
139 if options.for_qemu not in ('true', 'false'): 104 if options.enable_tablet not in ('true', 'false'):
140 parser.error("Please specify either true or false for --for_qemu") 105 parser.error("Please specify either true or false for --enable_tablet")
141 106
142 FixPostInst(options.mounted_dir) 107 if (options.enable_tablet == 'true'):
143 if (options.for_qemu == 'true'):
144 FixXorgConf(options.mounted_dir) 108 FixXorgConf(options.mounted_dir)
145 109
146 110
147 if __name__ == '__main__': 111 if __name__ == '__main__':
148 main() 112 main()
OLDNEW
« no previous file with comments | « no previous file | image_to_vm.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698