diff mbox

[U-Boot,11/14] mkimage: Allow display of a list of any image header category

Message ID 1467305540-13607-12-git-send-email-sjg@chromium.org
State Accepted
Commit 306642251234f68f14fa9e86b9f5df6a88632817
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass June 30, 2016, 4:52 p.m. UTC
Add a generic function which can display a list of items in any category.
This will allow displaying of images for the -A, -C, -O and -T flags. At
present only -T is supported.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/mkimage.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Tom Rini July 2, 2016, 1:36 a.m. UTC | #1
On Thu, Jun 30, 2016 at 10:52:17AM -0600, Simon Glass wrote:

> Add a generic function which can display a list of items in any category.
> This will allow displaying of images for the -A, -C, -O and -T flags. At
> present only -T is supported.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@konsulko.com>
Tom Rini July 16, 2016, 1:49 p.m. UTC | #2
On Thu, Jun 30, 2016 at 10:52:17AM -0600, Simon Glass wrote:

> Add a generic function which can display a list of items in any category.
> This will allow displaying of images for the -A, -C, -O and -T flags. At
> present only -T is supported.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Tom Rini <trini@konsulko.com>

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

Patch

diff --git a/tools/mkimage.c b/tools/mkimage.c
index 920d3be..d375c2a 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -25,6 +25,49 @@  static struct image_tool_params params = {
 	.imagename2 = "",
 };
 
+static enum ih_category cur_category;
+
+static int h_compare_category_name(const void *vtype1, const void *vtype2)
+{
+	const int *type1 = vtype1;
+	const int *type2 = vtype2;
+	const char *name1 = genimg_get_cat_short_name(cur_category, *type1);
+	const char *name2 = genimg_get_cat_short_name(cur_category, *type2);
+
+	return strcmp(name1, name2);
+}
+
+int show_valid_options(enum ih_category category)
+{
+	int *order;
+	int count;
+	int item;
+	int i;
+
+	count = genimg_get_cat_count(category);
+	order = calloc(count, sizeof(*order));
+	if (!order)
+		return -ENOMEM;
+
+	/* Sort the names in order of short name for easier reading */
+	for (item = 0; item < count; item++)
+		order[item] = item;
+	cur_category = category;
+	qsort(order, count, sizeof(int), h_compare_category_name);
+
+	fprintf(stderr, "\nInvalid %s, supported are:\n",
+		genimg_get_cat_desc(category));
+	for (i = 0; i < count; i++) {
+		item = order[i];
+		fprintf(stderr, "\t%-15s  %s\n",
+			genimg_get_cat_short_name(category, item),
+			genimg_get_cat_name(category, item));
+	}
+	fprintf(stderr, "\n");
+
+	return 0;
+}
+
 static int h_compare_image_name(const void *vtype1, const void *vtype2)
 {
 	const int *type1 = vtype1;