summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--Makefile.toolchain2
-rwxr-xr-xboard/twinkie/build_rw_variant29
-rw-r--r--board/twinkie/ec.tasklist8
-rw-r--r--board/twinkie/injector.c14
-rw-r--r--board/twinkie/sink.tasklist29
-rw-r--r--board/twinkie/sniffer.c7
7 files changed, 85 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 01581fba35..d2cbd9a148 100644
--- a/Makefile
+++ b/Makefile
@@ -64,15 +64,17 @@ UC_PROJECT:=$(call uppercase,$(PROJECT))
# are dependent on particular configurations.
includes=include core/$(CORE)/include $(dirs) $(out) test
ifeq "$(TEST_BUILD)" "y"
+ _tsk_lst_file:=ec.tasklist
_tsk_lst:=$(shell echo "CONFIG_TASK_LIST CONFIG_TEST_TASK_LIST" | \
$(CPP) -P -Iboard/$(BOARD) -Itest \
-D"TASK_NOTEST(n, r, d, s)=" -D"TASK_ALWAYS(n, r, d, s)=n" \
- -D"TASK_TEST(n, r, d, s)=n" -imacros ec.tasklist \
+ -D"TASK_TEST(n, r, d, s)=n" -imacros $(_tsk_lst_file) \
-imacros $(PROJECT).tasklist)
else
+ _tsk_lst_file:=$(PROJECT).tasklist
_tsk_lst:=$(shell echo "CONFIG_TASK_LIST" | $(CPP) -P \
-Iboard/$(BOARD) -D"TASK_NOTEST(n, r, d, s)=n" \
- -D"TASK_ALWAYS(n, r, d, s)=n" -imacros ec.tasklist)
+ -D"TASK_ALWAYS(n, r, d, s)=n" -imacros $(_tsk_lst_file))
endif
_tsk_cfg:=$(foreach t,$(_tsk_lst) ,HAS_TASK_$(t))
CPPFLAGS+=$(foreach t,$(_tsk_cfg),-D$(t))
diff --git a/Makefile.toolchain b/Makefile.toolchain
index 43f390cde4..a069fea3c9 100644
--- a/Makefile.toolchain
+++ b/Makefile.toolchain
@@ -32,7 +32,7 @@ CFLAGS_TEST=$(if $(TEST_BUILD),-DTEST_BUILD \
-DTEST_$(PROJECT) -DTEST_$(UC_PROJECT)
CFLAGS_COVERAGE=$(if $(TEST_COVERAGE),-fprofile-arcs -ftest-coverage \
-DTEST_COVERAGE,)
-CFLAGS_DEFINE=-DOUTDIR=$(out) -DCHIP=$(CHIP) -DBOARD_TASKFILE=ec.tasklist \
+CFLAGS_DEFINE=-DOUTDIR=$(out) -DCHIP=$(CHIP) -DBOARD_TASKFILE=$(_tsk_lst_file) \
-DBOARD=$(BOARD) -DCORE=$(CORE) -DPROJECT=$(PROJECT) \
-DCHIP_VARIANT=$(CHIP_VARIANT) -DCHIP_FAMILY=$(CHIP_FAMILY) \
-DBOARD_$(UC_BOARD) -DCHIP_$(UC_CHIP) -DCORE_$(UC_CORE) \
diff --git a/board/twinkie/build_rw_variant b/board/twinkie/build_rw_variant
new file mode 100755
index 0000000000..865914153b
--- /dev/null
+++ b/board/twinkie/build_rw_variant
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright (c) 2014 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.
+#
+
+#
+# Build a Twinkie firmware image with
+# the regular Twinkie sniffer firmware in the RO partition
+# and a firmware behaving as a USB PD sink in the RW partition.
+#
+BOARD=twinkie
+VARIANT=sink
+RO_SIZE=65536
+
+# Clean build
+make BOARD=${BOARD} clean
+make BOARD=${BOARD} out=build/${BOARD}_${VARIANT} clean
+# Build regular Twinkie sniffer firmware
+make BOARD=${BOARD}
+# Build Twinkie as a USB PD consumer/producer (defaulting as a sink)
+make BOARD=${BOARD} PROJECT=${VARIANT} out=build/${BOARD}_${VARIANT}
+
+# Generate the final image by concatenating the built images
+VERSION=$(echo "VERSION" | cpp -P -imacros build/${BOARD}/ec_version.h)
+FINAL_IMG=build/${BOARD}/${VERSION//\"}.combined.bin
+cp build/${BOARD}/ec.bin ${FINAL_IMG}
+dd if=build/${BOARD}_${VARIANT}/${VARIANT}.RW.bin of=${FINAL_IMG} bs=1 seek=${RO_SIZE} conv=notrunc
diff --git a/board/twinkie/ec.tasklist b/board/twinkie/ec.tasklist
index 1bc0b5212c..5b232b78fe 100644
--- a/board/twinkie/ec.tasklist
+++ b/board/twinkie/ec.tasklist
@@ -19,10 +19,4 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(SNIFFER, sniffer_task, NULL, TASK_STACK_SIZE) \
- /*Disabled: TASK_ALWAYS(PD, pd_task, NULL, LARGER_TASK_STACK_SIZE) */
-/*
- * To get Twinkie to behave as a USB Power Delivery consumer/provider
- * device rather than a transparent sniffer :
- * enable the PD task and comment out the SNIFFER task.
- */
+ TASK_ALWAYS(SNIFFER, sniffer_task, NULL, TASK_STACK_SIZE)
diff --git a/board/twinkie/injector.c b/board/twinkie/injector.c
index 7365712551..81e5217dfb 100644
--- a/board/twinkie/injector.c
+++ b/board/twinkie/injector.c
@@ -12,6 +12,7 @@
#include "hwtimer.h"
#include "injector.h"
#include "registers.h"
+#include "system.h"
#include "task.h"
#include "timer.h"
#include "usb_pd.h"
@@ -490,6 +491,17 @@ static int cmd_bufrd(int argc, char **argv)
return EC_SUCCESS;
}
+static int cmd_sink(int argc, char **argv)
+{
+ /*
+ * Jump to the RW section which should contain a firmware acting
+ * as a USB PD sink
+ */
+ system_run_image_copy(SYSTEM_IMAGE_RW);
+
+ return EC_SUCCESS;
+}
+
static int command_tw(int argc, char **argv)
{
if (!strcasecmp(argv[1], "send"))
@@ -504,6 +516,8 @@ static int command_tw(int argc, char **argv)
return cmd_cc_level(argc - 2, argv + 2);
else if (!strncasecmp(argv[1], "resistor", 3))
return cmd_resistor(argc - 2, argv + 2);
+ else if (!strcasecmp(argv[1], "sink"))
+ return cmd_sink(argc - 2, argv + 2);
else if (!strcasecmp(argv[1], "txclock"))
return cmd_tx_clock(argc - 2, argv + 2);
else if (!strncasecmp(argv[1], "rxthresh", 8))
diff --git a/board/twinkie/sink.tasklist b/board/twinkie/sink.tasklist
new file mode 100644
index 0000000000..600118314f
--- /dev/null
+++ b/board/twinkie/sink.tasklist
@@ -0,0 +1,29 @@
+/* Copyright (c) 2014 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.
+ */
+
+/*
+ * To get Twinkie to behave as a USB Power Delivery consumer/provider
+ * device rather than a transparent sniffer, build it as below :
+ * make BOARD=twinkie PROJ=sink
+ * to use this task file instead of the default ec.tasklist.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and
+ * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries,
+ * where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TASK_LIST \
+ TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/twinkie/sniffer.c b/board/twinkie/sniffer.c
index e1f2d5c8c2..f08bd8b68b 100644
--- a/board/twinkie/sniffer.c
+++ b/board/twinkie/sniffer.c
@@ -338,6 +338,13 @@ void recording_enable(uint8_t mask)
/* TODO implement */
}
+static void sniffer_sysjump(void)
+{
+ /* Stop DMA before jumping to avoid memory corruption */
+ recording_enable(0);
+}
+DECLARE_HOOK(HOOK_SYSJUMP, sniffer_sysjump, HOOK_PRIO_DEFAULT);
+
static int command_sniffer(int argc, char **argv)
{
ccprintf("Seq number:%d Overflows: %d\n", seq, oflow);