/* $Id$ */
/** @file
* Tool for modifying a BIOS image to write the BIOS checksum.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#ifndef RT_OS_WINDOWS
# include <unistd.h> /* unlink */
#endif
typedef unsigned char uint8_t;
static const char *g_argv0;
/**
* Find where the filename starts in the given path.
*/
{
if (!psz2)
#endif
}
/**
* Report an error.
*/
{
/* clean up */
if (g_pIn)
if (g_pOut)
if (g_pszOutFile)
return 1;
}
/**
* Calculate the checksum.
*/
{
size_t i;
for (i = 0; i < cb; i++)
if (i != iChecksum)
return -u8Sum;
}
/**
* Find a header in the binary.
*
* @param pb Where to search for the signature
* @param cb Size of the search area
* @param pbHeader Pointer to the start of the signature
* @returns 0 if signature was not found, 1 if found or
* 2 if more than one signature was found */
{
int fFound = 0;
unsigned int i;
for (i = 0; i < cb; i += 16)
{
if (fFound++)
return 2;
}
return fFound;
}
{
int fAdapterBios = 0;
if (argc != 3)
return fatal("Input file name and output file name required.\n");
if (!pIn)
if (!pOut)
/* safety precaution (aka. complete paranoia :-) */
/* align size to page size */
if ((cbIn % 4096) != 0)
return fatal("Size of system BIOS is not 64KB!\n");
if (fAdapterBios)
{
/* adapter BIOS */
/* set the length indicator */
}
else
{
/* system BIOS */
/* Set the BIOS32 header checksum. */
{
case 0:
return fatal("No BIOS32 header not found!\n");
case 2:
return fatal("More than one BIOS32 header found!\n");
case 1:
break;
}
/* Set the PIR header checksum according to PCI IRQ Routing table
* specification version 1.0, Microsoft Corporation, 1996 */
{
case 0:
return fatal("No PCI IRQ routing table found!\n");
case 2:
return fatal("More than one PCI IRQ routing table found!\n");
case 1:
break;
}
/* Set the SMBIOS header checksum according to System Management BIOS
* Reference Specification Version 2.5, DSP0134. */
{
case 0:
return fatal("No SMBIOS header found!\n");
case 2:
return fatal("More than one SMBIOS header found!\n");
case 1:
/* at first fix the DMI header starting at SMBIOS header offset 16 */
/* now fix the checksum of the whole SMBIOS header */
break;
}
}
/* set the BIOS checksum */
return 0;
}