Revise UDI

Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
Daniel Lublin 2023-01-05 14:10:49 +01:00
parent 21fffd3fed
commit f3c4e6c818
No known key found for this signature in database
GPG Key ID: 75BD0FEB8D3E7830
2 changed files with 20 additions and 15 deletions

View File

@ -332,7 +332,7 @@ Response to `FW_CMD_GET_UDI`.
|--------|----------------|-----------------------------------------------------|
| status | 1 | `STATUS_OK`/`STATUS_BAD` |
| udi | 4 | Integer (LE) with Reserved (4 bit), Vendor (2 byte),|
| | | Product (1 byte), Revision (4 bit) |
| | | Product ID (6 bit), Product Revision (6 bit) |
| udi | 4 | Integer serial number (LE) |

View File

@ -8,7 +8,7 @@
#
# The tool use HKDF (RFC5869) to generate the UDS.
#
# Copyright (C) 2022 - Tillitis AB
# Copyright (C) 2022, 2023 - Tillitis AB
# SPDX-License-Identifier: GPL-2.0-only
#
#=======================================================================
@ -20,6 +20,11 @@ from secrets import token_bytes
from binascii import unhexlify
from hkdf import Hkdf
VID_MAX = 2**16 - 1
PID_MAX = 2**6 - 1
REV_MAX = 2**6 - 1
SERIAL_MAX_EXPR = "(2**32-1)"
SERIAL_MAX = eval(SERIAL_MAX_EXPR)
#-------------------------------------------------------------------
#-------------------------------------------------------------------
@ -63,23 +68,23 @@ def gen_udi(verbose, pid, vid, rev, serial):
print("Generating UDI")
if vid == None:
vid = int(input("Enter Vendor ID (0 -- 65535): "))
vid = int(input("Enter Vendor ID (0 -- %d): " % VID_MAX))
if pid == None:
pid = int(input("Enter Product ID (0 -- 255): "))
pid = int(input("Enter Product ID (0 -- %d): " % PID_MAX))
if rev == None:
rev = int(input("Enter revision (0 -- 15): "))
rev = int(input("Enter Product Revision (0 -- %d): " % REV_MAX))
if serial == None:
serial = int(input("Enter serial number (0 -- (2**32 -1)): "))
serial = int(input("Enter serial number (0 -- %d %s): " % (SERIAL_MAX, SERIAL_MAX_EXPR)))
assert vid < 65536
assert pid < 256
assert rev < 16
assert serial < 2**32
assert vid <= VID_MAX
assert pid <= PID_MAX
assert rev <= REV_MAX
assert serial <= SERIAL_MAX
udi_hex = ("0%04x%02x%1x%08x" % (vid, pid, rev, serial))
udi_hex = "0%04x%03x%08x" % (vid, pid << 6 | rev, serial)
if verbose:
print("\nGenerated UDI:")
@ -108,10 +113,10 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="Verbose operation", action="store_true")
parser.add_argument("--ent", help="User supplied entropy", type=str)
parser.add_argument("--vid", help="Vendor id (0 -- 65535)", type=int)
parser.add_argument("--pid", help="Product id (0 -- 255", type=int)
parser.add_argument("--rev", help="Revision number (0 -- 15)", type=int)
parser.add_argument("--serial", help="Serial number (0 -- (2**31 - 1))", type=int)
parser.add_argument("--vid", help="Vendor ID (0 -- %d)" % VID_MAX, type=int)
parser.add_argument("--pid", help="Product ID (0 -- %d" % PID_MAX, type=int)
parser.add_argument("--rev", help="Product Revision (0 -- %d)" % REV_MAX, type=int)
parser.add_argument("--serial", help="Serial number (0 -- %d %s)" % (SERIAL_MAX, SERIAL_MAX_EXPR), type=int)
args = parser.parse_args()
if args.verbose: