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

Side by Side Diff: native_client_sdk/src/tools/sel_ldr.py

Issue 262753005: Allows sel_ldr.py to run arm binaries through qemu-arm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 | no next file » | 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 # 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
(...skipping 14 matching lines...) Expand all
25 class Error(Exception): 25 class Error(Exception):
26 pass 26 pass
27 27
28 28
29 def Log(msg): 29 def Log(msg):
30 if Log.verbose: 30 if Log.verbose:
31 sys.stderr.write(str(msg) + '\n') 31 sys.stderr.write(str(msg) + '\n')
32 Log.verbose = False 32 Log.verbose = False
33 33
34 34
35 def FindQemu():
36 qemu_locations = [os.path.join(SCRIPT_DIR, 'qemu_arm'),
37 os.path.join(SCRIPT_DIR, 'qemu-arm')]
38 qemu_locations += [os.path.join(path, 'qemu_arm')
39 for path in os.environ["PATH"].split(os.pathsep)]
40 qemu_locations += [os.path.join(path, 'qemu-arm')
41 for path in os.environ["PATH"].split(os.pathsep)]
42 # See if qemu is in any of these locations.
43 qemu_bin = None
44 for loc in qemu_locations:
45 if os.path.isfile(loc) and os.access(loc, os.X_OK):
46 qemu_bin = loc
47 break
48 return qemu_bin
49
50
35 def main(argv): 51 def main(argv):
36 usage = 'Usage: %prog [options] <.nexe>' 52 usage = 'Usage: %prog [options] <.nexe>'
37 epilog = 'Example: sel_ldr.py my_nexe.nexe' 53 epilog = 'Example: sel_ldr.py my_nexe.nexe'
38 parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog) 54 parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
39 parser.add_option('-v', '--verbose', action='store_true', 55 parser.add_option('-v', '--verbose', action='store_true',
40 help='Verbose output') 56 help='Verbose output')
41 parser.add_option('-d', '--debug', action='store_true', 57 parser.add_option('-d', '--debug', action='store_true',
42 help='Enable debug stub') 58 help='Enable debug stub')
43 parser.add_option('--debug-libs', action='store_true', 59 parser.add_option('--debug-libs', action='store_true',
44 help='For dynamic executables, reference debug ' 60 help='For dynamic executables, reference debug '
(...skipping 17 matching lines...) Expand all
62 Log.verbose = True 78 Log.verbose = True
63 79
64 osname = getos.GetPlatform() 80 osname = getos.GetPlatform()
65 if not os.path.exists(nexe): 81 if not os.path.exists(nexe):
66 raise Error('executable not found: %s' % nexe) 82 raise Error('executable not found: %s' % nexe)
67 if not os.path.isfile(nexe): 83 if not os.path.isfile(nexe):
68 raise Error('not a file: %s' % nexe) 84 raise Error('not a file: %s' % nexe)
69 85
70 arch, dynamic = create_nmf.ParseElfHeader(nexe) 86 arch, dynamic = create_nmf.ParseElfHeader(nexe)
71 87
72 if arch == 'arm': 88 if arch == 'arm' and osname != 'linux':
73 raise Error('Cannot run ARM executables under sel_ldr') 89 raise Error('Cannot run ARM executables under sel_ldr on ' + osname)
74 90
75 arch_suffix = arch.replace('-', '_') 91 arch_suffix = arch.replace('-', '_')
76 92
77 sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) 93 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) 94 irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix)
79 if osname == 'win': 95 if osname == 'win':
80 sel_ldr += '.exe' 96 sel_ldr += '.exe'
81 Log('ROOT = %s' % NACL_SDK_ROOT) 97 Log('ROOT = %s' % NACL_SDK_ROOT)
82 Log('SEL_LDR = %s' % sel_ldr) 98 Log('SEL_LDR = %s' % sel_ldr)
83 Log('IRT = %s' % irt) 99 Log('IRT = %s' % irt)
84 cmd = [sel_ldr] 100 cmd = [sel_ldr]
85 101
86 if osname == 'linux': 102 if osname == 'linux':
87 # Run sel_ldr under nacl_helper_bootstrap 103 # Run sel_ldr under nacl_helper_bootstrap
88 helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) 104 helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix)
89 Log('HELPER = %s' % helper) 105 Log('HELPER = %s' % helper)
90 cmd.insert(0, helper) 106 cmd.insert(0, helper)
91 cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX') 107 cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX')
92 cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX') 108 cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX')
93 109
94 cmd += ['-a', '-B', irt] 110 cmd += ['-a', '-B', irt]
95 111
96 if options.debug: 112 if options.debug:
97 cmd.append('-g') 113 cmd.append('-g')
98 114
99 if not options.verbose: 115 if not options.verbose:
100 cmd += ['-l', os.devnull] 116 cmd += ['-l', os.devnull]
101 117
118 if arch == 'arm':
119 # Use the QEMU arm emulator if available.
120 qemu_bin = FindQemu()
121 if qemu_bin:
122 qemu = [qemu_bin, '-cpu', 'cortex-a8', '-L',
123 os.path.abspath(os.path.join(NACL_SDK_ROOT, 'toolchain',
124 'linux_arm_trusted'))]
125 # '-Q' disables platform qualification, allowing arm binaries to run.
126 cmd = qemu + cmd + ['-Q']
127 else:
128 raise Error('Cannot run ARM executables under sel_ldr without an emulator'
129 '. Try installing QEMU (http://wiki.qemu.org/).')
130
102 if dynamic: 131 if dynamic:
103 if options.debug_libs: 132 if options.debug_libs:
104 libpath = os.path.join(NACL_SDK_ROOT, 'lib', 133 libpath = os.path.join(NACL_SDK_ROOT, 'lib',
105 'glibc_%s' % arch_suffix, 'Debug') 134 'glibc_%s' % arch_suffix, 'Debug')
106 else: 135 else:
107 libpath = os.path.join(NACL_SDK_ROOT, 'lib', 136 libpath = os.path.join(NACL_SDK_ROOT, 'lib',
108 'glibc_%s' % arch_suffix, 'Release') 137 'glibc_%s' % arch_suffix, 'Release')
109 toolchain = '%s_x86_glibc' % osname 138 toolchain = '%s_x86_glibc' % osname
110 sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', 139 sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain',
111 toolchain, 'x86_64-nacl') 140 toolchain, 'x86_64-nacl')
(...skipping 17 matching lines...) Expand all
129 rtn = subprocess.call(cmd) 158 rtn = subprocess.call(cmd)
130 return rtn 159 return rtn
131 160
132 161
133 if __name__ == '__main__': 162 if __name__ == '__main__':
134 try: 163 try:
135 sys.exit(main(sys.argv[1:])) 164 sys.exit(main(sys.argv[1:]))
136 except Error as e: 165 except Error as e:
137 sys.stderr.write(str(e) + '\n') 166 sys.stderr.write(str(e) + '\n')
138 sys.exit(1) 167 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698