Changeset 3420

Show
Ignore:
Timestamp:
07/11/08 02:06:38 (3 months ago)
Author:
hailfinger
Message:

Fix and clean up coreboot image detection heuristic.
Additional compile fix for NetBSD.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Stefan Reinauer <stepan@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/layout.c

    r3412 r3420  
    4646{ 
    4747        unsigned int *walk; 
     48        unsigned int mb_part_offset, mb_vendor_offset; 
     49        char *mb_part, *mb_vendor; 
     50 
     51        mainboard_vendor = def_name; 
     52        mainboard_part = def_name; 
    4853 
    4954        walk = (unsigned int *)(bios + size - 0x10); 
     
    6469         * (nonprintable and not \0). 
    6570         */ 
    66         if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || *walk > size || 
    67                 *(walk - 1) > size || *(walk - 2) > size || 
    68                 (!isprint((const char *)(bios + size - *(walk - 1))) && 
    69                 ((const char *)(bios + size - *(walk - 1)))) || 
    70                 (!isprint((const char *)(bios + size - *(walk - 2))) && 
    71                 ((const char *)(bios + size - *(walk - 2))))) { 
     71        mb_part_offset = *(walk - 1); 
     72        mb_vendor_offset = *(walk - 2); 
     73        if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || (*walk) > size || 
     74            mb_part_offset > size || mb_vendor_offset > size) { 
    7275                printf("Flash image seems to be a legacy BIOS. Disabling checks.\n"); 
    73                 mainboard_vendor = def_name; 
    74                 mainboard_part = def_name; 
     76                return 0; 
     77        } 
     78         
     79        mb_part = (char *)(bios + size - mb_part_offset); 
     80        mb_vendor = (char *)(bios + size - mb_vendor_offset); 
     81        if (!isprint((unsigned char)*mb_part) || 
     82            !isprint((unsigned char)*mb_vendor)) { 
     83                printf("Flash image seems to have garbage in the ID location." 
     84                        " Disabling checks.\n"); 
    7585                return 0; 
    7686        } 
     
    7989                     "(not ROM size) is %d bytes.\n", *walk); 
    8090 
    81         walk--; 
    82         mainboard_part = strdup((const char *)(bios + size - *walk)); 
    83         walk--; 
    84         mainboard_vendor = strdup((const char *)(bios + size - *walk)); 
     91        mainboard_part = strdup(mb_part); 
     92        mainboard_vendor = strdup(mb_vendor); 
    8593        printf_debug("Manufacturer: %s\n", mainboard_vendor); 
    8694        printf_debug("Mainboard ID: %s\n", mainboard_part);