cbfstool: Factor out compression algorithm list
Parse compression algorithm arguments using a single list. Change-Id: Idc5b14a53377b29964f24221e42db6e09a497d48 Signed-off-by: Sol Boucher <solb@chromium.org> Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Change-Id: I1a117a9473e895feaf455bb30d0f945f57de51eb Original-Signed-off-by: Sol Boucher <solb@chromium.org> Reviewed-on: http://review.coreboot.org/10931 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
parent
6533671ce0
commit
ec42486055
|
@ -96,11 +96,23 @@ static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t t
|
||||||
return default_value;
|
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)
|
static const char *get_cbfs_entry_type_name(uint32_t type)
|
||||||
{
|
{
|
||||||
return lookup_name_by_type(types_cbfs_entry, type, "(unknown)");
|
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 */
|
/* CBFS image */
|
||||||
|
|
||||||
static size_t cbfs_calculate_file_header_size(const char *name)
|
static size_t cbfs_calculate_file_header_size(const char *name)
|
||||||
|
|
|
@ -32,6 +32,10 @@ struct cbfs_image {
|
||||||
struct cbfs_header header;
|
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
|
/* Given a pointer, serialize the header from host-native byte format
|
||||||
* to cbfs format, i.e. big-endian. */
|
* to cbfs format, i.e. big-endian. */
|
||||||
void cbfs_put_header(void *dest, const struct cbfs_header *header);
|
void cbfs_put_header(void *dest, const struct cbfs_header *header);
|
||||||
|
|
|
@ -973,15 +973,15 @@ int main(int argc, char **argv)
|
||||||
WARN("Unknown type '%s' ignored\n",
|
WARN("Unknown type '%s' ignored\n",
|
||||||
optarg);
|
optarg);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c': {
|
||||||
if (!strncasecmp(optarg, "lzma", 5))
|
int algo = cbfs_parse_comp_algo(optarg);
|
||||||
param.compression = CBFS_COMPRESS_LZMA;
|
if (algo >= 0)
|
||||||
else if (!strncasecmp(optarg, "none", 5))
|
param.compression = algo;
|
||||||
param.compression = CBFS_COMPRESS_NONE;
|
|
||||||
else
|
else
|
||||||
WARN("Unknown compression '%s'"
|
WARN("Unknown compression '%s' ignored.\n",
|
||||||
" ignored.\n", optarg);
|
optarg);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'M':
|
case 'M':
|
||||||
param.fmap = optarg;
|
param.fmap = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue