All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 07/18] mkimage: Display a better list of available image types
Date: Tue, 12 May 2015 14:55:08 -0600	[thread overview]
Message-ID: <1431464119-21574-8-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1431464119-21574-1-git-send-email-sjg@chromium.org>

Offer to display the available image types in help. Also, rather than
hacking the genimg_get_type_id() function to display a list of types,
do this in the tool. Also, sort the list.

The list of image types is quite long, and hard to discover. Print it out
when we show help information.

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

Changes in v2: None

 common/image.c  | 58 +++++++++++++++++++++++++++++++-------------------------
 include/image.h | 11 +++++++++++
 tools/mkimage.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 95 insertions(+), 33 deletions(-)

diff --git a/common/image.c b/common/image.c
index fdec496..d18e02d 100644
--- a/common/image.c
+++ b/common/image.c
@@ -543,6 +543,15 @@ void genimg_print_time(time_t timestamp)
 }
 #endif
 
+const table_entry_t *get_table_entry(const table_entry_t *table, int id)
+{
+	for (; table->id >= 0; ++table) {
+		if (table->id == id)
+			return table;
+	}
+	return NULL;
+}
+
 /**
  * get_table_entry_name - translate entry id to long name
  * @table: pointer to a translation table for entries of a specific type
@@ -559,15 +568,14 @@ void genimg_print_time(time_t timestamp)
  */
 char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
 {
-	for (; table->id >= 0; ++table) {
-		if (table->id == id)
+	table = get_table_entry(table, id);
+	if (!table)
+		return msg;
 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
-			return table->lname;
+	return table->lname;
 #else
-			return table->lname + gd->reloc_off;
+	return table->lname + gd->reloc_off;
 #endif
-	}
-	return (msg);
 }
 
 const char *genimg_get_os_name(uint8_t os)
@@ -586,6 +594,20 @@ const char *genimg_get_type_name(uint8_t type)
 	return (get_table_entry_name(uimage_type, "Unknown Image", type));
 }
 
