From patchwork Sun Jul 3 23:56:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 643863 X-Patchwork-Delegate: trini@ti.com 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 3rjRsR6N1dz9ssP for ; Mon, 4 Jul 2016 09:57:30 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 427B6A7514; Mon, 4 Jul 2016 01:57:26 +0200 (CEST) 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 O2VrajOBt09W; Mon, 4 Jul 2016 01:57:25 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 86FEFA74E9; Mon, 4 Jul 2016 01:57:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C1609A74E9 for ; Mon, 4 Jul 2016 01:57:22 +0200 (CEST) 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 RnOVIvTNgHlz for ; Mon, 4 Jul 2016 01:57:22 +0200 (CEST) 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 foss.arm.com (foss.arm.com [217.140.101.70]) by theia.denx.de (Postfix) with ESMTP id 2FA24A74D6 for ; Mon, 4 Jul 2016 01:57:18 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C87928; Sun, 3 Jul 2016 16:58:14 -0700 (PDT) Received: from slackpad.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 702BD3F215; Sun, 3 Jul 2016 16:57:14 -0700 (PDT) From: Andre Przywara To: Hans de Goede , trini@konsulko.com Date: Mon, 4 Jul 2016 00:56:46 +0100 Message-Id: <1467590206-17955-1-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 Cc: Marek Vasut , u-boot@lists.denx.de, Ian Campbell , Stefan Roese Subject: [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage 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" As printf calls may be executed quite early, we should avoid using any BSS stored variables, since some boards put BSS in DRAM, which may not have been initialised yet. Explicitly mark those "static global" variables as belonging to the .data section, to keep tiny-printf clear of any BSS usage. Please note that this is quite a hack (which may need to be extended to other source files) and more sustainable solutions are warmly welcomed. Signed-off-by: Andre Przywara --- Hi, as mentioned before I don't like this hack very much, but as this fixes the WIP Pine64 SPL code I propose this solution for 2016.07. Cheers, Andre lib/tiny-printf.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 451f4f7..bc2995b 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -13,11 +13,18 @@ #include #include -static char *bf; -static char zs; +/* + * This code in here may execute before the DRAM is initialised, so + * we should make sure that it doesn't touch BSS, which some boards + * put in DRAM. + */ +#define NO_BSS __attribute__((section(".data"))) + +static char *bf NO_BSS; +static char zs NO_BSS; /* Current position in sprintf() output string */ -static char *outstr; +static char *outstr NO_BSS; static void out(char c) {