cli: Support macro processing with a fixed-size buffer

At present cli_simple_process_macros() requires that the caller provide
an output buffer that is exactly CONFIG_SYS_CBSIZE bytes in length. This
makes sense since it is designed to be used from the command line. But we
also want to use it for bootargs substitution.

Update the function to allow the caller to specify the buffer size. Also
return an error if the buffer is exhausted. The caller can ignore that if
preferred.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-11-05 10:33:47 -07:00 committed by Tom Rini
parent 488d89afb8
commit 1a62d64c7d
3 changed files with 19 additions and 8 deletions

View file

@ -322,7 +322,8 @@ static int label_localboot(struct pxe_label *label)
if (label->append) {
char bootargs[CONFIG_SYS_CBSIZE];
cli_simple_process_macros(label->append, bootargs);
cli_simple_process_macros(label->append, bootargs,
sizeof(bootargs));
env_set("bootargs", bootargs);
}
@ -430,7 +431,8 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
strcat(bootargs, ip_str);
strcat(bootargs, mac_str);
cli_simple_process_macros(bootargs, finalbootargs);
cli_simple_process_macros(bootargs, finalbootargs,
sizeof(finalbootargs));
env_set("bootargs", finalbootargs);
printf("append: %s\n", finalbootargs);
}