From ee3d25fa92aa15210b9cd4361828838fd5c8ae31 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Mon, 24 Oct 2011 11:00:33 -0700 Subject: Add top-level makefile Build output is now in ./build Fixed compiler warnings in ec_uartd, ec_console BUG=none TEST=make Change-Id: I9a46ab6b9d4e912e59a60c669e95dc0c6f8485df --- .gitignore | 1 + Makefile | 72 +++++++++++++++++++++++++ common.mk | 20 +++++++ cros_ec/Makefile | 56 ++++++++++++++------ cros_ec/chip_stub/ec_os.c | 4 +- cros_ec/chip_stub/ec_os_types.h | 93 --------------------------------- cros_ec/chip_stub/include/ec_os_types.h | 93 +++++++++++++++++++++++++++++++++ cros_ec/lib/ec_console.c | 2 +- cros_ec/test/Makefile | 45 ++++++++++++++++ utility/Makefile | 27 ++++++++-- utility/ec_uartd.c | 4 +- 11 files changed, 299 insertions(+), 118 deletions(-) create mode 100644 Makefile create mode 100644 common.mk delete mode 100644 cros_ec/chip_stub/ec_os_types.h create mode 100644 cros_ec/chip_stub/include/ec_os_types.h create mode 100644 cros_ec/test/Makefile diff --git a/.gitignore b/.gitignore index 7adf3653e7..598dd8d7cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ board/ +build/ vendor/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..58696c285f --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +# Copyright (c) 2011 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. + +export FIRMWARE_ARCH + +export CC ?= gcc +export CXX ?= g++ +export CFLAGS = -Wall -Werror + +ifeq (${DEBUG},) +CFLAGS += -O3 +else +CFLAGS += -O0 -g +endif + +# Fix compiling directly on host (outside of emake) +ifeq ($(ARCH),) +export ARCH=amd64 +endif + +ifneq (${DEBUG},) +CFLAGS += -DVBOOT_DEBUG +endif + +ifeq (${DISABLE_NDEBUG},) +CFLAGS += -DNDEBUG +endif + +export TOP = $(shell pwd) +export CROS_EC_DIR=$(TOP)/cros_ec +export CHIP_STUB_DIR=$(CROS_EC_DIR)/chip_stub + +INCLUDES = -I$(TOP)/chip_interface -I$(CROS_EC_DIR)/include + +ifeq ($(FIRMWARE_ARCH),) +INCLUDES += -I$(CHIP_STUB_DIR)/include +endif + +export INCLUDES + +export BUILD = ${TOP}/build +export CROS_EC_LIB = ${BUILD}/cros_ec.a +export CHIP_STUB_LIB = ${BUILD}/chip_stub.a + +ifeq ($(FIRMWARE_ARCH),) +SUBDIRS = cros_ec cros_ec/test utility +else +SUBDIRS = cros_ec +endif + +all: + set -e; \ + for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\ + sort -u); do \ + newdir=${BUILD}/$$d; \ + if [ ! -d $$newdir ]; then \ + mkdir -p $$newdir; \ + fi; \ + done; \ + for i in $(SUBDIRS); do \ + make -C $$i; \ + done + +clean: + /bin/rm -rf ${BUILD} + +install: + $(MAKE) -C utility install + +runtests: + $(MAKE) -C cros_ec/test runtests diff --git a/common.mk b/common.mk new file mode 100644 index 0000000000..f0de87987c --- /dev/null +++ b/common.mk @@ -0,0 +1,20 @@ +# 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. + +ALL_OBJS = $(ALL_SRCS:%.c=${BUILD_ROOT}/%.o) +ALL_DEPS = $(ALL_OBJS:%.o=%.o.d) + +# +# For this target (all) to be built by default, the including file must not +# define any other targets above the line including this file. +# +# This all: rule must be above the %.o: %.c rule below, otherwise the +# rule below becomes the default target. +# +all: ${ALL_OBJS} + +${BUILD_ROOT}/%.o : %.c + $(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $< + +-include ${ALL_DEPS} diff --git a/cros_ec/Makefile b/cros_ec/Makefile index dce7c20dbf..8653fa5fb8 100644 --- a/cros_ec/Makefile +++ b/cros_ec/Makefile @@ -2,26 +2,50 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -LIB_SRCS=\ - lib/ec_console.c +CROS_EC_TOP := $(shell pwd) +LIBDIR = $(CROS_EC_TOP)/lib +STUBDIR = $(CROS_EC_TOP)/chip_stub +TESTDIR = $(CROS_EC_TOP)/test +BUILD_ROOT := ${BUILD}/$(shell basename ${CROS_EC_TOP}) +LIBS = $(CROS_EC_LIB) # Firmware library must be self-contained -STUB_SRCS=\ - chip_stub/ec_os.c \ - chip_stub/ec_uart.c +INCLUDES = \ + -I$(CROS_EC_TOP)/include \ + -I$(LIBDIR)/include -TESTPROGS=fakemain ec_os_test +ifeq ($(FIRMWARE_ARCH),) +INCLUDES += -I$(STUBDIR)/include +else +INCLUDES += -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include +endif -CFLAGS=-Wall -I include -I chip_stub -pthread +# find ./lib -iname '*.c' | sort +LIB_SRCS = \ + ./lib/ec_console.c \ + ./lib/ec_host_command.c -all: $(TESTPROGS) +LIB_OBJS = $(LIB_SRCS:%.c=${BUILD_ROOT}/%.o) -clean: - rm -f $(TESTPROGS) +STUB_SRCS = \ + ./chip_stub/ec_os.c \ + ./chip_stub/ec_uart.c -ec_os_test: test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c - gcc $(CFLAGS) -o ec_os_test \ - test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c +STUB_OBJS = $(STUB_SRCS:%.c=${BUILD_ROOT}/%.o) -fakemain: test/fakemain.c $(LIB_SRCS) $(STUB_SRCS) - gcc $(CFLAGS) -o fakemain test/fakemain.c \ - $(LIB_SRCS) $(STUB_SRCS) +ALL_SRCS = ${LIB_SRCS} ${STUB_SRCS} + +ifeq ($(FIRMWARE_ARCH),) +all : $(CROS_EC_LIB) $(CHIP_STUB_LIB) +else +all : $(CROS_EC_LIB) +endif + +include ../common.mk + +$(CROS_EC_LIB) : $(LIB_OBJS) + rm -f $@ + ar qc $@ $^ + +$(CHIP_STUB_LIB) : $(STUB_OBJS) + rm -f $@ + ar qc $@ $^ diff --git a/cros_ec/chip_stub/ec_os.c b/cros_ec/chip_stub/ec_os.c index 1997bf9111..ff48a5bf0b 100644 --- a/cros_ec/chip_stub/ec_os.c +++ b/cros_ec/chip_stub/ec_os.c @@ -396,7 +396,7 @@ EcError EcEventPost(EcEvent* event, uint32_t bits) { EcError EcEventWaitAll(EcEvent* event, uint32_t bits, int timeout_usec) { EcEventInternal* ei = (EcEventInternal*)event; - int rv; + int rv = 0; pthread_mutex_lock(&ei->mutex); @@ -429,7 +429,7 @@ EcError EcEventWaitAll(EcEvent* event, uint32_t bits, int timeout_usec) { EcError EcEventWaitAny(EcEvent* event, uint32_t bits, uint32_t* got_bits_ptr, int timeout_usec) { EcEventInternal* ei = (EcEventInternal*)event; - int rv; + int rv = 0; pthread_mutex_lock(&ei->mutex); diff --git a/cros_ec/chip_stub/ec_os_types.h b/cros_ec/chip_stub/ec_os_types.h deleted file mode 100644 index f9c4a263e0..0000000000 --- a/cros_ec/chip_stub/ec_os_types.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (c) 2011 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. - */ - -/* Operating system object types for EC. These are - * implementation-dependent; this file should come from the - * implementation include directory. */ - -#ifndef __CROS_EC_OS_TYPES_H -#define __CROS_EC_OS_TYPES_H - -#include "ec_common.h" - -/* Structure sizes depend on the underlying implementation. These - * sizes are correct for the pthreads implementation. */ -#define EC_TASK_STRUCT_SIZE 32 -#define EC_SWI_STRUCT_SIZE 120 -#define EC_TIMER_STRUCT_SIZE 120 -#define EC_SEMAPHORE_STRUCT_SIZE 32 -#define EC_EVENT_STRUCT_SIZE 104 - -/*****************************************************************************/ -/* Tasks */ - -/* Task priority range */ -#define EC_TASK_PRIORITY_LOWEST 0 -#define EC_TASK_PRIORITY_DEFAULT 3 -#define EC_TASK_PRIORITY_HIGHEST 7 - -/* Task instance. Treat this as an opaque identifier. */ -typedef struct EcTask { - union { - uint64_t align; /* Align on something big */ - uint8_t data[EC_TASK_STRUCT_SIZE]; - }; -} EcTask; - -/*****************************************************************************/ -/* Software interrupts (SWI) */ - -/* SWI priority range */ -#define EC_SWI_PRIORITY_LOWEST 0 -#define EC_SWI_PRIORITY_DEFAULT 3 -#define EC_SWI_PRIORITY_HIGHEST 7 - -/* SWI instance. Treat this as an opaque identifier. */ -typedef struct EcSwi { - union { - uint64_t align; /* Align on something big */ - uint8_t data[EC_SWI_STRUCT_SIZE]; - }; -} EcSwi; - -/*****************************************************************************/ -/* Timers */ - -/* Timer priority range */ -#define EC_TIMER_PRIORITY_LOWEST 0 -#define EC_TIMER_PRIORITY_DEFAULT 3 -#define EC_TIMER_PRIORITY_HIGHEST 7 - -/* Timer instance. Treat this as an opaque identifier. */ -typedef struct EcTimer { - union { - uint64_t align; /* Align on something big */ - uint8_t data[EC_TIMER_STRUCT_SIZE]; - }; -} EcTimer; - -/*****************************************************************************/ -/* Semaphores */ - -/* Semaphore instance. Treat this as an opaque identifier. */ -typedef struct EcSemaphore { - union { - uint64_t align; /* Align on something big */ - uint8_t data[EC_SEMAPHORE_STRUCT_SIZE]; - }; -} EcSemaphore; - -/*****************************************************************************/ -/* Events */ - -/* Event instance. Treat this as an opaque identifier. */ -typedef struct EcEvent { - union { - uint64_t align; /* Align on something big */ - uint8_t data[EC_EVENT_STRUCT_SIZE]; - }; -} EcEvent; - -#endif diff --git a/cros_ec/chip_stub/include/ec_os_types.h b/cros_ec/chip_stub/include/ec_os_types.h new file mode 100644 index 0000000000..f9c4a263e0 --- /dev/null +++ b/cros_ec/chip_stub/include/ec_os_types.h @@ -0,0 +1,93 @@ +/* Copyright (c) 2011 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. + */ + +/* Operating system object types for EC. These are + * implementation-dependent; this file should come from the + * implementation include directory. */ + +#ifndef __CROS_EC_OS_TYPES_H +#define __CROS_EC_OS_TYPES_H + +#include "ec_common.h" + +/* Structure sizes depend on the underlying implementation. These + * sizes are correct for the pthreads implementation. */ +#define EC_TASK_STRUCT_SIZE 32 +#define EC_SWI_STRUCT_SIZE 120 +#define EC_TIMER_STRUCT_SIZE 120 +#define EC_SEMAPHORE_STRUCT_SIZE 32 +#define EC_EVENT_STRUCT_SIZE 104 + +/*****************************************************************************/ +/* Tasks */ + +/* Task priority range */ +#define EC_TASK_PRIORITY_LOWEST 0 +#define EC_TASK_PRIORITY_DEFAULT 3 +#define EC_TASK_PRIORITY_HIGHEST 7 + +/* Task instance. Treat this as an opaque identifier. */ +typedef struct EcTask { + union { + uint64_t align; /* Align on something big */ + uint8_t data[EC_TASK_STRUCT_SIZE]; + }; +} EcTask; + +/*****************************************************************************/ +/* Software interrupts (SWI) */ + +/* SWI priority range */ +#define EC_SWI_PRIORITY_LOWEST 0 +#define EC_SWI_PRIORITY_DEFAULT 3 +#define EC_SWI_PRIORITY_HIGHEST 7 + +/* SWI instance. Treat this as an opaque identifier. */ +typedef struct EcSwi { + union { + uint64_t align; /* Align on something big */ + uint8_t data[EC_SWI_STRUCT_SIZE]; + }; +} EcSwi; + +/*****************************************************************************/ +/* Timers */ + +/* Timer priority range */ +#define EC_TIMER_PRIORITY_LOWEST 0 +#define EC_TIMER_PRIORITY_DEFAULT 3 +#define EC_TIMER_PRIORITY_HIGHEST 7 + +/* Timer instance. Treat this as an opaque identifier. */ +typedef struct EcTimer { + union { + uint64_t align; /* Align on something big */ + uint8_t data[EC_TIMER_STRUCT_SIZE]; + }; +} EcTimer; + +/*****************************************************************************/ +/* Semaphores */ + +/* Semaphore instance. Treat this as an opaque identifier. */ +typedef struct EcSemaphore { + union { + uint64_t align; /* Align on something big */ + uint8_t data[EC_SEMAPHORE_STRUCT_SIZE]; + }; +} EcSemaphore; + +/*****************************************************************************/ +/* Events */ + +/* Event instance. Treat this as an opaque identifier. */ +typedef struct EcEvent { + union { + uint64_t align; /* Align on something big */ + uint8_t data[EC_EVENT_STRUCT_SIZE]; + }; +} EcEvent; + +#endif diff --git a/cros_ec/lib/ec_console.c b/cros_ec/lib/ec_console.c index 0196f84a92..1b87f3577c 100644 --- a/cros_ec/lib/ec_console.c +++ b/cros_ec/lib/ec_console.c @@ -129,7 +129,7 @@ const EcConsoleCommand* FindCommand(char* name) { EcError ConsoleHandleCommand(char* input) { char* argv[MAX_ARGS_PER_COMMAND]; const EcConsoleCommand *cmd; - int argc; + int argc = 0; /* Split input into words. Ignore words past our limit. */ SplitWords(input, MAX_ARGS_PER_COMMAND, &argc, argv); diff --git a/cros_ec/test/Makefile b/cros_ec/test/Makefile new file mode 100644 index 0000000000..035a3f825c --- /dev/null +++ b/cros_ec/test/Makefile @@ -0,0 +1,45 @@ +# Copyright (c) 2011 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. + +INCLUDES += -I./include \ + -I$(CROS_EC_DIR)/lib/include +BUILD_ROOT = ${BUILD}/cros_ec/test + +TEST_NAMES = ec_os_test + +TEST_BINS = $(addprefix ${BUILD_ROOT}/,$(TEST_NAMES)) + +# TODO: port over test lib from vboot_reference +# TEST_LIB = ${BUILD_ROOT}/test.a +# TEST_LIB_SRCS = test_common.c timer_utils.c +# TEST_LIB_OBJS = $(TEST_LIB_SRCS:%.c=${BUILD_ROOT}/%.o) +# ALL_DEPS = $(addsuffix .d,${TEST_BINS} ${TEST_LIB_OBJS}) + +# Allow multiple definitions, so tests can mock functions from other libraries +CFLAGS += -MMD -MF $@.d -Xlinker --allow-multiple-definition + +LIBS := ${TEST_LIB} $(CROS_EC_LIB) $(CHIP_STUB_LIB) + +ifneq (${RUNTESTS},) +EXTRA_TARGET = runtests +endif + +all: $(TEST_BINS) ${EXTRA_TARGET} + +# ${TEST_LIB}: ${TEST_LIB_OBJS} +# rm -f $@ +# ar qc $@ $^ + +${BUILD_ROOT}/%.o : %.c + $(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $< + +${BUILD_ROOT}/% : %.c ${LIBS} + $(CC) $(CFLAGS) $(INCLUDES) $< ${LIBS} -o $@ -lrt + +ALLTESTS = ec_os_test + +runtests: + ${BUILD_ROOT}/ec_os_test + +-include ${ALL_DEPS} diff --git a/utility/Makefile b/utility/Makefile index 5386089b91..660117744a 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -2,10 +2,27 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -all: ec_uartd +CFLAGS += $(INCLUDES) +CFLAGS += -MMD -MF $@.d +HOSTCC = cc -clean: - rm -f ec_uartd +BUILD_ROOT = ${BUILD}/utility -ec_uartd: ec_uartd.c - gcc -o ec_uartd -lftdi ec_uartd.c +DESTDIR ?= /usr/bin + +TARGET_NAMES = ec_uartd + +TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES)) +ALL_DEPS = $(addsuffix .d,${TARGET_BINS}) + +all: $(TARGET_BINS) + +${BUILD_ROOT}/ec_uartd: ec_uartd.c $(LIBS) + $(CC) $(CFLAGS) $< -o $@ $(LIBS) -lftdi + +install: $(TARGET_BINS) + mkdir -p $(DESTDIR) + cp -f $(TARGET_BINS) $(DESTDIR) + chmod a+rx $(patsubst %,$(DESTDIR)/%,$(TARGET_NAMES)) + +-include ${ALL_DEPS} diff --git a/utility/ec_uartd.c b/utility/ec_uartd.c index a21450c3a2..8a4a89ae3c 100644 --- a/utility/ec_uartd.c +++ b/utility/ec_uartd.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -69,7 +70,7 @@ int openpty(const char* desc) { int main(int argc, char **argv) { struct ftdi_context fcontext; - char buf[1024], buf_ec[1024], buf_x86[1024]; + unsigned char buf[1024], buf_ec[1024], buf_x86[1024]; int fd_ec, fd_x86; int rv, i; @@ -180,4 +181,5 @@ int main(int argc, char **argv) { close(fd_x86); ftdi_usb_close(&fcontext); ftdi_deinit(&fcontext); + return 0; } -- cgit v1.2.1