From patchwork Tue Jan 29 12:42:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot, V2, 3/7] lcd: prevent unaligned memory access when displaying splash screen X-Patchwork-Submitter: Nikita Kiryanov X-Patchwork-Id: 216519 X-Patchwork-Delegate: trini@ti.com Message-Id: <1359463349-11649-4-git-send-email-nikita@compulab.co.il> To: u-boot@lists.denx.de Cc: jeroen@myspectrum.nl, trini@ti.com Date: Tue, 29 Jan 2013 14:42:25 +0200 From: Nikita Kiryanov List-Id: U-Boot discussion When the bmp file is loaded to an address specified by the environment variable "splashimage", its header members might be unaligned. This happens because the bmp header starts with two byte-size fields followd by mostly 32 bit fields, so when the address in splashimage is not equal to aligned address plus/minus 2, the 32 bit members will be placed in unaligned addresses. This results in a data abort on targets that cannot handle unaligned memory accesses. Check that the address is safe to use, and fix it if it's not. Signed-off-by: Nikita Kiryanov Signed-off-by: Igor Grinberg --- NOTE: New patch in the series; no V1. common/lcd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/lcd.c b/common/lcd.c index 66d4f94..104125d 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -1046,6 +1046,14 @@ static void *lcd_logo(void) do_splash = 0; addr = simple_strtoul (s, NULL, 16); + /* + * In order for the fields of bmp header to be properly aligned + * in memory, splash image addr must be aligned to "aligned + * address plus 2". Fix addr if necessary. + */ + if (addr % 4 != 2) + addr += (addr % 4) ?: 2; + #ifdef CONFIG_SPLASH_SCREEN_ALIGN s = getenv("splashpos"); if (s != NULL) {