3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # sercomm-pid.py: Creates Sercomm device PID
7 # Copyright © 2022 Mikhail Zhilkin
21 def create_pid_file(args
):
22 pid_file
= open(args
.pid_file
, "wb")
28 buf
= bytearray([PADDING
] * PID_SIZE
)
30 enc
= args
.hw_version
.rjust(8, '0').encode('ascii')
31 struct
.pack_into('>8s', buf
, 0x0, enc
)
33 enc
= binascii
.hexlify(args
.hw_id
.encode())
34 struct
.pack_into('>6s', buf
, 0x8, enc
)
36 enc
= args
.sw_version
.rjust(4, '0').encode('ascii')
37 struct
.pack_into('>4s', buf
, 0x64, enc
)
39 if (args
.extra_padd_size
):
40 tail
= bytearray([PADDING_TAIL
] * args
.extra_padd_size
)
41 if (args
.extra_padd_byte
):
42 struct
.pack_into ('<i', tail
, 0x0,
51 parser
= argparse
.ArgumentParser(description
='This script \
52 generates firmware PID for the Sercomm-based devices')
54 parser
.add_argument('--hw-version',
58 help='Sercomm hardware version')
60 parser
.add_argument('--hw-id',
64 help='Sercomm hardware ID')
66 parser
.add_argument('--sw-version',
70 help='Sercomm software version')
72 parser
.add_argument('--pid-file',
76 help='Output PID file')
78 parser
.add_argument('--extra-padding-size',
79 dest
='extra_padd_size',
82 help='Size of extra NULL padding at the end of the file \
85 parser
.add_argument('--extra-padding-first-byte',
86 dest
='extra_padd_byte',
89 help='First byte of extra padding (optional)')
91 args
= parser
.parse_args()
93 if ((not args
.hw_version
) or
95 (not args
.sw_version
) or
100 create_pid_file(args
)