From patchwork Mon Jun 3 13:59:39 2013
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Piotr Wilczek
X-Patchwork-Id: 248288
X-Patchwork-Delegate: agust@denx.de
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from theia.denx.de (theia.denx.de [85.214.87.163])
by ozlabs.org (Postfix) with ESMTP id B5DCE2C00A4
for ;
Tue, 4 Jun 2013 00:00:35 +1000 (EST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 1D7FC4A088;
Mon, 3 Jun 2013 16:00:33 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at theia.denx.de
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id cNYouMpVrtyB; Mon, 3 Jun 2013 16:00:32 +0200 (CEST)
Received: from theia.denx.de (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 5A7754A04A;
Mon, 3 Jun 2013 16:00:31 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id DAAA74A04A
for ; Mon, 3 Jun 2013 16:00:23 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at theia.denx.de
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id KmDQVtqj4iZw for ;
Mon, 3 Jun 2013 16:00:17 +0200 (CEST)
X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5
NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested)
Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34])
by theia.denx.de (Postfix) with ESMTP id 175564A026
for ; Mon, 3 Jun 2013 16:00:11 +0200 (CEST)
Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27])
by mailout4.samsung.com
(Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit
(built Nov
17 2011)) with ESMTP id <0MNT00C28LK1T460@mailout4.samsung.com> for
u-boot@lists.denx.de; Mon, 03 Jun 2013 23:00:08 +0900 (KST)
X-AuditID: cbfee61b-b7f8e6d00000524c-d1-51aca16806c3
Received: from epmmp1.local.host ( [203.254.227.16])
by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 23.A2.21068.861ACA15;
Mon, 03 Jun 2013 23:00:08 +0900 (KST)
Received: from mcdsrvbld02.digital.local ([106.116.37.23])
by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01
(7.0.4.24.0) 64bit (built Nov 17 2011))
with ESMTPA id <0MNT00FMYLJL4K20@mmp1.samsung.com>; Mon,
03 Jun 2013 23:00:08 +0900 (KST)
From: Piotr Wilczek
To: u-boot@lists.denx.de
Date: Mon, 03 Jun 2013 15:59:39 +0200
Message-id: <1370267979-17800-1-git-send-email-p.wilczek@samsung.com>
X-Mailer: git-send-email 1.7.10
In-reply-to: <1369999573-15449-1-git-send-email-p.wilczek@samsung.com>
References: <1369999573-15449-1-git-send-email-p.wilczek@samsung.com>
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e+xgG7GwjWBBnfvqFusv7uE0eJs0xt2
izcPNzNadBxpYbRY92Qtq8XbvZ3sFpMfvmJ0YPeYN+sEi8fZOzsYPfq2rGIMYI7isklJzcks
Sy3St0vgylj3bw57wSy1ii0bfrM2MJ6S62Lk5JAQMJHobzzKDmGLSVy4t56ti5GLQ0hgEaPE
oymv2SGcLiaJCz+vMINUsQloSyx/84YRxBYRkJD41X+VEaSIWeAVo8SGqR/BEsICThInTj9h
ArFZBFQlbp1dwwJi8wq4Stx7Op0FYp28xNP7fWwgNqeAm8TCZZvA6oWAavb8fMw8gZF3ASPD
KkbR1ILkguKk9FwjveLE3OLSvHS95PzcTYzgMHomvYNxVYPFIUYBDkYlHt4AjzWBQqyJZcWV
uYcYJTiYlUR4rwQChXhTEiurUovy44tKc1KLDzFKc7AoifMebLUOFBJITyxJzU5NLUgtgsky
cXBKNTByL2B01Hkrv9h2929xr+T5ElPLkpTCrrqIOrdWOGhcV/lUUprfmKHK8/3TcquHF8LT
PdIVb858MZ3tburmf4nBDzc+mftOSEZm0XLVNOMkxb4cD6mWlkQX7xlCKZYnD0oFcZrsEJ7M
VsHjP3PpmaiDa/oXH78cN6Oj3I95/r2Nee9n8bU/1VViKc5INNRiLipOBACsUVpOHwIAAA==
Cc: Piotr Wilczek ,
Kyungmin Park
Subject: [U-Boot] [PATCH V2] lcd: align bmp header when uncopmressing image
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: U-Boot discussion
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
MIME-Version: 1.0
Sender: u-boot-bounces@lists.denx.de
Errors-To: u-boot-bounces@lists.denx.de
When compressed image is loaded, it must be decompressed
to an aligned address + 2 to avoid unaligned access exception
on some ARM platforms.
Signed-off-by: Piotr Wilczek
Signed-off-by: Kyungmin Park
CC: Anatolij Gustschin
CC: Wolfgang Denk
---
Changes for V2:
- add additional space for uncompressed bmp header due to alignment requirements
- fix to 32-bit-aligned-address + 2 alignent
common/cmd_bmp.c | 42 ++++++++++++++++++++++++++++--------------
include/lcd.h | 3 ++-
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c
index 5a52edd..06634b2 100644
--- a/common/cmd_bmp.c
+++ b/common/cmd_bmp.c
@@ -38,14 +38,19 @@ static int bmp_info (ulong addr);
/*
* Allocate and decompress a BMP image using gunzip().
*
- * Returns a pointer to the decompressed image data. Must be freed by
- * the caller after use.
+ * Returns a pointer to the decompressed image data. This pointer is
+ * 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
-bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
+bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp,
+ void **alloc_addr)
{
void *dst;
unsigned long len;
@@ -55,12 +60,19 @@ bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
* Decompress bmp image
*/
len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
- dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
+ dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 0x04);
if (dst == NULL) {
puts("Error: malloc in gunzip failed!\n");
return NULL;
}
- if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, (uchar *)addr, &len) != 0) {
+
+ bmp = dst;
+
+ /* align to 32-bit-aligned-address + 2 */
+ if ((unsigned int)bmp % 0x04 != 0x02)
+ bmp = (bmp_image_t *)((((unsigned int)dst + 0x2) & ~0x1) | 0x2);
+
+ if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, (uchar *)addr, &len) != 0) {
free(dst);
return NULL;
}
@@ -68,8 +80,6 @@ bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
puts("Image could be truncated"
" (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
- bmp = dst;
-
/*
* Check for bmp mark 'BM'
*/
@@ -81,10 +91,12 @@ bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
debug("Gzipped BMP image detected!\n");
+ *alloc_addr = dst;
return bmp;
}
#else
-bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
+bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp,
+ void **alloc_addr)
{
return NULL;
}
@@ -189,11 +201,12 @@ U_BOOT_CMD(
static int bmp_info(ulong addr)
{
bmp_image_t *bmp=(bmp_image_t *)addr;
+ 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 = gunzip_bmp(addr, &len, &bmp_alloc_addr);
if (bmp == NULL) {
printf("There is no valid bmp file at the given address\n");
@@ -205,8 +218,8 @@ static int bmp_info(ulong addr)
printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
- if ((unsigned long)bmp != addr)
- free(bmp);
+ if (bmp_alloc_addr)
+ free(bmp_alloc_addr);
return(0);
}
@@ -225,11 +238,12 @@ int bmp_display(ulong addr, int x, int y)
{
int ret;
bmp_image_t *bmp = (bmp_image_t *)addr;
+ 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 = gunzip_bmp(addr, &len, &bmp_alloc_addr);
if (!bmp) {
printf("There is no valid bmp file at the given address\n");
@@ -244,8 +258,8 @@ int bmp_display(ulong addr, int x, int y)
# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
#endif
- if ((unsigned long)bmp != addr)
- free(bmp);
+ if (bmp_alloc_addr)
+ free(bmp_alloc_addr);
return ret;
}
diff --git a/include/lcd.h b/include/lcd.h
index c6e7fc5..482e606 100644
--- a/include/lcd.h
+++ b/include/lcd.h
@@ -46,7 +46,8 @@ void lcd_initcolregs(void);
int lcd_getfgcolor(void);
/* gunzip_bmp used if CONFIG_VIDEO_BMP_GZIP */
-struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp);
+struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
+ void **alloc_addr);
int bmp_display(ulong addr, int x, int y);
/**