[U-Boot] [PATCH 2/5] lcd: use bmp_layout API

Nikita Kiryanov nikita at compulab.co.il
Mon Feb 4 12:39:36 CET 2013


If the BMP headers are located in unaligned addresses, accessing them
directly may lead to a data abort on some architectures. Use the safer
bmp_layout API instead.

Signed-off-by: Nikita Kiryanov <nikita at compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg at compulab.co.il>
Cc: Anatolij Gustschin <agust at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
Cc: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: Jeroen Hofstee <jeroen at myspectrum.nl>>
---
 common/lcd.c |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/common/lcd.c b/common/lcd.c
index 66d4f94..4c0c87f 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -750,9 +750,9 @@ static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
 	int x, y;
 	int decode = 1;
 
-	width = le32_to_cpu(bmp->header.width);
-	height = le32_to_cpu(bmp->header.height);
-	bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
+	width = bmp_get_width(bmp);
+	height = bmp_get_height(bmp);
+	bmap = (uchar *)bmp + bmp_get_data_offset(bmp);
 
 	x = 0;
 	y = height - 1;
@@ -866,16 +866,15 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
 	unsigned long pwidth = panel_info.vl_col;
 	unsigned colors, bpix, bmp_bpix;
 
-	if (!bmp || !((bmp->header.signature[0] == 'B') &&
-		(bmp->header.signature[1] == 'M'))) {
+	if (!bmp || !bmp_signature_valid(bmp)) {
 		printf("Error: no valid bmp image at %lx\n", bmp_image);
 
 		return 1;
 	}
 
-	width = le32_to_cpu(bmp->header.width);
-	height = le32_to_cpu(bmp->header.height);
-	bmp_bpix = le16_to_cpu(bmp->header.bit_count);
+	width = bmp_get_width(bmp);
+	height = bmp_get_height(bmp);
+	bmp_bpix = bmp_get_bit_count(bmp);
 	colors = 1 << bmp_bpix;
 
 	bpix = NBITS(panel_info.vl_bpix);
@@ -891,7 +890,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
 	if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
 		printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
 			bpix,
-			le16_to_cpu(bmp->header.bit_count));
+			bmp_get_bit_count(bmp));
 
 		return 1;
 	}
@@ -960,7 +959,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
 	if ((y + height) > panel_info.vl_row)
 		height = panel_info.vl_row - y;
 
-	bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
+	bmap = (uchar *)bmp + bmp_get_data_offset(bmp);
 	fb   = (uchar *) (lcd_base +
 		(y + height - 1) * lcd_line_length + x * bpix / 8);
 
@@ -968,7 +967,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
 	case 1: /* pass through */
 	case 8:
 #ifdef CONFIG_LCD_BMP_RLE8
-		if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
+		if (bmp_get_compression(bmp) == BMP_BI_RLE8) {
 			if (bpix != 16) {
 				/* TODO implement render code for bpix != 16 */
 				printf("Error: only support 16 bpix");
-- 
1.7.10.4



More information about the U-Boot mailing list