Debian Codegraph @

src/lib/render_bmp.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <boot/coreboot_tables.h>
4 #include <bootmode.h>
5 #include <bootsplash.h>
6 #include <bootstate.h>
7 #include <console/console.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "render_bmp.h"
12
13 static bool is_bmp_image_valid(struct bmp_image_header *header)
14 {
15 /* Check if the BMP Header Signature is valid */
16 if (header->CharB != 'B' || header->CharM != 'M')
17 return false;
18
19 /* Check if the BMP Image Header Length is valid */
20 if (!header->PixelHeight || !header->PixelWidth)
21 return false;
22
23 if (header->Size < header->ImageOffset)
24 return false;
25
26 if (header->ImageOffset < sizeof(struct bmp_image_header))
27 return false;
28
29 return true;
30 }
31
32 static bool is_bmp_image_compressed(struct bmp_image_header *header)
33 {
34 return header->CompressionType != 0;
35 }
36
37 static bool is_bitmap_format_supported(struct bmp_image_header *header)
38 {
39 /*
40 * Check BITMAP format is supported
41 * BMP_IMAGE_HEADER = BITMAP_FILE_HEADER + BITMAP_INFO_HEADER
42 */
43 if (header->HeaderSize != sizeof(struct bmp_image_header) -
44 OFFSET_OF(struct bmp_image_header, HeaderSize))
45 return false;
46
47 return true;
48 }
49
50 static bool do_bmp_image_authentication(struct bmp_image_header *header)
51 {
52 if (!is_bmp_image_valid(header)) {
53 printk(BIOS_ERR, "%s: BMP Image Header is invalid.\n", __func__);
54 return false;
55 }
56
57 /*
58 * BMP image compression is unsupported by FSP implementation,
59 * hence, exit if the BMP image is compressed.
60 */
61 if (is_bmp_image_compressed(header)) {
62 printk(BIOS_ERR, "%s: BMP Image Compression is unsupported.\n", __func__);
63 return false;
64 }
65
66 if (!is_bitmap_format_supported(header)) {
67 printk(BIOS_ERR, "%s: BmpHeader Header Size (0x%x) is not as expected.\n",
68 __func__, header->HeaderSize);
69 return false;
70 }
71
72 return true;
73 }
74
75 static uint32_t calculate_blt_buffer_size(struct bmp_image_header *header)
76 {
77 uint32_t blt_buffer_size;
78
79 /* Calculate the size required for BLT buffer */
80 blt_buffer_size = header->PixelWidth * header->PixelHeight *
81 sizeof(struct blt_pixel);
82 if (!blt_buffer_size)
83 return 0;
84
85 return blt_buffer_size;
86 }
87
88 static int get_color_map_num(struct bmp_image_header *header)
89 {
90 int col_map_number;
91
92 switch (header->BitPerPixel) {
93 case 1:
94 col_map_number = 2;
95 break;
96 case 4:
97 col_map_number = 16;
98 break;
99 case 8:
100 col_map_number = 256;
101 break;
102 default:
103 /*
104 * For other bit depths (e.g., 24-bit and 32-bit) that doesn't have
105 * a standard palette, col_map_number remains 0.
106 */
107 col_map_number = 0;
108 break;
109 }
110
111 /*
112 * At times BMP file may have padding data between its header section and the
113 * data section.
114 */
115 if (header->ImageOffset - sizeof(struct bmp_image_header) <
116 sizeof(struct bmp_color_map) * col_map_number)
117 return -1;
118
119 return col_map_number;
120 }
121
122 /*
123 * Visual Representation of the Flipping:
124 *
125 * Original BMP Image:
126 *
127 * 0 -----------------------------------------PixelWidth-1
128 * | |
129 * | |
130 * | |
131 * PixelHeight-1------------------------------|
132 *
133 * Blitting Region:
134 *
135 * (x, y) ----------------------------------- (x + blt_width, y)
136 * | |
137 * | |
138 * (x, y + blt_height) -------------------- --(x + blt_width, y + blt_height)
139 *
140 * Flipped Coordinates:
141 *
142 * flipped_x: Represents the horizontal coordinate from the `right` edge of the BMP,
143 * accounting for the blit width.
144 *
145 * flipped_y: Represents the vertical coordinate from the `bottom` edge of the BMP,
146 * accounting for the blit height.
147 *
148 * Example (Orientation: LB_FB_ORIENTATION_BOTTOM_UP):
149 *
150 * If blt_width is small, flipped_x will be near PixelWidth.
151 * If blt_height is small, flipped_y will be near PixelHeight.
152 *
153 * The blit then starts at (flipped_x, blt_height), effectively flipping the
154 * horizontal position and using the original blit height.
155 *
156 * This allows for blitting from the bottom-left corner of the display panel.
157 */
158 static bool calculate_adj_height_width(const struct bmp_image_header *header, size_t *adjusted_x,
159 size_t *adjusted_y, enum lb_fb_orientation orientation, int blt_width, int blt_height)
160 {
161 size_t flipped_x = header->PixelWidth - blt_width - 1;
162 size_t flipped_y = header->PixelHeight - blt_height - 1;
163
164 switch (orientation) {
165 case LB_FB_ORIENTATION_LEFT_UP:
166 *adjusted_x = flipped_y;
167 *adjusted_y = flipped_x;
168 break;
169
170 case LB_FB_ORIENTATION_BOTTOM_UP:
171 *adjusted_x = flipped_x;
172 *adjusted_y = blt_height;
173 break;
174
175 case LB_FB_ORIENTATION_RIGHT_UP:
176 *adjusted_x = blt_height;
177 *adjusted_y = blt_width;
178 break;
179
180 case LB_FB_ORIENTATION_NORMAL:
181 default:
182 *adjusted_x = blt_width;
183 *adjusted_y = flipped_y;
184 break;
185 }
186
187 return true;
188 }
189
190 /*
191 * Visual Representation of gop_width and calculate linear offset into the GOP buffer:
192 *
193 * GOP Display Buffer:
194 *
195 * +------------------------------------------------+
196 * | 0 |
197 * | |--> gop_width pixels in this row |
198 * +------------------------------------------------+
199 * | gop_width |
200 * | |
201 * | gop_width |
202 * | ... |
203 * +------------------------------------------------+
204 * | gop_width |
205 * +------------------------------------------------+
206 *
207 * gop_width: Represents the width of a row in the GOP buffer.
208 * - It is determined by the `orientation` of the image.
209 * - For `LEFT_UP` and `RIGHT_UP`, the GOP width is the BMP image's `PixelHeight`.
210 * - For `BOTTOM_UP` and `NORMAL`, the GOP width is the BMP image's `PixelWidth`.
211 *
212 * gop_x, gop_y: Coordinates within the GOP buffer where the blit will start.
213 * - These are calculated by `calculate_adj_height_width` based on the `orientation`,
214 * `blt_width`, and `blt_height`.
215 *
216 * Pointer to the calculated pixel in the GOP blit buffer, or NULL on error.
217 * - Calculate `gop_blt_offset`as `gop_y * gop_width + gop_x` to determine the offset
218 * to access the correct pixel within `gop_blt_buffer`.
219 * - `gop_y * gop_width` calculates the offset of the row.
220 * - `gop_x` calculates the offset within that row.
221 */
222 static struct blt_pixel *get_gop_blt_pixel(
223 struct blt_pixel *gop_blt_buffer, const struct bmp_image_header *header,
224 int blt_width, int blt_height, enum lb_fb_orientation orientation)
225 {
226 size_t gop_x;
227 size_t gop_y;
228 size_t gop_width;
229
230 switch (orientation) {
231 case LB_FB_ORIENTATION_LEFT_UP:
232 case LB_FB_ORIENTATION_RIGHT_UP:
233 gop_width = header->PixelHeight;
234 break;
235
236 case LB_FB_ORIENTATION_BOTTOM_UP:
237 case LB_FB_ORIENTATION_NORMAL:
238 default:
239 gop_width = header->PixelWidth;
240 break;
241 }
242
243 if (!calculate_adj_height_width(header, &gop_x, &gop_y, orientation,
244 blt_width, blt_height))
245 return NULL;
246
247 /*
248 * Calculated pixel in the Graphics Output Protocol (GOP) blit buffer.
249 * This offset represents the starting position where the blitted region will be placed
250 * in the framebuffer.
251 */
252 return &gop_blt_buffer[gop_y * gop_width + gop_x];
253 }
254
255 /*
256 * Fill BMP image into BLT buffer format with optional orientation
257 *
258 * +------------------------------------------------------------------+
259 * | BMP Image (header: bmp_image_header) |
260 * | (PixelWidth, PixelHeight) |
261 * +------------------------------------------------------------------+
262 * |
263 * | (blt_width, blt_height) : Region to blit
264 * V
265 * +------------------------------------------------------------------+
266 * | calculate_adj_height_width(header, adjusted_x, adjusted_y, |
267 * | orientation, blt_width, blt_height)|
268 * +------------------------------------------------------------------+
269 * |
270 * | Calculates adjusted coordinates based on orientation:
271 * | - flipped_x = header->PixelWidth - blt_width - 1
272 * | - flipped_y = header->PixelHeight - blt_height - 1
273 * | - Depending on 'orientation', adjusted_x and adjusted_y are set.
274 * V
275 * +-------------------------------------------------------------------+
276 * | get_gop_blt_pixel(gop_blt_buffer, header, blt_width, blt_height, |
277 * | orientation) |
278 * +-------------------------------------------------------------------+
279 * |
280 * | 1. Determines gop_width based on orientation:
281 * | - LEFT_UP/RIGHT_UP: gop_width = header->PixelHeight,
282 * | - BOTTOM_UP/NORMAL: gop_width = header->PixelWidth,
283 * | 2. Calls calculate_adj_height_width to get gop_x and gop_y.
284 * | 3. GOP BLT offset: calculates linear offset into the GOP buffer
285 * | - gop_blt_offset = gop_y * gop_width + gop_x
286 * | 4. GOP BLT offset is used to access the correct regions in:
287 * V
288 * +------------------------------------------------------------------+
289 * | GOP Blit Buffer (Framebuffer) |
290 * +------------------------------------------------------------------+
291 */
292 static void *fill_blt_buffer(struct bmp_image_header *header,
293 uintptr_t logo, size_t blt_buffer_size, enum lb_fb_orientation orientation)
294 {
295 struct blt_pixel *gop_blt_buffer;
296 struct blt_pixel *gop_blt_ptr;
297 struct blt_pixel *gop_blt;
298 uint8_t *bmp_image;
299 uint8_t *bmp_header;
300 struct bmp_color_map *color_map;
301 size_t image_index;
302
303 gop_blt_ptr = malloc(sizeof(blt_buffer_size));
304 if (!gop_blt_ptr)
305 die("%s: out of memory. Consider increasing the `CONFIG_HEAP_SIZE`\n",
306 __func__);
307
308 bmp_image = ((uint8_t *)logo) + header->ImageOffset;
309 bmp_header = bmp_image;
310 gop_blt_buffer = gop_blt_ptr;
311 color_map = (struct bmp_color_map *)(logo + sizeof(struct bmp_image_header));
312
313 for (size_t height = 0; height < header->PixelHeight; height++) {
314 for (size_t width = 0; width < header->PixelWidth; width++, bmp_image++) {
315 size_t index = 0;
316
317 gop_blt = get_gop_blt_pixel(gop_blt_buffer, header, width, height,
318 orientation);
319 if (!gop_blt) {
320 free(gop_blt_ptr);
321 return NULL;
322 }
323
324 switch (header->BitPerPixel) {
325 /* Translate 1-bit (2 colors) BMP to 24-bit color */
326 case 1:
327 for (index = 0; index < 8 && width < header->PixelWidth; index++) {
328 uint8_t bit = ((*bmp_image) >> (7 - index)) & 0x1;
329 gop_blt->Red = color_map[bit].Red;
330 gop_blt->Green = color_map[bit].Green;
331 gop_blt->Blue = color_map[bit].Blue;
332 width++;
333 gop_blt = get_gop_blt_pixel(gop_blt_buffer, header, width, height,
334 orientation);
335 if (!gop_blt) {
336 free(gop_blt_ptr);
337 return NULL;
338 }
339 }
340 width--;
341 break;
342
343 /* Translate 4-bit (16 colors) BMP Palette to 24-bit color */
344 case 4:
345 index = (*bmp_image) >> 4;
346 gop_blt->Red = color_map[index].Red;
347 gop_blt->Green = color_map[index].Green;
348 gop_blt->Blue = color_map[index].Blue;
349 if (width < (header->PixelWidth - 1)) {
350 width++;
351 gop_blt = get_gop_blt_pixel(gop_blt_buffer, header, width, height,
352 orientation);
353 if (!gop_blt) {
354 free(gop_blt_ptr);
355 return NULL;
356 }
357 index = (*bmp_image) & 0x0f;
358 gop_blt->Red = color_map[index].Red;
359 gop_blt->Green = color_map[index].Green;
360 gop_blt->Blue = color_map[index].Blue;
361 }
362 break;
363
364 /* Translate 8-bit (256 colors) BMP Palette to 24-bit color */
365 case 8:
366 gop_blt->Red = color_map[*bmp_image].Red;
367 gop_blt->Green = color_map[*bmp_image].Green;
368 gop_blt->Blue = color_map[*bmp_image].Blue;
369 break;
370
371 /* For 24-bit BMP */
372 case 24:
373 gop_blt->Blue = *bmp_image++;
374 gop_blt->Green = *bmp_image++;
375 gop_blt->Red = *bmp_image;
376 break;
377
378 /* Convert 32 bit to 24bit bmp - just ignore the final byte of each pixel */
379 case 32:
380 gop_blt->Blue = *bmp_image++;
381 gop_blt->Green = *bmp_image++;
382 gop_blt->Red = *bmp_image++;
383 break;
384
385 /* Other bit format of BMP is not supported. */
386 default:
387 free(gop_blt_ptr);
388 gop_blt_ptr = NULL;
389
390 printk(BIOS_ERR, "%s, BMP Bit format not supported. 0x%X\n", __func__,
391 header->BitPerPixel);
392 return NULL;
393 }
394 }
395 image_index = (uintptr_t)bmp_image - (uintptr_t)bmp_header;
396 /* Each row in BMP Image should be 4-byte align */
397 if ((image_index % 4) != 0)
398 bmp_image = bmp_image + (4 - (image_index % 4));
399 }
400
401 return gop_blt_ptr;
402 }
403
404 /* Helper function to perform the common BMP to GOP BLT conversion logic */
405 static bool convert_bmp_to_gop_blt_common(uintptr_t logo, size_t logo_size,
406 uintptr_t *blt, size_t *blt_size, uint32_t *pixel_height,
407 uint32_t *pixel_width, enum lb_fb_orientation orientation)
408 {
409 size_t blt_buffer_size;
410 struct bmp_image_header *bmp_header;
411
412 bmp_header = (struct bmp_image_header *)logo;
413
414 /* Authenticate BMP header and validate size against provided logo_size */
415 if (!do_bmp_image_authentication(bmp_header) || (bmp_header->Size != logo_size))
416 return false;
417
418 blt_buffer_size = calculate_blt_buffer_size(bmp_header);
419 if (!blt_buffer_size)
420 return false;
421
422 if (get_color_map_num(bmp_header) < 0)
423 return false;
424
425 bool is_standard_orientation = (orientation == LB_FB_ORIENTATION_NORMAL ||
426 orientation == LB_FB_ORIENTATION_BOTTOM_UP);
427
428 *blt_size = blt_buffer_size;
429 *pixel_height = is_standard_orientation ? bmp_header->PixelHeight : bmp_header->PixelWidth;
430 *pixel_width = is_standard_orientation ? bmp_header->PixelWidth : bmp_header->PixelHeight;
431 *blt = (uintptr_t)fill_blt_buffer(bmp_header, logo, blt_buffer_size, orientation);
432
433 return true;
434 }
435
436 /* Convert a *.BMP graphics image to a blt buffer */
437 void load_and_convert_bmp_to_blt(uintptr_t *logo, size_t *logo_size,
438 uintptr_t *blt, size_t *blt_size, uint32_t *pixel_height, uint32_t *pixel_width,
439 enum lb_fb_orientation orientation)
440 {
441 uintptr_t bmp;
442 size_t bmp_size;
443
444 if (!logo || !logo_size || !blt || !blt_size || !pixel_height || !pixel_width)
445 return;
446
447 bmp = (uintptr_t)bmp_load_logo(&bmp_size);
448
449 if (!bmp || bmp_size < sizeof(struct bmp_image_header))
450 return;
451
452 *logo = bmp;
453 *logo_size = bmp_size;
454
455 convert_bmp_to_gop_blt_common(*logo, *logo_size, blt, blt_size,
456 pixel_height, pixel_width, orientation);
457 }
458
459 /* Convert a *.BMP graphics image (as per input `logo`) to a GOP blt buffer */
460 void convert_bmp_to_blt(uintptr_t logo, size_t logo_size,
461 uintptr_t *blt, size_t *blt_size, uint32_t *pixel_height, uint32_t *pixel_width,
462 enum lb_fb_orientation orientation)
463 {
464 if (!blt || !blt_size || !pixel_height || !pixel_width)
465 return;
466
467 if (!logo || logo_size < sizeof(struct bmp_image_header))
468 return;
469
470 convert_bmp_to_gop_blt_common(logo, logo_size, blt, blt_size,
471 pixel_height, pixel_width, orientation);
472 }
473
474 /*
475 * Calculates the destination coordinates for the logo based on both horizontal and
476 * vertical alignment settings.
477 *
478 * horizontal_resolution: The horizontal resolution of the display panel.
479 * vertical_resolution: The vertical resolution of the display panel.
480 * logo_width: The width of the logo bitmap.
481 * logo_height: The height of the logo bitmap.
482 * halignment: The horizontal alignment setting. Use FW_SPLASH_HALIGNMENT_NONE
483 * if only vertical alignment is specified.
484 * valignment: The vertical alignment setting. Use FW_SPLASH_VALIGNMENT_NONE
485 * if only horizontal alignment is specified.
486 *
487 * Returning `struct logo_coordinates` that contains the calculated x and y coordinates
488 * for rendering the logo.
489 */
490 static struct logo_coordinates calculate_logo_coordinates(
491 uint32_t horizontal_resolution, uint32_t vertical_resolution,
492 uint32_t logo_width, uint32_t logo_height,
493 enum fw_splash_horizontal_alignment halignment,
494 enum fw_splash_vertical_alignment valignment)
495 {
496 struct logo_coordinates coords;
497
498 /* Calculate X coordinate */
499 switch (halignment) {
500 case FW_SPLASH_HALIGNMENT_LEFT:
501 coords.x = 0;
502 break;
503 case FW_SPLASH_HALIGNMENT_RIGHT:
504 coords.x = horizontal_resolution - logo_width;
505 break;
506 default: /* FW_SPLASH_HALIGNMENT_CENTER (default) */
507 coords.x = (horizontal_resolution - logo_width) / 2;
508 break;
509 }
510
511 /* Calculate Y coordinate */
512 switch (valignment) {
513 case FW_SPLASH_VALIGNMENT_MIDDLE:
514 coords.y = vertical_resolution / 2;
515 break;
516 case FW_SPLASH_VALIGNMENT_TOP:
517 coords.y = 0;
518 break;
519 case FW_SPLASH_VALIGNMENT_BOTTOM:
520 coords.y = vertical_resolution - logo_height;
521 break;
522 default: /* FW_SPLASH_VALIGNMENT_CENTER (default) */
523 coords.y = (vertical_resolution - logo_height) / 2;
524 break;
525 }
526
527 return coords;
528 }
529
530 /*
531 * Copies the logo to the framebuffer.
532 *
533 * framebuffer_base: The base address of the framebuffer.
534 * bytes_per_scanline: The number of bytes per scanline in the framebuffer.
535 * logo_buffer: The address of the logo data in BLT format.
536 * logo_width: The width of the logo bitmap.
537 * logo_height: The height of the logo bitmap.
538 * dest_x: The destination x-coordinate in the framebuffer for rendering the logo.
539 * dest_y: The destination y-coordinate in the framebuffer for rendering the logo.
540 */
541 static void copy_logo_to_framebuffer(
542 uintptr_t framebuffer_base, uint32_t bytes_per_scanline,
543 uintptr_t logo_buffer, uint32_t logo_width, uint32_t logo_height,
544 uint32_t dest_x, uint32_t dest_y)
545 {
546 size_t pixel_size = sizeof(struct blt_pixel);
547 size_t bytes_per_logo_line = logo_width * pixel_size;
548 uint8_t *framebuffer_offset = (uint8_t *)framebuffer_base + dest_y * bytes_per_scanline
549 + dest_x * pixel_size;
550 uint8_t *dst_row_address = framebuffer_offset;
551 uint8_t *src_row_address = (uint8_t *)logo_buffer;
552 for (uint32_t i = 0; i < logo_height; i++) {
553 memcpy(dst_row_address, src_row_address, bytes_per_logo_line);
554 dst_row_address += bytes_per_scanline;
555 src_row_address += bytes_per_logo_line;
556 }
557 }
558
559 /*
560 * Adjust logo layout based on the panel orientation.
561 *
562 * logo_type: Logo type.
563 * config: Logo configuration information.
564 * logo_halignment: Resultant horizontal alignment setting.
565 * logo_valignment: Resultant vertical alignment setting.
566 * logo_bottom_margin: Resultant bottom margin.
567 */
568 static void get_logo_layout(
569 enum bootsplash_type logo_type,
570 struct logo_config *config,
571 enum fw_splash_horizontal_alignment *logo_halignment,
572 enum fw_splash_vertical_alignment *logo_valignment,
573 uint8_t *logo_bottom_margin
574 )
575 {
576 if (!config || !logo_halignment || !logo_valignment || !logo_bottom_margin)
577 return;
578
579 if (logo_type == BOOTSPLASH_LOW_BATTERY || logo_type == BOOTSPLASH_CENTER) {
580 *logo_halignment = config->halignment;
581 *logo_valignment = config->valignment;
582 /* Override logo alignment if the default screen orientation is not normal */
583 if (config->panel_orientation != LB_FB_ORIENTATION_NORMAL)
584 *logo_valignment = FW_SPLASH_VALIGNMENT_CENTER;
585 *logo_bottom_margin = 0;
586 } else if (logo_type == BOOTSPLASH_FOOTER) {
587 *logo_halignment = FW_SPLASH_HALIGNMENT_CENTER;
588 *logo_valignment = FW_SPLASH_VALIGNMENT_CENTER;
589 switch (config->panel_orientation) {
590 case LB_FB_ORIENTATION_RIGHT_UP:
591 *logo_halignment = FW_SPLASH_HALIGNMENT_LEFT;
592 break;
593 case LB_FB_ORIENTATION_LEFT_UP:
594 *logo_halignment = FW_SPLASH_HALIGNMENT_RIGHT;
595 break;
596 case LB_FB_ORIENTATION_BOTTOM_UP:
597 *logo_valignment = FW_SPLASH_VALIGNMENT_TOP;
598 break;
599 default: /* LB_FB_ORIENTATION_NORMAL (default) */
600 *logo_valignment = FW_SPLASH_VALIGNMENT_BOTTOM;
601 break;
602 }
603 *logo_bottom_margin = config->logo_bottom_margin;
604 } else { // Default values
605 *logo_halignment = FW_SPLASH_HALIGNMENT_CENTER;
606 *logo_valignment = FW_SPLASH_VALIGNMENT_CENTER;
607 *logo_bottom_margin = 0;
608 }
609 }
610
611 /*
612 * Loads, converts, and renders a BMP logo to the framebuffer.
613 *
614 * logo_type: Logo type.
615 * config: Logo configuration information.
616 *
617 * Returns 0 on success, -1 on failure.
618 */
619 static int load_and_render_logo_to_framebuffer(
620 enum bootsplash_type logo_type,
621 struct logo_config *config
622 )
623 {
624 uintptr_t logo;
625 size_t logo_size;
626 size_t blt_size;
627 uintptr_t blt_buffer;
628 uint32_t logo_height, logo_width;
629 struct logo_coordinates logo_coords;
630 enum fw_splash_horizontal_alignment halignment;
631 enum fw_splash_vertical_alignment valignment;
632 uint8_t logo_bottom_margin;
633
634 if (!config)
635 return -1;
636
637 logo = (uintptr_t)bmp_load_logo_by_type(logo_type, &logo_size);
638
639 if (!logo || logo_size < sizeof(struct bmp_image_header)) {
640 printk(BIOS_ERR, "%s: BMP image (%zu) is less than expected minimum size (%zu).\n",
641 __func__, logo_size, sizeof(struct bmp_image_header));
642 return -1;
643 }
644
645 convert_bmp_to_blt(logo, logo_size, &blt_buffer, &blt_size,
646 &logo_height, &logo_width, config->panel_orientation);
647
648 get_logo_layout(logo_type, config, &halignment, &valignment, &logo_bottom_margin);
649
650 logo_coords = calculate_logo_coordinates(config->horizontal_resolution,
651 config->vertical_resolution, logo_width, logo_height, halignment, valignment);
652
653 if (logo_bottom_margin) {
654 switch (config->panel_orientation) {
655 case LB_FB_ORIENTATION_RIGHT_UP:
656 logo_coords.x = logo_bottom_margin;
657 break;
658 case LB_FB_ORIENTATION_LEFT_UP:
659 logo_coords.x -= logo_bottom_margin;
660 break;
661 case LB_FB_ORIENTATION_BOTTOM_UP:
662 logo_coords.y = logo_bottom_margin;
663 break;
664 default: /* LB_FB_ORIENTATION_NORMAL (default) */
665 logo_coords.y -= logo_bottom_margin;
666 break;
667 }
668 }
669
670 copy_logo_to_framebuffer(config->framebuffer_base, config->bytes_per_scanline, blt_buffer,
671 logo_width, logo_height, logo_coords.x, logo_coords.y);
672
673 bmp_release_logo();
674
675 return 0;
676 }
677
678 /*
679 * Loads, converts, and renders a BMP logo to the framebuffer.
680 * The logo type (primary or low battery etc.) is seletcted dynamically.
681 *
682 * config: Logo configuration information.
683 *
684 */
685 void render_logo_to_framebuffer(struct logo_config *config)
686 {
687 if (!config)
688 return;
689
690 if (config->framebuffer_base == 0) {
691 /* Try to load from already populated framebuffer information */
692 struct lb_framebuffer framebuffer;
693 memset(&framebuffer, 0, sizeof(struct lb_framebuffer));
694 fill_lb_framebuffer(&framebuffer);
695 /* Exit if framebuffer is still not available */
696 if (framebuffer.physical_address == 0)
697 return;
698 config->framebuffer_base = framebuffer.physical_address;
699 config->horizontal_resolution = framebuffer.x_resolution;
700 config->vertical_resolution = framebuffer.y_resolution;
701 config->bytes_per_scanline = framebuffer.bytes_per_line;
702 }
703
704 /*
705 * If the device is in low-battery mode and the low-battery splash screen is being
706 * displayed, prevent further operation and bail out early.
707 */
708 if (platform_is_low_battery_shutdown_needed()) {
709 if (load_and_render_logo_to_framebuffer(BOOTSPLASH_LOW_BATTERY, config) != 0) {
710 printk(BIOS_ERR, "%s: Failed to render low-battery logo.\n", __func__);
711 }
712 return;
713 }
714
715 /* Render the main logo */
716 if (load_and_render_logo_to_framebuffer(BOOTSPLASH_CENTER, config) != 0) {
717 printk(BIOS_ERR, "%s: Failed to render main splash screen logo.\n", __func__);
718 } else if (CONFIG(SPLASH_SCREEN_FOOTER)) {
719 /* Render the footer logo */
720 if (load_and_render_logo_to_framebuffer(BOOTSPLASH_FOOTER, config) != 0)
721 printk(BIOS_ERR, "%s: Failed to render footer logo.\n", __func__);
722 }
723 }
724
725 static void release_logo(void *arg_unused)
726 {
727 bmp_release_logo();
728 }
729
730 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, release_logo, NULL);