+const char *genimg_get_type_short_name(uint8_t type)
+{
+	const table_entry_t *table;
+
+	table = get_table_entry(uimage_type, type);
+	if (!table)
+		return "unknown";
+#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
+	return table->sname;
+#else
+	return table->sname + gd->reloc_off;
+#endif
+}
+
 const char *genimg_get_comp_name(uint8_t comp)
 {
 	return (get_table_entry_name(uimage_comp, "Unknown Compression",
@@ -610,34 +632,18 @@ int get_table_entry_id(const table_entry_t *table,
 		const char *table_name, const char *name)
 {
 	const table_entry_t *t;
-#ifdef USE_HOSTCC
-	int first = 1;
-
-	for (t = table; t->id >= 0; ++t) {
-		if (t->sname && strcasecmp(t->sname, name) == 0)
-			return(t->id);
-	}
 
-	fprintf(stderr, "\nInvalid %s Type - valid names are", table_name);
-	for (t = table; t->id >= 0; ++t) {
-		if (t->sname == NULL)
-			continue;
-		fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname);
-		first = 0;
-	}
-	fprintf(stderr, "\n");
-#else
 	for (t = table; t->id >= 0; ++t) {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
-		if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
+		if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0)
 #else
-		if (t->sname && strcmp(t->sname, name) == 0)
+		if (t->sname && strcasecmp(t->sname, name) == 0)
 #endif
 			return (t->id);
 	}
 	debug("Invalid %s Type: %s\n", table_name, name);
-#endif /* USE_HOSTCC */
-	return (-1);
+
+	return -1;
 }
 
 int genimg_get_os_id(const char *name)
diff --git a/include/image.h b/include/image.h
index 60b924a..a4a8ff6 100644
--- a/include/image.h
+++ b/include/image.h
@@ -245,6 +245,8 @@ struct lmb;
 #define IH_TYPE_X86_SETUP	20	/* x86 setup.bin Image		*/
 #define IH_TYPE_LPC32XXIMAGE	21	/* x86 setup.bin Image		*/
 
+#define IH_TYPE_COUNT		22	/* Number of image types */
+
 /*
  * Compression Types
  */
@@ -410,6 +412,15 @@ char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
 const char *genimg_get_os_name(uint8_t os);
 const char *genimg_get_arch_name(uint8_t arch);
 const char *genimg_get_type_name(uint8_t type);
+
+/**
+ * genimg_get_type_short_name() - get the short name for an image type
+ *
+ * @param type	Image type (IH_TYPE_...)
+ * @return image short name, or "unknown" if unknown
+ */
+const char *genimg_get_type_short_name(uint8_t type);
+
 const char *genimg_get_comp_name(uint8_t comp);
 int genimg_get_os_id(const char *name);
 int genimg_get_arch_id(const char *name);
diff --git a/tools/mkimage.c b/tools/mkimage.c
index 5ccd951..8808d70 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -26,8 +26,48 @@ struct image_tool_params params = {
 	.imagename2 = "",
 };
 
-int
-main (int argc, char **argv)
+static int h_compare_image_name(const void *vtype1, const void *vtype2)
+{
+	const int *type1 = vtype1;
+	const int *type2 = vtype2;
+	const char *name1 = genimg_get_type_short_name(*type1);
+	const char *name2 = genimg_get_type_short_name(*type2);
+
+	return strcmp(name1, name2);
+}
+
+/* Show all image types supported by mkimage */
+static void show_image_types(void)
+{
+	struct image_type_params *tparams;
+	int order[IH_TYPE_COUNT];
+	int count;
+	int type;
+	int i;
+
+	/* Sort the names in order of short name for easier reading */
+	memset(order, '\0', sizeof(order));
+	for (count = 0, type = 0; type < IH_TYPE_COUNT; type++) {
+		tparams = imagetool_get_type(type);
+		if (tparams)
+			order[count++] = type;
+	}
+	qsort(order, count, sizeof(int), h_compare_image_name);
+
+	fprintf(stderr, "\nInvalid image type. Supported image types:\n");
+	for (i = 0; i < count; i++) {
+		type = order[i];
+		tparams = imagetool_get_type(type);
+		if (tparams) {
+			fprintf(stderr, "\t%-15s  %s\n",
+				genimg_get_type_short_name(type),
+				genimg_get_type_name(type));
+		}
+	}
+	fprintf(stderr, "\n");
+}
+
+int main(int argc, char **argv)
 {
 	int ifd = -1;
 	struct stat sbuf;
@@ -75,12 +115,16 @@ main (int argc, char **argv)
 					usage ();
 				goto NXTARG;
 			case 'T':
-				if ((--argc <= 0) ||
-					(params.type =
-					genimg_get_type_id (*++argv)) < 0)
-					usage ();
+				params.type = -1;
+				if (--argc >= 0 && argv[1]) {
+					params.type =
+						genimg_get_type_id(*++argv);
+				}
+				if (params.type < 0) {
+					show_image_types();
+					usage();
+				}
 				goto NXTARG;
-
 			case 'a':
 				if (--argc <= 0)
 					usage ();
@@ -546,6 +590,7 @@ static void usage(void)
 #endif
 	fprintf (stderr, "       %s -V ==> print version information and exit\n",
 		params.cmdname);
+	fprintf(stderr, "Use -T to see a list of available image types\n");
 
 	exit (EXIT_FAILURE);
 }
-- 
2.2.0.rc0.207.ga3a616c

  parent reply	other threads:[~2015-05-12 20:55 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 20:55 [U-Boot] [PATCH v2 00/18] dm: Introduce device tree support in SPL (for Rockchip) Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 01/18] dm: ns16550: Support CONFIG_SYS_NS16550_MEM32 with driver model Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 02/18] fdt: arm: Drop device tree padding Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 03/18] dts: Disable device tree for SPL on all boards Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 04/18] dm: serial: Don't support CONFIG_CONS_INDEX with device tree Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 05/18] Add a simple version of memalign() Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 06/18] Remove SPL undefine of CONFIG_OF_CONTROL Simon Glass
2015-06-11 20:19   ` Simon Glass
2015-05-12 20:55 ` Simon Glass [this message]
2015-05-12 20:55 ` [U-Boot] [PATCH v2 08/18] fdt: Add a function to remove unused strings from a device tree Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 09/18] fdt: Add fdt_first/next_region() functions Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 10/18] fdt: Add fdtgrep tool Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 11/18] dm: Reduce SPL device tree size Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 12/18] dm: rockchip: Add serial support Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 13/18] rockchip: Bring in RK3288 device tree file includes and bindings Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 14/18] rockchip: Add base SoC files Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 15/18] rockchip: Add basic support for firefly-rk3288 Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 16/18] rockchip: Add the beginnings of an image tool Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 17/18] rockchip: Add a simple README Simon Glass
2015-05-12 20:55 ` [U-Boot] [PATCH v2 18/18] rockchip: Add basic support for jerry Simon Glass
2015-06-04 23:48 ` [U-Boot] [PATCH v2 00/18] dm: Introduce device tree support in SPL (for Rockchip) Simon Glass
2015-06-11  2:50   ` Simon Glass
2015-06-11 12:15     ` Tom Rini

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=1431464119-21574-8-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --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.