]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: Add a panic_str() function to reduce code size
authorSimon Glass <sjg@chromium.org>
Sat, 28 Feb 2015 05:06:32 +0000 (22:06 -0700)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:30:15 +0000 (22:30 +0200)
The printf() in panic() adds about 1.5KB of code size to SPL when compiled
with Thumb-2. Provide a smaller version that does not support printf()-style
arguments and use it in two commonly compiled places.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/serial/serial-uclass.c
include/vsprintf.h
lib/fdtdec.c
lib/vsprintf.c

index b239691efe945ba77d02429243a81186ded32454..b8c2f482288913475af367869b0ab086e6fd5943 100644 (file)
@@ -70,7 +70,7 @@ static void serial_find_console_or_panic(void)
        if (uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) &&
            uclass_get_device(UCLASS_SERIAL, INDEX, &dev) &&
            (uclass_first_device(UCLASS_SERIAL, &dev) || !dev))
-               panic("No serial driver found");
+               panic_str("No serial driver found");
 #undef INDEX
        gd->cur_serial_dev = dev;
 }
index 5624482d573b947fb3d533562bda755d75995853..09c8abd951d09c48ea8b937542549c25efb8ad79 100644 (file)
@@ -39,9 +39,32 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
 unsigned long long simple_strtoull(const char *cp, char **endp,
                                        unsigned int base);
 long simple_strtol(const char *cp, char **endp, unsigned int base);
+
+/**
+ * panic() - Print a message and reset/hang
+ *
+ * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
+ * defined, then it will hang instead of reseting.
+ *
+ * @param fmt: printf() format string for message, which should not include
+ *             \n, followed by arguments
+ */
 void panic(const char *fmt, ...)
                __attribute__ ((format (__printf__, 1, 2), noreturn));
 
+/**
+ * panic_str() - Print a message and reset/hang
+ *
+ * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
+ * defined, then it will hang instead of reseting.
+ *
+ * This function can be used instead of panic() when your board does not
+ * already use printf(), * to keep code size small.
+ *
+ * @param fmt: string to display, which should not include \n
+ */
+void panic_str(const char *str) __attribute__ ((noreturn));
+
 /**
  * Format a string and place it in a buffer
  *
index 331eae2ce1e093f04efa6ba055c485efc9a3c1f1..577c60ed0d9e94a04facb6965ae91dc28f467de1 100644 (file)
@@ -565,9 +565,11 @@ int fdtdec_prepare_fdt(void)
 {
        if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) ||
            fdt_check_header(gd->fdt_blob)) {
-               printf("No valid FDT found - please append one to U-Boot "
-                       "binary, use u-boot-dtb.bin or define "
-                       "CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
+#ifdef CONFIG_SPL_BUILD
+               puts("Missing DTB\n");
+#else
+               puts("No valid device tree binary found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
+#endif
                return -1;
        }
        return 0;
index e0f264850f7fa75bc6cbeaad2537d3fffc4a318d..bedc865240de0dd7a2d50fa9be5a73dce5084b7b 100644 (file)
@@ -842,13 +842,11 @@ int sprintf(char *buf, const char *fmt, ...)
        return i;
 }
 
-void panic(const char *fmt, ...)
+static void panic_finish(void) __attribute__ ((noreturn));
+
+static void panic_finish(void)
 {
-       va_list args;
-       va_start(args, fmt);
-       vprintf(fmt, args);
        putc('\n');
-       va_end(args);
 #if defined(CONFIG_PANIC_HANG)
        hang();
 #else
@@ -859,6 +857,21 @@ void panic(const char *fmt, ...)
                ;
 }
 
+void panic_str(const char *str)
+{
+       puts(str);
+       panic_finish();
+}
+
+void panic(const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       vprintf(fmt, args);
+       va_end(args);
+       panic_finish();
+}
+
 void __assert_fail(const char *assertion, const char *file, unsigned line,
                   const char *function)
 {