99import sys
1010import struct
1111
12- from bin2hpm import hpm , rle , bitfile , __version__
12+ from bin2hpm import hpm_conv , bitfile , __version__
1313
1414def swap32 (i ):
1515 return struct .unpack ("<I" , struct .pack (">I" , i ))[0 ]
@@ -107,22 +107,10 @@ def main():
107107 print (f'Component { args .component } , Device { args .device } ' )
108108 print (f'FW version { v_maj } .{ v_min :02d} / 0x{ args .auxillary :08x} \n ' )
109109
110- # Build HPM upgrade image header
111- result = hpm .upg_image_hdr (
112- device_id = args .device ,
113- manufacturer_id = args .manufacturer ,
114- product_id = args .product ,
115- components = components ,
116- version_major = v_maj ,
117- version_minor = v_min ,
118- version_aux = v_aux ,
119- )
120-
121- # Append HPM upgrade action (HPM prepare action)
122- result += hpm .upg_action_hdr (
123- action_type = hpm .UpgradeActionType .Prepare ,
124- components = components
125- )
110+ # Determine outfile name
111+ outfile = args .outfile
112+ if not outfile :
113+ outfile = os .path .splitext (args .infile )[0 ] + '.hpm'
126114
127115 # Read input file
128116 with open (args .infile , 'rb' ) as f :
@@ -132,37 +120,19 @@ def main():
132120 if bitmode :
133121 img_data = bitfile .parse_bitfile (img_data )
134122
135- # Compress data if compression enabled
136- if args .compress :
137- enc_data = rle .encode (img_data )
138- print ('Verifying compressed data...' , end = '' )
139- if rle .decode (enc_data ) != img_data :
140- print (f'RLE compression verify mismatch' , file = sys .stderr )
141- sys .exit (- 1 )
142- print ('OK\n ' )
143-
144- img_comp_hdr = b'COMPRESSED\x00 '
145- img_comp_hdr += int .to_bytes (len (img_data ), length = 4 , byteorder = 'big' )
146- img_data = img_comp_hdr + enc_data
147-
148- # Append HPM upgrade action image
149- result += hpm .upg_action_img (
123+ # Do the actual conversion
124+ result = hpm_conv .hpm_conv (
150125 img_data ,
126+ args .compress ,
127+ device_id = args .device ,
128+ manufacturer_id = args .manufacturer ,
129+ product_id = args .product ,
151130 components = components ,
152131 version_major = v_maj ,
153132 version_minor = v_min ,
154133 version_aux = v_aux ,
155134 desc_str = args .description or os .path .basename (args .infile )[:20 ]
156135 )
157-
158- # Append MD5 hash
159- result += hpm .upg_img_hash (result )
160-
161- # Determine outfile name
162- outfile = args .outfile
163- if not outfile :
164- outfile = os .path .splitext (args .infile )[0 ] + '.hpm'
165-
166136 # Write HPM file
167137 with open (outfile , 'wb' ) as f :
168138 f .write (result )
0 commit comments