aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-12-02 21:52:30 +0100
committerTom Rini <trini@konsulko.com>2023-12-20 10:46:54 -0500
commit400cb2a850546e8cc9246cf97f0902ffe57867ab (patch)
tree4418f6d17faf5c99111b67786097a952e05f2981
parent921f63e5723880bbbaf65429564e5638b7bbd002 (diff)
downloadu-boot-400cb2a850546e8cc9246cf97f0902ffe57867ab.zip
u-boot-400cb2a850546e8cc9246cf97f0902ffe57867ab.tar.gz
u-boot-400cb2a850546e8cc9246cf97f0902ffe57867ab.tar.bz2
command: Allocate history buffer using calloc()
The history buffer is currently a static array which can be some 10-40 kiB depending on configuration, and so adds considerably to the U-Boot binary size. Allocate it dynamically instead to reduce the U-Boot binary size. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
-rw-r--r--common/cli_readline.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 06b8d46..85453be 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -12,6 +12,8 @@
#include <bootretry.h>
#include <cli.h>
#include <command.h>
+#include <hang.h>
+#include <malloc.h>
#include <time.h>
#include <watchdog.h>
#include <asm/global_data.h>
@@ -85,7 +87,6 @@ static int hist_cur = -1;
static unsigned hist_num;
static char *hist_list[HIST_MAX];
-static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
@@ -97,8 +98,9 @@ static void getcmd_putchars(int count, int ch)
getcmd_putch(ch);
}
-static void hist_init(void)
+static int hist_init(void)
{
+ unsigned char *hist;
int i;
hist_max = 0;
@@ -106,10 +108,14 @@ static void hist_init(void)
hist_cur = -1;
hist_num = 0;
- for (i = 0; i < HIST_MAX; i++) {
- hist_list[i] = hist_lines[i];
- hist_list[i][0] = '\0';
- }
+ hist = calloc(HIST_MAX, HIST_SIZE + 1);
+ if (!hist)
+ return -ENOMEM;
+
+ for (i = 0; i < HIST_MAX; i++)
+ hist_list[i] = hist + (i * (HIST_SIZE + 1));
+
+ return 0;
}
static void cread_add_to_hist(char *line)
@@ -493,8 +499,9 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
#else /* !CONFIG_CMDLINE_EDITING */
-static inline void hist_init(void)
+static inline int hist_init(void)
{
+ return 0;
}
static int cread_line(const char *const prompt, char *buf, unsigned int *len,
@@ -643,8 +650,9 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
*/
if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
if (!initted) {
- hist_init();
- initted = 1;
+ rc = hist_init();
+ if (rc == 0)
+ initted = 1;
}
if (prompt)