VBoot Reference: Refactoring Part 3

Refactor and restructure reference code into individual self-contain modules. I have revamped the way the code is structured to make it easy to determine which parts belong in the firmware and which are used by userland tools.

common/ - common utilities and stub functions (Firmware)
cryptolib/ - crypto library (Firmware)
misclibs/ - miscellaneous userland libraries (Userland)
sctips/ - Miscellaenous scripts (Userland)
tests/ - Tests (Userland)
vfirmware/ - Verified Firmware Implementation
vfirmware/firmware_image_fw.c (Firmware)
vfirmware/firmware_image.c (Userland)

vkernel/ - Verified Kernel Implementation
vkernel/kernel_image_fw.c (Firmware)
vkernel/kernel_image.c (Userland)

Review URL: http://codereview.chromium.org/1581005
This commit is contained in:
Gaurav Shah
2010-03-31 13:26:55 -07:00
parent 5411c7a9f0
commit fc70d72aaa
46 changed files with 106 additions and 44 deletions

View File

@@ -5,10 +5,12 @@
export CC ?= gcc
export CFLAGS = -Wall -DNDEBUG -O3 -Werror
export TOP = $(shell pwd)
export INCLUDEDIR = $(TOP)/include
export INCLUDES = -I$(INCLUDEDIR)
export INCLUDES = \
-I$(TOP)/common/include \
-I$(TOP)/cryptolib/include \
-I$(TOP)/misclibs/include
SUBDIRS=common crypto utils tests
SUBDIRS=common cryptolib misclibs vfirmware vkernel utility tests
all:
for i in $(SUBDIRS); do \

2
README
View File

