From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8E9FC433EF for ; Sat, 25 Sep 2021 13:05:48 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1685B610CF for ; Sat, 25 Sep 2021 13:05:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1685B610CF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E717883549; Sat, 25 Sep 2021 15:05:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="aUqSqW+R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0728483513; Sat, 25 Sep 2021 15:04:12 +0200 (CEST) Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CD2918352C for ; Sat, 25 Sep 2021 15:03:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc35.google.com with SMTP id m14-20020a4ad50e000000b002912a944a47so4218704oos.12 for ; Sat, 25 Sep 2021 06:03:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tzu6lMh7rIO/ZoLUyz1YfNT1ErvAtTxM6CyuV54SAcA=; b=aUqSqW+Rth7CE8SXkE3nY9b9PwSi6ldJyPqyuE7fMsBZS+vcUdc/aPlsd4nEdORjPn oVVw9PW1ToWQSC0ljFseLlmYphccQBYLVWqpDiMTewD77GkEz+22/4Sb5vRYaxZqjJGa lK3Dn685BdB2QztJ1rBTMp2sjUr4DG4qeeigg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tzu6lMh7rIO/ZoLUyz1YfNT1ErvAtTxM6CyuV54SAcA=; b=jLMsQfK6XO+4mGu7rZkhIbSvQbEJu6G0qs6K9mZKXH8RufXQDQTHTevnQ6JlJPin+U LXJ7SsM30WWCsQVnToXM5YMYjoACdZrORNXF160bKlh7TcqcNJcec78uFxTbgo+NBd+r /OmEo20kpxGnd1P62q20Y72WHbHt1eyX130qiCK5rHo5ixrr0xA+t63eApN61/OUtsFh dDbZDxu8dVeFGwAipzz2Yp5a03VY0XQxQN+jvzt4pfNO1EJQAKueQBf3zmZpatSvDDuc muoWQ3YL8m76owD+o2zNPiYVEujACznvbrdQdsS2rpqn0e34iDdMz4s2nWGxoJvhaTmi p4Kg== X-Gm-Message-State: AOAM530bBu8LleF23Z3x1QAcGp/U5bJDlpqcvCbCgbZV2KPdjfuw1xQk 7IciS0umKRySORGqpuNlgwq9xD/KLPrBqA== X-Google-Smtp-Source: ABdhPJzw/FoHXNreO4lUFW2muxr1jlsN55U87lCYe0crlIeHy3U8ifmfZ01PDXbSlaGuAFb4lXJb6Q== X-Received: by 2002:a4a:b994:: with SMTP id e20mr1313065oop.50.1632575027250; Sat, 25 Sep 2021 06:03:47 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id f61sm2770018otf.73.2021.09.25.06.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Sep 2021 06:03:46 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Alexandru Gagniuc , Bin Meng , Tom Rini , Simon Glass , Joe Hershberger , Marek Vasut Subject: [PATCH v4 09/15] image: Update image_decomp() to avoid ifdefs Date: Sat, 25 Sep 2021 07:03:14 -0600 Message-Id: <20210925070255.v4.9.I9c9eaf576574f98e5faa89e29f5eb11dc3444816@changeid> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog In-Reply-To: <20210925130320.7824-1-sjg@chromium.org> References: <20210925130320.7824-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Adjust this function so that preprocessor macros are not needed. With this, the host build uses more of the same header files as the target build. Rather than definining CONFIG_SYS_MALLOC_LEN, add a CONSERVE_MEMORY define, since that is the purpose of the value. This appears to have no impact on code size from a spot check of a few boards (snow, firefly-rk3288, boston32r2el, m53menlo). Signed-off-by: Simon Glass --- (no changes since v1) common/image.c | 145 ++++++++++++++++++-------------------- configs/sandbox_defconfig | 1 + 2 files changed, 69 insertions(+), 77 deletions(-) diff --git a/common/image.c b/common/image.c index 7fd4a567626..80aeb4398ec 100644 --- a/common/image.c +++ b/common/image.c @@ -22,12 +22,9 @@ #include #endif -#include #include -#include #include -#include #include #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT @@ -43,13 +40,6 @@ #include #include -#include -#include -#include -#include -#include -#include - #ifdef CONFIG_CMD_BDI extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); @@ -61,7 +51,15 @@ DECLARE_GLOBAL_DATA_PTR; static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, int verify); #endif + +/* Set this if we have less than 4 MB of malloc() space */ +#if CONFIG_SYS_MALLOC_LEN < (4096 * 1024) +#define CONSERVE_MEMORY true #else +#define CONSERVE_MEMORY false +#endif + +#else /* USE_HOSTCC */ #include "mkimage.h" #include #include @@ -70,10 +68,23 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, #ifndef __maybe_unused # define __maybe_unused /* unimplemented */ #endif + +#define CONSERVE_MEMORY false + #endif /* !USE_HOSTCC*/ -#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #ifndef CONFIG_SYS_BARGSIZE #define CONFIG_SYS_BARGSIZE 512 @@ -466,83 +477,63 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, else ret = -ENOSPC; break; -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(GZIP) - case IH_COMP_GZIP: { - ret = gunzip(load_buf, unc_len, image_buf, &image_len); + case IH_COMP_GZIP: + if (!host_build() && CONFIG_IS_ENABLED(GZIP)) + ret = gunzip(load_buf, unc_len, image_buf, &image_len); break; - } -#endif /* CONFIG_GZIP */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(BZIP2) - case IH_COMP_BZIP2: { - uint size = unc_len; + case IH_COMP_BZIP2: + if (!host_build() && CONFIG_IS_ENABLED(BZIP2)) { + uint size = unc_len; - /* - * If we've got less than 4 MB of malloc() space, - * use slower decompression algorithm which requires - * at most 2300 KB of memory. - */ - ret = BZ2_bzBuffToBuffDecompress(load_buf, &size, - image_buf, image_len, - CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); - image_len = size; + /* + * If we've got less than 4 MB of malloc() space, + * use slower decompression algorithm which requires + * at most 2300 KB of memory. + */ + ret = BZ2_bzBuffToBuffDecompress(load_buf, &size, + image_buf, image_len, CONSERVE_MEMORY, 0); + image_len = size; + } break; - } -#endif /* CONFIG_BZIP2 */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(LZMA) - case IH_COMP_LZMA: { - SizeT lzma_len = unc_len; + case IH_COMP_LZMA: + if (!host_build() && CONFIG_IS_ENABLED(LZMA)) { + SizeT lzma_len = unc_len; - ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, - image_buf, image_len); - image_len = lzma_len; + ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, + image_buf, image_len); + image_len = lzma_len; + } break; - } -#endif /* CONFIG_LZMA */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(LZO) - case IH_COMP_LZO: { - size_t size = unc_len; + case IH_COMP_LZO: + if (!host_build() && CONFIG_IS_ENABLED(LZO)) { + size_t size = unc_len; - ret = lzop_decompress(image_buf, image_len, load_buf, &size); - image_len = size; + ret = lzop_decompress(image_buf, image_len, load_buf, &size); + image_len = size; + } break; - } -#endif /* CONFIG_LZO */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(LZ4) - case IH_COMP_LZ4: { - size_t size = unc_len; + case IH_COMP_LZ4: + if (!host_build() && CONFIG_IS_ENABLED(LZ4)) { + size_t size = unc_len; - ret = ulz4fn(image_buf, image_len, load_buf, &size); - image_len = size; + ret = ulz4fn(image_buf, image_len, load_buf, &size); + image_len = size; + } break; - } -#endif /* CONFIG_LZ4 */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(ZSTD) - case IH_COMP_ZSTD: { - struct abuf in, out; - - abuf_init_set(&in, image_buf, image_len); - abuf_init_set(&in, load_buf, unc_len); - ret = zstd_decompress(&in, &out); - if (ret >= 0) { - image_len = ret; - ret = 0; + case IH_COMP_ZSTD: + if (!host_build() && CONFIG_IS_ENABLED(ZSTD)) { + struct abuf in, out; + + abuf_init_set(&in, image_buf, image_len); + abuf_init_set(&in, load_buf, unc_len); + ret = zstd_decompress(&in, &out); + if (ret >= 0) { + image_len = ret; + ret = 0; + } } break; } -#endif /* CONFIG_ZSTD */ -#endif - } if (ret == -ENOSYS) { printf("Unimplemented compression type %d\n", comp); return ret; @@ -960,7 +951,7 @@ int get_table_entry_id(const table_entry_t *table, const table_entry_t *t; for (t = table; t->id >= 0; ++t) { -#ifdef CONFIG_NEEDS_MANUAL_RELOC +#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC) if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0) #else if (t->sname && strcasecmp(t->sname, name) == 0) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index f1067b9adaa..d6016771907 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -56,6 +56,7 @@ CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEM_SEARCH=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_UNZIP=y CONFIG_CMD_BIND=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y -- 2.33.0.685.g46640cef36-goog