summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/cbfstool/cbfs_image.c12
-rw-r--r--util/cbfstool/cbfs_image.h4
-rw-r--r--util/cbfstool/cbfstool.c14
3 files changed, 23 insertions, 7 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 783999ce9b..f5fddcbe43 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -96,11 +96,23 @@ static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t t
return default_value;
}
+static int lookup_type_by_name(const struct typedesc_t *desc, const char *name)
+{
+ int i;
+ for (i = 0; desc[i].name && strcasecmp(name, desc[i].name); ++i);
+ return desc[i].name ? (int)desc[i].type : -1;
+}
+
static const char *get_cbfs_entry_type_name(uint32_t type)
{
return lookup_name_by_type(types_cbfs_entry, type, "(unknown)");
}
+int cbfs_parse_comp_algo(const char *name)
+{
+ return lookup_type_by_name(types_cbfs_compression, name);
+}
+
/* CBFS image */
static size_t cbfs_calculate_file_header_size(const char *name)
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 5df5dd271a..cb2935b754 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -32,6 +32,10 @@ struct cbfs_image {
struct cbfs_header header;
};
+/* Given the string name of a compression algorithm, return the corresponding
+ * enum comp_algo if it's supported, or a number < 0 otherwise. */
+int cbfs_parse_comp_algo(const char *name);
+
/* Given a pointer, serialize the header from host-native byte format
* to cbfs format, i.e. big-endian. */
void cbfs_put_header(void *dest, const struct cbfs_header *header);
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index cae1227200..b6a486fd37 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -973,15 +973,15 @@ int main(int argc, char **argv)
WARN("Unknown type '%s' ignored\n",
optarg);
break;
- case 'c':
- if (!strncasecmp(optarg, "lzma", 5))
- param.compression = CBFS_COMPRESS_LZMA;
- else if (!strncasecmp(optarg, "none", 5))
- param.compression = CBFS_COMPRESS_NONE;
+ case 'c': {
+ int algo = cbfs_parse_comp_algo(optarg);
+ if (algo >= 0)
+ param.compression = algo;
else
- WARN("Unknown compression '%s'"
- " ignored.\n", optarg);
+ WARN("Unknown compression '%s' ignored.\n",
+ optarg);
break;
+ }
case 'M':
param.fmap = optarg;
break;