Skip to contentSkip to conversation

display_options: Refactor to allow obtaining the banner

PATCH Superseded Simon Glass 3 participants 17 messages Jun 16, 2017 – Jul 6, 2017 Library code

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/6 display_options: Refactor to allow obtaining the banner

Move the display options code into a separate function so that the U-Boot banner can be obtained from other code. Adjust the 'version' command to use it.

---

Changes in v3: None
Changes in v2:
- Update the code to be more testable
- Avoid a warning on spring, etc.

 cmd/version.c             |  4 +++-
 include/display_options.h | 19 +++++++++++++++++++
 lib/display_options.c     | 36 +++++++++++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 6 deletions(-)
cmd/version.c +3 -1
index 1be0667f09..15aab5dc18 100644
@@ -17,7 +17,9 @@ const char __weak version_string[] = U_BOOT_VERSION_STRING;
 
 static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	printf("\n%s\n", version_string);
+	char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
+
+	printf(display_options_get_banner(false, buf, sizeof(buf)));
 #ifdef CC_VERSION_STRING
 	puts(CC_VERSION_STRING "\n");
 #endif
include/display_options.h +19 -0
index ac44c459b3..ad707a344c 100644
@@ -56,4 +56,23 @@ int print_buffer(ulong addr, const void *data, uint width, uint count,
  */
 int display_options(void);
 
+/* Suggested length of the buffer to pass to display_options_get_banner() */
+#define DISPLAY_OPTIONS_BANNER_LENGTH	200
+
+/**
+ * display_options_get_banner() - Get the U-Boot banner as a string
+ *
+ * This returns the U-Boot banner string
+ *
+ * @newlines: true to include two newlines at the start
+ * @buf: place to put string
+ * @size: Size of buf (string is truncated to fit)
+ * @return buf
+ */
+char *display_options_get_banner(bool newlines, char *buf, int size);
+
+/** This function is used for testing only */
+char *display_options_get_banner_priv(bool newlines, const char *build_tag,
+				      char *buf, int size);
+
 #endif
lib/display_options.c +31 -5
index 29343fc00e..4ea27ca99d 100644
@@ -13,13 +13,39 @@
 #include <linux/ctype.h>
 #include <asm/io.h>
 
-int display_options (void)
+char *display_options_get_banner_priv(bool newlines, const char *build_tag,
+				      char *buf, int size)
 {
-#if defined(BUILD_TAG)
-	printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
-#else
-	printf ("\n\n%s\n\n", version_string);
+	int len;
+
+	len = snprintf(buf, size, "%s%s", newlines ? "\n\n" : "",
+		       version_string);
+	if (build_tag && len < size)
+		len += snprintf(buf + len, size - len, ", Build: %s",
+				build_tag);
+	if (len > size - 3)
+		len = size - 3;
+	strcpy(buf + len, "\n\n");
+
+	return buf;
+}
+
+#ifndef BUILD_TAG
+#define BUILD_TAG NULL
 #endif
+
+char *display_options_get_banner(bool newlines, char *buf, int size)
+{
+	return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size);
+}
+
+int display_options(void)
+{
+	char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
+
+	display_options_get_banner(true, buf, sizeof(buf));
+	printf("%s", buf);
+
 	return 0;
 }
 
Signature · 1 line
2.13.1.518.g3df882009-goog
#1 lore raw

PATCH v3 2/6 Allow displaying the U-Boot banner on a video display

At present the U-Boot banner is only displayed on the serial console. If this is not visible to the user, the banner does not show. Some devices have a video display which can usefully display this information.

Add a banner which is printed after relocation only on non-serial devices if CONFIG_DISPLAY_BOARDINFO_LATE is defined.

---

Changes in v3: None
Changes in v2:
- Reword function comment for console_announce_r() slighty

 common/board_r.c  |  1 +
 common/console.c  | 17 +++++++++++++----
 include/console.h | 12 ++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)
common/board_r.c +1 -0
index adc1f1937e..8d9f0a3c5e 100644
@@ -832,6 +832,7 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 	console_init_r,		/* fully init console as a device */
 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
