| 1 |
|
| 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 |
|
| 16 |
if (header->CharB != 'B' || header->CharM != 'M') |
| 17 |
return false; |
| 18 |
|
| 19 |
|
| 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 |
|
| 41 |
|
| 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 |
|
| 59 |
|
| 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 |
|
| 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 |
|
| 105 |
|
| 106 |
|
| 107 |
col_map_number = 0; |
| 108 |
break; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 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 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 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 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 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 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
return &gop_blt_buffer[gop_y * gop_width + gop_x]; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 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 |
|
| 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: |
| 507 |
coords.x = (horizontal_resolution - logo_width) / 2; |
| 508 |
break; |
| 509 |
} |
| 510 |
|
| 511 |
|
| 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: |
| 523 |
coords.y = (vertical_resolution - logo_height) / 2; |
| 524 |
break; |
| 525 |
} |
| 526 |
|
| 527 |
return coords; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 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 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 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 |
|
| 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: |
| 600 |
*logo_valignment = FW_SPLASH_VALIGNMENT_BOTTOM; |
| 601 |
break; |
| 602 |
} |
| 603 |
*logo_bottom_margin = config->logo_bottom_margin; |
| 604 |
} else { |
| 605 |
*logo_halignment = FW_SPLASH_HALIGNMENT_CENTER; |
| 606 |
*logo_valignment = FW_SPLASH_VALIGNMENT_CENTER; |
| 607 |
*logo_bottom_margin = 0; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 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: |
| 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 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 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 |
|
| 692 |
struct lb_framebuffer framebuffer; |
| 693 |
memset(&framebuffer, 0, sizeof(struct lb_framebuffer)); |
| 694 |
fill_lb_framebuffer(&framebuffer); |
| 695 |
|
| 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 |
|
| 706 |
|
| 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 |
|
| 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 |
|
| 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); |