16
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
17
*/
18
18
19
- #include <libpayload .h>
19
+ #include <boot_device .h>
20
20
#include <cbfs.h>
21
+ #include <cbfs_glue.h>
21
22
#include <coreboot_tables.h>
22
23
#include <curses.h>
23
24
#include <flash_access.h>
25
+ #include <libpayload.h>
26
+ #include <rtc_clock_menu.h>
24
27
#include <sec_reg_menu.h>
25
28
#include <spi/spi_lock_menu.h>
26
- #include <rtc_clock_menu.h>
27
29
28
30
#include "version.h"
29
31
@@ -502,7 +504,7 @@ static void show_boot_device_list(char buffer[MAX_DEVICES][MAX_LENGTH],
502
504
(sd3_toggle ) ? "Enabled" : "Disabled" );
503
505
printf (" g Reverse order of PCI addresses - Currently %s\n" ,
504
506
(pciereverse_toggle ) ? "Enabled" : "Disabled" );
505
-
507
+
506
508
#ifndef COREBOOT_LEGACY
507
509
printf (" v IOMMU - Currently %s\n" ,
508
510
(iommu_toggle ) ? "Enabled" : "Disabled" );
@@ -521,31 +523,26 @@ static void show_boot_device_list(char buffer[MAX_DEVICES][MAX_LENGTH],
521
523
static int fetch_bootorder_from_cbfs (char destination [MAX_DEVICES ][MAX_LENGTH ],
522
524
u8 * line_count )
523
525
{
524
- char * cbfs_dat ;
525
- struct cbfs_handle * bootorder_handle ;
526
+ void * bootorder_mapping ;
526
527
size_t cbfs_length ;
527
528
528
- bootorder_handle = cbfs_get_handle (CBFS_DEFAULT_MEDIA , BOOTORDER_FILE );
529
-
530
- flash_address = (void * )(bootorder_handle -> media_offset +
531
- bootorder_handle -> content_offset );
532
-
533
- if ((u32 )flash_address & 0xfff )
534
- printf ("Warning: The bootorder file is not 4k aligned!\n" );
535
-
536
- cbfs_dat = cbfs_get_file_content (CBFS_DEFAULT_MEDIA , BOOTORDER_FILE ,
537
- CBFS_TYPE_RAW , & cbfs_length );
529
+ bootorder_mapping = cbfs_map (BOOTORDER_FILE , & cbfs_length );
538
530
539
- if (!cbfs_dat ) {
531
+ if (!bootorder_mapping ) {
540
532
printf ("Error: file [%s] not found!\n" , BOOTORDER_FILE );
541
533
return -1 ;
542
534
}
543
535
544
- if (cbfs_dat [0 ] == 0xFF || cbfs_dat [0 ] == 0x00 ) {
536
+ printf ("The bootorder file size is %zu!\n" , cbfs_length );
537
+
538
+ if ((u32 )bootorder_mapping & 0xfff )
539
+ printf ("Warning: The bootorder file is not 4k aligned!\n" );
540
+
541
+ if (* (u16 * )bootorder_mapping == 0xFFFF || * (u16 * )bootorder_mapping == 0x0000 ) {
545
542
printf ("Error: bootorder is empty!\n" );
546
543
return -1 ;
547
544
}
548
- memcpy (bootorder_data , cbfs_dat , cbfs_length );
545
+ memcpy (bootorder_data , bootorder_mapping , cbfs_length );
549
546
550
547
if (fetch_file_from_cbfs (BOOTORDER_FILE , destination , line_count ))
551
548
return -1 ;
@@ -557,37 +554,35 @@ static int fetch_bootorder(char destination[MAX_DEVICES][MAX_LENGTH],
557
554
u8 * line_count )
558
555
{
559
556
char tmp ;
560
- int offset = 0 , char_cnt = 0 ;
561
- u32 bootorder_offset , bootorder_size ;
562
- struct cbfs_media default_media ;
563
- struct cbfs_media * media = & default_media ;
564
-
557
+ u16 offset = 0 , char_cnt = 0 ;
558
+ static struct cbfs_boot_device rw ;
565
559
u32 rom_begin = (0xFFFFFFFF - lib_sysinfo .spi_flash .size ) + 1 ;
566
560
567
- int rc = fmap_region_by_name (lib_sysinfo .fmap_offset , "BOOTORDER" ,
568
- & bootorder_offset , & bootorder_size );
569
- if (rc == -1 ) {
561
+ if (fmap_locate_area ("BOOTORDER" , & rw .dev .offset , & rw .dev .size )) {
562
+ printf ("BOOTORDER area not found, fetching from CBFS...\n" );
570
563
return fetch_bootorder_from_cbfs (destination , line_count );
571
- } else {
572
- flash_address = (void * )(rom_begin + bootorder_offset );
573
-
574
- if (init_default_cbfs_media (media ))
575
- return -1 ;
576
-
577
- media -> open (media );
578
- if (!media -> read (media , bootorder_data , bootorder_offset ,
579
- bootorder_size ))
580
- return -1 ;
581
- media -> close (media );
582
564
}
583
565
566
+ flash_address = (void * )(rom_begin + rw .dev .offset );
584
567
if ((u32 )flash_address & 0xfff )
585
568
printf ("Warning: The bootorder file is not 4k aligned!\n" );
586
569
587
- if (bootorder_data [0 ] == 0xFF || bootorder_data [0 ] == 0x00 )
570
+ if (!rw .dev .size ) {
571
+ printf ("BOOTORDER area size is zero, fetching from CBFS...\n" );
588
572
return fetch_bootorder_from_cbfs (destination , line_count );
573
+ }
589
574
590
- //count up the lines and display
575
+ if (boot_device_read (bootorder_data , rw .dev .offset , rw .dev .size ) != rw .dev .size ) {
576
+ printf ("Failed to read bootorder data, fetching from CBFS...\n" );
577
+ return fetch_bootorder_from_cbfs (destination , line_count );
578
+ }
579
+
580
+ if (bootorder_data [0 ] == 0xFF || bootorder_data [0 ] == 0x00 ) {
581
+ printf ("Invalid bootorder region data, fetching from CBFS: (0x%x)...\n" , bootorder_data [0 ] );
582
+ return fetch_bootorder_from_cbfs (destination , line_count );
583
+ }
584
+
585
+ // Count up the lines and display
591
586
* line_count = 0 ;
592
587
while (1 ) {
593
588
tmp = * (bootorder_data + offset ++ );
@@ -597,21 +592,21 @@ static int fetch_bootorder(char destination[MAX_DEVICES][MAX_LENGTH],
597
592
char_cnt = 0 ;
598
593
}
599
594
else if ((tmp == 0xFF ) || (tmp == NUL ) ||
600
- (offset > bootorder_size ))
595
+ (offset > rw . dev . size ))
601
596
break ;
602
597
else
603
598
char_cnt ++ ;
604
599
605
600
if (* line_count > MAX_DEVICES ) {
606
- printf ("aborting due to excessive line_count \n" );
601
+ printf ("Aborting due to excessive line count: %d \n" , * line_count );
607
602
break ;
608
603
}
609
604
if (char_cnt > MAX_LENGTH ) {
610
- printf ("aborting due to excessive char count\n" );
605
+ printf ("Aborting due to excessive char count: %d \n" , char_cnt );
611
606
break ;
612
607
}
613
- if (offset > (MAX_LENGTH * MAX_DEVICES )) {
614
- printf ("aborting due to excessive cbfs ptr length\n" );
608
+ if (offset > (MAX_LENGTH * MAX_DEVICES )) {
609
+ printf ("Aborting due to excessive cbfs ptr length: %d \n" , offset );
615
610
break ;
616
611
}
617
612
}
@@ -646,7 +641,7 @@ static int fetch_file_from_cbfs(char *filename,
646
641
int cbfs_offset = 0 , char_cnt = 0 ;
647
642
size_t cbfs_length ;
648
643
649
- cbfs_dat = (char * ) cbfs_get_file_content ( CBFS_DEFAULT_MEDIA , filename , CBFS_TYPE_RAW , & cbfs_length );
644
+ cbfs_dat = (char * ) cbfs_map ( filename , & cbfs_length );
650
645
if (!cbfs_dat ) {
651
646
printf ("Error: file [%s] not found!\n" , filename );
652
647
return 1 ;
@@ -679,6 +674,8 @@ static int fetch_file_from_cbfs(char *filename,
679
674
break ;
680
675
}
681
676
}
677
+
678
+ cbfs_unmap (cbfs_dat );
682
679
return 0 ;
683
680
}
684
681
@@ -764,7 +761,7 @@ static void update_wdg_timeout(char buffer[MAX_DEVICES][MAX_LENGTH],
764
761
buffer [* max_lines ][strlen (tag )+ 5 ] = '\n' ;
765
762
buffer [* max_lines ][strlen (tag )+ 6 ] = '0' ;
766
763
(* max_lines )++ ;
767
- }
764
+ }
768
765
}
769
766
#endif
770
767
0 commit comments