From patchwork Mon Apr 10 07:28:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikhil Jain X-Patchwork-Id: 1767081 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.a=rsa-sha256 header.s=ti-com-17Q1 header.b=iNLptZfX; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pw0zk5KW9z1yXv for ; Mon, 10 Apr 2023 17:32:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2C56B86022; Mon, 10 Apr 2023 09:32:07 +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="iNLptZfX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5A86856FA; Mon, 10 Apr 2023 09:29:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 48CA784D02 for ; Mon, 10 Apr 2023 09:29:06 +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 fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 33A7T1RE093740; Mon, 10 Apr 2023 02:29:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1681111741; bh=semhEbHj+H+Eib3acVtmpEwdzVWeHr+CA4PytsyNIrM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=iNLptZfX1GrrPUP/7OTg85Q1FG+Sw7RToh9mo2Hg7zWQJUdod1UOnxqAni6YUKJfX WwIhZbWjuzNLhi1lbmkxsbd1mJ5wzY7m8io+xtDyFc3lzlQg68pP7rppD64ER9agFR 8xS1myLT7zqY3iHvvwvxWFE27d40yhmp8gfFgR0g= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 33A7T1eh094225 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 10 Apr 2023 02:29:01 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 10 Apr 2023 02:29:01 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE103.ent.ti.com (10.64.6.24) 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; Mon, 10 Apr 2023 02:29:01 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 33A7T0o0093759; Mon, 10 Apr 2023 02:29:01 -0500 From: Nikhil M Jain To: , , CC: , , , Subject: [PATCH V7 08/14] cmd: bmp: Split bmp commands and functions Date: Mon, 10 Apr 2023 12:58:37 +0530 Message-ID: <20230410072843.97922-9-n-jain1@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410072843.97922-1-n-jain1@ti.com> References: <20230410072843.97922-1-n-jain1@ti.com> MIME-Version: 1.0 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 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 Reviewed-by: Simon Glass --- V7: - No change. 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 | 153 +++++++++++++++++++++++++++++++++++++++++++++ include/video.h | 8 +++ 3 files changed, 163 insertions(+), 160 deletions(-) create mode 100644 common/bmp.c diff --git a/cmd/bmp.c b/cmd/bmp.c index 46d0d916e8..8f43a40daf 100644 --- a/cmd/bmp.c +++ b/cmd/bmp.c @@ -9,84 +9,12 @@ */ #include -#include #include -#include -#include #include -#include -#include #include #include #include -#include - -static int bmp_info (ulong addr); - -/* - * 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 -struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, - void **alloc_addr) -{ - void *dst; - unsigned long len; - struct bmp_image *bmp; - - /* - * 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 +#include static int do_bmp_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -137,7 +65,7 @@ static int do_bmp_display(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; } - return (bmp_display(addr, x, y)); + return (bmp_display(addr, x, y)); } static struct cmd_tbl cmd_bmp_sub[] = { @@ -145,22 +73,6 @@ static struct cmd_tbl cmd_bmp_sub[] = { U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""), }; -#ifdef CONFIG_NEEDS_MANUAL_RELOC -void bmp_reloc(void) { - fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub)); -} -#endif - -/* - * Subroutine: do_bmp - * - * Description: Handler for 'bmp' command.. - * - * Inputs: argv[1] contains the subcommand - * - * Return: None - * - */ static int do_bmp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct cmd_tbl *c; @@ -183,73 +95,3 @@ U_BOOT_CMD( "info - display image info\n" "bmp display [x y] - display image at x,y" ); - -/* - * Subroutine: bmp_info - * - * Description: Show information about bmp file in memory - * - * Inputs: addr address of the bmp file - * - * Return: None - * - */ -static 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/common/bmp.c b/common/bmp.c new file mode 100644 index 0000000000..d98ba9d882 --- /dev/null +++ b/common/bmp.c @@ -0,0 +1,153 @@ +// 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 +#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 +struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, + void **alloc_addr) +{ + void *dst; + unsigned long len; + struct bmp_image *bmp; + + /* + * 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..29c4f51efb 100644 --- a/include/video.h +++ b/include/video.h @@ -357,4 +357,12 @@ 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 + * Returns: 0 if OK, else 1 if bmp image not found + */ +int bmp_info(ulong addr); + #endif