cert_create: update help message
The help message printed by the cert_create tool using the command
line option -h (or --help) does not correctly list all the available
command line options.
This patch reworks the print_help() function to print the help
messages in a data driven approach. For each command line option
registered, an optional help message can be specified, which will
be printed by print_help().
Help messages for the TBBR options (certificates, keys and images)
are also provided.
Fix a small bug in the short options string passed to getopt_long:
the ':' was missing in the '-a' option (this option must take an
argument).
Fixes ARM-software/tf-issues#337
Change-Id: I9d08c2dfd349022808fcc884724f677eefdc1452
diff --git a/tools/cert_create/src/cmd_opt.c b/tools/cert_create/src/cmd_opt.c
index 3847b98..ecf84ab 100644
--- a/tools/cert_create/src/cmd_opt.c
+++ b/tools/cert_create/src/cmd_opt.c
@@ -28,26 +28,35 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <assert.h>
#include <getopt.h>
#include <stddef.h>
+#include <stdlib.h>
#include <cmd_opt.h>
+#include "debug.h"
/* Command line options */
static struct option long_opt[CMD_OPT_MAX_NUM+1];
+static const char *help_msg[CMD_OPT_MAX_NUM+1];
static int num_reg_opt;
-int cmd_opt_add(const char *name, int has_arg, int val)
+void cmd_opt_add(const cmd_opt_t *cmd_opt)
{
+ assert(cmd_opt != NULL);
+
if (num_reg_opt >= CMD_OPT_MAX_NUM) {
- return -1;
+ ERROR("Out of memory. Please increase CMD_OPT_MAX_NUM\n");
+ exit(1);
}
- long_opt[num_reg_opt].name = name;
- long_opt[num_reg_opt].has_arg = has_arg;
+
+ long_opt[num_reg_opt].name = cmd_opt->long_opt.name;
+ long_opt[num_reg_opt].has_arg = cmd_opt->long_opt.has_arg;
long_opt[num_reg_opt].flag = 0;
- long_opt[num_reg_opt].val = val;
- num_reg_opt++;
+ long_opt[num_reg_opt].val = cmd_opt->long_opt.val;
- return 0;
+ help_msg[num_reg_opt] = cmd_opt->help_msg;
+
+ num_reg_opt++;
}
const struct option *cmd_opt_get_array(void)
@@ -63,3 +72,12 @@
return long_opt[idx].name;
}
+
+const char *cmd_opt_get_help_msg(int idx)
+{
+ if (idx >= num_reg_opt) {
+ return NULL;
+ }
+
+ return help_msg[idx];
+}