From patchwork Mon Apr 22 19:48:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1088865 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="BGEjIoUK"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44nxvt4vDgz9sPZ for ; Tue, 23 Apr 2019 05:48:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 66917C21C8B; Mon, 22 Apr 2019 19:48:19 +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 50CCCC21C2F; Mon, 22 Apr 2019 19:48:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F23EAC21C2F; Mon, 22 Apr 2019 19:48:14 +0000 (UTC) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by lists.denx.de (Postfix) with ESMTPS id CCBCAC21C2C for ; Mon, 22 Apr 2019 19:48:13 +0000 (UTC) Received: by mail-wm1-f52.google.com with SMTP id v14so15682832wmf.2 for ; Mon, 22 Apr 2019 12:48:13 -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=3d8FSmp5bz/GUttOPLqIYUAt4UbMgTEquXJGSmuwa7Y=; b=BGEjIoUK1BPVAcvyBTaR+6GFEpJnNyA63qGuzMv200hQswnq/JI32V4k0vx6fsqW6x pvK8fUSAq/eDFqs+I20U2RqrpLZ1T1YzOFb/G+C6sqr6cjcDlGQdxU0kZXTMf6LFHXPZ kSYFEbRRMobs/9vPiHrILCKlE3oyoueQt9ZDnOBBLI7V33/AtDpkTAvoKzbjL9+Iv8iB vFlVmpgP17EZYFCxrllPafuAAOXYm7F22ikpWw1do8CyNa3T6xmXoJfDIldmLlFjEPd3 hxC1TFP9uGgj3zTddxDa1saOufdI4SIF0t5hI3DcPhNez/o7j7fRqJ0bGjL9w2K35fcj loGw== 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=3d8FSmp5bz/GUttOPLqIYUAt4UbMgTEquXJGSmuwa7Y=; b=BbU9ZaCxII4s68r8G1JNYHf/zhFKJNgN5/+96xcpnrS/IVLMeHUwN/gWqU0UhTzUZr Jh+jiTvZ5pcWHRzYALZncaZb1+FA5FeVBmANpcKevg4qhGERgp9VXdS8N8gBhN6Pw9Nv djRc4f7TsPlzEQWmo2bzmIbfp3aFXXAHFu3tdZLtrVYLkAQoYQ7OgeijlzHYaX3WNEcz yAAbLH36HfxqJ0l0KqrpObzCd+3RfgvpY3hVTpgDU0L/bN/joYWMW/DB4Z/gW7RMO3DS S/BsC13ALe9SFQXO7tIElmXdulBpcRH7m1EG7zJWi2bVV0ARkWQgFdYuQ2rr7rcBI/NO 920Q== X-Gm-Message-State: APjAAAUuAfryxaxK52TmC2BxXLSOj15jyApY8VPTSaYonnbHN/3EMaVf EvDhqVv1zKKxJqjRBeIaEGg= X-Google-Smtp-Source: APXvYqwWra2Sc/08AoaIjAxloJXIZP6qs/xpmbE0BpqWWT5VsUXK+KihykZfD1xBng/PW/zKWtJKGw== X-Received: by 2002:a1c:1d49:: with SMTP id d70mr13352482wmd.36.1555962493388; Mon, 22 Apr 2019 12:48:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:8071:6a3:700:4110:359:5d24:3425]) by smtp.gmail.com with ESMTPSA id h8sm12598448wrx.45.2019.04.22.12.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 12:48:12 -0700 (PDT) From: Simon Goldschmidt To: Tom Rini Date: Mon, 22 Apr 2019 21:48:06 +0200 Message-Id: <20190422194806.9227-1-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: Teddy Reed , Baruch Siach , Michal Simek , Joe Hershberger , Thomas Petazzoni , Stefan Roese , Marek Vasut , Tien Fong Chee , Ryder Lee , Heinrich Schuchardt , Alexander Graf , Otavio Salvador , Chris Packham , u-boot@lists.denx.de Subject: [U-Boot] [PATCH] 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 --- Kconfig | 8 -------- Makefile | 2 +- common/spl/Kconfig | 36 ++++++++++++++++++++++++++++++++++++ tools/Makefile | 2 ++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Kconfig b/Kconfig index ca31bcebde..7a5491bd67 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 ac375f396c..df674b0e96 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 diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 206c24076d..24ddab3a48 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 d377d85f74..d3b950553f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -199,6 +199,8 @@ hostprogs-$(CONFIG_RISCV) += prelink-riscv hostprogs-y += fdtgrep fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o +hostprogs-y += spl_size_limit + hostprogs-$(CONFIG_MIPS) += mips-relocs # We build some files with extra pedantic flags to try to minimize things