@@ -9,7 +9,7 @@ include/ - Contains all the code headers. firmware_image.h and
kernel_image.h contains the structures that represent a verified boot
firmware and kernel image. Note that the
crypto/ - Contains the implementation for the crypto library. This
cryptolib/ - Contains the implementation for the crypto library. This
includes implementations for SHA1, SHA256, SHA512, and RSA signature
verification (for PKCS #1 v1.5 signatures).

View File

@@ -2,8 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
SRCS = utility_stub.c tlcl_stub.c
SRCS = rollback_index.c tlcl_stub.c utility_stub.c
OBJS = $(SRCS:.c=.o)
INCLUDES += -I./include/
all: libcommon.a

View File

@@ -2,17 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
TOP ?= ../
SRCS = rsa.c sha1.c sha2.c padding.c rsa_utility.c sha_utility.c
OBJS = $(SRCS:.c=.o)
CFLAGS += -DUNROLL_LOOPS -DHAVE_ENDIAN_H -DHAVE_LITTLE_ENDIAN
INCLUDES += -I./include/ -I$(TOP)/common/include/
all: libcrypto.a
libcrypto.a: $(OBJS)
ar rs libcrypto.a $(OBJS)
padding.c: genpadding.sh
./genpadding.sh >$@
padding.c: $(TOP)/scripts/genpadding.sh
$(TOP)/scripts/genpadding.sh >$@
.c.o: $(OBJS)
$(CC) $(CFLAGS) -ansi $(INCLUDES) -c $< -o $@

24
misclibs/Makefile Normal file
View File

@@ -0,0 +1,24 @@
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
TOP ?= ../
CC ?= gcc
INCLUDES += -I./include \
-I$(TOP)/common/include \
-I$(TOP)/cryptolib/include \
-I$(TOP)/vfirmware/include \
-I$(TOP)/vkernel/include
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror $(INCLUDES)
TOP ?= ../
MISCLIB_OUT = file_keys.o signature_digest.o
all: $(MISCLIB_OUT)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
rm -f $(MISCLIB_OUT)

View File

@@ -4,15 +4,18 @@
CC ?= gcc
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror
INCLUDES ?= -I../include/
TOP ?= ../
BASE_LIBS = $(TOP)/crypto/libcrypto.a $(TOP)/common/libcommon.a
IMAGE_LIBS = $(TOP)/utils/firmware_image.o \
$(TOP)/utils/firmware_image_fw.o \
$(TOP)/utils/kernel_image.o \
$(TOP)/utils/kernel_image_fw.o
UTIL_LIBS = $(TOP)/utils/file_keys.o $(TOP)/utils/signature_digest.o
INCLUDES += -I./include \
-I../cryptolib/include \
-I../common/include \
-I../misclibs/include \
-I../vfirmware/include\
-I../vkernel/include
BASE_LIBS = $(TOP)/cryptolib/libcrypto.a $(TOP)/common/libcommon.a
IMAGE_LIBS = $(TOP)/vfirmware/firmware_image.o \
$(TOP)/vfirmware/firmware_image_fw.o \
$(TOP)/vkernel/kernel_image.o \
$(TOP)/vkernel/kernel_image_fw.o
UTIL_LIBS = $(TOP)/misclibs/file_keys.o $(TOP)/misclibs/signature_digest.o
LIBS = $(IMAGE_LIBS) $(UTIL_LIBS) -lcrypto $(BASE_LIBS)
TEST_BINS = big_firmware_tests \

View File

@@ -15,7 +15,7 @@ else
SCRIPT_DIR="`pwd`"/"`dirname $0`"
fi
UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils
UTIL_DIR=`dirname ${SCRIPT_DIR}`/utility
TEST_DIR=${SCRIPT_DIR}
TESTKEY_DIR=${SCRIPT_DIR}/testkeys
TESTCASE_DIR=${SCRIPT_DIR}/testcases

View File

@@ -2,24 +2,25 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
TOP ?= ../
CC ?= gcc
CXX ?= g++
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror
INCLUDES ?= -I../include/
TOP ?= ../
INCLUDES += -I./include \
-I../cryptolib/include \
-I../common/include \
-I../misclibs/include \
-I../vfirmware/include\
-I../vkernel/include
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror $(INCLUDES)
LIBS = $(TOP)/misclibs/file_keys.o \
$(TOP)/misclibs/signature_digest.o \
$(TOP)/vfirmware/firmware_image.o \
$(TOP)/vfirmware/firmware_image_fw.o \
$(TOP)/vkernel/kernel_image.o \
$(TOP)/vkernel/kernel_image_fw.o
FIRMWARELIBS = $(TOP)/cryptolib/libcrypto.a $(TOP)/common/libcommon.a
LIBS = file_keys.o \
firmware_image.o \
firmware_image_fw.o \
kernel_image.o \
kernel_image_fw.o \
rollback_index.o \
signature_digest.o
FIRMWARELIBS = $(TOP)/crypto/libcrypto.a $(TOP)/common/libcommon.a
TARGET_BINS = $(LIBS) \
dumpRSAPublicKey \
TARGET_BINS = dumpRSAPublicKey \
firmware_utility \
kernel_utility \
signature_digest_utility \
@@ -27,23 +28,14 @@ TARGET_BINS = $(LIBS) \
all: $(TARGET_BINS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
dumpRSAPublicKey: dumpRSAPublicKey.c
$(CC) $(CFLAGS) $< -o $@ -lcrypto
firmware_image_fw.o: firmware_image_fw.c
$(CC) $(CFLAGS) -ansi $(INCLUDES) -c $^ -o $@
$(CC) $(CFLAGS) $(INCLUDES) $< -o $@ -lcrypto
firmware_utility: firmware_utility.cc $(LIBS) $(FIRMWARELIBS)
$(CXX) $(CFLAGS) $(INCLUDES) -ggdb -D__STDC_LIMIT_MACROS $< \
-o $@ $(FIRMWARELIBS) $(LIBS) $(TOP)/common/libcommon.a \
-lcrypto
kernel_image_fw.o: kernel_image_fw.c
$(CC) $(CFLAGS) -ansi $(INCLUDES) -c $< -o $@
kernel_utility: kernel_utility.cc $(LIBS) $(FIRMWARELIBS)
$(CXX) $(CFLAGS) $(INCLUDES) -ggdb -D__STDC_LIMIT_MACROS $< \
-o $@ $(FIRMWARELIBS) $(LIBS) $(TOP)/common/libcommon.a \
@@ -56,5 +48,5 @@ verify_data: verify_data.c $(LIBS) $(FIRMWARELIBS)
$(CC) $(CFLAGS) $(INCLUDES) $< -o $@ $(LIBS) $(FIRMWARELIBS) -lcrypto
clean:
rm -f $(TARGET_BINS) $(LIBS)
rm -f $(TARGET_BINS)

View File

@@ -21,7 +21,7 @@
/* ANSI Color coding sequences. */
#define COL_GREEN "\e[1;32m"
#define COL_RED "\e[0;31m]"
#define COL_RED "\e[0;31m"
#define COL_STOP "\e[m"
uint8_t* read_signature(char* input_file, int len) {

19
vfirmware/Makefile Normal file
View File

@@ -0,0 +1,19 @@
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
CC ?= gcc
INCLUDES += -I./include \
-I../cryptolib/include \
-I../common/include \
-I../misclibs/include
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror
FIRMWARE_OUT = firmware_image_fw.o firmware_image.o
all: $(FIRMWARE_OUT)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
rm -f $(FIRMWARE_OUT)

19
vkernel/Makefile Normal file
View File

@@ -0,0 +1,19 @@
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
CC ?= gcc
INCLUDES += -I./include \
-I../cryptolib/include \
-I../common/include \
-I../misclibs/include
CFLAGS ?= -Wall -DNDEBUG -O3 -Werror
KERNEL_OUT = kernel_image_fw.o kernel_image.o
all: $(KERNEL_OUT)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
rm -f $(KERNEL_OUT)