+ (void) flag;
+
+ cmd_tbl_t *tbl_start = get_cmd_tbl_base(cmdtp);
+
+ char *optenv = getenv_str(PSTR("cmd"));
+ bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
+
+ if (argc == 1) { /*show list of commands */
+ int cmd_items = cmd_tbl_item_count(tbl_start);
+ cmd_tbl_t *cmd_array[cmd_items];
+ cmd_tbl_t *tp = tbl_start;
+ uint_fast8_t max_len = 0;
+
+ /* Make array of commands from .uboot_cmd section */
+ for (int i = 0; i < cmd_items; i++) {
+ cmd_array[i] = tp++;
+ uint_fast8_t l = strlen_P(cmd_array[i]->name);
+ if (l > max_len)
+ max_len = l;
+ }
+
+ /* Sort command list */
+ qsort(cmd_array, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
+
+ /* print short help (usage) */
+ for (int i = 0; i < cmd_items; i++) {
+ if (opt_debug || cmd_array[i]->name[0] != '!') {
+ const FLASH char *usage = cmd_array[i]->usage;
+
+ /* allow user abort */
+ if (ctrlc ())
+ return CMD_RET_FAILURE;
+ if (usage == NULL)
+ continue;
+#if defined(GCC_BUG_61443) || 1
+ print_usage_line(cmd_array[i]->name, max_len, usage);
+#else
+ printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"),
+ cmd_array[i]->name, usage);
+#endif
+ }
+ }
+ return CMD_RET_SUCCESS;
+ }
+
+ /*
+ * command help (long version)
+ */
+ for (uint8_t i = 1; i < argc; ++i) {
+ if ((cmdtp = find_cmd(argv[i], tbl_start)) != NULL &&
+ (opt_debug || cmdtp->name[0] != '!')) {
+ cmd_usage(cmdtp);
+ } else {
+ printf_P(PSTR("Unknown command '%s' - try 'help'"
+ " without arguments.\n\n"), argv[i]
+ );
+ return CMD_RET_FAILURE;
+ }
+ }
+
+ return CMD_RET_SUCCESS;