| 207 |
theseven |
1 |
#!/usr/bin/env python
|
|
|
2 |
#
|
|
|
3 |
#
|
|
|
4 |
# Copyright 2010 TheSeven
|
|
|
5 |
#
|
|
|
6 |
#
|
| 427 |
farthen |
7 |
# This file is part of emCORE.
|
| 207 |
theseven |
8 |
#
|
| 427 |
farthen |
9 |
# emCORE is free software: you can redistribute it and/or
|
| 207 |
theseven |
10 |
# modify it under the terms of the GNU General Public License as
|
|
|
11 |
# published by the Free Software Foundation, either version 2 of the
|
|
|
12 |
# License, or (at your option) any later version.
|
|
|
13 |
#
|
| 427 |
farthen |
14 |
# emCORE is distributed in the hope that it will be useful,
|
| 207 |
theseven |
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
17 |
# See the GNU General Public License for more details.
|
|
|
18 |
#
|
|
|
19 |
# You should have received a copy of the GNU General Public License along
|
| 427 |
farthen |
20 |
# with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 207 |
theseven |
21 |
#
|
|
|
22 |
#
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
import sys
|
|
|
26 |
import time
|
| 427 |
farthen |
27 |
import libemcoreldr
|
| 207 |
theseven |
28 |
|
| 532 |
farthen |
29 |
from misc import to_int
|
| 207 |
theseven |
30 |
|
| 532 |
farthen |
31 |
|
| 207 |
theseven |
32 |
def usage():
|
|
|
33 |
print ""
|
|
|
34 |
print "Please provide a command and (if needed) parameters as command line arguments"
|
|
|
35 |
print ""
|
|
|
36 |
print "Available commands:"
|
|
|
37 |
print ""
|
|
|
38 |
print " upload <address> <file>"
|
|
|
39 |
print " Uploads the specified file to the specified memory address on the device."
|
|
|
40 |
print ""
|
|
|
41 |
print " download <address> <size> <file>"
|
|
|
42 |
print " Downloads <size> bytes of data from the specified address on the device,"
|
|
|
43 |
print " and stores it in the specified file."
|
|
|
44 |
print ""
|
|
|
45 |
print " execute <address> <stack>"
|
|
|
46 |
print " Executes code at the specified address in the device's memory."
|
|
|
47 |
print " The stack pointer will be set to <stack> before jumping to <address>."
|
|
|
48 |
print " iBugger will probably lose control of the device,"
|
|
|
49 |
print " if the code isn't explicitly written for it."
|
|
|
50 |
print ""
|
|
|
51 |
print " run <file>"
|
|
|
52 |
print " Loads the specified file to 0x08000000 (SDRAM) and executes it."
|
|
|
53 |
print " This is what you usually want to do."
|
|
|
54 |
print ""
|
| 532 |
farthen |
55 |
print "All numbers can be provided as either hex (0x prefix), binary (0b prefix) or decimal (no prefix)"
|
| 207 |
theseven |
56 |
exit(2)
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
def parsecommand(dev, argv):
|
|
|
60 |
if len(argv) < 2: usage()
|
|
|
61 |
|
|
|
62 |
elif argv[1] == "upload":
|
|
|
63 |
if len(argv) != 4: usage()
|
|
|
64 |
dev.upload(int(argv[2], 16), argv[3])
|
|
|
65 |
|
|
|
66 |
elif argv[1] == "download":
|
|
|
67 |
if len(argv) != 5: usage()
|
| 532 |
farthen |
68 |
dev.download(to_int(argv[2]), to_int(argv[3]), argv[4])
|
| 207 |
theseven |
69 |
|
|
|
70 |
elif argv[1] == "execute":
|
|
|
71 |
if len(argv) != 4: usage()
|
| 532 |
farthen |
72 |
dev.execute(to_int(argv[2]), to_int(argv[3]))
|
| 207 |
theseven |
73 |
|
|
|
74 |
elif argv[1] == "run":
|
|
|
75 |
if len(argv) != 3: usage()
|
|
|
76 |
dev.run(argv[2])
|
|
|
77 |
|
|
|
78 |
else: usage()
|
|
|
79 |
|
|
|
80 |
|
| 427 |
farthen |
81 |
dev = libemcoreldr.emcoreldr()
|
| 207 |
theseven |
82 |
parsecommand(dev, sys.argv)
|