All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Opaniuk <igor.opaniuk@foundries.io>
To: u-boot@lists.denx.de
Cc: Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Igor Opaniuk <igor.opaniuk@gmail.com>,
	Ivan Khoronzhuk <ivan.khoronzhuk@gmail.com>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 5/7] common: avb_verify: add str_avb_io_error/str_avb_slot_error
Date: Fri,  9 Feb 2024 20:20:43 +0100	[thread overview]
Message-ID: <20240209192045.3961832-6-igor.opaniuk@foundries.io> (raw)
In-Reply-To: <20240209192045.3961832-1-igor.opaniuk@foundries.io>

From: Igor Opaniuk <igor.opaniuk@gmail.com>

Introduce str_avb_io_error() and str_avb_slot_error() functions,
that provide a pointer to AVB runtime error message.

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
---

Changes in v2:
- Mattijs Korpershoek R-b tag applied

 common/avb_verify.c  | 49 ++++++++++++++++++++++++++++++++++++++++++++
 include/avb_verify.h |  3 ++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/common/avb_verify.c b/common/avb_verify.c
index ed58239cf8a..cff9117d92f 100644
--- a/common/avb_verify.c
+++ b/common/avb_verify.c
@@ -119,6 +119,55 @@ static const unsigned char avb_root_pub[1032] = {
 	0xd8, 0x7e,
 };
 
+const char *str_avb_io_error(AvbIOResult res)
+{
+	switch (res) {
+	case AVB_IO_RESULT_OK:
+		return "Requested operation was successful";
+	case AVB_IO_RESULT_ERROR_IO:
+		return "Underlying hardware encountered an I/O error";
+	case AVB_IO_RESULT_ERROR_OOM:
+		return "Unable to allocate memory";
+	case AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION:
+		return "Requested partition does not exist";
+	case AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION:
+		return "Bytes requested is outside the range of partition";
+	case AVB_IO_RESULT_ERROR_NO_SUCH_VALUE:
+		return "Named persistent value does not exist";
+	case AVB_IO_RESULT_ERROR_INVALID_VALUE_SIZE:
+		return "Named persistent value size is not supported";
+	case AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE:
+		return "Buffer is too small for the requested operation";
+	default:
+		return "Unknown AVB error";
+	}
+}
+
+const char *str_avb_slot_error(AvbSlotVerifyResult res)
+{
+	switch (res) {
+	case AVB_SLOT_VERIFY_RESULT_OK:
+		return "Verification passed successfully";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_OOM:
+		return "Allocation of memory failed";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_IO:
+		return "I/O error occurred while trying to load data";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION:
+		return "Digest didn't match or signature checks failed";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX:
+		return "Rollback index is less than its stored value";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED:
+		return "Public keys are not accepted";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA:
+		return "Metadata is invalid or inconsistent";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION:
+		return "Metadata requires a newer version of libavb";
+	case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_ARGUMENT:
+		return "Invalid arguments are used";
+	default:
+		return "Unknown AVB slot verification error";
+	}
+}
 /**
  * ============================================================================
  * Boot states support (GREEN, YELLOW, ORANGE, RED) and dm_verity
diff --git a/include/avb_verify.h b/include/avb_verify.h
index 2fb850044d9..5d998b5a302 100644
--- a/include/avb_verify.h
+++ b/include/avb_verify.h
@@ -52,7 +52,8 @@ char *avb_set_enforce_verity(const char *cmdline);
 char *avb_set_ignore_corruption(const char *cmdline);
 
 char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
-
+const char *str_avb_io_error(AvbIOResult res);
+const char *str_avb_slot_error(AvbSlotVerifyResult res);
 /**
  * ============================================================================
  * I/O helper inline functions
-- 
2.34.1


  parent reply	other threads:[~2024-02-09 19:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 19:20 [PATCH v2 0/7] AVB: cosmetic adjustments/improvements Igor Opaniuk
2024-02-09 19:20 ` [PATCH v2 1/7] common: avb_verify: don't call mmc_switch_part for SD Igor Opaniuk
2024-02-09 19:37   ` Dragan Simic
2024-02-12  7:05   ` Dan Carpenter
2024-02-12  8:05     ` Igor Opaniuk
2024-02-13  8:13       ` Mattijs Korpershoek
2024-02-13 11:19         ` Igor Opaniuk
2024-02-13 13:31           ` Mattijs Korpershoek
2024-02-09 19:20 ` [PATCH v2 2/7] avb: move SPDX license identifiers to the first line Igor Opaniuk
2024-02-09 19:20 ` [PATCH v2 3/7] common: avb_verify: rework error/debug prints Igor Opaniuk
2024-02-09 19:20 ` [PATCH v2 4/7] cmd: avb: rework prints Igor Opaniuk
2024-02-13  8:20   ` Mattijs Korpershoek
2024-02-09 19:20 ` Igor Opaniuk [this message]
2024-02-09 19:20 ` [PATCH v2 6/7] cmd: avb: rework do_avb_verify_part Igor Opaniuk
2024-02-09 19:20 ` [PATCH v2 7/7] doc: android: avb: sync usage details Igor Opaniuk
2024-02-13  8:22   ` Mattijs Korpershoek
2024-02-13 15:18 ` [PATCH v2 0/7] AVB: cosmetic adjustments/improvements Mattijs Korpershoek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240209192045.3961832-6-igor.opaniuk@foundries.io \
    --to=igor.opaniuk@foundries.io \
    --cc=igor.opaniuk@gmail.com \
    --cc=ivan.khoronzhuk@gmail.com \
    --cc=jens.wiklander@linaro.org \
    --cc=mkorpershoek@baylibre.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.