Index: tools/scripts/odxgen.py
===================================================================
--- tools/scripts/odxgen.py	(revision 72210)
+++ tools/scripts/odxgen.py	(working copy)
@@ -1,11 +1,13 @@
-import hashlib, os
+from array import array
+import hashlib
+from optparse import OptionParser
 from os import curdir, sep, pardir
-from zipfile import ZipFile
-from optparse import OptionParser
-from array import array
+import os
 import re
 import shutil
+from subprocess import Popen, PIPE
 import sys
+from zipfile import ZipFile
 
 import odxutils
 from odxtypes import *
@@ -70,7 +72,8 @@
         'images':[{'file':'micro_app.hex', 'start_addr':0x80010000},\
                   {'file':'FFDB.hex', 'start_addr':0x80070000}],\
         'segments':[],\
-        'sdgs':[]
+        'sdgs':[],
+        'compress':False
      },
       # for some reason, addresses starting with 000 are not valid (the BTP tester comlains with some XML schematic error message),
       # that might be the reason why we see addresses like 0x40004000 rather than 0x00004000, although the latter is the one in the amp.
@@ -80,7 +83,8 @@
         'segment_size':256, 'sha1':'', 'file':'FD01.bin', 'size':0, 'content':'DATA',\
         'images':[{'file':'DSPDB1.hex', 'start_addr':0x40004000}],\
         'segments':[],\
-        'sdgs':[]
+        'sdgs':[],
+        'compress':False
      },
      {
         'name':'FD02', 'alias':'RNDB', 'start_addr':0x40064000, 'end_addr':0x400A3fff,\
@@ -87,7 +91,8 @@
         'segment_size':256, 'sha1':'', 'file':'FD02.bin', 'size':0, 'content':'DATA',\
         'images':[{'file':'RNDB_jfc_r9mto.hex', 'start_addr':0x40064000}],\
         'segments':[],\
-        'sdgs':[{'name':'KnownValues', 'key':'maxNumberOfBlockLength','value':'0800'}]
+        'sdgs':[{'name':'KnownValues', 'key':'maxNumberOfBlockLength','value':'0800'}],
+        'compress':True
      }]
 
  
@@ -366,9 +371,9 @@
             fin = open(os.path.join(images_dir, image['file']), 'r')
             #with open(os.path.join(images_dir, image['file']), 'r') as fin:
             img_buffer = intel_hex.intelhex2bin(fin.readlines())
-            img_len = len(img_buffer)
             fin.close()
 
+            img_len = len(img_buffer)
             print "Block length: %X" %(len(mem_block))
             offset = image['start_addr'] - block['start_addr']
             print 'Offset: 0x%X length: %X' %(offset,img_len)
@@ -393,6 +398,17 @@
         block['segments'].extend(get_valid_data_segments(mem_block, block['segment_size']))
         image_data = ''.join(shrink_image(mem_block, block['segments']))
         print 'Image size: %d bytes' %len(image_data)
+
+        # Compress the image
+        if doCompression and block['compress']:
+            print 'Compressing Image...'
+            p = Popen(compress_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+            image_data, stderr = p.communicate(image_data)
+            if len(stderr) > 0:
+                print 'Error: compression failed.\n%s' %stderr
+                sys.exit(1)
+            print 'Compressed Image size: %d bytes' %len(image_data)
+
         fout.write(image_data)
         fout.close()
 
@@ -415,8 +431,10 @@
     parser.add_option("-o", "--output",\
                       dest="output_dir",\
                       help="Where the PDX file will be placed")
+    parser.add_option("--compress_cmd",\
+                      dest="compress_cmd",\
+                      help="Command that will compress data. The script will pipe in the data to compress from stdin, and expect the compressed data from stdout.")
 
-
     (options,args) = parser.parse_args()
 
     if options.cartype_dir is None:
@@ -425,6 +443,12 @@
     if options.output_dir is None:
         parser.error("Output directory must be defined")
 
+    if options.compress_cmd is None:
+        doCompression = False
+    else:
+        doCompression = True
+        compress_cmd = options.compress_cmd
+
     # Change directory to the current script path
     root_dir = os.path.abspath(os.getcwd())
     cur_dir = os.path.abspath(os.path.dirname(__file__))
@@ -444,7 +468,6 @@
     db_config_dir = os.path.join(cartype_dir, 'db/config')
     db_tune_dir = os.path.join(cartype_dir, 'db/tuning')
 
-    
     carmodels = get_carmodel_list(db_tune_dir + '/config.tune')
     
     # generate customer image for each carmodel in list

