From patchwork Tue Dec 4 15:40:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 1007717 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=none (p=none dis=none) header.from=denx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 438R0R5kt0z9s7W for ; Wed, 5 Dec 2018 02:40:55 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5EC57C222DF; Tue, 4 Dec 2018 15:40:52 +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=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 872E6C21F7A; Tue, 4 Dec 2018 15:40:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8E53CC21F7A; Tue, 4 Dec 2018 15:40:48 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by lists.denx.de (Postfix) with ESMTPS id 0F238C21F04 for ; Tue, 4 Dec 2018 15:40:48 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 438R0H61wQz1r0Hd for ; Tue, 4 Dec 2018 16:40:47 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 438R0H5rT4z1qw6B for ; Tue, 4 Dec 2018 16:40:47 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id TuPLPFYzp6y4 for ; Tue, 4 Dec 2018 16:40:47 +0100 (CET) X-Auth-Info: MZwlW3QIAZOy0QfF2eZ/OwueRM3L3Xh40/7dQifsmMg= Received: from janitor.denx.de (unknown [62.91.23.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Tue, 4 Dec 2018 16:40:47 +0100 (CET) Received: by janitor.denx.de (Postfix, from userid 119) id 8BC0AFD; Tue, 4 Dec 2018 16:40:46 +0100 (CET) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id 0EC6DF8; Tue, 4 Dec 2018 16:40:40 +0100 (CET) Received: by gemini.denx.de (Postfix, from userid 500) id D0A8324226E; Tue, 4 Dec 2018 16:40:39 +0100 (CET) From: Wolfgang Denk To: u-boot@lists.denx.de Date: Tue, 4 Dec 2018 16:40:35 +0100 Message-Id: <20181204154035.16299-1-wd@denx.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Cc: Otavio Salvador , Vanessa Maegima , Stefan Roese , John Weber Subject: [U-Boot] [PATCH] Enable expression support for CONFIG_BOARD_SIZE_LIMIT 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" So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use #define CONFIG_BOARD_SIZE_LIMIT (768 << 10) in the board configuration. Signed-off-by: Wolfgang Denk Cc: Fabio Estevam Cc: Stefano Babic Cc: Vanessa Maegima Cc: Otavio Salvador Cc: John Weber Cc: Stefan Roese Reviewed-by: Otavio Salvador Tested-by: Fabio Estevam --- Note 1: As gawk lacks an eval function, we use bash's $((...)) mechanism to evaluate the expression. This has the additional benefit that it supports expressions like "<<" which awk does not understand. OK, one could replace awk by something better... Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a lter commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 0d11ff9797..d4c8f697cf 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \ ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 53d9e5f42b..230a5c73aa 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -60,15 +60,14 @@ endif ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif