From patchwork Sat Feb 28 05:06:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 444790 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 628941400D5 for ; Mon, 2 Mar 2015 07:11:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 830594B66F; Sun, 1 Mar 2015 21:11:25 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9cdYYYIBfXTy; Sun, 1 Mar 2015 21:11:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A2CB1A7418; Sun, 1 Mar 2015 21:11:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6FCA74B372 for ; Sat, 28 Feb 2015 06:36:21 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HW-ImL5ICx_r for ; Sat, 28 Feb 2015 06:36:21 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vc0-f201.google.com (mail-vc0-f201.google.com [209.85.220.201]) by theia.denx.de (Postfix) with ESMTPS id 440254A046 for ; Sat, 28 Feb 2015 06:36:08 +0100 (CET) Received: by mail-vc0-f201.google.com with SMTP id le20so444575vcb.0 for ; Fri, 27 Feb 2015 21:36:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CVY1czoBSbhISv6afYLOk5SSaNnXgfGM16mtRkHYL38=; b=UN0q0zNuJDRFvP/1NRv2+L9tXf+fFwg1T7eEIP11C0/D68epatM2kq3md15JuQw1D2 bT3/lbyf4H0UYctDjrQyAKDH0uX7x74PS48PQYfzl1s05OoyK7D+3T57wnUyNISdS840 LHgdUmB61ajKDc+TonPvErImiY8DwQx0Af8cERAqC2rw7uiqHnVSj43omWWz8NsIaXTb y8XA/5Zy+fBDt1YqV06JBpS6oOo8Hv66ljepbRkleadioXp7pzKpftqgU4anb2Qzjb0f KqezSECyueTIHJZQq7Ac0bHM3Y5F9nU/bOFUKgYZOaogCfb+JzQLlWps5WJcsQ8zELEz tZmA== X-Gm-Message-State: ALoCoQkaiv/PmZ6lb3siQAcFFWGYU/FSSj39LzqA0Igvw7G6RiYIOB41UlCZ4MH2AyyFukuE/JJ/ X-Received: by 10.52.88.67 with SMTP id be3mr16292776vdb.3.1425100053008; Fri, 27 Feb 2015 21:07:33 -0800 (PST) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id t7si240454yho.3.2015.02.27.21.07.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Feb 2015 21:07:32 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id wSSRf0by.1; Fri, 27 Feb 2015 21:07:32 -0800 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 2C951220F8F; Fri, 27 Feb 2015 22:07:32 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Fri, 27 Feb 2015 22:06:32 -0700 Message-Id: <1425100013-4796-9-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1425100013-4796-1-git-send-email-sjg@chromium.org> References: <1425100013-4796-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH 08/29] dm: Add a panic_str() function to reduce code size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- drivers/serial/serial-uclass.c | 2 +- include/vsprintf.h | 23 +++++++++++++++++++++++ lib/fdtdec.c | 8 +++++--- lib/vsprintf.c | 23 ++++++++++++++++++----- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 3fc7104..13ba606 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -72,7 +72,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; } diff --git a/include/vsprintf.h b/include/vsprintf.h index 5624482..09c8abd 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -39,10 +39,33 @@ 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 * * @param buf The buffer to place the result into diff --git a/lib/fdtdec.c b/lib/fdtdec.c index dd58bbb..cc5ba20 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -564,9 +564,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 \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 \n"); +#endif return -1; } return 0; diff --git a/lib/vsprintf.c b/lib/vsprintf.c index e0f2648..bedc865 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -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) {