mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 10:14:55 +00:00
Make vboot_reference build in MSVC command line environment.
This is a mostly NOOP change which modifies the source code to compile cleanly in the MSVC command line build environment. A new makefile is introduced (msc/nmakefile) along with a README.txt in the same directory explaining how to build the code in the DOS window. As of this submission the build is running in a 32 bit environment, the intention is to use the same makefile for 64 bit builds in the future. Enabling high compilation warnings level allowed to identify a couple of bugs in the code which are being fixed. Not all sources are being compiled in the MSVC environment, only those in firmware/ and most of those in test/ subdirectories. The benchmark calculations require porting of the timer facilities and are being postponed. TEST Built in DOS and linux environments. Ran unit tests in linux environment. Review URL: http://codereview.chromium.org/2809037
This commit is contained in:
3
Makefile
3
Makefile
@@ -4,8 +4,7 @@
|
||||
|
||||
export CC ?= gcc
|
||||
export CXX ?= g++
|
||||
export CFLAGS = -Wall -DNDEBUG -O3 -Werror -DCHROMEOS_ENVIRONMENT \
|
||||
-DVBOOT_DEBUG
|
||||
export CFLAGS = -Wall -DNDEBUG -O3 -Werror -DCHROMEOS_ENVIRONMENT -DVBOOT_DEBUG
|
||||
export TOP = $(shell pwd)
|
||||
export FWDIR=$(TOP)/firmware
|
||||
export HOSTDIR=$(TOP)/host
|
||||
|
||||
@@ -26,12 +26,20 @@
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
/* 64-bit operations, for platforms where they need to be function calls */
|
||||
#define UINT64_RSHIFT(v, shiftby) (((uint64_t)(v)) >> (shiftby))
|
||||
#define UINT64_MULT32(v, multby) (((uint64_t)(v)) * ((uint32_t)(multby)))
|
||||
|
||||
#else
|
||||
#include "biosincludes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define __pragma(...)
|
||||
#endif
|
||||
|
||||
#if defined (CHROMEOS_ENVIRONMENT) || defined (TARGET_TEST_MODE)
|
||||
|
||||
/* 64-bit operations, for platforms where they need to be function calls */
|
||||
#define UINT64_RSHIFT(v, shiftby) (((uint64_t)(v)) >> (shiftby))
|
||||
#define UINT64_MULT32(v, multby) (((uint64_t)(v)) * ((uint32_t)(multby)))
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* VBOOT_REFERENCE_SYSINCLUDES_H_ */
|
||||
|
||||
@@ -52,10 +52,10 @@ void Free(void* ptr);
|
||||
int Memcmp(const void* src1, const void* src2, size_t n);
|
||||
|
||||
/* Copy [n] bytes from [src] to [dest]. */
|
||||
void* Memcpy(void* dest, const void* src, size_t n);
|
||||
void* Memcpy(void* dest, const void* src, uint64_t n);
|
||||
|
||||
/* Set [n] bytes starting at [s] to [c]. */
|
||||
void* Memset(void *dest, const uint8_t c, size_t n);
|
||||
void* Memset(void *dest, const uint8_t c, uint64_t n);
|
||||
|
||||
/* Compare [n] bytes starting at [s1] with [s2] and return 0 if they match,
|
||||
* 1 if they don't. Time taken to perform the comparison is only dependent on
|
||||
|
||||
@@ -115,7 +115,7 @@ int IsKernelEntry(const GptEntry* e) {
|
||||
}
|
||||
|
||||
|
||||
int CheckEntries(GptEntry* entries, GptHeader* h, uint64_t drive_sectors) {
|
||||
int CheckEntries(GptEntry* entries, GptHeader* h) {
|
||||
|
||||
GptEntry* entry;
|
||||
uint32_t crc32;
|
||||
@@ -227,17 +227,17 @@ int GptSanityCheck(GptData *gpt) {
|
||||
* Note that we use the same header in both checks. This way we'll
|
||||
* catch the case where (header1,entries1) and (header2,entries2)
|
||||
* are both valid, but (entries1 != entries2). */
|
||||
if (0 == CheckEntries(entries1, goodhdr, gpt->drive_sectors))
|
||||
if (0 == CheckEntries(entries1, goodhdr))
|
||||
gpt->valid_entries |= MASK_PRIMARY;
|
||||
if (0 == CheckEntries(entries2, goodhdr, gpt->drive_sectors))
|
||||
if (0 == CheckEntries(entries2, goodhdr))
|
||||
gpt->valid_entries |= MASK_SECONDARY;
|
||||
|
||||
/* If both headers are good but neither entries were good, check the
|
||||
* entries with the secondary header. */
|
||||
if (MASK_BOTH == gpt->valid_headers && !gpt->valid_entries) {
|
||||
if (0 == CheckEntries(entries1, header2, gpt->drive_sectors))
|
||||
if (0 == CheckEntries(entries1, header2))
|
||||
gpt->valid_entries |= MASK_PRIMARY;
|
||||
if (0 == CheckEntries(entries2, header2, gpt->drive_sectors))
|
||||
if (0 == CheckEntries(entries2, header2))
|
||||
gpt->valid_entries |= MASK_SECONDARY;
|
||||
if (gpt->valid_entries) {
|
||||
/* Sure enough, header2 had a good CRC for one of the entries. Mark
|
||||
|
||||
@@ -83,7 +83,7 @@ uint32_t HeaderCrc(GptHeader* h);
|
||||
/* Check entries.
|
||||
*
|
||||
* Returns 0 if entries are valid, 1 if invalid. */
|
||||
int CheckEntries(GptEntry* entries, GptHeader* h, uint64_t drive_sectors);
|
||||
int CheckEntries(GptEntry* entries, GptHeader* h);
|
||||
|
||||
/* Check GptData, headers, entries.
|
||||
*
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
|
||||
#include "sysincludes.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push,1) /* Support packing for MSVC. */
|
||||
#endif
|
||||
__pragma(pack(push,1)) /* Support packing for MSVC. */
|
||||
|
||||
#define GPT_HEADER_SIGNATURE "EFI PART"
|
||||
#define GPT_HEADER_SIGNATURE_SIZE sizeof(GPT_HEADER_SIGNATURE)
|
||||
@@ -117,8 +115,6 @@ typedef struct {
|
||||
|
||||
#define GPTENTRY_EXPECTED_SIZE 128
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop) /* Support packing for MSVC. */
|
||||
#endif
|
||||
__pragma(pack(pop)) /* Support packing for MSVC. */
|
||||
|
||||
#endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
|
||||
#include "sysincludes.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, 1) /* Support packing for MSVC. */
|
||||
#endif
|
||||
__pragma(pack(push, 1)) /* Support packing for MSVC. */
|
||||
|
||||
/* Public key data */
|
||||
typedef struct VbPublicKey {
|
||||
@@ -133,8 +131,6 @@ typedef struct VbKernelPreambleHeader {
|
||||
|
||||
#define EXPECTED_VBKERNELPREAMBLEHEADER_SIZE 96
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop) /* Support packing for MSVC. */
|
||||
#endif
|
||||
__pragma(pack(pop)) /* Support packing for MSVC. */
|
||||
|
||||
#endif /* VBOOT_REFERENCE_VBOOT_STRUCT_H_ */
|
||||
|
||||
@@ -17,6 +17,9 @@ uint16_t g_firmware_version = 0;
|
||||
uint16_t g_kernel_key_version = 0;
|
||||
uint16_t g_kernel_version = 0;
|
||||
|
||||
/* disable MSVC warning on const logical expression (as in } while(0);) */
|
||||
__pragma(warning (disable: 4127))
|
||||
|
||||
#define RETURN_ON_FAILURE(tpm_command) do { \
|
||||
uint32_t result; \
|
||||
if ((result = (tpm_command)) != TPM_SUCCESS) { \
|
||||
@@ -369,7 +372,8 @@ uint32_t LockKernelVersionsByLockingPP() {
|
||||
return TlclLockPhysicalPresence();
|
||||
}
|
||||
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
/* NEW APIS! HELP ME LUIGI, YOU'RE MY ONLY HOPE! */
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ int WriteAndFreeGptData(GptData* gptdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* disable MSVC warning on const logical expression (as in } while(0);) */
|
||||
__pragma(warning(disable: 4127))
|
||||
|
||||
int LoadKernel(LoadKernelParams* params) {
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
#include "boot_device.h"
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -11,4 +11,24 @@
|
||||
* CHROMEOS_ENVIRONMENT is not defined at compilation time.
|
||||
*/
|
||||
|
||||
#ifdef TARGET_TEST_MODE
|
||||
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned size_t;
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*) 0)
|
||||
#endif
|
||||
|
||||
#define UINT64_C(x) ((uint64_t)x)
|
||||
#define __attribute__(x)
|
||||
#define PRIu64 "%ll"
|
||||
extern void debug(const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /*CHROMEOS_SRC_PLATFORM_VBOOT_REFERENCE_FIRMWARE_STUB_BIOSINCLUDES_H_*/
|
||||
|
||||
@@ -35,9 +35,13 @@ int GetFirmwareBody(LoadFirmwareParams* params, uint64_t index) {
|
||||
case 0:
|
||||
size = ci->firmwareA_size;
|
||||
fw = ci->firmwareA;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
size = ci->firmwareB_size;
|
||||
fw = ci->firmwareB;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Anything else is invalid */
|
||||
return 1;
|
||||
@@ -68,6 +72,7 @@ int VerifyFirmwareDriver_stub(uint8_t* root_key_blob,
|
||||
int rv;
|
||||
|
||||
CallerInternal ci;
|
||||
LoadFirmwareParams p;
|
||||
|
||||
/* Copy the firmware volume pointers to our global variables. */
|
||||
ci.firmwareA = firmwareA;
|
||||
@@ -78,7 +83,6 @@ int VerifyFirmwareDriver_stub(uint8_t* root_key_blob,
|
||||
ci.firmwareB_size = 0;
|
||||
|
||||
/* Set up the params for LoadFirmware() */
|
||||
LoadFirmwareParams p;
|
||||
p.caller_internal = &ci;
|
||||
p.firmware_root_key_blob = root_key_blob;
|
||||
p.verification_block_0 = verification_headerA;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
#include "tss_constants.h"
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
void TlclLibInit(void) { return; }
|
||||
uint32_t TlclStartup(void) { return TPM_SUCCESS; }
|
||||
uint32_t TlclSelftestfull(void) { return TPM_SUCCESS; }
|
||||
|
||||
@@ -48,13 +48,14 @@ int Memcmp(const void* src1, const void* src2, size_t n) {
|
||||
return memcmp(src1, src2, n);
|
||||
}
|
||||
|
||||
void* Memcpy(void* dest, const void* src, size_t n) {
|
||||
return memcpy(dest, src, n);
|
||||
void* Memcpy(void* dest, const void* src, uint64_t n) {
|
||||
return memcpy(dest, src, (size_t)n);
|
||||
}
|
||||
|
||||
void* Memset(void* dest, const uint8_t c, size_t n) {
|
||||
void* Memset(void* d, const uint8_t c, uint64_t n) {
|
||||
uint8_t *dest = d; /* the only way to keep both cl and gcc happy */
|
||||
while (n--) {
|
||||
*((uint8_t*)dest++) = c;
|
||||
*dest++ = c;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
char* VbootVersion = "VBOOv=c6976ffa";
|
||||
char* VbootVersion = "VBOOv=0c991073";
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#ifndef VBOOT_REFERENCE_HOST_COMMON_H_
|
||||
#define VBOOT_REFERENCE_HOST_COMMON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cryptolib.h"
|
||||
#include "host_key.h"
|
||||
#include "host_keyblock.h"
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#ifndef VBOOT_REFERENCE_HOST_KEY_H_
|
||||
#define VBOOT_REFERENCE_HOST_KEY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cryptolib.h"
|
||||
#include "utility.h"
|
||||
#include "vboot_struct.h"
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#ifndef VBOOT_REFERENCE_HOST_KEYBLOCK_H_
|
||||
#define VBOOT_REFERENCE_HOST_KEYBLOCK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "host_key.h"
|
||||
#include "vboot_struct.h"
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
#ifndef VBOOT_REFERENCE_HOST_MISC_H_
|
||||
#define VBOOT_REFERENCE_HOST_MISC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "host_misc.h"
|
||||
#include "utility.h"
|
||||
#include "vboot_struct.h"
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#ifndef VBOOT_REFERENCE_HOST_SIGNATURE_H_
|
||||
#define VBOOT_REFERENCE_HOST_SIGNATURE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cryptolib.h"
|
||||
#include "host_key.h"
|
||||
#include "utility.h"
|
||||
|
||||
25
msc/README.txt
Normal file
25
msc/README.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
This directory contains the Microsoft Visual C makefile for building vboot
|
||||
reference code (and testing, eventually) in a 32 bit DOS window.
|
||||
|
||||
Microsoft Visual C 2008 (or later) is the prerequisite for this to work.
|
||||
|
||||
To build vboot_reference tree in the DOS window do the following:
|
||||
|
||||
- untar or git clone the vboot_reference source tree
|
||||
|
||||
- open a DOS window
|
||||
|
||||
- run the MSVC provided script vcvars32.bat to create the command line build
|
||||
environment. Script location is MSVC installation specific. For instance:
|
||||
|
||||
c:\> \bios\devtls\MSVC9\Vc\bin\vcvars32.bat
|
||||
|
||||
- define a directory where the nmake output should go into
|
||||
|
||||
c:\> set MOD=z:\shared\tmp
|
||||
|
||||
- start the make job as follows:
|
||||
|
||||
c:\> nmake /f %path_to_vboot_reference_tree%\msc\nmakefile
|
||||
|
||||
- observe the output generated in %MOD%
|
||||
55
msc/nmakefile
Normal file
55
msc/nmakefile
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
!IF "$(MOD)" == ""
|
||||
!ERROR MOD (Make output dir) is not defined
|
||||
!ENDIF
|
||||
|
||||
O = $(MOD)
|
||||
R = z:\shared\vboot_reference
|
||||
|
||||
ALL_OBJS = $O\main.obj $O\stateful_util.obj $O\cgptlib_internal.obj \
|
||||
$O\cgptlib.obj $O\crc32.obj $O\vboot_common.obj $O\vboot_kernel.obj \
|
||||
$O\vboot_firmware.obj $O\rollback_index.obj $O\sha_utility.obj $O\rsa.obj \
|
||||
$O\rsa_utility.obj $O\padding.obj $O\sha2.obj $O\sha1.obj \
|
||||
$O\load_firmware_stub.obj $O\tlcl.obj $O\utility_stub.obj \
|
||||
$O\boot_device_stub.obj $O\crc32_test.obj $O\rollback_index_mock.obj \
|
||||
$O\test_common.obj $O\cgptlib_test.obj $O\rsa_padding_test.obj \
|
||||
$O\sha_tests.obj $O\vboot_common_tests.obj $O\vboot_common2_tests.obj \
|
||||
$O\vboot_common3_tests.obj
|
||||
|
||||
CFLAGS = $(CFLAGS) /I $R\firmware\lib\include
|
||||
CFLAGS = $(CFLAGS) /I $R\firmware\lib\cgptlib\include
|
||||
CFLAGS = $(CFLAGS) /I $R\firmware\include
|
||||
CFLAGS = $(CFLAGS) /I $R\firmware\stub\include
|
||||
CFLAGS = $(CFLAGS) /I $R\firmware\lib\cryptolib\include
|
||||
CFLAGS = $(CFLAGS) /I $R\host\include
|
||||
|
||||
CFLAGS = $(CFLAGS) /W4 /WX /D TARGET_TEST_MODE
|
||||
|
||||
COMPILE = $(CC) $(CFLAGS) /Fo$@ -c $<
|
||||
|
||||
all: $(ALL_OBJS)
|
||||
|
||||
{$R\firmware\linktest}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
{$R\firmware\lib}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
{$R\firmware\lib\cgptlib}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
{$R\firmware\lib\cryptolib}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
{$R\firmware\stub}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
{$R\tests}.c{$O}.obj:
|
||||
$(COMPILE)
|
||||
|
||||
#{$R\cgpt}.c{$O}.obj:
|
||||
#$R/firmware/lib/cgptlibc.$O.obj:
|
||||
#$R/firmware/lib/cryptolibc.$O.obj:
|
||||
#$R/firmware/stubc.$O.obj:
|
||||
#$R/utilityc.$O.obj:
|
||||
# $(CC) $(CFLAGS) -Fd$O\ -c $<
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "crc32.h"
|
||||
#include "crc32_test.h"
|
||||
#include "gpt.h"
|
||||
#include "test_common.h"
|
||||
#include "utility.h"
|
||||
|
||||
/* Testing partition layout (sector_bytes=512)
|
||||
@@ -560,12 +561,12 @@ static int EntriesCrcTest() {
|
||||
|
||||
/* Modify the first byte of primary entries, and expect the CRC is wrong. */
|
||||
BuildTestGptData(gpt);
|
||||
EXPECT(0 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(0 == CheckEntries(e2, h1, gpt->drive_sectors));
|
||||
EXPECT(0 == CheckEntries(e1, h1));
|
||||
EXPECT(0 == CheckEntries(e2, h1));
|
||||
gpt->primary_entries[0] ^= 0xa5; /* just XOR a non-zero value */
|
||||
gpt->secondary_entries[TOTAL_ENTRIES_SIZE-1] ^= 0x5a;
|
||||
EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(1 == CheckEntries(e2, h1, gpt->drive_sectors));
|
||||
EXPECT(1 == CheckEntries(e1, h1));
|
||||
EXPECT(1 == CheckEntries(e2, h1));
|
||||
|
||||
return TEST_OK;
|
||||
}
|
||||
@@ -586,26 +587,26 @@ static int ValidEntryTest() {
|
||||
BuildTestGptData(gpt);
|
||||
e1[0].starting_lba = h1->first_usable_lba - 1;
|
||||
RefreshCrc32(gpt);
|
||||
EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(1 == CheckEntries(e1, h1));
|
||||
|
||||
/* error case: entry.EndingLBA > header.LastUsableLBA */
|
||||
BuildTestGptData(gpt);
|
||||
e1[2].ending_lba = h1->last_usable_lba + 1;
|
||||
RefreshCrc32(gpt);
|
||||
EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(1 == CheckEntries(e1, h1));
|
||||
|
||||
/* error case: entry.StartingLBA > entry.EndingLBA */
|
||||
BuildTestGptData(gpt);
|
||||
e1[3].starting_lba = e1[3].ending_lba + 1;
|
||||
RefreshCrc32(gpt);
|
||||
EXPECT(1 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(1 == CheckEntries(e1, h1));
|
||||
|
||||
/* case: non active entry should be ignored. */
|
||||
BuildTestGptData(gpt);
|
||||
Memset(&e1[1].type, 0, sizeof(e1[1].type));
|
||||
e1[1].starting_lba = e1[1].ending_lba + 1;
|
||||
RefreshCrc32(gpt);
|
||||
EXPECT(0 == CheckEntries(e1, h1, gpt->drive_sectors));
|
||||
EXPECT(0 == CheckEntries(e1, h1));
|
||||
|
||||
return TEST_OK;
|
||||
}
|
||||
@@ -667,7 +668,7 @@ static int OverlappedPartitionTest() {
|
||||
}
|
||||
RefreshCrc32(gpt);
|
||||
|
||||
EXPECT(cases[i].overlapped == CheckEntries(e, h, gpt->drive_sectors));
|
||||
EXPECT(cases[i].overlapped == CheckEntries(e, h));
|
||||
}
|
||||
return TEST_OK;
|
||||
}
|
||||
@@ -823,39 +824,39 @@ static int EntryAttributeGetSetTest() {
|
||||
GptData* gpt = GetEmptyGptData();
|
||||
GptEntry* e = (GptEntry*)(gpt->primary_entries);
|
||||
|
||||
e->attrs.whole = 0x0000000000000000LLU;
|
||||
e->attrs.whole = 0x0000000000000000ULL;
|
||||
SetEntrySuccessful(e, 1);
|
||||
EXPECT(0x0100000000000000LLU == e->attrs.whole);
|
||||
EXPECT(0x0100000000000000ULL == e->attrs.whole);
|
||||
EXPECT(1 == GetEntrySuccessful(e));
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU;
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
|
||||
SetEntrySuccessful(e, 0);
|
||||
EXPECT(0xFEFFFFFFFFFFFFFFLLU == e->attrs.whole);
|
||||
EXPECT(0xFEFFFFFFFFFFFFFFULL == e->attrs.whole);
|
||||
EXPECT(0 == GetEntrySuccessful(e));
|
||||
|
||||
e->attrs.whole = 0x0000000000000000LLU;
|
||||
e->attrs.whole = 0x0000000000000000ULL;
|
||||
SetEntryTries(e, 15);
|
||||
EXPECT(15 == GetEntryTries(e));
|
||||
EXPECT(0x00F0000000000000LLU == e->attrs.whole);
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU;
|
||||
EXPECT(0x00F0000000000000ULL == e->attrs.whole);
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
|
||||
SetEntryTries(e, 0);
|
||||
EXPECT(0xFF0FFFFFFFFFFFFFLLU == e->attrs.whole);
|
||||
EXPECT(0xFF0FFFFFFFFFFFFFULL == e->attrs.whole);
|
||||
EXPECT(0 == GetEntryTries(e));
|
||||
|
||||
e->attrs.whole = 0x0000000000000000LLU;
|
||||
e->attrs.whole = 0x0000000000000000ULL;
|
||||
SetEntryPriority(e, 15);
|
||||
EXPECT(0x000F000000000000LLU == e->attrs.whole);
|
||||
EXPECT(0x000F000000000000ULL == e->attrs.whole);
|
||||
EXPECT(15 == GetEntryPriority(e));
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU;
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
|
||||
SetEntryPriority(e, 0);
|
||||
EXPECT(0xFFF0FFFFFFFFFFFFLLU == e->attrs.whole);
|
||||
EXPECT(0xFFF0FFFFFFFFFFFFULL == e->attrs.whole);
|
||||
EXPECT(0 == GetEntryPriority(e));
|
||||
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFLLU;
|
||||
e->attrs.whole = 0xFFFFFFFFFFFFFFFFULL;
|
||||
EXPECT(1 == GetEntrySuccessful(e));
|
||||
EXPECT(15 == GetEntryPriority(e));
|
||||
EXPECT(15 == GetEntryTries(e));
|
||||
|
||||
e->attrs.whole = 0x0123000000000000LLU;
|
||||
e->attrs.whole = 0x0123000000000000ULL;
|
||||
EXPECT(1 == GetEntrySuccessful(e));
|
||||
EXPECT(2 == GetEntryTries(e));
|
||||
EXPECT(3 == GetEntryPriority(e));
|
||||
@@ -1091,6 +1092,8 @@ static int UpdateInvalidKernelTypeTest() {
|
||||
return TEST_OK;
|
||||
}
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define VBOOT_REFERENCE_CGPTLIB_TEST_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sysincludes.h"
|
||||
|
||||
enum {
|
||||
TEST_FAIL = -1,
|
||||
@@ -13,14 +14,12 @@ enum {
|
||||
};
|
||||
|
||||
#define TEST_CASE(func) #func, func
|
||||
typedef int (*test_func)(void);
|
||||
typedef int (*test_func)();
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
/* ANSI Color coding sequences. */
|
||||
#define COL_GREEN "\e[1;32m"
|
||||
#define COL_RED "\e[0;31m"
|
||||
#define COL_STOP "\e[m"
|
||||
/* disable MSVC warning on const logical expression (as in } while(0);) */
|
||||
__pragma(warning (disable: 4127))
|
||||
|
||||
#define EXPECT(expr) \
|
||||
do { \
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "crc32_test.h"
|
||||
#include "cgptlib_test.h"
|
||||
#include "crc32.h"
|
||||
#include "test_common.h"
|
||||
#include "utility.h"
|
||||
|
||||
#define MAX_VECTOR_LEN 256
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "rollback_index.h"
|
||||
#include "tss_constants.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uint16_t g_firmware_key_version = 0;
|
||||
@@ -16,6 +15,9 @@ uint16_t g_firmware_version = 0;
|
||||
uint16_t g_kernel_key_version = 0;
|
||||
uint16_t g_kernel_version = 0;
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
uint32_t SetupTPM(int mode, int developer_flag) {
|
||||
#ifndef NDEBUG
|
||||
debug("Rollback Index Library Mock: TPM initialized.\n");
|
||||
|
||||
@@ -78,6 +78,9 @@ int SHA512_tests(void) {
|
||||
return success;
|
||||
}
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int success = 1;
|
||||
/* Initialize long_msg with 'a' x 1,000,000 */
|
||||
|
||||
@@ -13,11 +13,6 @@
|
||||
#include "file_keys.h"
|
||||
#include "utility.h"
|
||||
|
||||
/* ANSI Color coding sequences. */
|
||||
#define COL_GREEN "\e[1;32m"
|
||||
#define COL_RED "\e[0;31m"
|
||||
#define COL_STOP "\e[m"
|
||||
|
||||
/* Global test success flag. */
|
||||
int gTestSuccess = 1;
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#ifndef VBOOT_REFERENCE_TEST_COMMON_H_
|
||||
#define VBOOT_REFERENCE_TEST_COMMON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern int gTestSuccess;
|
||||
|
||||
/* Return 1 if result is equal to expected_result, else return 0.
|
||||
@@ -18,4 +16,12 @@ int TEST_EQ(int result, int expected_result, char* testname);
|
||||
* Also update the global gTestSuccess flag if test fails. */
|
||||
int TEST_NEQ(int result, int not_expected_result, char* testname);
|
||||
|
||||
/* ANSI Color coding sequences.
|
||||
*
|
||||
* Don't use \e as MSC does not recognize it as a valid escape sequence.
|
||||
*/
|
||||
#define COL_GREEN "\x1b[1;32m"
|
||||
#define COL_RED "\x1b[0;31m"
|
||||
#define COL_STOP "\x1b[m"
|
||||
|
||||
#endif /* VBOOT_REFERENCE_TEST_COMMON_H_ */
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
#ifndef VBOOT_REFERENCE_TIMER_UTILS_H_
|
||||
#define VBOOT_REFERENCE_TIMER_UTILS_H_
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
|
||||
typedef struct ClockTimer {
|
||||
|
||||
@@ -34,7 +34,8 @@ static void VerifyPublicKeyToRSA(const VbPublicKey* orig_key) {
|
||||
rsa = PublicKeyToRSA(orig_key);
|
||||
TEST_NEQ((size_t)rsa, 0, "PublicKeyToRSA() ok");
|
||||
if (rsa) {
|
||||
TEST_EQ(rsa->algorithm, key->algorithm, "PublicKeyToRSA() algorithm");
|
||||
TEST_EQ((int)rsa->algorithm, (int)key->algorithm,
|
||||
"PublicKeyToRSA() algorithm");
|
||||
RSAPublicKeyFree(rsa);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +78,7 @@ static void VerifyDigestTest(const VbPublicKey* public_key,
|
||||
|
||||
sig = CalculateSignature(test_data, sizeof(test_data), private_key);
|
||||
rsa = PublicKeyToRSA(public_key);
|
||||
digest = DigestBuf(test_data, sizeof(test_data), public_key->algorithm);
|
||||
digest = DigestBuf(test_data, sizeof(test_data), (int)public_key->algorithm);
|
||||
TEST_NEQ(sig && rsa && digest, 0, "VerifyData() prerequisites");
|
||||
if (!sig || !rsa || !digest)
|
||||
return;
|
||||
@@ -109,7 +110,7 @@ static void VerifyKernelPreambleTest(const VbPublicKey* public_key,
|
||||
VbKernelPreambleHeader *hdr;
|
||||
VbKernelPreambleHeader *h;
|
||||
RSAPublicKey* rsa;
|
||||
uint64_t hsize;
|
||||
unsigned hsize;
|
||||
|
||||
/* Create a dummy signature */
|
||||
VbSignature *body_sig = SignatureAlloc(56, 78);
|
||||
@@ -120,7 +121,7 @@ static void VerifyKernelPreambleTest(const VbPublicKey* public_key,
|
||||
TEST_NEQ(hdr && rsa, 0, "VerifyKernelPreamble2() prerequisites");
|
||||
if (!hdr)
|
||||
return;
|
||||
hsize = hdr->preamble_size;
|
||||
hsize = (unsigned) hdr->preamble_size;
|
||||
h = (VbKernelPreambleHeader*)Malloc(hsize + 16384);
|
||||
|
||||
TEST_EQ(VerifyKernelPreamble2(hdr, hsize, rsa), 0,
|
||||
|
||||
@@ -31,13 +31,13 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key,
|
||||
|
||||
VbKeyBlockHeader *hdr;
|
||||
VbKeyBlockHeader *h;
|
||||
uint64_t hsize;
|
||||
unsigned hsize;
|
||||
|
||||
hdr = KeyBlockCreate(data_key, private_key, 0x1234);
|
||||
TEST_NEQ((size_t)hdr, 0, "KeyBlockVerify() prerequisites");
|
||||
if (!hdr)
|
||||
return;
|
||||
hsize = hdr->key_block_size;
|
||||
hsize = (unsigned) hdr->key_block_size;
|
||||
h = (VbKeyBlockHeader*)Malloc(hsize + 1024);
|
||||
|
||||
TEST_EQ(KeyBlockVerify(hdr, hsize, NULL), 0,
|
||||
@@ -149,7 +149,7 @@ static void VerifyFirmwarePreambleTest(const VbPublicKey* public_key,
|
||||
VbFirmwarePreambleHeader *hdr;
|
||||
VbFirmwarePreambleHeader *h;
|
||||
RSAPublicKey* rsa;
|
||||
uint64_t hsize;
|
||||
unsigned hsize;
|
||||
|
||||
/* Create a dummy signature */
|
||||
VbSignature *body_sig = SignatureAlloc(56, 78);
|
||||
@@ -159,7 +159,7 @@ static void VerifyFirmwarePreambleTest(const VbPublicKey* public_key,
|
||||
TEST_NEQ(hdr && rsa, 0, "VerifyFirmwarePreamble2() prerequisites");
|
||||
if (!hdr)
|
||||
return;
|
||||
hsize = hdr->preamble_size;
|
||||
hsize = (unsigned) hdr->preamble_size;
|
||||
h = (VbFirmwarePreambleHeader*)Malloc(hsize + 16384);
|
||||
|
||||
TEST_EQ(VerifyFirmwarePreamble2(hdr, hsize, rsa), 0,
|
||||
|
||||
@@ -31,24 +31,24 @@ static void VerifyHelperFunctions(void) {
|
||||
|
||||
{
|
||||
uint8_t p[1];
|
||||
TEST_EQ(OffsetOf(p, p), 0, "OffsetOf() equal");
|
||||
TEST_EQ(OffsetOf(p, p+10), 10, "OffsetOf() positive");
|
||||
TEST_EQ(OffsetOf(p, p+0x12345678), 0x12345678, "OffsetOf() large");
|
||||
TEST_EQ((int)OffsetOf(p, p), 0, "OffsetOf() equal");
|
||||
TEST_EQ((int)OffsetOf(p, p+10), 10, "OffsetOf() positive");
|
||||
TEST_EQ((int)OffsetOf(p, p+0x12345678), 0x12345678, "OffsetOf() large");
|
||||
}
|
||||
|
||||
{
|
||||
VbPublicKey k = {sizeof(k), 2, 3, 4};
|
||||
TEST_EQ(OffsetOf(&k, GetPublicKeyData(&k)), sizeof(k),
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyData(&k)), sizeof(k),
|
||||
"GetPublicKeyData() adjacent");
|
||||
TEST_EQ(OffsetOf(&k, GetPublicKeyDataC(&k)), sizeof(k),
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyDataC(&k)), sizeof(k),
|
||||
"GetPublicKeyDataC() adjacent");
|
||||
}
|
||||
|
||||
{
|
||||
VbPublicKey k = {123, 2, 3, 4};
|
||||
TEST_EQ(OffsetOf(&k, GetPublicKeyData(&k)), 123,
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyData(&k)), 123,
|
||||
"GetPublicKeyData() spaced");
|
||||
TEST_EQ(OffsetOf(&k, GetPublicKeyDataC(&k)), 123,
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyDataC(&k)), 123,
|
||||
"GetPublicKeyDataC() spaced");
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ static void VerifyHelperFunctions(void) {
|
||||
"MemberInside member too big");
|
||||
TEST_EQ(VerifyMemberInside(p, 20, p, 4, 21, 0), 1,
|
||||
"MemberInside data after parent");
|
||||
TEST_EQ(VerifyMemberInside(p, 20, p, 4, -1, 0), 1,
|
||||
TEST_EQ(VerifyMemberInside(p, 20, p, 4, (uint64_t)-1, 0), 1,
|
||||
"MemberInside data before parent");
|
||||
TEST_EQ(VerifyMemberInside(p, 20, p, 4, 4, 17), 1,
|
||||
"MemberInside data too big");
|
||||
@@ -101,6 +101,8 @@ static void VerifyHelperFunctions(void) {
|
||||
|
||||
}
|
||||
|
||||
/* disable MSVC warnings on unused arguments */
|
||||
__pragma(warning (disable: 4100))
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int error_code = 0;
|
||||
|
||||
@@ -20,12 +20,6 @@
|
||||
#include "utility.h"
|
||||
#include "vboot_kernel.h"
|
||||
|
||||
/* ANSI Color coding sequences. */
|
||||
#define COL_GREEN "\e[1;32m"
|
||||
#define COL_RED "\e[0;31m"
|
||||
#define COL_STOP "\e[m"
|
||||
|
||||
|
||||
#define LBA_BYTES 512
|
||||
#define KERNEL_BUFFER_SIZE 0x600000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user