<div dir="auto">Quick note sort copyright lines earlier years below later years.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 4, 2020, 4:09 PM Amar Takhar <<a href="mailto:amar@rtems.org">amar@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> * Fix exceptions and print exception message.<br>
* Also add myself to copyright.<br>
---<br>
misc/tools/mkimage.py | 42 ++++++++++++++++++++++--------------------<br>
1 file changed, 22 insertions(+), 20 deletions(-)<br>
<br>
diff --git a/misc/tools/mkimage.py b/misc/tools/mkimage.py<br>
index 2b1524c..0845ee4 100755<br>
--- a/misc/tools/mkimage.py<br>
+++ b/misc/tools/mkimage.py<br>
@@ -3,6 +3,7 @@<br>
# A quickly bashed together replacement for u-boot's mkimage written in python<br>
#<br>
# Copyright 2010 Craig Barker<br>
+# Copyright 2020 Amar Takhar <<a href="mailto:amar@rtems.org" target="_blank" rel="noreferrer">amar@rtems.org</a>><br>
#<br>
# Redistribution and use in source and binary forms, with or without<br>
# modification, are permitted provided that the following conditions are met:<br>
@@ -27,7 +28,7 @@<br>
# POSSIBILITY OF SUCH DAMAGE.<br>
<br>
<br>
-from optparse import OptionParser<br>
+import argparse<br>
from struct import *<br>
import sys<br>
import os.path<br>
@@ -53,30 +54,31 @@ types = {'invalid':0, 'standalone':1, 'kernel':2, 'ramdisk':3, 'multi':4,<br>
<br>
comps = {'none':0, 'bzip2':2, 'gzip':1, 'lzma':3 }<br>
<br>
-usage = "usage: %prog [options] image"<br>
-parser = OptionParser(usage=usage)<br>
-parser.add_option("-A","--arch", dest="arch", default="powerpc",<br>
+parser = argparse.ArgumentParser()<br>
+<br>
+parser.add_argument("-A","--arch", dest="arch", default="powerpc",<br>
help="set architecture to 'arch'", metavar="ARCH")<br>
-parser.add_option("-O","--os", dest="os", default="linux",<br>
+parser.add_argument("-O","--os", dest="os", default="linux",<br>
help="set operating system to 'os'", metavar="OS")<br>
-parser.add_option("-T","--type", dest="type", default="kernel",<br>
+parser.add_argument("-T","--type", dest="type", default="kernel",<br>
help="set image type to 'type'", metavar="TYPE")<br>
-parser.add_option("-C","--comp", dest="comp", default="gzip",<br>
+parser.add_argument("-C","--comp", dest="comp", default="gzip",<br>
help="set compression type 'comp'", metavar="COMP")<br>
-parser.add_option("-a","--addr", dest="addr", default="0",<br>
+parser.add_argument("-a","--addr", dest="addr", default="0",<br>
help="set load address to 'addr' (hex)", metavar="ADDR")<br>
-parser.add_option("-e","--ep", dest="ep", default="0",<br>
+parser.add_argument("-e","--ep", dest="ep", default="0",<br>
help="set entry point to 'ep' (hex)", metavar="EP")<br>
-parser.add_option("-n","--name", dest="name", default="",<br>
+parser.add_argument("-n","--name", dest="name", default="",<br>
help="set image name to 'name'", metavar="NAME")<br>
-parser.add_option("-d","--datafile", dest="datafile",<br>
- help="use image data from 'datafile'", metavar="DATAFILE")<br>
-parser.add_option("-x","--xip", action="store_true", dest="xip", default=False,<br>
+parser.add_argument("-d","--datafile", dest="datafile",<br>
+ help="use image data from 'datafile'", metavar="DATAFILE", required=True)<br>
+parser.add_argument("-x","--xip", action="store_true", dest="xip", default=False,<br>
help="set XIP (execute in place)")<br>
+parser.add_argument("outputfile",<br>
+ help="Output file.", metavar="OUTPUTFILE")<br>
<br>
-(options, args) = parser.parse_args()<br>
<br>
-if len(args) != 1: parser.print_help()<br>
+options = parser.parse_args()<br>
<br>
if options.arch not in archs:<br>
print "Invalid architecture specified, aborting"<br>
@@ -98,15 +100,15 @@ try:<br>
inputsize = os.path.getsize(options.datafile)<br>
inputfile = open(options.datafile, 'rb')<br>
<br>
-except IOError:<br>
- print "Invalid datafile specified, aborting"<br>
+except OSError as e:<br>
+ print "Invalid datafile specified, aborting: %s" % e<br>
sys.exit(2)<br>
<br>
try:<br>
- outputfile = open(args[0],'wb')<br>
+ outputfile = open(options.outputfile,'wb')<br>
<br>
-except IOError:<br>
- print "Error opening output file for writing, aborting"<br>
+except IOError as e:<br>
+ print "Error opening output file for writing, aborting: %s" % e<br>
sys.exit(1)<br>
<br>
struct = Struct("!IIIIIIIBBBB"+str(IMG_NAME_LENGTH)+"s")<br>
-- <br>
2.25.0<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank" rel="noreferrer">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>