OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 3 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 # | 6 # |
7 | 7 |
8 # Prepares a raspbian image to support fletch. We use qemu to edit the image | 8 # Prepares a raspbian image to support dartino. We use qemu to edit the image |
9 # since this allows us to run commands and push data to the image without using | 9 # since this allows us to run commands and push data to the image without using |
10 # sudo. This script will "edit" the image in place, so take a copy before using. | 10 # sudo. This script will "edit" the image in place, so take a copy before using. |
11 | 11 |
12 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import pexpect | 14 import pexpect |
15 import pxssh | 15 import pxssh |
16 import sys | 16 import sys |
17 import time | 17 import time |
18 | 18 |
19 HOSTNAME = 'localhost' | 19 HOSTNAME = 'localhost' |
20 USERNAME = 'pi' | 20 USERNAME = 'pi' |
21 PASSWORD = 'raspberry' | 21 PASSWORD = 'raspberry' |
22 KERNEL = 'third_party/raspbian/kernel/kernel-qemu' | 22 KERNEL = 'third_party/raspbian/kernel/kernel-qemu' |
23 CONFIG = 'tools/raspberry-pi2/raspbian-scripts/fletch-configuration' | 23 CONFIG = 'tools/raspberry-pi2/raspbian-scripts/dartino-configuration' |
24 QEMU = 'third_party/qemu/linux/qemu/bin/qemu-system-arm' | 24 QEMU = 'third_party/qemu/linux/qemu/bin/qemu-system-arm' |
25 PORT = 10022 | 25 PORT = 10022 |
26 | 26 |
27 def Options(): | 27 def Options(): |
28 result = optparse.OptionParser() | 28 result = optparse.OptionParser() |
29 result.add_option('--agent', | 29 result.add_option('--agent', |
30 default=None, | 30 default=None, |
31 help='The arm agent deb file.') | 31 help='The arm agent deb file.') |
32 # We assume that this file has been patched to remove the /etc/ld.so.preload | 32 # We assume that this file has been patched to remove the /etc/ld.so.preload |
33 # entries and that /etc/fstab entries are also fixed. We will remove the | 33 # entries and that /etc/fstab entries are also fixed. We will remove the |
34 # comment markers in these files in this script. | 34 # comment markers in these files in this script. |
35 result.add_option('--image', | 35 result.add_option('--image', |
36 default=None, | 36 default=None, |
37 help='The raspbian image file.') | 37 help='The raspbian image file.') |
38 result.add_option('--src', | 38 result.add_option('--src', |
39 default=None, | 39 default=None, |
40 help='The source tarball that we ship with the image.') | 40 help='The source tarball that we ship with the image.') |
41 (options, args) = result.parse_args() | 41 (options, args) = result.parse_args() |
42 return options | 42 return options |
43 | 43 |
44 def InstallAgent(qemu, agent): | 44 def InstallAgent(qemu, agent): |
45 deb_dst = '/tmp/agent.deb' | 45 deb_dst = '/tmp/agent.deb' |
46 qemu.put_file(agent, deb_dst) | 46 qemu.put_file(agent, deb_dst) |
47 qemu.run_command('sudo sudo dpkg -i %s' % deb_dst) | 47 qemu.run_command('sudo sudo dpkg -i %s' % deb_dst) |
48 qemu.run_command('rm %s' % deb_dst) | 48 qemu.run_command('rm %s' % deb_dst) |
49 # This will fail, but it lets us validate that the binary was installed. | 49 # This will fail, but it lets us validate that the binary was installed. |
50 # (it fails due to the simulated cpu not being armv7) | 50 # (it fails due to the simulated cpu not being armv7) |
51 qemu.run_command('fletch-vm --version') | 51 qemu.run_command('dartino-vm --version') |
52 | 52 |
53 def InstallConfig(qemu): | 53 def InstallConfig(qemu): |
54 config_dst = '/tmp/fletch-configuration' | 54 config_dst = '/tmp/dartino-configuration' |
55 qemu.put_file(CONFIG, config_dst) | 55 qemu.put_file(CONFIG, config_dst) |
56 qemu.run_command('sudo cp /tmp/fletch-configuration /etc/init.d') | 56 qemu.run_command('sudo cp /tmp/dartino-configuration /etc/init.d') |
57 qemu.run_command('sudo chown root:root /etc/init.d/fletch-configuration') | 57 qemu.run_command('sudo chown root:root /etc/init.d/dartino-configuration') |
58 qemu.run_command('sudo chmod 755 /etc/init.d/fletch-configuration') | 58 qemu.run_command('sudo chmod 755 /etc/init.d/dartino-configuration') |
59 qemu.run_command('sudo insserv fletch-configuration') | 59 qemu.run_command('sudo insserv dartino-configuration') |
60 qemu.run_command('sudo update-rc.d fletch-configuration enable') | 60 qemu.run_command('sudo update-rc.d dartino-configuration enable') |
61 | 61 |
62 def InstallSrcTarball(qemu, src): | 62 def InstallSrcTarball(qemu, src): |
63 src_dst = os.path.join('/home', 'pi', os.path.basename(src)) | 63 src_dst = os.path.join('/home', 'pi', os.path.basename(src)) |
64 qemu.put_file(src, src_dst) | 64 qemu.put_file(src, src_dst) |
65 | 65 |
66 def FixRasbianConfigs(qemu): | 66 def FixRasbianConfigs(qemu): |
67 # This removes the comment markers created by: | 67 # This removes the comment markers created by: |
68 # tools/raspberry-pi2/qemufy-image.sh | 68 # tools/raspberry-pi2/qemufy-image.sh |
69 qemu.run_command('sudo sed -i "/mmcblk/s/#//g" /etc/fstab') | 69 qemu.run_command('sudo sed -i "/mmcblk/s/#//g" /etc/fstab') |
70 qemu.run_command('sudo sed -i "s/#//g" /etc/ld.so.preload') | 70 qemu.run_command('sudo sed -i "s/#//g" /etc/ld.so.preload') |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 # The process did not shut down, kill it | 172 # The process did not shut down, kill it |
173 print 'Qemu did not shut down nicely, killing it' | 173 print 'Qemu did not shut down nicely, killing it' |
174 self.process.terminate(force=True) | 174 self.process.terminate(force=True) |
175 self.process.read() | 175 self.process.read() |
176 self.logfile.close() | 176 self.logfile.close() |
177 # We should actually throw here, but since we can't nicely shut down we | 177 # We should actually throw here, but since we can't nicely shut down we |
178 # allow this for now, see issue 277 | 178 # allow this for now, see issue 277 |
179 | 179 |
180 if __name__ == '__main__': | 180 if __name__ == '__main__': |
181 sys.exit(Main()) | 181 sys.exit(Main()) |
OLD | NEW |