3 # Small utility to upload kernel and/or ramdisk to
4 # the compulab board through the ARMmon firmware.
5 # Requires pyserial : http://pyserial.sourceforge.net
8 import sys
, os
, serial
, getopt
, atexit
, re
10 # regular expression to match valid IPv4 addresses
11 ipv4_regex
= r
"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
13 def wait_flash_complete():
18 if data
.split(" ")[0] == "Finished":
22 # write some nonsense to the monitor and
23 # check if armmon replies accordingly
26 s
.read(len("nonsense\n")+1)
27 data
= s
.read(len("Illegal"))
28 if data
.split(" ")[0] != "Illegal":
29 sys
.exit("Error: ARMmon not responding. Linux running maybe?")
36 sys
.stderr
.write("""USAGE: %s [options] <server ip>
37 armmon_xfer - data upload tool for cmx270/ARMmon
40 -p, --port=PORT: serial port, default='/dev/ttyUSB0'
41 -k, --kernel=KERNEL: upload and flash kernel image KERNEL
42 -r, --ramdisk=RAMDISK: upload and flash ramdisk image RAMDISK
43 -b, --bootos: boot Linux
44 -R, --reboot: reboot cmx270
45 -q, --quiet be quiet, little output
46 -h, --help: print this help screen
50 if __name__
== '__main__':
68 opts
, args
= getopt
.getopt(sys
.argv
[1:],
70 ["port=", "kernel=","ramdisk=","bootos","reboot","help","quiet"]
72 except getopt
.GetoptError
:
77 if o
in ("-h","--help"):
80 elif o
in ("-k","--kernel"):
82 elif o
in ("-r","--ramdisk"):
84 elif o
in ("-b","--bootos"):
86 elif o
in ("-R","--reboot"):
88 elif o
in ("-p","--port"):
90 elif o
in ("-q","--quiet"):
93 # check for arguments and validate IP address
94 # when required by commands
95 if len(args
)>0 and re
.match(ipv4_regex
,args
[0]):
99 sys
.exit("Error: invalid IP address!")
102 s
= serial
.Serial('/dev/ttyUSB0',38400)
104 sys
.stderr
.write("Error: Could not open port: %s\n" % (port
))
107 # test if armmon is responding on bogus input
113 print "Rebooting compulab ..."
121 print "Downloading kernel ..."
122 cmd
= "download kernel tftp %s %s\n" % (kernel
,tftp_ip
)
127 print "Flashing kernel ..."
128 cmd
= "flash kernel\n"
130 wait_flash_complete()
134 print "Downloading ramdisk ..."
135 cmd
= "download ramdisk tftp %s %s\n" % (ramdisk
,tftp_ip
)
140 print "Flashing ramdisk ..."
141 cmd
= "flash ramdisk\n"
143 wait_flash_complete()
146 print "Booting Linux ..."