]> Git Repo - J-u-boot.git/blame - cmd/bmp.c
env: Drop the ACTION typedef
[J-u-boot.git] / cmd / bmp.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
059ae173
WD
2/*
3 * (C) Copyright 2002
b37c7e5e 4 * Detlev Zundel, DENX Software Engineering, [email protected].
059ae173
WD
5 */
6
7/*
8 * BMP handling routines
9 */
10
11#include <common.h>
12#include <bmp_layout.h>
13#include <command.h>
0c670fc1
SG
14#include <dm.h>
15#include <gzip.h>
16#include <lcd.h>
c29ab9d7 17#include <malloc.h>
72b335e9 18#include <mapmem.h>
ff8fb56b 19#include <splash.h>
f674f7cf 20#include <video.h>
0c670fc1 21#include <asm/byteorder.h>
059ae173 22
059ae173 23static int bmp_info (ulong addr);
059ae173 24
43ef1c38
HCE
25/*
26 * Allocate and decompress a BMP image using gunzip().
27 *
f7ef9d61
PW
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.
31 *
32 * The allocation address is passed to 'alloc_addr' and must be freed
33 * by the caller after use.
43ef1c38
HCE
34 *
35 * Returns NULL if decompression failed, or if the decompressed data
36 * didn't contain a valid BMP signature.
37 */
38#ifdef CONFIG_VIDEO_BMP_GZIP
1c3dbe56
SG
39struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
40 void **alloc_addr)
43ef1c38
HCE
41{
42 void *dst;
43 unsigned long len;
1c3dbe56 44 struct bmp_image *bmp;
43ef1c38
HCE
45
46 /*
47 * Decompress bmp image
48 */
6d0f6bcf 49 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
f7ef9d61
PW
50 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
51 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3);
43ef1c38
HCE
52 if (dst == NULL) {
53 puts("Error: malloc in gunzip failed!\n");
54 return NULL;
55 }
f7ef9d61
PW
56
57 bmp = dst;
58
59 /* align to 32-bit-aligned-address + 2 */
77195216 60 bmp = (struct bmp_image *)((((uintptr_t)dst + 1) & ~3) + 2);
f7ef9d61 61
72b335e9
SG
62 if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
63 &len) != 0) {
43ef1c38
HCE
64 free(dst);
65 return NULL;
66 }
6d0f6bcf 67 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
43ef1c38 68 puts("Image could be truncated"
6d0f6bcf 69 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
43ef1c38 70
43ef1c38
HCE
71 /*
72 * Check for bmp mark 'BM'
73 */
74 if (!((bmp->header.signature[0] == 'B') &&
75 (bmp->header.signature[1] == 'M'))) {
76 free(dst);
77 return NULL;
78 }
79
17f79e45 80 debug("Gzipped BMP image detected!\n");
43ef1c38 81
f7ef9d61 82 *alloc_addr = dst;
43ef1c38
HCE
83 return bmp;
84}
85#else
1c3dbe56
SG
86struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
87 void **alloc_addr)
43ef1c38
HCE
88{
89 return NULL;
90}
91#endif
92
54841ab5 93static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
9acd4f0e
FM
94{
95 ulong addr;
43ef1c38 96
9acd4f0e
FM
97 switch (argc) {
98 case 1: /* use load_addr as default address */
99 addr = load_addr;
100 break;
101 case 2: /* use argument */
102 addr = simple_strtoul(argv[1], NULL, 16);
103 break;
104 default:
4c12eeb8 105 return CMD_RET_USAGE;
9acd4f0e
FM
106 }
107
108 return (bmp_info(addr));
109}
110
54841ab5 111static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
059ae173
WD
112{
113 ulong addr;
4b248f3f 114 int x = 0, y = 0;
059ae173 115
ff8fb56b
AG
116 splash_get_pos(&x, &y);
117
059ae173 118 switch (argc) {
9acd4f0e 119 case 1: /* use load_addr as default address */
059ae173
WD
120 addr = load_addr;
121 break;
9acd4f0e
FM
122 case 2: /* use argument */
123 addr = simple_strtoul(argv[1], NULL, 16);
059ae173 124 break;
9acd4f0e
FM
125 case 4:
126 addr = simple_strtoul(argv[1], NULL, 16);
b0fcedb7
PD
127 if (!strcmp(argv[2], "m"))
128 x = BMP_ALIGN_CENTER;
129 else
130 x = simple_strtoul(argv[2], NULL, 10);
131 if (!strcmp(argv[3], "m"))
132 y = BMP_ALIGN_CENTER;
133 else
134 y = simple_strtoul(argv[3], NULL, 10);
93e14596 135 break;
059ae173 136 default:
4c12eeb8 137 return CMD_RET_USAGE;
059ae173
WD
138 }
139
9acd4f0e
FM
140 return (bmp_display(addr, x, y));
141}
142
143static 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, "", ""),
146};
147
2e5167cc 148#ifdef CONFIG_NEEDS_MANUAL_RELOC
f1d2b313
HS
149void bmp_reloc(void) {
150 fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
151}
152#endif
153
9acd4f0e
FM
154/*
155 * Subroutine: do_bmp
156 *
157 * Description: Handler for 'bmp' command..
158 *
159 * Inputs: argv[1] contains the subcommand
160 *
161 * Return: None
162 *
163 */
54841ab5 164static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
9acd4f0e
FM
165{
166 cmd_tbl_t *c;
167
168 /* Strip off leading 'bmp' command argument */
169 argc--;
170 argv++;
171
172 c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub));
173
47e26b1b 174 if (c)
9acd4f0e 175 return c->cmd(cmdtp, flag, argc, argv);
47e26b1b 176 else
4c12eeb8 177 return CMD_RET_USAGE;
059ae173
WD
178}
179
0d498393 180U_BOOT_CMD(
4b248f3f 181 bmp, 5, 1, do_bmp,
2fb2604d 182 "manipulate BMP image data",
4b248f3f 183 "info <imageAddr> - display image info\n"
a89c33db 184 "bmp display <imageAddr> [x y] - display image at x,y"
b0fce99b
WD
185);
186
059ae173
WD
187/*
188 * Subroutine: bmp_info
189 *
190 * Description: Show information about bmp file in memory
191 *
192 * Inputs: addr address of the bmp file
193 *
194 * Return: None
195 *
196 */
197static int bmp_info(ulong addr)
198{
72b335e9 199 struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
f7ef9d61 200 void *bmp_alloc_addr = NULL;
43ef1c38 201 unsigned long len;
c29ab9d7 202
059ae173 203 if (!((bmp->header.signature[0]=='B') &&
43ef1c38 204 (bmp->header.signature[1]=='M')))
f7ef9d61 205 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
c29ab9d7 206
43ef1c38 207 if (bmp == NULL) {
059ae173 208 printf("There is no valid bmp file at the given address\n");
43ef1c38 209 return 1;
059ae173 210 }
43ef1c38 211
059ae173
WD
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));
c29ab9d7 216
f7ef9d61
PW
217 if (bmp_alloc_addr)
218 free(bmp_alloc_addr);
c29ab9d7 219
059ae173
WD
220 return(0);
221}
222
223/*
224 * Subroutine: bmp_display
225 *
226 * Description: Display bmp file located in memory
227 *
228 * Inputs: addr address of the bmp file
229 *
230 * Return: None
231 *
232 */
de3b49c4 233int bmp_display(ulong addr, int x, int y)
059ae173 234{
b01c7923
SG
235#ifdef CONFIG_DM_VIDEO
236 struct udevice *dev;
237#endif
43ef1c38 238 int ret;
72b335e9 239 struct bmp_image *bmp = map_sysmem(addr, 0);
f7ef9d61 240 void *bmp_alloc_addr = NULL;
43ef1c38
HCE
241 unsigned long len;
242
243 if (!((bmp->header.signature[0]=='B') &&
244 (bmp->header.signature[1]=='M')))
f7ef9d61 245 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
43ef1c38
HCE
246
247 if (!bmp) {
248 printf("There is no valid bmp file at the given address\n");
249 return 1;
250 }
72b335e9 251 addr = map_to_sysmem(bmp);
43ef1c38 252
b01c7923 253#ifdef CONFIG_DM_VIDEO
3f603cbb 254 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
b01c7923 255 if (!ret) {
3f603cbb 256 bool align = false;
b01c7923 257
b0fcedb7
PD
258 if (CONFIG_IS_ENABLED(SPLASH_SCREEN_ALIGN) ||
259 x == BMP_ALIGN_CENTER ||
260 y == BMP_ALIGN_CENTER)
261 align = true;
262
3f603cbb 263 ret = video_bmp_display(dev, addr, x, y, align);
b01c7923 264 }
b01c7923 265#elif defined(CONFIG_LCD)
72b335e9 266 ret = lcd_display_bitmap(addr, x, y);
281e00a3 267#elif defined(CONFIG_VIDEO)
72b335e9 268 ret = video_display_bitmap(addr, x, y);
281e00a3
WD
269#else
270# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
4b248f3f 271#endif
43ef1c38 272
f7ef9d61
PW
273 if (bmp_alloc_addr)
274 free(bmp_alloc_addr);
43ef1c38 275
e517db73 276 return ret ? CMD_RET_FAILURE : 0;
059ae173 277}
This page took 0.5255 seconds and 4 git commands to generate.