]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
zynq: Do not use argparse module in boot.bin generation
authorMichal Simek <michal.simek@xilinx.com>
Thu, 30 Jan 2014 10:06:37 +0000 (11:06 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Fri, 7 Feb 2014 06:57:54 +0000 (07:57 +0100)
Not all PCs have argparse installed. Use getopt way.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
tools/zynq-boot-bin.py

index a5c11ca4802a2b712bf75e5c6bdf7ec31eb1c5cc..e35379bdb8b46163fc9053a98308120cb5df744d 100755 (executable)
@@ -29,15 +29,33 @@ __email__ = "andrey@elphel.com"
 __status__ = "Development"
 import os
 import struct
-import argparse # http://docs.python.org/2/howto/argparse.html
-
-
-parser = argparse.ArgumentParser()
-parser.add_argument('-o', '--outfile',   help='Path to save the generated boot file')
-parser.add_argument('-u', '--uboot',      help='path to the u-boot.bin to get it\'s length (second pass, when u-boot.bin is already generated)')
-
-args = parser.parse_args()
-#print args
+import sys, getopt
+
+inputfile = ''
+outputfile = ''
+argv = sys.argv[1:]
+try:
+  opts, args = getopt.getopt(argv,"hu:o:",["uboot=","outfile="])
+except getopt.GetoptError:
+  print 'test.py -u <inputfile> -o <outputfile>'
+  sys.exit(2)
+
+if len(argv) == 0:
+  print 'test.py -u <inputfile> -o <outputfile>'
+  sys.exit()
+
+for opt, arg in opts:
+  if opt == '-h':
+      print 'test.py -u <inputfile> -o <outputfile>'
+      sys.exit()
+  elif opt in ("-u", "--uboot"):
+      inputfile = arg
+  elif opt in ("-o", "--outfile"):
+      outputfile = arg
+print 'Input file is:', inputfile
+print 'Output file is:', outputfile
+
+exit
 
 ACCESSIBLE_REGISTERS=((0xe0001000,0xe0001fff), # UART1 controller registers
                       (0xe000d000,0xe000efff), # QUAD SPI controller registers
@@ -170,12 +188,13 @@ def image_generator (image,
         image[waddr]=0
         waddr+=1
 
-if (args.uboot):
+if (inputfile):
     try:
-        uboot_image_len=os.path.getsize(args.uboot)
-        print 'Using %s to get image length - it is %i (0x%x) bytes'%(os.path.abspath(args.uboot),uboot_image_len,uboot_image_len)
+        uboot_image_len=os.path.getsize(inputfile)
+        print 'Using %s to get image length - it is %i (0x%x) bytes'%(os.path.abspath(inputfile),uboot_image_len,uboot_image_len)
     except:
-        print 'Specified u-boot.bin file: %s (%s) not found'%(args.uboot,os.path.abspath(args.uboot))
+        print 'Specified u-boot.bin file: %s (%s) not found'%(inputfile,os.path.abspath(inputfile))
+        sys.exit()
 else:
     uboot_image_len=int(raw_options['CONFIG_EZYNQ_BOOT_OCM_IMAGE_LENGTH'],0)
     print 'No u-boot.bin path specified, using provided CONFIG_EZYNQ_BOOT_OCM_IMAGE_LENGTH as image size of %i (0x%x) bytes for the RBL header'%(uboot_image_len,uboot_image_len)
@@ -197,13 +216,13 @@ image_generator (image,
                  uboot_image_len, #ocm_len,
                  0) #start_exec)
 
-if args.outfile:
-    print 'Generating binary output ',os.path.abspath(args.outfile)
-    bf=open(args.outfile,'wb')
+if outputfile:
+    print 'Generating binary output ',os.path.abspath(outputfile)
+    bf=open(outputfile,'wb')
     data=struct.pack('I' * len(image), *image)
     bf.write(data)
 
-    spl=open(args.uboot,'rb')
+    spl=open(inputfile,'rb')
     bf.write(spl.read())
 
     bf.close()