[U-Boot] [PATCH V2 3/7] lcd: prevent unaligned memory access when displaying splash screen

Nikita Kiryanov nikita at compulab.co.il
Tue Jan 29 13:42:25 CET 2013


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 <nikita at compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg at compulab.co.il>
---
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) {
-- 
1.7.10.4



More information about the U-Boot mailing list