+	console_announce_r,
 	show_board_info,
 #endif
 #ifdef CONFIG_ARCH_MISC_INIT
common/console.c +13 -4
index 1232808df5..60e7a94a56 100644
@@ -202,7 +202,6 @@ static void console_putc(int file, const char c)
 	}
 }
 
-#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
 static void console_puts_noserial(int file, const char *s)
 {
 	int i;
@@ -214,7 +213,6 @@ static void console_puts_noserial(int file, const char *s)
 			dev->puts(dev, s);
 	}
 }
-#endif
 
 static void console_puts(int file, const char *s)
 {
@@ -248,13 +246,11 @@ static inline void console_putc(int file, const char c)
 	stdio_devices[file]->putc(stdio_devices[file], c);
 }
 
-#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
 static inline void console_puts_noserial(int file, const char *s)
 {
 	if (strcmp(stdio_devices[file]->name, "serial") != 0)
 		stdio_devices[file]->puts(stdio_devices[file], s);
 }
-#endif
 
 static inline void console_puts(int file, const char *s)
 {
@@ -699,6 +695,19 @@ static void console_update_silent(void)
 #endif
 }
 
+int console_announce_r(void)
+{
+#if !CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
+	char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
+
+	display_options_get_banner(false, buf, sizeof(buf));
+
+	console_puts_noserial(stdout, buf);
+#endif
+
+	return 0;
+}
+
 /* Called before relocation - use serial functions */
 int console_init_f(void)
 {
include/console.h +12 -0
index 3d37f6a53b..cea29ed6dc 100644
@@ -42,6 +42,18 @@ void console_record_reset(void);
  */
 void console_record_reset_enable(void);
 
+/**
+ * console_announce_r() - print a U-Boot console on non-serial consoles
+ *
+ * When U-Boot starts up with a display it generally does not announce itself
+ * on the display. The banner is instead emitted on the UART before relocation.
+ * This function prints a banner on devices which (we assume) did not receive
+ * it before relocation.
+ *
+ * @return 0 (meaning no errors)
+ */
+int console_announce_r(void);
+
 /*
  * CONSOLE multiplexing.
  */
Signature · 1 line
2.13.1.518.g3df882009-goog
#2 lore raw

PATCH v3 2/6 Allow displaying the U-Boot banner on a video display

Quoted 10 lines · Simon Glass

At present the U-Boot banner is only displayed on the serial console. If this is not visible to the user, the banner does not show. Some devices have a video display which can usefully display this information.

Add a banner which is printed after relocation only on non-serial devices if CONFIG_DISPLAY_BOARDINFO_LATE is defined.

---

Quoted 9 lines

Changes in v3: None
Changes in v2:
- Reword function comment for console_announce_r() slighty

 common/board_r.c  |  1 +
 common/console.c  | 17 +++++++++++++----
 include/console.h | 12 ++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)
#3 lore raw

PATCH v3 2/6 Allow displaying the U-Boot banner on a video display

Quoted 10 lines · Simon Glass

At present the U-Boot banner is only displayed on the serial console. If this is not visible to the user, the banner does not show. Some devices have a video display which can usefully display this information.

Add a banner which is printed after relocation only on non-serial devices if CONFIG_DISPLAY_BOARDINFO_LATE is defined.

---

Quoted 9 lines

Changes in v3: None
Changes in v2:
- Reword function comment for console_announce_r() slighty

 common/board_r.c  |  1 +
 common/console.c  | 17 +++++++++++++----
 include/console.h | 12 ++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!

#4 lore raw

PATCH v3 3/6 test: Add a test for snprintf() and the banner/version

In reply to Simon Glass

Add a simple test to make sure that these functions obey the buffer size passed into them.

---

Changes in v3: None
Changes in v2:
- Fix buffer overflow problem when there is not enough space for the build tag
- Add test to check for buffer overflow problems

 test/Makefile   |  1 +
 test/print_ut.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 test/print_ut.c
