[coreboot] [PATCH] flashrom: Improve coreboot image detection heuristic

Stefan Reinauer stepan at coresystems.de
Thu Jul 3 16:37:40 CEST 2008


Carl-Daniel Hailfinger wrote:
> Improve coreboot image detection heuristic in flashrom. It's not
> absolutely perfect, but the likelihood of this check to fail is
> 0.000000000000000000000000013 (1.3*10^-26) which is good enough for me.
>   


I think at some point we should go to a better concept of doing things,  
but it seems what you are saying is that your code will probably not 
fail on any bios that has been developed to date, as I doubt it is more 
than 10^26 bioses.

Acked-by: Stefan Reinauer <stepan at coresystems.de>


> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
>
> Index: flashrom-tmp1/layout.c
> ===================================================================
> --- flashrom-tmp1/layout.c	(Revision 3407)
> +++ flashrom-tmp1/layout.c	(Arbeitskopie)
> @@ -21,6 +21,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <ctype.h>
>  #include <stdint.h>
>  #include "flash.h"
>  
> @@ -57,7 +58,18 @@
>  		walk--;
>  	}
>  
> -	if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) {
> +	/*
> +	 * Check if coreboot last image size is 0 or not a multiple of 1k or
> +	 * bigger than the chip or if the pointers to vendor ID or mainboard ID
> +	 * are outside the image of if the start of ID strings are nonsensical
> +	 * (nonprintable and not \0).
> +	 */
> +	if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || *walk > size ||
> +		*(walk - 1) > size || *(walk - 2) > size ||
> +		(!isprint((const char *)(bios + size - *(walk - 1))) &&
> +		((const char *)(bios + size - *(walk - 1)))) ||
> +		(!isprint((const char *)(bios + size - *(walk - 2))) &&
> +		((const char *)(bios + size - *(walk - 2))))) {
>  		printf("Flash image seems to be a legacy BIOS. Disabling checks.\n");
>  		mainboard_vendor = def_name;
>  		mainboard_part = def_name;
>
>
>   


-- 
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
      Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: info at coresystems.dehttp://www.coresystems.de/
Registergericht: Amtsgericht Freiburg • HRB 7656
Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20080703/72e01870/attachment.sig>


More information about the coreboot mailing list