summaryrefslogtreecommitdiff
path: root/common/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/system.c')
-rw-r--r--common/system.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/common/system.c b/common/system.c
index 61ef4882fc..036de2235e 100644
--- a/common/system.c
+++ b/common/system.c
@@ -27,6 +27,7 @@
#include "mpu.h"
#endif
#include "panic.h"
+#include "shared_mem.h"
#include "sysjump.h"
#include "system.h"
#include "task.h"
@@ -1016,15 +1017,19 @@ DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate,
static void print_build_string(void)
{
const char *full_build_string;
- const char *p;
+ char *p;
char symbol;
+ char *next;
+ int index;
+ size_t len;
int seen_colonv;
ccprintf("Build: ");
full_build_string = system_get_build_info();
+ len = strlen(full_build_string);
/* 50 characters or less, will fit into the terminal line. */
- if (strlen(full_build_string) < 50) {
+ if (len < 50) {
ccprintf("%s\n", full_build_string);
return;
}
@@ -1034,24 +1039,41 @@ static void print_build_string(void)
* space (this is where the main version ends), and then on each space
* after the ":v" substring, this is where subcomponent versions are
* separated.
+ *
+ * To avoid invoking ccprintf() for one character at a time let's
+ * create a mutable copy and modify it to print in multiple lines.
*/
- p = full_build_string;
+ if (shared_mem_acquire(len + 1, &p) != EC_SUCCESS) {
+ /*
+ * Should never happen, but if it does let's
+ * just print it in single line.
+ */
+ ccprintf("%s\n", full_build_string);
+ return;
+ }
+
+ memcpy(p, full_build_string, len + 1);
+ next = p;
+ index = 0;
seen_colonv = 1;
- symbol = *p++;
- while (symbol) {
+ do {
+ symbol = next[index++];
if ((symbol == ' ') && seen_colonv) {
+ next[index - 1] = '\0';
seen_colonv = 0;
/* Indent each line under 'Build: ' */
- ccprintf("\n ");
- } else {
- if ((symbol == ':') && (*p == 'v'))
- seen_colonv = 1;
- ccprintf("%c", symbol);
+ ccprintf("%s\n ", next);
+ next += index;
+ index = 0;
+ continue;
}
- symbol = *p++;
- }
- ccprintf("\n");
+ if ((symbol == ':') && (next[index] == 'v'))
+ seen_colonv = 1;
+ } while (symbol);
+ ccprintf("%s\n", next);
+
+ shared_mem_release(p);
}
static int command_version(int argc, char **argv)