1 // SPDX-License-Identifier: GPL-2.0+
4 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
8 * BMP handling routines
12 #include <bmp_layout.h>
21 #include <asm/byteorder.h>
23 static int bmp_info (ulong addr
);
26 * Allocate and decompress a BMP image using gunzip().
28 * Returns a pointer to the decompressed image data. This pointer is
29 * aligned to 32-bit-aligned-address + 2.
30 * See doc/README.displaying-bmps for explanation.
32 * The allocation address is passed to 'alloc_addr' and must be freed
33 * by the caller after use.
35 * Returns NULL if decompression failed, or if the decompressed data
36 * didn't contain a valid BMP signature.
38 #ifdef CONFIG_VIDEO_BMP_GZIP
39 struct bmp_image
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
,
44 struct bmp_image
*bmp
;
47 * Decompress bmp image
49 len
= CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
;
50 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
51 dst
= malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
+ 3);
53 puts("Error: malloc in gunzip failed!\n");
59 /* align to 32-bit-aligned-address + 2 */
60 bmp
= (struct bmp_image
*)((((uintptr_t)dst
+ 1) & ~3) + 2);
62 if (gunzip(bmp
, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
, map_sysmem(addr
, 0),
67 if (len
== CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
)
68 puts("Image could be truncated"
69 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
72 * Check for bmp mark 'BM'
74 if (!((bmp
->header
.signature
[0] == 'B') &&
75 (bmp
->header
.signature
[1] == 'M'))) {
80 debug("Gzipped BMP image detected!\n");
86 struct bmp_image
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
,
93 static int do_bmp_info(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
98 case 1: /* use load_addr as default address */
101 case 2: /* use argument */
102 addr
= simple_strtoul(argv
[1], NULL
, 16);
105 return CMD_RET_USAGE
;
108 return (bmp_info(addr
));
111 static int do_bmp_display(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
116 splash_get_pos(&x
, &y
);
119 case 1: /* use load_addr as default address */
122 case 2: /* use argument */
123 addr
= simple_strtoul(argv
[1], NULL
, 16);
126 addr
= simple_strtoul(argv
[1], NULL
, 16);
127 if (!strcmp(argv
[2], "m"))
128 x
= BMP_ALIGN_CENTER
;
130 x
= simple_strtoul(argv
[2], NULL
, 10);
131 if (!strcmp(argv
[3], "m"))
132 y
= BMP_ALIGN_CENTER
;
134 y
= simple_strtoul(argv
[3], NULL
, 10);
137 return CMD_RET_USAGE
;
140 return (bmp_display(addr
, x
, y
));
143 static cmd_tbl_t cmd_bmp_sub
[] = {
144 U_BOOT_CMD_MKENT(info
, 3, 0, do_bmp_info
, "", ""),
145 U_BOOT_CMD_MKENT(display
, 5, 0, do_bmp_display
, "", ""),
148 #ifdef CONFIG_NEEDS_MANUAL_RELOC
149 void bmp_reloc(void) {
150 fixup_cmdtable(cmd_bmp_sub
, ARRAY_SIZE(cmd_bmp_sub
));
157 * Description: Handler for 'bmp' command..
159 * Inputs: argv[1] contains the subcommand
164 static int do_bmp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
168 /* Strip off leading 'bmp' command argument */
172 c
= find_cmd_tbl(argv
[0], &cmd_bmp_sub
[0], ARRAY_SIZE(cmd_bmp_sub
));
175 return c
->cmd(cmdtp
, flag
, argc
, argv
);
177 return CMD_RET_USAGE
;
182 "manipulate BMP image data",
183 "info <imageAddr> - display image info\n"
184 "bmp display <imageAddr> [x y] - display image at x,y"
188 * Subroutine: bmp_info
190 * Description: Show information about bmp file in memory
192 * Inputs: addr address of the bmp file
197 static int bmp_info(ulong addr
)
199 struct bmp_image
*bmp
= (struct bmp_image
*)map_sysmem(addr
, 0);
200 void *bmp_alloc_addr
= NULL
;
203 if (!((bmp
->header
.signature
[0]=='B') &&
204 (bmp
->header
.signature
[1]=='M')))
205 bmp
= gunzip_bmp(addr
, &len
, &bmp_alloc_addr
);
208 printf("There is no valid bmp file at the given address\n");
212 printf("Image size : %d x %d\n", le32_to_cpu(bmp
->header
.width
),
213 le32_to_cpu(bmp
->header
.height
));
214 printf("Bits per pixel: %d\n", le16_to_cpu(bmp
->header
.bit_count
));
215 printf("Compression : %d\n", le32_to_cpu(bmp
->header
.compression
));
218 free(bmp_alloc_addr
);
224 * Subroutine: bmp_display
226 * Description: Display bmp file located in memory
228 * Inputs: addr address of the bmp file
233 int bmp_display(ulong addr
, int x
, int y
)
235 #ifdef CONFIG_DM_VIDEO
239 struct bmp_image
*bmp
= map_sysmem(addr
, 0);
240 void *bmp_alloc_addr
= NULL
;
243 if (!((bmp
->header
.signature
[0]=='B') &&
244 (bmp
->header
.signature
[1]=='M')))
245 bmp
= gunzip_bmp(addr
, &len
, &bmp_alloc_addr
);
248 printf("There is no valid bmp file at the given address\n");
251 addr
= map_to_sysmem(bmp
);
253 #ifdef CONFIG_DM_VIDEO
254 ret
= uclass_first_device_err(UCLASS_VIDEO
, &dev
);
258 if (CONFIG_IS_ENABLED(SPLASH_SCREEN_ALIGN
) ||
259 x
== BMP_ALIGN_CENTER
||
260 y
== BMP_ALIGN_CENTER
)
263 ret
= video_bmp_display(dev
, addr
, x
, y
, align
);
265 #elif defined(CONFIG_LCD)
266 ret
= lcd_display_bitmap(addr
, x
, y
);
267 #elif defined(CONFIG_VIDEO)
268 ret
= video_display_bitmap(addr
, x
, y
);
270 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
274 free(bmp_alloc_addr
);
276 return ret
? CMD_RET_FAILURE
: 0;