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 <[email protected]>
Signed-off-by: Igor Grinberg <[email protected]>
---
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

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to