Author Topic: Python script to combine 3458A firmware ROMs  (Read 973 times)

0 Members and 1 Guest are viewing this topic.

Offline perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 653
  • Country: gb
Python script to combine 3458A firmware ROMs
« on: July 10, 2024, 11:39:17 am »
I downloaded the script to combine the roms from XDEVS.

When I ran it I got:   
Code: [Select]
File "D:\Electronics\HP-Agilent-Keysight\3458A\Rev 9 Firmware\bincomp.py", line 6
    print "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"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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: [Select]
Combine tool for 6 FW ROMs into 1 512KB ROM, hardcoded filenames in code
 (C) 2016 xDevs.com https://xdevs.com/fix/hp3458a
 Output is generated into output_rev9.bin
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" % (a.read(1),b.read(1)))
             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
TypeError: %c requires int or char

As 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?

Thanks
David


 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11510
  • Country: us
    • Personal site
Re: Python script to combine 3458A firmware ROMs
« Reply #1 on: July 10, 2024, 01:46:37 pm »
Wrap a.read(1) and b.read(1) into int(). Like int(a.read(1)).
Alex
 

Offline perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 653
  • Country: gb
Re: Python script to combine 3458A firmware ROMs
« Reply #2 on: July 10, 2024, 02:37:00 pm »
Not quite I fear - unless I misunderstood you:

Code: [Select]
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'
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11510
  • Country: us
    • Personal site
Re: Python script to combine 3458A firmware ROMs
« Reply #3 on: July 10, 2024, 02:50:38 pm »
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.
Alex
 

Offline perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 653
  • Country: gb
Re: Python script to combine 3458A firmware ROMs
« Reply #4 on: July 10, 2024, 05:09:51 pm »
I fear that doesn't work either:

T
Code: [Select]
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11510
  • Country: us
    • Personal site
Re: Python script to combine 3458A firmware ROMs
« Reply #5 on: July 10, 2024, 05:42:22 pm »
What version of Python do you have?

Since it is a single byte, you can just try a.read(1)[0]. I think this would return integer.
Alex
 

Offline perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 653
  • Country: gb
Re: Python script to combine 3458A firmware ROMs
« Reply #6 on: July 10, 2024, 06:32:24 pm »
Python 3.11.3
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11510
  • Country: us
    • Personal site
Re: Python script to combine 3458A firmware ROMs
« Reply #7 on: July 10, 2024, 06:40:13 pm »
What are 'a' and 'b'? Regular files? How they were opened?

Did a.read(1)[0] work?
Alex
 

Offline perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 653
  • Country: gb
Re: Python script to combine 3458A firmware ROMs
« Reply #8 on: July 10, 2024, 08:16:24 pm »
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:
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11510
  • Country: us
    • Personal site
Re: Python script to combine 3458A firmware ROMs
« Reply #9 on: July 10, 2024, 08:41:00 pm »
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'))
Alex
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3134
  • Country: us
Re: Python script to combine 3458A firmware ROMs
« Reply #10 on: July 11, 2024, 04:40:14 am »
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/
 

Offline colorburst

  • Contributor
  • Posts: 38
  • Country: us
Re: Python script to combine 3458A firmware ROMs
« Reply #11 on: July 11, 2024, 08:10:08 am »
perdrix, can you check if this works?

Code: [Select]
# xDevs.com Firmware combine tool
# https://xdevs.com/fix/hp3245a/

import os

print("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')

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 329
  • Country: us
Re: Python script to combine 3458A firmware ROMs
« Reply #12 on: July 12, 2024, 05:41:13 am »
Python 3.11.3

That'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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf