summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2011-10-24 11:00:33 -0700
committerRandall Spangler <rspangler@chromium.org>2011-10-24 12:39:09 -0700
commitee3d25fa92aa15210b9cd4361828838fd5c8ae31 (patch)
tree7791a22d164846c287fb7f0cce8798ef548ccb1c
parent7860a64e420b61c28d101bf5998ae1381094d78f (diff)
downloadchrome-ec-ee3d25fa92aa15210b9cd4361828838fd5c8ae31.tar.gz
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
-rw-r--r--.gitignore1
-rw-r--r--Makefile72
-rw-r--r--common.mk20
-rw-r--r--cros_ec/Makefile56
-rw-r--r--cros_ec/chip_stub/ec_os.c4
-rw-r--r--cros_ec/chip_stub/include/ec_os_types.h (renamed from cros_ec/chip_stub/ec_os_types.h)0
-rw-r--r--cros_ec/lib/ec_console.c2
-rw-r--r--cros_ec/test/Makefile45
-rw-r--r--utility/Makefile27
-rw-r--r--utility/ec_uartd.c4
10 files changed, 206 insertions, 25 deletions
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/include/ec_os_types.h
index f9c4a263e0..f9c4a263e0 100644
--- a/cros_ec/chip_stub/ec_os_types.h
+++ b/cros_ec/chip_stub/include/ec_os_types.h
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 <ftdi.h>
#include <getopt.h>
#include <stdio.h>
+#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
@@ -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;
}