[U-Boot] [PATCH v2 18/27] image: Add functions to obtain short names

Simon Glass sjg at chromium.org
Tue Feb 23 06:55:50 CET 2016


Sometimes it is useful to obtain the short name for an Operating System,
architecture or compression mechanism. Provide functions for this.

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

Changes in v2: None

 common/image.c  | 26 ++++++++++++++++++++++----
 include/image.h | 27 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/common/image.c b/common/image.c
index 7d3a543..26d6c9a 100644
--- a/common/image.c
+++ b/common/image.c
@@ -608,11 +608,9 @@ 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)
+static const char *genimg_get_short_name(const table_entry_t *table, int val)
 {
-	const table_entry_t *table;
-
-	table = get_table_entry(uimage_type, type);
+	table = get_table_entry(table, val);
 	if (!table)
 		return "unknown";
 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
@@ -622,12 +620,32 @@ const char *genimg_get_type_short_name(uint8_t type)
 #endif
 }
 
+const char *genimg_get_type_short_name(uint8_t type)
+{
+	return genimg_get_short_name(uimage_type, type);
+}
+
 const char *genimg_get_comp_name(uint8_t comp)
 {
 	return (get_table_entry_name(uimage_comp, "Unknown Compression",
 					comp));
 }
 
+const char *genimg_get_comp_short_name(uint8_t comp)
+{
+	return genimg_get_short_name(uimage_comp, comp);
+}
+
+const char *genimg_get_os_short_name(uint8_t os)
+{
+	return genimg_get_short_name(uimage_os, os);
+}
+
+const char *genimg_get_arch_short_name(uint8_t arch)
+{
+	return genimg_get_short_name(uimage_arch, arch);
+}
+
 /**
  * get_table_entry_id - translate short entry name to id
  * @table: pointer to a translation table for entries of a specific type
diff --git a/include/image.h b/include/image.h
index 78dcac7..6b86119 100644
--- a/include/image.h
+++ b/include/image.h
@@ -413,7 +413,25 @@ int get_table_entry_id(const table_entry_t *table,
 char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
 
 const char *genimg_get_os_name(uint8_t os);
+
+/**
+ * genimg_get_os_short_name() - get the short name for an OS
+ *
+ * @param os	OS (IH_OS_...)
+ * @return OS short name, or "unknown" if unknown
+ */
+const char *genimg_get_os_short_name(uint8_t comp);
+
 const char *genimg_get_arch_name(uint8_t arch);
+
+/**
+ * genimg_get_arch_short_name() - get the short name for an architecture
+ *
+ * @param arch	Architecture type (IH_ARCH_...)
+ * @return architecture short name, or "unknown" if unknown
+ */
+const char *genimg_get_arch_short_name(uint8_t arch);
+
 const char *genimg_get_type_name(uint8_t type);
 
 /**
@@ -425,6 +443,15 @@ const char *genimg_get_type_name(uint8_t type);
 const char *genimg_get_type_short_name(uint8_t type);
 
 const char *genimg_get_comp_name(uint8_t comp);
+
+/**
+ * genimg_get_comp_short_name() - get the short name for a compression method
+ *
+ * @param comp	compression method (IH_COMP_...)
+ * @return compression method short name, or "unknown" if unknown
+ */
+const char *genimg_get_comp_short_name(uint8_t comp);
+
 int genimg_get_os_id(const char *name);
 int genimg_get_arch_id(const char *name);
 int genimg_get_type_id(const char *name);
-- 
2.7.0.rc3.207.g0ac5344



More information about the U-Boot mailing list