[U-Boot] [PATCH V2] lcd: align bmp header when uncopmressing image

Wolfgang Denk wd at denx.de
Mon Jun 3 20:44:52 CEST 2013


Dear Piotr Wilczek,

In message <1370267979-17800-1-git-send-email-p.wilczek at samsung.com> you wrote:
> When compressed image is loaded, it must be decompressed
> to an aligned address + 2 to avoid unaligned access exception
> on some ARM platforms.
...

> -	dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
> +	dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 0x04);

Why + 4?  This needs a comment.  And please write 4 as 4, and not as
0x4 when there is no good reason for it.

> +	/* align to 32-bit-aligned-address + 2 */
> +	if ((unsigned int)bmp % 0x04 != 0x02)
> +		bmp = (bmp_image_t *)((((unsigned int)dst + 0x2) & ~0x1) | 0x2);

This is difficult to read and inefficient.

If you want to do it manually, just write it as

	bmp = (bmp_image_t *)((((unsigned int)dst + 1) & ~3) + 2);

[Actually adding 3 to the "malloc()" size above would be sufficient
with this].

A more readable way but slightly less efficient way might be:

	u32_t n = (u32_t)dst;

	bmp = (bmp_image_t *)(ALIGN(n, 4) + 2);

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I've got to get something inside me. Some coffee  or  something.  And
then the world will somehow be better.
                                     - Terry Pratchett, _Men at Arms_


More information about the U-Boot mailing list