From patchwork Fri May 24 20:07:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1105147 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oyjabpfw"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459cpy1qQcz9s9y for ; Sat, 25 May 2019 06:07:22 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D717EC21F51; Fri, 24 May 2019 20:07:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 935E7C21DC1; Fri, 24 May 2019 20:07:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ED07AC21DD4; Fri, 24 May 2019 20:07:14 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id 926D6C21DA1 for ; Fri, 24 May 2019 20:07:14 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id e2so2367058wrv.6 for ; Fri, 24 May 2019 13:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9CVGArCn52uX3EWvwSgJGdinKLNrnc5P33v/ZNDJI04=; b=oyjabpfwp3Owons43k8J282F3JDVWRNjBvM5Rm1qfvwGp/gVAHxoE41qO+IcvlN+HA p3JxLMhBKwNKHWZ8hV/H5VajWUvffpApB8ANPfDNJKh/h0mvcfDYCltrbJsavzjU9wSr trxhZPR2p8GaMZ/IIH+4H7YQSEUbIJUWEpRUmrcNsPX0UEE28jYkMEKkJpuOE7FZREsY cWoiye4cNYQ/zXB1II+dUA5+b47cfBWfw7ffHXsx6tAQkZnb3gGcOfCKrV9WAsNOg1ak b4tYpsO0bNAKDWaPv2lfWLnsxePf1bTKI4u/9BxCKH+/4kYCEQXT9zxhD27GxyjCS/7f qcbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9CVGArCn52uX3EWvwSgJGdinKLNrnc5P33v/ZNDJI04=; b=HCLpSkbgxO+rZ3KK84cjnWIy9NBSE4KXx37gqJA2j/NNXUIkNPSLhzpSOwGafb2TYH lQlcUP/AES7O3HgciBQU7mCtOvk3a/Zbcf3mLE4EPzm+Dzk4xo3ztYM9o51cFIa70uZ9 kiI1YdiJB8J2AZVYp8Uhu8bLM+t8vci7AA0SkIyMdJJvheTtkW78Gae00oPeArgimdWw D0gMKxKiBn4Mg2LW7XMu/pObn+oMBP0/wbvh/FkoC1Y2ndaGnZFzEQ6gh2bL8X1OOHY+ gOVOuCdOjnC4FPP9SdRvZLLumVJNEkKPLwOkN3Z0kfAzRNnriQIBawy56xxL72e4pldV IRbw== X-Gm-Message-State: APjAAAUkf1NTrOe9V2A1g6fdd4Fg2c2DHnQznjvZdhb//3tXtUp20VmB jVXn4V69oTGbMPL/4gIZp8A= X-Google-Smtp-Source: APXvYqxN6C8Tky2eiZ+bjTbBeHhMEZv0PMgvDMNBdb0dCBT6mD8hqaT6X1CNQFXLLej0P8tPNZTVQw== X-Received: by 2002:a5d:440d:: with SMTP id z13mr3394897wrq.263.1558728434133; Fri, 24 May 2019 13:07:14 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:dc62:9b88:b594:4b62]) by smtp.gmail.com with ESMTPSA id v5sm6365203wra.83.2019.05.24.13.07.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 13:07:13 -0700 (PDT) From: Simon Goldschmidt To: Tom Rini Date: Fri, 24 May 2019 22:07:04 +0200 Message-Id: <20190524200704.29373-1-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: Teddy Reed , Baruch Siach , u-boot@lists.denx.de, Thomas Petazzoni , Stefan Roese , Fabrice Fontaine , Tien Fong Chee , Heinrich Schuchardt , Michal Simek , Otavio Salvador , Chris Packham Subject: [U-Boot] [PATCH v3] spl: add overall SPL size check X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This adds a size check for SPL that can dynamically check generated SPL binaries (including devicetree) for a size limit that ensures this image plus global data, heap and stack fit in initial SRAM. Since some of these sizes are not available to make, a new host tool 'spl_size_limit' is added that dumps the resulting maximum size for an SPL binary to stdout. This tool is used in toplevel Makefile to implement the size check on SPL binaries. Signed-off-by: Simon Goldschmidt --- Changes in v3: - don't build this new tools for 'make tools-only' Changes in v2: - added missing tools/spl_size_limit.c Kconfig | 8 -------- Makefile | 3 ++- common/spl/Kconfig | 36 ++++++++++++++++++++++++++++++++++++ tools/Makefile | 4 ++++ tools/spl_size_limit.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 tools/spl_size_limit.c diff --git a/Kconfig b/Kconfig index 1221d1af69..5f5c5ccfd6 100644 --- a/Kconfig +++ b/Kconfig @@ -172,14 +172,6 @@ config TPL_SYS_MALLOC_F_LEN particular needs this to operate, so that it can allocate the initial serial device and any others that are needed. -config SPL_SIZE_LIMIT - int "Maximum size of SPL image" - depends on SPL - default 0 - help - Specifies the maximum length of the U-Boot SPL image. - If this value is zero, it is ignored. - menuconfig EXPERT bool "Configure standard U-Boot features (expert users)" default y diff --git a/Makefile b/Makefile index 7d910b3682..ed7e12120f 100644 --- a/Makefile +++ b/Makefile @@ -797,7 +797,7 @@ BOARD_SIZE_CHECK = endif ifneq ($(CONFIG_SPL_SIZE_LIMIT),0) -SPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_SPL_SIZE_LIMIT)) +SPL_SIZE_CHECK = @$(call size_check,$@,$$(tools/spl_size_limit)) else SPL_SIZE_CHECK = endif @@ -1779,6 +1779,7 @@ checkarmreloc: u-boot envtools: scripts_basic $(version_h) $(timestamp_h) $(Q)$(MAKE) $(build)=tools/env +tools-only: export TOOLS_ONLY=y tools-only: scripts_basic $(version_h) $(timestamp_h) $(Q)$(MAKE) $(build)=tools diff --git a/common/spl/Kconfig b/common/spl/Kconfig index c7cd34449a..6a98536f20 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -25,6 +25,42 @@ config SPL_FRAMEWORK supports MMC, NAND and YMODEM and other methods loading of U-Boot and the Linux Kernel. If unsure, say Y. +config SPL_SIZE_LIMIT + hex "Maximum size of SPL image" + depends on SPL + default 0 + help + Specifies the maximum length of the U-Boot SPL image. + If this value is zero, it is ignored. + +config SPL_SIZE_LIMIT_SUBTRACT_GD + bool "SPL image size check: provide space for global data" + depends on SPL_SIZE_LIMIT > 0 + help + If enabled, aligned size of global data is reserved in + SPL_SIZE_LIMIT check to ensure such an image does not overflow SRAM + if SPL_SIZE_LIMIT describes the size of SRAM available for SPL when + pre-reloc global data is put into this SRAM, too. + +config SPL_SIZE_LIMIT_SUBTRACT_MALLOC + bool "SPL image size check: provide space for malloc() pool before relocation" + depends on SPL_SIZE_LIMIT > 0 + help + If enabled, SPL_SYS_MALLOC_F_LEN is reserved in SPL_SIZE_LIMIT check + to ensure such an image does not overflow SRAM if SPL_SIZE_LIMIT + describes the size of SRAM available for SPL when pre-reloc malloc + pool is put into this SRAM, too. + +config SPL_SIZE_LIMIT_PROVIDE_STACK + hex "SPL image size check: provide stack space before relocation" + depends on SPL_SIZE_LIMIT > 0 + default 0 + help + If set, this size is reserved in SPL_SIZE_LIMIT check to ensure such + an image does not overflow SRAM if SPL_SIZE_LIMIT describes the size + of SRAM available for SPL when the stack required before reolcation + uses this SRAM, too. + config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" depends on BLOBLIST diff --git a/tools/Makefile b/tools/Makefile index e2f572cae1..33e90a8025 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -199,6 +199,10 @@ hostprogs-$(CONFIG_RISCV) += prelink-riscv hostprogs-y += fdtgrep fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o +ifneq ($(TOOLS_ONLY),y) +hostprogs-y += spl_size_limit +endif + hostprogs-$(CONFIG_MIPS) += mips-relocs # We build some files with extra pedantic flags to try to minimize things diff --git a/tools/spl_size_limit.c b/tools/spl_size_limit.c new file mode 100644 index 0000000000..98ff491867 --- /dev/null +++ b/tools/spl_size_limit.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2019, Simon Goldschmidt + * + * This tool helps to return the size available for SPL image during build + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int spl_size_limit = 0; + +#ifdef CONFIG_SPL_SIZE_LIMIT + spl_size_limit = CONFIG_SPL_SIZE_LIMIT; +#ifdef CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD + spl_size_limit -= GENERATED_GBL_DATA_SIZE; +#endif +#ifdef CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC + spl_size_limit -= CONFIG_SPL_SYS_MALLOC_F_LEN; +#endif +#ifdef CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK + spl_size_limit -= CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK; +#endif +#endif + + printf("%d", spl_size_limit); + return 0; +}