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
)
31 enc
= args
.hw_version
.rjust(14, '0').encode('ascii')
32 struct
.pack_into('>14s', buf
, 0x0, enc
)
34 enc
= args
.hw_version
.rjust(8, '0').encode('ascii')
35 struct
.pack_into('>8s', buf
, 0x0, enc
)
37 enc
= binascii
.hexlify(args
.hw_id
.encode())
38 struct
.pack_into('>6s', buf
, 0x8, enc
)
40 enc
= args
.sw_version
.rjust(4, '0').encode('ascii')
41 struct
.pack_into('>4s', buf
, 0x64, enc
)
43 if (args
.extra_padd_size
):
44 tail
= bytearray([PADDING_TAIL
] * args
.extra_padd_size
)
45 if (args
.extra_padd_byte
):
46 struct
.pack_into ('<i', tail
, 0x0,
58 parser
= argparse
.ArgumentParser(description
='This script \
59 generates firmware PID for the Sercomm-based devices')
61 parser
.add_argument('--hw-version',
65 help='Sercomm hardware version')
67 parser
.add_argument('--hw-id',
71 help='Sercomm hardware ID')
73 parser
.add_argument('--sw-version',
77 help='Sercomm software version')
79 parser
.add_argument('--pid-file',
83 help='Output PID file')
85 parser
.add_argument('--extra-padding-size',
86 dest
='extra_padd_size',
89 help='Size of extra NULL padding at the end of the file \
92 parser
.add_argument('--extra-padding-first-byte',
93 dest
='extra_padd_byte',
96 help='First byte of extra padding (optional)')
98 args
= parser
.parse_args()
100 if ((not args
.hw_version
) or
101 (not args
.sw_version
) or
102 (not args
.pid_file
)):
106 create_pid_file(args
)