test/Makefile +1 -0
index 0f5de57399..6305afb211 100644
@@ -8,4 +8,5 @@ obj-$(CONFIG_UNIT_TEST) += cmd_ut.o
 obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
+obj-$(CONFIG_SANDBOX) += print_ut.o
 obj-$(CONFIG_UT_TIME) += time_ut.o
test/print_ut.c new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
2.13.1.518.g3df882009-goog
#5 lore raw

PATCH v3 3/6 test: Add a test for snprintf() and the banner/version

Quoted 11 lines · Simon Glass

Add a simple test to make sure that these functions obey the buffer size passed into them.

---

Changes in v3: None
Changes in v2:
- Fix buffer overflow problem when there is not enough space for the build tag
- Add test to check for buffer overflow problems

Quoted 5 lines
 test/Makefile   |  1 +
 test/print_ut.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 test/print_ut.c
#6 lore raw

PATCH v3 3/6 test: Add a test for snprintf() and the banner/version

Quoted 11 lines · Simon Glass

Add a simple test to make sure that these functions obey the buffer size passed into them.

---

Changes in v3: None
Changes in v2:
- Fix buffer overflow problem when there is not enough space for the build tag
- Add test to check for buffer overflow problems

Quoted 5 lines
 test/Makefile   |  1 +
 test/print_ut.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 test/print_ut.c

Applied to u-boot-dm, thanks!

#7 lore raw

PATCH v3 4/6 console: Use map_sysmem() for the pre-relocation console

In reply to Simon Glass

At present this feature casts the address to a pointer. Use the map_sysmem() function so that it will work correctly on sandbox.

---

Changes in v3:
- Add new patch to use map_sysmem() for the pre-relocation console

Changes in v2: None

 common/console.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
common/console.c +9 -2
index 60e7a94a56..762d5f291c 100644
@@ -11,6 +11,7 @@
 #include <stdarg.h>
 #include <iomux.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <os.h>
 #include <serial.h>
 #include <stdio_dev.h>
@@ -416,9 +417,13 @@ int tstc(void)
 
 static void pre_console_putc(const char c)
 {
-	char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
+	char *buffer;
+
+	buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
 
 	buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
+
+	unmap_sysmem(buffer);
 }
 
 static void pre_console_puts(const char *s)
@@ -430,14 +435,16 @@ static void pre_console_puts(const char *s)
 static void print_pre_console_buffer(int flushpoint)
 {
 	unsigned long in = 0, out = 0;
-	char *buf_in = (char *)CONFIG_PRE_CON_BUF_ADDR;
 	char buf_out[CONFIG_PRE_CON_BUF_SZ + 1];
+	char *buf_in;
 
+	buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
 	if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
 		in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
 
 	while (in < gd->precon_buf_idx)
 		buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)];
+	unmap_sysmem(buf_in);
 
 	buf_out[out] = 0;
 
Signature · 1 line
2.13.1.518.g3df882009-goog
#8 lore raw

PATCH v3 4/6 console: Use map_sysmem() for the pre-relocation console

Quoted 6 lines · Simon Glass

At present this feature casts the address to a pointer. Use the map_sysmem() function so that it will work correctly on sandbox.

---

Quoted 8 lines

Changes in v3:
- Add new patch to use map_sysmem() for the pre-relocation console

Changes in v2: None

 common/console.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
#9 lore raw

PATCH v3 4/6 console: Use map_sysmem() for the pre-relocation console

Quoted 6 lines · Simon Glass

At present this feature casts the address to a pointer. Use the map_sysmem() function so that it will work correctly on sandbox.

---

Quoted 8 lines

Changes in v3:
- Add new patch to use map_sysmem() for the pre-relocation console

Changes in v2: None

 common/console.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

#10 lore raw

PATCH v3 5/6 sandbox: Enable more console options

In reply to Simon Glass

Enable the pre-console buffer, displaying the model and post-relocation console announce on sandbox. Also add a model name to the device tree. This allows testing of these features.

---

