diff mbox series

[1/3] image: Add a function to modify category information

Message ID ccb802ae-6d11-a62c-d7ed-3513565380d3@lineo.co.jp
State Accepted
Commit 02d41b01bd78dc863614c2919375f366abdeff40
Delegated to: Tom Rini
Headers show
Series mkimage: modify show_valid_options for usability | expand

Commit Message

Naoki Hayama Oct. 7, 2020, 2:21 a.m. UTC
Add a generic function which can check whether a category has an
entry ID.

Signed-off-by: Naoki Hayama <naoki.hayama@lineo.co.jp>
---

 common/image.c  | 18 ++++++++++++++++++
 include/image.h |  9 +++++++++
 2 files changed, 27 insertions(+)

Comments

Simon Glass Oct. 12, 2020, 3:34 a.m. UTC | #1
On Tue, 6 Oct 2020 at 20:21, Naoki Hayama <naoki.hayama@lineo.co.jp> wrote:
>
> Add a generic function which can check whether a category has an
> entry ID.
>
> Signed-off-by: Naoki Hayama <naoki.hayama@lineo.co.jp>
> ---
>
>  common/image.c  | 18 ++++++++++++++++++
>  include/image.h |  9 +++++++++
>  2 files changed, 27 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Oct. 23, 2020, 12:27 a.m. UTC | #2
On Wed, Oct 07, 2020 at 11:21:25AM +0900, Naoki Hayama wrote:

> Add a generic function which can check whether a category has an
> entry ID.
> 
> Signed-off-by: Naoki Hayama <naoki.hayama@lineo.co.jp>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/image.c b/common/image.c
index 645bfef169..4fc4a0f1c4 100644
--- a/common/image.c
+++ b/common/image.c
@@ -858,6 +858,24 @@  const char *genimg_get_cat_desc(enum ih_category category)
 	return table_info[category].desc;
 }
 
+/**
+ * genimg_cat_has_id - check whether category has entry id
+ * @category: category to look up (enum ih_category)
+ * @id: entry id to be checked
+ *
+ * This will scan the translation table trying to find the entry that matches
+ * the given id.
+ *
+ * @return true if category has entry id; false if not
+ */
+bool genimg_cat_has_id(enum ih_category category, uint id)
+{
+	if (get_table_entry(table_info[category].table, id))
+		return true;
+
+	return false;
+}
+
 /**
  * get_table_entry_name - translate entry id to long name
  * @table: pointer to a translation table for entries of a specific type
diff --git a/include/image.h b/include/image.h
index 9a5a87dbf8..6222057f27 100644
--- a/include/image.h
+++ b/include/image.h
@@ -568,6 +568,15 @@  int genimg_get_cat_count(enum ih_category category);
  */
 const char *genimg_get_cat_desc(enum ih_category category);
 
+/**
+ * genimg_cat_has_id() - Check whether a category has an item
+ *
+ * @category:	Category to check
+ * @id:		Item ID
+ * @return true or false as to whether a category has an item
+ */
+bool genimg_cat_has_id(enum ih_category category, uint id);
+
 int genimg_get_os_id(const char *name);
 int genimg_get_arch_id(const char *name);
 int genimg_get_type_id(const char *name);