22
33#include <linux/fb.h>
44#include <linux/linux_logo.h>
5+ #include <linux/fs.h>
6+ #include <linux/slab.h>
7+ #include <linux/string.h>
8+ #include <linux/uaccess.h>
9+ #include <linux/file.h>
10+ #include <linux/kernel.h>
11+ #include <linux/firmware.h>
512
613#include "fb_internal.h"
714
815bool fb_center_logo __read_mostly ;
916int fb_logo_count __read_mostly = -1 ;
17+ static int fullscreen_logo_enabled ;
18+ static char * fullscreen_logo_path ;
19+
20+ struct image_palette {
21+ u8 colors [224 ][3 ];
22+ };
1023
1124static inline unsigned int safe_shift (unsigned int d , int n )
1225{
@@ -79,6 +92,22 @@ static void fb_set_logo_truepalette(struct fb_info *info,
7992 }
8093}
8194
95+ static void fb_set_logo_RGB_palette (struct image_palette * palette ,
96+ u32 * palette_to_write , int current_rows )
97+ {
98+ // Set the kernel palette from an array of RGB values
99+ uint32_t color_code ;
100+ int i ;
101+
102+ // Color format is RGB565, remove LSB 3 bits, and move to correct position
103+ for (i = 0 ; i < current_rows ; i ++ ) {
104+ color_code = ((((uint16_t )palette -> colors [i ][0 ]) >> 3 ) << 11 ) |
105+ ((((uint16_t )palette -> colors [i ][1 ]) >> 2 ) << 5 ) |
106+ (((uint16_t )palette -> colors [i ][2 ]) >> 3 );
107+ palette_to_write [i + 32 ] = color_code ;
108+ }
109+ }
110+
82111static void fb_set_logo_directpalette (struct fb_info * info ,
83112 const struct linux_logo * logo ,
84113 u32 * palette )
@@ -275,6 +304,162 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
275304 }
276305}
277306
307+ static int __init fb_fullscreen_logo_setup (char * str )
308+ {
309+ fullscreen_logo_enabled = 1 ;
310+ fullscreen_logo_path = str ;
311+ pr_info ("Fullscreen splash enabled, using image path: %s" , fullscreen_logo_path );
312+ return 1 ;
313+ }
314+
315+ __setup ("fullscreen_logo_name=" , fb_fullscreen_logo_setup );
316+
317+ static bool fb_palette_contains_entry (struct image_palette * palette , int num_existing_rows ,
318+ u8 * entry_to_add , int cols , int * index )
319+ {
320+ for (int i = 0 ; i < num_existing_rows ; i ++ ) {
321+ bool match = true;
322+
323+ for (int j = 0 ; j < cols ; j ++ ) {
324+ if (palette -> colors [i ][j ] != entry_to_add [j ]) {
325+ match = false;
326+ break ;
327+ }
328+ }
329+ if (match ) {
330+ * index = i ; // Update the index
331+ return true; // Found a duplicate
332+ }
333+ }
334+ return false; // No duplicate found
335+ }
336+
337+ static void fb_set_logo_from_file (struct fb_info * info , const char * filepath ,
338+ struct fb_image * image , u32 * palette )
339+ {
340+ int current_rows = 0 , palette_index = 0 , actual_row , skip_x = 0 , skip_y = 0 , ret ;
341+ unsigned char * read_logo = NULL , * header ;
342+ const char * file_content = NULL ;
343+ const struct firmware * fw ;
344+ struct image_palette image_palette ;
345+ const char * current_ptr , * end_ptr ;
346+ long width = 0 , height = 0 ;
347+ bool top_to_bottom ;
348+ u8 B , G , R ;
349+ u8 entry [3 ];
350+ ssize_t len ;
351+
352+ ret = request_firmware (& fw , filepath , info -> device );
353+ if (ret ) {
354+ pr_info ("Failed to load logo file '%s': %d\n" , filepath , ret );
355+ goto cleanup ;
356+ }
357+ len = fw -> size ;
358+ file_content = fw -> data ;
359+
360+ if (len > 0 ) {
361+ current_ptr = file_content ;
362+ end_ptr = file_content + len ;
363+ if (len < 18 ) {
364+ pr_err ("Invalid logo file: TGA file too small for header\n" );
365+ goto cleanup ;
366+ }
367+ header = (unsigned char * )file_content ;
368+
369+ // Skip color map info (bytes 3-7)
370+ // Skip image origin (bytes 8-11)
371+ width = header [12 ] | (header [13 ] << 8 );
372+ height = header [14 ] | (header [15 ] << 8 );
373+
374+ // Only supports uncompressed true-color images (type 2) with 24-bit depth
375+ if (header [2 ] != 2 || header [16 ] != 24 ) {
376+ pr_err ("Unsupported TGA logo format: Type=%d, Depth=%d (only support Type=2, Depth=24)\n" ,
377+ header [2 ], header [16 ]);
378+ goto cleanup ;
379+ }
380+ // Skip header + ID field
381+ current_ptr = file_content + 18 + header [0 ];
382+
383+ read_logo = kmalloc_array (width , height , GFP_KERNEL );
384+ if (!read_logo )
385+ goto cleanup ;
386+
387+ image -> data = read_logo ;
388+
389+ // TGA pixels are stored bottom-to-top by default, unless bit 5 of
390+ // image_descriptor is set
391+ top_to_bottom = (header [17 ] & 0x20 ) != 0 ;
392+ skip_x = 0 ;
393+ skip_y = 0 ;
394+
395+ if (image -> width > info -> var .xres ) {
396+ pr_info ("Logo is larger than screen, clipping horizontally" );
397+ skip_x = (image -> width - info -> var .xres ) / 2 ;
398+ }
399+ if (image -> height > info -> var .yres ) {
400+ pr_info ("Logo is larger than screen, clipping vertically" );
401+ skip_y = (image -> height - info -> var .yres ) / 2 ;
402+ }
403+ current_ptr += skip_y * width * 3 + skip_x * 3 ;
404+ // Parse pixel data (BGR format in TGA)
405+ for (int i = 0 ; i < height - 2 * skip_y ; i ++ ) {
406+ for (int j = 0 ; j < width - 2 * skip_x ; j ++ ) {
407+ if (current_ptr + 3 > end_ptr ) {
408+ pr_info ("TGA: Unexpected end of file\n" );
409+ goto cleanup ;
410+ }
411+ B = (unsigned char )* current_ptr ++ ;
412+ G = (unsigned char )* current_ptr ++ ;
413+ R = (unsigned char )* current_ptr ++ ;
414+ entry [0 ] = R ;
415+ entry [1 ] = G ;
416+ entry [2 ] = B ;
417+ palette_index = 0 ;
418+
419+ if (!fb_palette_contains_entry (& image_palette , current_rows ,
420+ entry , 3 , & palette_index )) {
421+ for (int k = 0 ; k < 3 ; k ++ )
422+ image_palette .colors [current_rows ][k ] = entry [k ];
423+ palette_index = current_rows ;
424+ current_rows ++ ;
425+ }
426+ actual_row = top_to_bottom ? i : (height - 1 - i );
427+
428+ read_logo [actual_row * (width - 2 * skip_x ) + j ] =
429+ palette_index + 32 ;
430+ }
431+ current_ptr += skip_x * 3 * 2 ;
432+ }
433+
434+ // Set logo palette
435+ palette = kmalloc (256 * 4 , GFP_KERNEL );
436+ if (palette == NULL )
437+ goto cleanup ;
438+ fb_set_logo_RGB_palette (& image_palette , palette , current_rows );
439+ info -> pseudo_palette = palette ;
440+
441+ } else {
442+ pr_err ("Error: logo TGA file is empty. Not drawing fullscreen logo.\n" );
443+ }
444+
445+ image -> width = min_t (unsigned int , width , info -> var .xres );
446+ image -> height = min_t (unsigned int , height , info -> var .yres );
447+ image -> dx = 0 ;
448+ image -> dy = 0 ;
449+ image -> depth = 8 ;
450+
451+ if (image -> height < info -> var .yres )
452+ image -> dy = (info -> var .yres - image -> height ) / 2 ;
453+ if (image -> width < info -> var .xres )
454+ image -> dx = (info -> var .xres - image -> width ) / 2 ;
455+
456+ cleanup :
457+ kfree (read_logo );
458+ if (file_content )
459+ kvfree (file_content );
460+ }
461+
462+
278463static int fb_show_logo_line (struct fb_info * info , int rotate ,
279464 const struct linux_logo * logo , int y ,
280465 unsigned int n )
@@ -288,66 +473,85 @@ static int fb_show_logo_line(struct fb_info *info, int rotate,
288473 info -> fbops -> owner )
289474 return 0 ;
290475
291- image .depth = 8 ;
292- image .data = logo -> data ;
476+ if (fullscreen_logo_enabled ) {
477+ fb_set_logo_from_file (info , fullscreen_logo_path ,
478+ & image , palette );
479+ } else {
480+ image .depth = 8 ;
481+ image .data = logo -> data ;
293482
294- if (fb_logo .needs_cmapreset )
295- fb_set_logocmap (info , logo );
483+ if (fb_logo .needs_cmapreset )
484+ fb_set_logocmap (info , logo );
296485
297- if (fb_logo .needs_truepalette ||
298- fb_logo .needs_directpalette ) {
299- palette = kmalloc (256 * 4 , GFP_KERNEL );
300- if (palette == NULL )
301- return 0 ;
486+ if (fb_logo .needs_truepalette ||
487+ fb_logo .needs_directpalette ) {
488+ palette = kmalloc (256 * 4 , GFP_KERNEL );
489+ if (palette == NULL )
490+ return 0 ;
302491
303- if (fb_logo .needs_truepalette )
304- fb_set_logo_truepalette (info , logo , palette );
305- else
306- fb_set_logo_directpalette (info , logo , palette );
492+ if (fb_logo .needs_truepalette )
493+ fb_set_logo_truepalette (info , logo , palette );
494+ else
495+ fb_set_logo_directpalette (info , logo , palette );
307496
308- saved_pseudo_palette = info -> pseudo_palette ;
309- info -> pseudo_palette = palette ;
310- }
497+ saved_pseudo_palette = info -> pseudo_palette ;
498+ info -> pseudo_palette = palette ;
499+ }
311500
312- if (fb_logo .depth <= 4 ) {
313- logo_new = kmalloc_array (logo -> width , logo -> height ,
314- GFP_KERNEL );
315- if (logo_new == NULL ) {
316- kfree (palette );
317- if (saved_pseudo_palette )
318- info -> pseudo_palette = saved_pseudo_palette ;
319- return 0 ;
501+ if (fb_logo .depth <= 4 ) {
502+ logo_new = kmalloc_array (logo -> width , logo -> height ,
503+ GFP_KERNEL );
504+ if (logo_new == NULL ) {
505+ kfree (palette );
506+ if (saved_pseudo_palette )
507+ info -> pseudo_palette = saved_pseudo_palette ;
508+ return 0 ;
509+ }
510+ image .data = logo_new ;
511+ fb_set_logo (info , logo , logo_new , fb_logo .depth );
320512 }
321- image .data = logo_new ;
322- fb_set_logo (info , logo , logo_new , fb_logo .depth );
323- }
324513
325- if (fb_center_logo ) {
326- int xres = info -> var .xres ;
327- int yres = info -> var .yres ;
514+ if (fb_center_logo ) {
515+ int xres = info -> var .xres ;
516+ int yres = info -> var .yres ;
328517
329- if (rotate == FB_ROTATE_CW || rotate == FB_ROTATE_CCW ) {
330- xres = info -> var .yres ;
331- yres = info -> var .xres ;
332- }
518+ if (rotate == FB_ROTATE_CW || rotate == FB_ROTATE_CCW ) {
519+ xres = info -> var .yres ;
520+ yres = info -> var .xres ;
521+ }
333522
334- while (n && (n * (logo -> width + 8 ) - 8 > xres ))
335- -- n ;
336- image .dx = (xres - (n * (logo -> width + 8 ) - 8 )) / 2 ;
337- image .dy = y ?: (yres - logo -> height ) / 2 ;
338- } else {
339- image .dx = 0 ;
340- image .dy = y ;
341- }
523+ while (n && (n * (logo -> width + 8 ) - 8 > xres ))
524+ -- n ;
525+ image .dx = (xres - (n * (logo -> width + 8 ) - 8 )) / 2 ;
526+ image .dy = y ?: (yres - logo -> height ) / 2 ;
527+ } else {
528+ image .dx = 0 ;
529+ image .dy = y ;
530+ }
342531
343- image .width = logo -> width ;
344- image .height = logo -> height ;
532+ image .width = logo -> width ;
533+ image .height = logo -> height ;
345534
346- if (rotate ) {
347- logo_rotate = kmalloc_array (logo -> width , logo -> height ,
348- GFP_KERNEL );
349- if (logo_rotate )
350- fb_rotate_logo (info , logo_rotate , & image , rotate );
535+ if (rotate ) {
536+ logo_rotate = kmalloc_array (logo -> width , logo -> height ,
537+ GFP_KERNEL );
538+ if (logo_rotate )
539+ fb_rotate_logo (info , logo_rotate , & image , rotate );
540+ }
541+ }
542+ if (fullscreen_logo_enabled ) {
543+ // Fullscreen logo data may not fill screen
544+ // Fill remainder of screen with border color of logo for continuous feel
545+ u32 fill_color = image .data [0 ];
546+ struct fb_fillrect region ;
547+
548+ region .color = fill_color ;
549+ region .dx = 0 ;
550+ region .dy = 0 ;
551+ region .width = info -> var .xres ;
552+ region .height = info -> var .yres ;
553+ region .rop = ROP_COPY ;
554+ info -> fbops -> fb_fillrect (info , & region );
351555 }
352556
353557 fb_do_show_logo (info , & image , rotate , n );
0 commit comments