[U-Boot] [PATCH 1/5] Add bmp_layout module for accessing BMP header data

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


Currently code that displays BMP files does two things:
* assume that any address is a valid load address for a BMP
* access in-memory BMP header fields directly

Since some BMP header fields are 32 bit wide, this has a potential
for causing data aborts when these fields are placed in unaligned
addresses.

Create an API for safely accessing BMP header data, and compile it with
$(PLATFORM_NO_UNALIGNED) to give it the ability to emulate unaligned memory
accesses.

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/Makefile      |    8 +++++
 common/bmp_layout.c  |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/bmp_layout.h |   15 ++++++++
 3 files changed, 119 insertions(+)
 create mode 100644 common/bmp_layout.c

diff --git a/common/Makefile b/common/Makefile
index 54fcc81..2a972c8 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -187,7 +187,14 @@ endif
 ifdef CONFIG_SPD_EEPROM
 SPD := y
 endif
+ifdef CONFIG_CMD_BMP
+BMP_LAYOUT := y
+endif
+ifdef CONFIG_SPLASH_SCREEN
+BMP_LAYOUT := y
+endif
 COBJS-$(SPD) += ddr_spd.o
+COBJS-$(BMP_LAYOUT) += bmp_layout.o
 COBJS-$(CONFIG_HWCONFIG) += hwconfig.o
 COBJS-$(CONFIG_BOOTSTAGE) += bootstage.o
 COBJS-$(CONFIG_CONSOLE_MUX) += iomux.o
@@ -250,6 +257,7 @@ $(obj)../tools/envcrc:
 # SEE README.arm-unaligned-accesses
 $(obj)hush.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
 $(obj)fdt_support.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
+$(obj)bmp_layout.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
 
 #########################################################################
 
diff --git a/common/bmp_layout.c b/common/bmp_layout.c
new file mode 100644
index 0000000..c55b653
--- /dev/null
+++ b/common/bmp_layout.c
@@ -0,0 +1,96 @@
+/* (C) Copyright 2013
+ * Nikita Kiryanov, Compulab, nikita at compulab.co.il.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <asm/types.h>
+#include <bmp_layout.h>
+#include <compiler.h>
+
+int bmp_signature_valid(bmp_image_t *bmp)
+{
+	return bmp->header.signature[0] == 'B' &&
+		bmp->header.signature[1] == 'M';
+}
+
+__u32 bmp_get_file_size(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.file_size);
+}
+
+__u32 bmp_get_data_offset(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.data_offset);
+}
+
+__u32 bmp_get_size(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.size);
+}
+
+__u32 bmp_get_width(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.width);
+}
+
+__u32 bmp_get_height(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.height);
+}
+
+__u16 bmp_get_planes(bmp_image_t *bmp)
+{
+	return le16_to_cpu(bmp->header.planes);
+}
+
+__u16 bmp_get_bit_count(bmp_image_t *bmp)
+{
+	return le16_to_cpu(bmp->header.bit_count);
+}
+
+__u32 bmp_get_compression(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.compression);
+}
+
+__u32 bmp_get_image_size(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.image_size);
+}
+
+__u32 bmp_get_x_pixels_per_m(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.x_pixels_per_m);
+}
+
+__u32 bmp_get_y_pixels_per_m(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.y_pixels_per_m);
+}
+
+__u32 bmp_get_colors_used(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.colors_used);
+}
+
+__u32 bmp_get_colors_important(bmp_image_t *bmp)
+{
+	return le32_to_cpu(bmp->header.colors_important);
+}
diff --git a/include/bmp_layout.h b/include/bmp_layout.h
index d823de9..a983147 100644
--- a/include/bmp_layout.h
+++ b/include/bmp_layout.h
@@ -74,4 +74,19 @@ typedef struct bmp_image {
 #define BMP_BI_RLE8	1
 #define BMP_BI_RLE4	2
 
+int bmp_signature_valid(bmp_image_t *bmp);
+__u32 bmp_get_file_size(bmp_image_t *bmp);
+__u32 bmp_get_data_offset(bmp_image_t *bmp);
+__u32 bmp_get_size(bmp_image_t *bmp);
+__u32 bmp_get_width(bmp_image_t *bmp);
+__u32 bmp_get_height(bmp_image_t *bmp);
+__u16 bmp_get_planes(bmp_image_t *bmp);
+__u16 bmp_get_bit_count(bmp_image_t *bmp);
+__u32 bmp_get_compression(bmp_image_t *bmp);
+__u32 bmp_get_image_size(bmp_image_t *bmp);
+__u32 bmp_get_x_pixels_per_m(bmp_image_t *bmp);
+__u32 bmp_get_y_pixels_per_m(bmp_image_t *bmp);
+__u32 bmp_get_colors_used(bmp_image_t *bmp);
+__u32 bmp_get_colors_important(bmp_image_t *bmp);
+
 #endif							/* _BMP_H_ */
-- 
1.7.10.4



More information about the U-Boot mailing list