Python script to combine 3458A firmware ROMs - Page 1
Forum section: electronics / general

author: perdrix
author_rank: Frequent Contributor
timestamp: July 10, 2024, 11:39:17 am
content: I downloaded the script to combine the roms from XDEVS.When I ran it I got:Code:File "D:\Electronics\HP-Agilent-Keysight\3458A\Rev 9 Firmware\bincomp.py", line 6print "Combine tool for 6 FW ROMs into 1 512KB ROM, hardcoded filenames in code\r\n (C) 2016 xDevs.com https://xdevs.com/fix/hp3458a\r\n Output isgenerated into output_rev9.bin"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?So I wrapped the print command in () and moved to the next error:Code:Combine tool for 6 FW ROMs into 1 512KB ROM, hardcoded filenames in code(C) 2016 xDevs.com https://xdevs.com/fix/hp3458aOutput is generated into output_rev9.binTraceback (most recent call last):File "D:\Electronics\HP-Agilent-Keysight\3458A\Rev 9 Firmware\bincomp.py", line 15, in <module>x.write ("%c%c" % (a.read(1),b.read(1)))~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~TypeError: %c requires int or charAs I'm not Python literate, what do I need to change to accommodate the difference between (I assume) Python 2 and Python 3 so the script will work?ThanksDavid

author: ataradov
author_rank: Super Contributor
timestamp: July 10, 2024, 01:46:37 pm
content: Wrap a.read(1) and b.read(1) into int(). Like int(a.read(1)).

author: perdrix
author_rank: Frequent Contributor
timestamp: July 10, 2024, 02:37:00 pm
content: Not quite I fear - unless I misunderstood you:Code:Traceback (most recent call last):File "D:\Electronics\HP-Agilent-Keysight\3458A\Rev 9 Firmware\bincomp.py", line 15, in <module>x.write ("%c%c" % (int(a.read(1)),int(b.read(1))))^^^^^^^^^^^^^^ValueError: invalid literal for int() with base 10: b'\x01'

author: ataradov
author_rank: Super Contributor
timestamp: July 10, 2024, 02:50:38 pm
content: Well, it really depends on what those reads return. In this case they return byte string. So, you need to do more complicated stuff. I think something like this should work:int.from_bytes(a.read(1), 'big'). Last part is byte order, but for 1 byte it does not matter.

author: perdrix
author_rank: Frequent Contributor
timestamp: July 10, 2024, 05:09:51 pm
content: I fear that doesn't work either:TCode:raceback (most recent call last):File "D:\Electronics\HP-Agilent-Keysight\3458A\Rev 9 Firmware\bincomp.py", line 15, in <module>x.write ("%c%c" % (int.from_bytes(a.read(1), 'big'),int.from_bytes(b.read(1), 'big')))TypeError: a bytes-like object is required, not 'str'D.

author: ataradov
author_rank: Super Contributor
timestamp: July 10, 2024, 05:42:22 pm
content: What version of Python do you have?Since it is a single byte, you can just try a.read(1). I think this would return integer.

author: perdrix
author_rank: Frequent Contributor
timestamp: July 10, 2024, 06:32:24 pm
content: Python 3.11.3

author: ataradov
author_rank: Super Contributor
timestamp: July 10, 2024, 06:40:13 pm
content: What are 'a' and 'b'? Regular files? How they were opened?Did a.read(1) work?

author: perdrix
author_rank: Frequent Contributor
timestamp: July 10, 2024, 08:16:24 pm
content: with open('03458_88890_061108_rev9_u110.bin','rb') as a:with open('03458_88891_061108_rev9_u111.bin','rb') as b:with open('03458_88892_061108_rev9_u112.bin','rb') as c:with open('03458_88893_061108_rev9_u113.bin','rb') as d:with open('03458_88894_061108_rev9_u114.bin','rb') as e:with open('03458_88895_061108_rev9_u115.bin','rb') as f:with open('output_rev9.bin','wb') as x:

author: ataradov
author_rank: Super Contributor
timestamp: July 10, 2024, 08:41:00 pm
content: Ah, the complaint now is not on building the string, but on writing it back. You need to convert the resulting string into a byte stream:x.write (bytes("%c%c" % (......), 'ascii'))

author: ledtester
author_rank: Super Contributor
timestamp: July 11, 2024, 04:40:14 am
content: I would run the original script with Python 2 - the first error you got with the print statement clearly suggests it was intended to be run under Python 2.https://www.delftstack.com/howto/python/switch-between-python-2-and-3/

author: colorburst
author_rank: Regular Contributor
timestamp: July 11, 2024, 08:10:08 am
content: perdrix, can you check if this works?Code:# xDevs.com Firmware combine tool# https://xdevs.com/fix/hp3245a/import osprint("Combine tool for 6 FW ROMs into 1 512KB ROM, hardcoded filenames in code\r\n (C) 2016 xDevs.com https://xdevs.com/fix/hp3458a\r\n Output is generated into output_rev9.bin")with open('03458_88890_061108_rev9_u110.bin','rb') as a:with open('03458_88891_061108_rev9_u111.bin','rb') as b:with open('03458_88892_061108_rev9_u112.bin','rb') as c:with open('03458_88893_061108_rev9_u113.bin','rb') as d:with open('03458_88894_061108_rev9_u114.bin','rb') as e:with open('03458_88895_061108_rev9_u115.bin','rb') as f:with open('output_rev9.bin','wb') as x:for cnt in range(0, 65536):x.write(a.read(1) + b.read(1))for cnt in range(0, 65536):x.write(c.read(1) + d.read(1))for cnt in range(0, 65536):x.write(e.read(1) + f.read(1))for cnt in range(0, 65536):x.write(b'\xff\xff')

author: abeyer
author_rank: Frequent Contributor
timestamp: July 12, 2024, 05:41:13 am
content: Quote from: perdrix on July 10, 2024, 06:32:24 pmThat's your problem. It's a python 2 script, you should run it on the last version of 2.7 and it will likely just work, unless you really want to port it to python 3.