OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Wrapper script for launching application within the sel_ldr. | 6 """Wrapper script for launching application within the sel_ldr. |
7 """ | 7 """ |
8 | 8 |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 | 13 |
14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
15 sys.path.append(SCRIPT_DIR) | |
Sam Clegg
2014/05/01 19:19:10
This is the default for python normally.
I think
cdonner
2014/05/02 17:58:06
Reverted.
| |
16 | |
14 import create_nmf | 17 import create_nmf |
15 import getos | 18 import getos |
16 | 19 |
17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
18 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) | 20 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) |
19 | 21 |
20 if sys.version_info < (2, 6, 0): | 22 if sys.version_info < (2, 6, 0): |
21 sys.stderr.write("python 2.6 or later is required run this script\n") | 23 sys.stderr.write("python 2.6 or later is required run this script\n") |
22 sys.exit(1) | 24 sys.exit(1) |
23 | 25 |
24 | 26 |
25 class Error(Exception): | 27 class Error(Exception): |
26 pass | 28 pass |
27 | 29 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 Log.verbose = True | 64 Log.verbose = True |
63 | 65 |
64 osname = getos.GetPlatform() | 66 osname = getos.GetPlatform() |
65 if not os.path.exists(nexe): | 67 if not os.path.exists(nexe): |
66 raise Error('executable not found: %s' % nexe) | 68 raise Error('executable not found: %s' % nexe) |
67 if not os.path.isfile(nexe): | 69 if not os.path.isfile(nexe): |
68 raise Error('not a file: %s' % nexe) | 70 raise Error('not a file: %s' % nexe) |
69 | 71 |
70 arch, dynamic = create_nmf.ParseElfHeader(nexe) | 72 arch, dynamic = create_nmf.ParseElfHeader(nexe) |
71 | 73 |
72 if arch == 'arm': | 74 if arch == 'arm' and osname != 'linux': |
73 raise Error('Cannot run ARM executables under sel_ldr') | 75 raise Error('Cannot run ARM executables under sel_ldr on ' + osname) |
74 | 76 |
75 arch_suffix = arch.replace('-', '_') | 77 arch_suffix = arch.replace('-', '_') |
76 | 78 |
77 sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) | 79 sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) |
78 irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) | 80 irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) |
79 if osname == 'win': | 81 if osname == 'win': |
80 sel_ldr += '.exe' | 82 sel_ldr += '.exe' |
81 Log('ROOT = %s' % NACL_SDK_ROOT) | 83 Log('ROOT = %s' % NACL_SDK_ROOT) |
82 Log('SEL_LDR = %s' % sel_ldr) | 84 Log('SEL_LDR = %s' % sel_ldr) |
83 Log('IRT = %s' % irt) | 85 Log('IRT = %s' % irt) |
84 cmd = [sel_ldr] | 86 cmd = [sel_ldr] |
85 | 87 |
86 if osname == 'linux': | 88 if osname == 'linux': |
87 # Run sel_ldr under nacl_helper_bootstrap | 89 # Run sel_ldr under nacl_helper_bootstrap |
88 helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) | 90 helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) |
89 Log('HELPER = %s' % helper) | 91 Log('HELPER = %s' % helper) |
90 cmd.insert(0, helper) | 92 cmd.insert(0, helper) |
91 cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX') | 93 cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX') |
92 cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX') | 94 cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX') |
93 | 95 |
94 cmd += ['-a', '-B', irt] | 96 cmd += ['-a', '-B', irt] |
95 | 97 |
96 if options.debug: | 98 if options.debug: |
97 cmd.append('-g') | 99 cmd.append('-g') |
98 | 100 |
99 if not options.verbose: | 101 if not options.verbose: |
100 cmd += ['-l', os.devnull] | 102 cmd += ['-l', os.devnull] |
101 | 103 |
104 if arch == 'arm': | |
105 # Use the QEMU arm emulator if available. | |
106 qemu_locations = [os.path.join(SCRIPT_DIR, 'qemu_arm'), | |
107 os.path.join(SCRIPT_DIR, 'qemu-arm')] | |
108 qemu_locations += [os.path.join(path, 'qemu_arm') | |
109 for path in os.environ["PATH"].split(os.pathsep)] | |
Sam Clegg
2014/05/01 19:19:10
Can probably drop these two lines? Isn't it alway
cdonner
2014/05/02 17:58:06
google3 has qemu_arm, but I noticed that the nativ
| |
110 qemu_locations += [os.path.join(path, 'qemu-arm') | |
111 for path in os.environ["PATH"].split(os.pathsep)] | |
112 # See if qemu is in any of these locations. | |
113 qemu_bin = None | |
114 for loc in qemu_locations: | |
115 if os.path.isfile(loc) and os.access(loc, os.X_OK): | |
116 qemu_bin = loc | |
117 break | |
118 if qemu_bin: | |
119 qemu = [qemu_bin, '-cpu', 'cortex-a8', '-L', | |
120 os.path.abspath(os.path.join(NACL_SDK_ROOT, 'toolchain', | |
121 'linux_arm_trusted'))] | |
122 # '-Q' disables platform qualification, allowing arm binaries to run. | |
123 cmd = qemu + cmd + ['-Q'] | |
124 else: | |
125 raise Error('Cannot run ARM executables under sel_ldr without an emulator' | |
126 '. Try installing QEMU (http://wiki.qemu.org/).') | |
Sam Clegg
2014/05/01 19:19:10
How about a separate FindQemu() function?
cdonner
2014/05/02 17:58:06
Done.
| |
127 | |
102 if dynamic: | 128 if dynamic: |
103 if options.debug_libs: | 129 if options.debug_libs: |
104 libpath = os.path.join(NACL_SDK_ROOT, 'lib', | 130 libpath = os.path.join(NACL_SDK_ROOT, 'lib', |
105 'glibc_%s' % arch_suffix, 'Debug') | 131 'glibc_%s' % arch_suffix, 'Debug') |
106 else: | 132 else: |
107 libpath = os.path.join(NACL_SDK_ROOT, 'lib', | 133 libpath = os.path.join(NACL_SDK_ROOT, 'lib', |
108 'glibc_%s' % arch_suffix, 'Release') | 134 'glibc_%s' % arch_suffix, 'Release') |
109 toolchain = '%s_x86_glibc' % osname | 135 toolchain = '%s_x86_glibc' % osname |
110 sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', | 136 sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', |
111 toolchain, 'x86_64-nacl') | 137 toolchain, 'x86_64-nacl') |
(...skipping 17 matching lines...) Expand all Loading... | |
129 rtn = subprocess.call(cmd) | 155 rtn = subprocess.call(cmd) |
130 return rtn | 156 return rtn |
131 | 157 |
132 | 158 |
133 if __name__ == '__main__': | 159 if __name__ == '__main__': |
134 try: | 160 try: |
135 sys.exit(main(sys.argv[1:])) | 161 sys.exit(main(sys.argv[1:])) |
136 except Error as e: | 162 except Error as e: |
137 sys.stderr.write(str(e) + '\n') | 163 sys.stderr.write(str(e) + '\n') |
138 sys.exit(1) | 164 sys.exit(1) |
OLD | NEW |