From patchwork Sat Feb 7 18:51:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 437587 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 E8EAD14017B for ; Sun, 8 Feb 2015 05:52:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4EBC34A05D; Sat, 7 Feb 2015 19:52: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 11YYCYdN3gu5; Sat, 7 Feb 2015 19:52:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F3C74A050; Sat, 7 Feb 2015 19:52:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ECF784A053 for ; Sat, 7 Feb 2015 19:52:19 +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 1E_0yvqnSLmV for ; Sat, 7 Feb 2015 19:52:19 +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-qc0-f202.google.com (mail-qc0-f202.google.com [209.85.216.202]) by theia.denx.de (Postfix) with ESMTPS id 8A8994A050 for ; Sat, 7 Feb 2015 19:52:17 +0100 (CET) Received: by mail-qc0-f202.google.com with SMTP id r5so2215538qcx.1 for ; Sat, 07 Feb 2015 10:52:16 -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=WpUosGtbg9y1j0jcMlXZNdHN7cnoeG5XJwTxQtwIuZM=; b=P/Rn0hzPyvq8+qQJAT7WsL+v7C/C96DVI/luzC0SCLFaPLhwL82SGc0JEOHQk0KU/L Yn3E12lSHKnSUBZbJkeu94Roratx+aWbPR1LWE5q7iCY1aaG0pfgS95W+n2/d8QNC0gn ZR1iSgkHqX21kpc0qExcBdbygFL3bdur3YuZ1ja32Apx4RrPleKYw9bRvMtd029U7tVN D3mO0h9ZIZCA/+Ks8ZuhC54wLuOXrD5pSxjmFEx0d/oGdP38cVt4H5QNroGP89FedjrG rOotNUFoBKoM+ig2aJshEWnGmoQC1XBozBm+BoVEHufTbyqgwqzUX741Az4ca2G5rFNF M2EA== X-Gm-Message-State: ALoCoQlazpLgvM4mB1+PN5rSyg7HGjGnWYGK42oiUD4YkGznrIU14FXWf9NnQFtth173UlM0uiRH X-Received: by 10.236.66.234 with SMTP id h70mr8379478yhd.41.1423335135885; Sat, 07 Feb 2015 10:52:15 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id s10si1142569qcl.3.2015.02.07.10.52.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Feb 2015 10:52:15 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id 4lIPFAS6.1; Sat, 07 Feb 2015 10:52:15 -0800 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 5FF18220383; Sat, 7 Feb 2015 11:52:15 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Sat, 7 Feb 2015 11:51:34 -0700 Message-Id: <1423335112-24585-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1423335112-24585-1-git-send-email-sjg@chromium.org> References: <1423335112-24585-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v2 01/19] Introduce board_init_f_mem() to handle early memory layout 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" At present on some architectures we set up the following before calling board_init_f(): - global_data - stack - early malloc memory Adding the code to support early malloc and global data setup to every arch's assembler start-up is a pain. Also this code is not actually architecture-specific. We can use common code for all architectures and with a bit of care we can write this code in C. Add a new function to deal with this. It should be called after memory is available, with a pointer to the top of the area that should be used before relocation. The function will set things up and return the lowest memory address that it allocated/used. That can then be set as the top of the stack. Note that on some archs this function will use the stack, so the stack pointer should be set to same value as is pased to board_init_f_mem(). A margin of 128 bytes will be left for this stack, so that it is not overwritten. This means that 64 bytes is wasted by this early call. This is not strictly necessary on several more modern archs, so we could remove this at the cost of some arch-dependent code. With this function there is no-longer any need for the assembler code to zero global_data or set up the early malloc pointers. Signed-off-by: Simon Glass --- Changes in v2: - Reduce reserved stack space for board_init_f_mem() to 64 bytes common/board_f.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/board_f.c b/common/board_f.c index 7953137..07f5118 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -1075,4 +1075,22 @@ void board_init_f_r(void) /* NOTREACHED - board_init_r() does not return */ hang(); } +#else +ulong board_init_f_mem(ulong top) +{ + /* Leave space for the stack we are running with now */ + top -= 0x40; + + top -= sizeof(struct global_data); + top = ALIGN(top, 16); + gd = (struct global_data *)top; + memset((void *)gd, '\0', sizeof(*gd)); + +#ifdef CONFIG_SYS_MALLOC_F_LEN + top -= CONFIG_SYS_MALLOC_F_LEN; + gd->malloc_base = top; +#endif + + return top; +} #endif /* CONFIG_X86 */