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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A17FBC7618D for ; Thu, 6 Apr 2023 06:27:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 53B1485FE0; Thu, 6 Apr 2023 08:27:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com 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=ti.com header.i=@ti.com header.b="TgYQqIji"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 98BEF85FE7; Thu, 6 Apr 2023 08:27:42 +0200 (CEST) Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 51C9585FC9 for ; Thu, 6 Apr 2023 08:27:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=n-jain1@ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3366RTBV094031; Thu, 6 Apr 2023 01:27:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1680762449; bh=QjRHnvD9CbNiSEqDkAuyP+VqL4r1g/AOdxVEzdAJxr4=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=TgYQqIjiogiLHqbAArGOan3/ey2PX5zARJl8u/FxgsjtTqm8vH4JavffTw5cmpv5C 4+IitxW4gkeRIMD5fR0z4m7U09uMLA/K5MX9bsSijJb2PPZR0lhYglSsolQqve61Ad g331tbcfeemlp8Bl2yVl20y82cXyWkToYUwoUK0E= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3366RTfd101608 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 6 Apr 2023 01:27:29 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Thu, 6 Apr 2023 01:27:28 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Thu, 6 Apr 2023 01:27:28 -0500 Received: from [172.24.145.96] (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3366RQr7110178; Thu, 6 Apr 2023 01:27:27 -0500 Message-ID: Date: Thu, 6 Apr 2023 11:57:26 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH V6 08/13] cmd: bmp: Split bmp commands and functions Content-Language: en-US To: Simon Glass CC: , , , , References: <20230404130610.65022-1-n-jain1@ti.com> <20230404130610.65022-9-n-jain1@ti.com> From: Nikhil M Jain In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean Hi Simon, On 06/04/23 00:07, Simon Glass wrote: > On Wed, 5 Apr 2023 at 01:06, Nikhil M Jain wrote: >> >> To enable splash screen at SPL, need to compile cmd/bmp.c which also >> includes bmp commands, since SPL doesn't use commands split bmp.c into >> common/bmp.c which includes all bmp functions and cmd/bmp.c which only >> contains bmp commands. >> >> Add function delclaration for bmp_info in video.h. >> >> Signed-off-by: Nikhil M Jain >> --- >> V6: >> - Fix commit message. >> - Remove unused header files. >> >> V5: >> - Rename cmd/bmp_cmd to cmd/bmp. >> >> V4: >> - No change. >> >> V3 (patch introduced): >> - Split bmp functions and commands. >> >> cmd/bmp.c | 162 +----------------------------------------------- >> common/bmp.c | 152 +++++++++++++++++++++++++++++++++++++++++++++ >> include/video.h | 7 +++ >> 3 files changed, 161 insertions(+), 160 deletions(-) >> create mode 100644 common/bmp.c > > Reviewed-by: Simon Glass > > Please see below > > >> diff --git a/common/bmp.c b/common/bmp.c >> new file mode 100644 >> index 0000000000..6134ada5a7 >> --- /dev/null >> +++ b/common/bmp.c >> @@ -0,0 +1,152 @@ >> +// SPDX-License-Identifier: GPL-2.0+ >> +/* >> + * (C) Copyright 2002 >> + * Detlev Zundel, DENX Software Engineering, dzu@denx.de. >> + */ >> + >> +/* >> + * BMP handling routines >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +/* >> + * Allocate and decompress a BMP image using gunzip(). >> + * >> + * Returns a pointer to the decompressed image data. This pointer is >> + * aligned to 32-bit-aligned-address + 2. >> + * See doc/README.displaying-bmps for explanation. >> + * >> + * The allocation address is passed to 'alloc_addr' and must be freed >> + * by the caller after use. >> + * >> + * Returns NULL if decompression failed, or if the decompressed data >> + * didn't contain a valid BMP signature. >> + */ >> +#ifdef CONFIG_VIDEO_BMP_GZIP > > You can drop this #ifdef and see below > >> +struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, >> + void **alloc_addr) >> +{ >> + void *dst; >> + unsigned long len; >> + struct bmp_image *bmp; >> + > > if (!IS_ENABLED(CONFIG_VIDEO_BMP_GZIP)) > return NULL; > I preferred to use #if to avoid compilation of code when not required. For example, if someone doesn't want to display a gzip bmp image they wouldn't want the code to be compiled, so that binary size doesn't increase. >> + /* >> + * Decompress bmp image >> + */ >> + len = CONFIG_VIDEO_LOGO_MAX_SIZE; >> + /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */ >> + dst = malloc(CONFIG_VIDEO_LOGO_MAX_SIZE + 3); >> + if (!dst) { >> + puts("Error: malloc in gunzip failed!\n"); >> + return NULL; >> + } >> + >> + /* align to 32-bit-aligned-address + 2 */ >> + bmp = dst + 2; >> + >> + if (gunzip(bmp, CONFIG_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0), >> + &len)) { >> + free(dst); >> + return NULL; >> + } >> + if (len == CONFIG_VIDEO_LOGO_MAX_SIZE) >> + puts("Image could be truncated (increase CONFIG_VIDEO_LOGO_MAX_SIZE)!\n"); >> + >> + /* >> + * Check for bmp mark 'BM' >> + */ >> + if (!((bmp->header.signature[0] == 'B') && >> + (bmp->header.signature[1] == 'M'))) { >> + free(dst); >> + return NULL; >> + } >> + >> + debug("Gzipped BMP image detected!\n"); >> + >> + *alloc_addr = dst; >> + return bmp; >> +} >> +#else >> +struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, >> + void **alloc_addr) >> +{ >> + return NULL; >> +} >> +#endif >> + >> + >> +#ifdef CONFIG_NEEDS_MANUAL_RELOC >> +void bmp_reloc(void) { >> + fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub)); >> +} >> +#endif >> + >> +int bmp_info(ulong addr) >> +{ >> + struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0); >> + void *bmp_alloc_addr = NULL; >> + unsigned long len; >> + >> + if (!((bmp->header.signature[0]=='B') && >> + (bmp->header.signature[1]=='M'))) >> + bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr); >> + >> + if (bmp == NULL) { >> + printf("There is no valid bmp file at the given address\n"); >> + return 1; >> + } >> + >> + printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width), >> + le32_to_cpu(bmp->header.height)); >> + printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count)); >> + printf("Compression : %d\n", le32_to_cpu(bmp->header.compression)); >> + >> + if (bmp_alloc_addr) >> + free(bmp_alloc_addr); >> + >> + return(0); >> +} >> + >> +int bmp_display(ulong addr, int x, int y) >> +{ >> + struct udevice *dev; >> + int ret; >> + struct bmp_image *bmp = map_sysmem(addr, 0); >> + void *bmp_alloc_addr = NULL; >> + unsigned long len; >> + >> + if (!((bmp->header.signature[0]=='B') && >> + (bmp->header.signature[1]=='M'))) >> + bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr); >> + >> + if (!bmp) { >> + printf("There is no valid bmp file at the given address\n"); >> + return 1; >> + } >> + addr = map_to_sysmem(bmp); >> + >> + ret = uclass_first_device_err(UCLASS_VIDEO, &dev); >> + if (!ret) { >> + bool align = false; >> + >> + if (x == BMP_ALIGN_CENTER || y == BMP_ALIGN_CENTER) >> + align = true; >> + >> + ret = video_bmp_display(dev, addr, x, y, align); >> + } >> + >> + if (bmp_alloc_addr) >> + free(bmp_alloc_addr); >> + >> + return ret ? CMD_RET_FAILURE : 0; >> +} >> diff --git a/include/video.h b/include/video.h >> index 4d99e5dc27..b38fb9081a 100644 >> --- a/include/video.h >> +++ b/include/video.h >> @@ -357,4 +357,11 @@ void *video_get_u_boot_logo(void); >> */ >> int bmp_display(ulong addr, int x, int y); >> >> +/* >> + * bmp_info() - Show information about bmp file >> + * >> + * @addr: address of bmp file > > Return: ... > >> + */ >> +int bmp_info(ulong addr); >> + >> #endif >> -- >> 2.34.1 >> > > Regards, > SImon