From patchwork Mon Jun 12 10:13:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ivanhu X-Patchwork-Id: 1793848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=RzZxqmwC; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QfnbT1KsRz20Vx for ; Mon, 12 Jun 2023 20:14:12 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1q8eYn-0002ik-Qk; Mon, 12 Jun 2023 10:14:05 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1q8eYl-0002ib-Vs for fwts-devel@lists.ubuntu.com; Mon, 12 Jun 2023 10:14:03 +0000 Received: from canonical.com (unknown [10.101.194.165]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 01DF53F15B for ; Mon, 12 Jun 2023 10:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1686564841; bh=PDGSkEP2y58MQH3jjqYF+F7Tm+e2LSkKYDgtylQ/EMw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RzZxqmwCPPh4vCoDrcdhULkB/4yVaQoXYoVZt/ICXPIL8I9mry2rTAgE/zetggnO1 qWn6kRxocqf/eNXgK2kgfEqSbUuqXLNcpmZHX3hvo+VzbWkU1c2/VgoMlMOSobZYzy P7DVVashp6Ls3xu0V3BI9Q5ySRdEAIx+wEvDnDeDCUZyypbgbdDhX/8HL6SlHjzlnj Iw/0pfCw/5URVULqhNEpdPjIqa0OVcA8b7nyuF+SKzoNS8l7NboPF7eoT4glV9b7Fz 7zlfqKrXpICo5LomAL0zlaQsyYENumbF8tygEGNbcYkCX/rFQ9+9JgIGhaITfhJpcU uP+gveq6eSp+A== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_dump_data: add library function for dumping all raw data with prefix Date: Mon, 12 Jun 2023 18:13:57 +0800 Message-Id: <20230612101357.60792-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" BugLink: https://bugs.launchpad.net/fwts/+bug/2023542 Signed-off-by: Ivan Hu --- src/lib/include/fwts_dump_data.h | 2 +- src/lib/src/fwts_dump_data.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib/include/fwts_dump_data.h b/src/lib/include/fwts_dump_data.h index 5e255754..c2e01606 100644 --- a/src/lib/include/fwts_dump_data.h +++ b/src/lib/include/fwts_dump_data.h @@ -24,5 +24,5 @@ void fwts_dump_raw_data(char *buffer, const size_t len, const uint8_t *data, const int where, const size_t bytes); void fwts_dump_raw_data_prefix(char *buffer, const size_t len, const uint8_t *data, const char *prefix, const size_t bytes); - +void fwts_hexdump_data_prefix_all(fwts_framework *fw, const uint8_t *data, const char *prefix, const size_t nbytes); #endif diff --git a/src/lib/src/fwts_dump_data.c b/src/lib/src/fwts_dump_data.c index 60287a9d..251e2668 100644 --- a/src/lib/src/fwts_dump_data.c +++ b/src/lib/src/fwts_dump_data.c @@ -87,3 +87,27 @@ void fwts_dump_raw_data_prefix( buffer[n] = '\0'; } + +/* + * fwts_hexdump_data_prefix_all() + * print all raw uint8 data of length `nbytes` as a hex dump with prefix. + * The prefix could be used as alighment. + */ +void fwts_hexdump_data_prefix_all( + fwts_framework *fw, + const uint8_t *data, /* Octects to dump */ + const char *prefix, /* Prefix string or for alignment for each line */ + const size_t nbytes) /* Number of bytes to dump for all data */ +{ + + size_t i; + + for (i = 0; i < nbytes; i += 16) { + char buffer[128]; + const size_t left = nbytes - i; + + fwts_dump_raw_data_prefix(buffer, sizeof(buffer), data + i, prefix, left > 16 ? 16 : left); + fwts_log_info_verbatim(fw, "%s", buffer); + } +} +