Changes in v3:
- Add new patch to enable more console options on sandbox

Changes in v2: None

 arch/sandbox/dts/sandbox.dts | 1 +
 common/Kconfig               | 2 +-
 configs/sandbox_defconfig    | 2 ++
 include/configs/sandbox.h    | 1 +
 4 files changed, 5 insertions(+), 1 deletion(-)
arch/sandbox/dts/sandbox.dts +1 -0
index 40f423da25..0aba6c9a6d 100644
@@ -5,6 +5,7 @@
 / {
 	#address-cells = <1>;
 	#size-cells = <1>;
+	model = "sandbox";
 
 	aliases {
 		eth5 = "/eth at 90000000";
common/Kconfig +1 -1
index c49199bb1a..4853863470 100644
@@ -472,7 +472,7 @@ config DISPLAY_CPUINFO
 
 config DISPLAY_BOARDINFO
 	bool "Display information about the board during start up"
-	default y if ARM || M68K || MIPS || PPC || XTENSA
+	default y if ARM || M68K || MIPS || PPC || SANDBOX || XTENSA
 	help
 	  Display information about the board that U-Boot is running on
 	  when U-Boot starts up. The board function checkboard() is called
configs/sandbox_defconfig +2 -0
index 6a6e7741d8..7a1b9ef052 100644
@@ -14,6 +14,8 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
+CONFIG_PRE_CONSOLE_BUFFER=y
+CONFIG_PRE_CON_BUF_ADDR=0
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_BOOTZ=y
include/configs/sandbox.h +1 -0
index 9276cf9734..1e8404cbdf 100644
@@ -41,6 +41,7 @@
 
 #define CONFIG_SYS_LONGHELP			/* #undef to save memory */
 #define CONFIG_SYS_CBSIZE		1024	/* Console I/O Buffer Size */
+#define CONFIG_DISPLAY_BOARDINFO_LATE
 
 /* Print Buffer Size */
 #define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
Signature · 1 line
2.13.1.518.g3df882009-goog
#11 lore raw

PATCH v3 5/6 sandbox: Enable more console options

Quoted 10 lines · Simon Glass

Enable the pre-console buffer, displaying the model and post-relocation console announce on sandbox. Also add a model name to the device tree. This allows testing of these features.

---

Changes in v3:
- Add new patch to enable more console options on sandbox

Quoted 8 lines

Changes in v2: None

 arch/sandbox/dts/sandbox.dts | 1 +
 common/Kconfig               | 2 +-
 configs/sandbox_defconfig    | 2 ++
 include/configs/sandbox.h    | 1 +
 4 files changed, 5 insertions(+), 1 deletion(-)
#12 lore raw

PATCH v3 5/6 sandbox: Enable more console options

Quoted 10 lines · Simon Glass

Enable the pre-console buffer, displaying the model and post-relocation console announce on sandbox. Also add a model name to the device tree. This allows testing of these features.

---

Changes in v3:
- Add new patch to enable more console options on sandbox

Quoted 8 lines

Changes in v2: None

 arch/sandbox/dts/sandbox.dts | 1 +
 common/Kconfig               | 2 +-
 configs/sandbox_defconfig    | 2 ++
 include/configs/sandbox.h    | 1 +
 4 files changed, 5 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

#13 lore raw

PATCH v3 6/6 sandbox: Drop special case console code for sandbox

In reply to Simon Glass

At present sandbox has a special case where it directly calls os_putc() when it does not have a console yet.

Now that we have the pre-console buffer enabled we can drop this. Any early characters will be buffered and output later.

---

Changes in v3:
- Add new patch to drop special case console code for sandbox

Changes in v2: None

 common/console.c | 13 -------------
 1 file changed, 13 deletions(-)
common/console.c +0 -13
index 762d5f291c..c6156f33bb 100644
@@ -465,13 +465,6 @@ static inline void print_pre_console_buffer(int flushpoint) {}
 
 void putc(const char c)
 {
-#ifdef CONFIG_SANDBOX
-	/* sandbox can send characters to stdout before it has a console */
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
-		os_putc(c);
-		return;
-	}
-#endif
 #ifdef CONFIG_DEBUG_UART
 	/* if we don't have a console yet, use the debug UART */
 	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
@@ -508,12 +501,6 @@ void putc(const char c)
 
 void puts(const char *s)
 {
-#ifdef CONFIG_SANDBOX
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
-		os_puts(s);
-		return;
-	}
-#endif
 #ifdef CONFIG_DEBUG_UART
 	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
 		while (*s) {
Signature · 1 line
2.13.1.518.g3df882009-goog
#14 lore raw

PATCH v3 6/6 sandbox: Drop special case console code for sandbox

Quoted 9 lines · Simon Glass

At present sandbox has a special case where it directly calls os_putc() when it does not have a console yet.

Now that we have the pre-console buffer enabled we can drop this. Any early characters will be buffered and output later.

---

Quoted 8 lines

Changes in v3:
- Add new patch to drop special case console code for sandbox

Changes in v2: None

 common/console.c | 13 -------------
 1 file changed, 13 deletions(-)
#15 lore raw

PATCH v3 6/6 sandbox: Drop special case console code for sandbox

Quoted 9 lines · Simon Glass

At present sandbox has a special case where it directly calls os_putc() when it does not have a console yet.

Now that we have the pre-console buffer enabled we can drop this. Any early characters will be buffered and output later.

---

Quoted 8 lines

Changes in v3:
- Add new patch to drop special case console code for sandbox

Changes in v2: None

 common/console.c | 13 -------------
 1 file changed, 13 deletions(-)

Applied to u-boot-dm, thanks!

#16 lore raw

PATCH v3 1/6 display_options: Refactor to allow obtaining the banner

In reply to Simon Glass
Quoted 12 lines · Simon Glass

Move the display options code into a separate function so that the U-Boot banner can be obtained from other code. Adjust the 'version' command to use it.

---

Changes in v3: None
Changes in v2:
- Update the code to be more testable
- Avoid a warning on spring, etc.

Quoted 5 lines
 cmd/version.c             |  4 +++-
 include/display_options.h | 19 +++++++++++++++++++
 lib/display_options.c     | 36 +++++++++++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 6 deletions(-)

One nits below.

Quoted 29 lines
cmd/version.c +3 -1
index 1be0667f09..15aab5dc18 100644
@@ -17,7 +17,9 @@ const char __weak version_string[] = U_BOOT_VERSION_STRING;
 
 static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       printf("\n%s\n", version_string);
+       char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
+
+       printf(display_options_get_banner(false, buf, sizeof(buf)));
 #ifdef CC_VERSION_STRING
        puts(CC_VERSION_STRING "\n");
 #endif
include/display_options.h +6 -0
index ac44c459b3..ad707a344c 100644
@@ -56,4 +56,23 @@ int print_buffer(ulong addr, const void *data, uint width, uint count,
  */
 int display_options(void);
 
+/* Suggested length of the buffer to pass to display_options_get_banner() */
+#define DISPLAY_OPTIONS_BANNER_LENGTH  200
+
+/**
+ * display_options_get_banner() - Get the U-Boot banner as a string
+ *

include/display_options.h int print_buffer(ulong addr, const void *data, uint width, uint count, · line 74

Quoted 10 lines
include/display_options.h +10 -0
+ * This returns the U-Boot banner string
+ *
+ * @newlines: true to include two newlines at the start
+ * @buf: place to put string
+ * @size: Size of buf (string is truncated to fit)
+ * @return buf
+ */
+char *display_options_get_banner(bool newlines, char *buf, int size);
+
+/** This function is used for testing only */

nits: /*

include/display_options.h int print_buffer(ulong addr, const void *data, uint width, uint count, · line 78

Quoted 4 lines
include/display_options.h +3 -0
+char *display_options_get_banner_priv(bool newlines, const char *build_tag,
+                                     char *buf, int size);
+
 #endif

[snip]

Regards,
Bin