From 0cb1dc02771ce1c4cad20017a6d5616718db3877 Mon Sep 17 00:00:00 2001 From: Mikhail Zhilkin Date: Sat, 19 Mar 2022 19:35:51 +0000 Subject: [PATCH] scripts: add support for Sercomm PID This scripts creates Sercomm PID file. PID is necessary for the factory images creation of variuos Sercomm-based devices (Beeline, Netgear, Etisalat). Size: 0x70 +-------+------+---------------+------------------+ | Start | Size | Value* (ASCII)| Description | +=======+======+===============+==================+ | 0x0 | 0x8 | 10100 | Hardware version | +-------+------+---------------+------------------+ | 0x8 | 0x8 | 444245 (DBE) | Hardware ID | +-------+------+---------------+------------------+ | 0x64 | 0x4 | 1002 | Software version | +-------+------+---------------+------------------+ *for Beeline Smartbox GIGA Signed-off-by: Mikhail Zhilkin --- scripts/sercomm-pid.py | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 scripts/sercomm-pid.py diff --git a/scripts/sercomm-pid.py b/scripts/sercomm-pid.py new file mode 100755 index 0000000000..b89977a5b9 --- /dev/null +++ b/scripts/sercomm-pid.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +""" +# SPDX-License-Identifier: GPL-2.0-or-later +# +# sercomm-pid.py: Creates Sercomm device PID +# +# Copyright © 2022 Mikhail Zhilkin +""" + +import argparse +import binascii +import struct + +PID_SIZE = 0x70 +PADDING = 0x30 +PADDING_TAIL = 0x0 + +def auto_int(x): + return int(x, 0) + +def create_pid_file(args): + pid_file = open(args.pid_file, "wb") + buf = get_pid(args) + pid_file.write(buf) + pid_file.close() + +def get_pid(args): + buf = bytearray([PADDING] * PID_SIZE) + + enc = args.hw_version.rjust(8, '0').encode('ascii') + struct.pack_into('>8s', buf, 0x0, enc) + + enc = binascii.hexlify(args.hw_id.encode()) + struct.pack_into('>6s', buf, 0x8, enc) + + enc = args.sw_version.rjust(4, '0').encode('ascii') + struct.pack_into('>4s', buf, 0x64, enc) + + if (args.extra_padd_size): + tail = bytearray([PADDING_TAIL] * args.extra_padd_size) + if (args.extra_padd_byte): + struct.pack_into ('