tools/crypto/ccp/dbc_cli.py

Source file repositories/reference/linux-study-clean/tools/crypto/ccp/dbc_cli.py

File Facts

System
Linux kernel
Corpus path
tools/crypto/ccp/dbc_cli.py
Extension
.py
Size
4637 bytes
Lines
135
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0
import argparse
import binascii
import os
import errno
from dbc import *

ERRORS = {
    errno.EACCES: "Access is denied",
    errno.E2BIG: "Excess data provided",
    errno.EINVAL: "Bad parameters",
    errno.EAGAIN: "Bad state",
    errno.ENOENT: "Not implemented or message failure",
    errno.EBUSY: "Busy",
    errno.ENFILE: "Overflow",
    errno.EPERM: "Signature invalid",
}

messages = {
    "get-fmax-cap": PARAM_GET_FMAX_CAP,
    "set-fmax-cap": PARAM_SET_FMAX_CAP,
    "get-power-cap": PARAM_GET_PWR_CAP,
    "set-power-cap": PARAM_SET_PWR_CAP,
    "get-graphics-mode": PARAM_GET_GFX_MODE,
    "set-graphics-mode": PARAM_SET_GFX_MODE,
    "get-current-temp": PARAM_GET_CURR_TEMP,
    "get-fmax-max": PARAM_GET_FMAX_MAX,
    "get-fmax-min": PARAM_GET_FMAX_MIN,
    "get-soc-power-max": PARAM_GET_SOC_PWR_MAX,
    "get-soc-power-min": PARAM_GET_SOC_PWR_MIN,
    "get-soc-power-cur": PARAM_GET_SOC_PWR_CUR,
}


def _pretty_buffer(ba):
    return str(binascii.hexlify(ba, " "))


def parse_args():
    parser = argparse.ArgumentParser(
        description="Dynamic Boost control command line interface"
    )
    parser.add_argument(
        "command",
        choices=["get-nonce", "get-param", "set-param", "set-uid"],
        help="Command to send",
    )
    parser.add_argument("--device", default="/dev/dbc", help="Device to operate")
    parser.add_argument("--signature", help="File containing signature for command")
    parser.add_argument("--message", choices=messages.keys(), help="Message index")
    parser.add_argument("--data", help="Argument to pass to message")
    parser.add_argument("--uid", help="File containing UID to pass")
    return parser.parse_args()


def pretty_error(code):
    if code in ERRORS:
        print(ERRORS[code])
    else:
        print("failed with return code %d" % code)


if __name__ == "__main__":
    args = parse_args()
    data = 0
    sig = None
    uid = None
    if not os.path.exists(args.device):
        raise IOError("Missing device {device}".format(device=args.device))

Annotation

Implementation Notes