summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--Makefile.toolchain1
-rw-r--r--board/nucleo-f072rb/ec.tasklist3
-rw-r--r--board/stm32l476g-eval/ec.tasklist4
-rw-r--r--cts/README6
-rw-r--r--cts/build.mk10
-rwxr-xr-xcts/cts.py178
-rw-r--r--cts/gpio/dut.c15
-rw-r--r--cts/gpio/th.c15
-rw-r--r--include/task_id.h6
10 files changed, 250 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 4a8d2fe33f..ac296ad6dd 100644
--- a/Makefile
+++ b/Makefile
@@ -65,10 +65,16 @@ ifeq "$(TEST_BUILD)" "y"
-D"TASK_NOTEST(n, r, d, s)=" -D"TASK_ALWAYS(n, r, d, s)=n" \
-D"TASK_TEST(n, r, d, s)=n" -imacros $(_tsk_lst_file) \
-imacros $(PROJECT).tasklist)
+else ifdef CTS_MODULE
+ _tsk_lst_file:=$(PROJECT).tasklist
+ _tsk_lst:=$(shell echo "CONFIG_TASK_LIST" | $(CPP) -P \
+ -I$(BDIR) -D"TASK_NOTEST(n, r, d, s)=n" -D"TASK_CTS(n, r, d, s)=n" \
+ -D"TASK_ALWAYS(n, r, d, s)=n" -imacros $(_tsk_lst_file))
else
_tsk_lst_file:=$(PROJECT).tasklist
_tsk_lst:=$(shell echo "CONFIG_TASK_LIST" | $(CPP) -P \
-I$(BDIR) -D"TASK_NOTEST(n, r, d, s)=n" \
+ -D"TASK_CTS(n, r, d, s)=" \
-D"TASK_ALWAYS(n, r, d, s)=n" -imacros $(_tsk_lst_file))
endif
_tsk_cfg:=$(foreach t,$(_tsk_lst) ,HAS_TASK_$(t))
@@ -111,6 +117,10 @@ objs_from_dir=$(foreach obj, $($(2)-y), $(1)/$(obj))
# Get build configuration from sub-directories
# Note that this re-includes the board and chip makefiles
+
+ifdef CTS_MODULE
+include cts/build.mk
+endif
include $(BDIR)/build.mk
include chip/$(CHIP)/build.mk
include core/$(CORE)/build.mk
@@ -139,8 +149,11 @@ endif
all-obj-y+=$(call objs_from_dir,common,common)
all-obj-y+=$(call objs_from_dir,driver,driver)
all-obj-y+=$(call objs_from_dir,power,power)
+ifdef CTS_MODULE
+all-obj-y+=$(call objs_from_dir,cts,cts)
+endif
all-obj-y+=$(call objs_from_dir,test,$(PROJECT))
-dirs=core/$(CORE) chip/$(CHIP) $(BDIR) common power test
+dirs=core/$(CORE) chip/$(CHIP) $(BDIR) common power test cts/common cts/$(CTS_MODULE)
dirs+= private $(PDIR)
dirs+=$(shell find driver -type d)
common_dirs=util
diff --git a/Makefile.toolchain b/Makefile.toolchain
index 5956c7ad26..26e9c57690 100644
--- a/Makefile.toolchain
+++ b/Makefile.toolchain
@@ -35,6 +35,7 @@ CFLAGS_DEBUG= -g
CFLAGS_INCLUDE=$(foreach i,$(includes),-I$(i) ) -I.
CFLAGS_TEST=$(if $(TEST_BUILD),-DTEST_BUILD \
-DTEST_TASKFILE=$(PROJECT).tasklist,) \
+ $(if $(CTS_MODULE), -DCTS_MODULE=$(CTS_MODULE)) \
$(if $(EMU_BUILD),-DEMU_BUILD) \
$(if $($(PROJECT)-scale),-DTEST_TIME_SCALE=$($(PROJECT)-scale)) \
-DTEST_$(PROJECT) -DTEST_$(UC_PROJECT)
diff --git a/board/nucleo-f072rb/ec.tasklist b/board/nucleo-f072rb/ec.tasklist
index 1944ef3874..c9b8950f71 100644
--- a/board/nucleo-f072rb/ec.tasklist
+++ b/board/nucleo-f072rb/ec.tasklist
@@ -18,4 +18,5 @@
*/
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
+ TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
+ TASK_CTS(CTS, cts_task, NULL, TASK_STACK_SIZE)
diff --git a/board/stm32l476g-eval/ec.tasklist b/board/stm32l476g-eval/ec.tasklist
index 0c19123e58..be8895ba73 100644
--- a/board/stm32l476g-eval/ec.tasklist
+++ b/board/stm32l476g-eval/ec.tasklist
@@ -18,4 +18,6 @@
*/
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
+ TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
+ TASK_CTS(CTS, cts_task, NULL, TASK_STACK_SIZE)
+
diff --git a/cts/README b/cts/README
new file mode 100644
index 0000000000..3a22e9846f
--- /dev/null
+++ b/cts/README
@@ -0,0 +1,6 @@
+The first time you use this with a particular th,
+connect only th and run ./cts/cts.py --th from
+the ec directory.
+
+Then connect both boards and you can run
+./cts/cts to flash both boards. \ No newline at end of file
diff --git a/cts/build.mk b/cts/build.mk
new file mode 100644
index 0000000000..af01cfb102
--- /dev/null
+++ b/cts/build.mk
@@ -0,0 +1,10 @@
+# -*- makefile -*-
+# Copyright 2016 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.
+
+ifeq ($(BOARD),stm32l476g-eval)
+ cts-y+=$(CTS_MODULE)/th.o
+else
+ cts-y+=$(CTS_MODULE)/dut.o
+endif \ No newline at end of file
diff --git a/cts/cts.py b/cts/cts.py
new file mode 100755
index 0000000000..9c4940b6ff
--- /dev/null
+++ b/cts/cts.py
@@ -0,0 +1,178 @@
+#!/usr/bin/python2
+# Copyright 2016 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.
+
+# This file is a utility to quickly flash boards
+
+
+import os
+import subprocess as sp
+import sys
+import argparse
+
+# example of call this method will make
+# make BOARD=nucleo-f072rb CTS_MODULE=gpio -j
+
+ocd_script_dir = '/usr/local/share/openocd/scripts'
+th_board = 'stm32l476g-eval'
+th_serial_filename = 'th_hla_serial'
+
+def make(module, dut_board, ecDirectory):
+ sp.call(['make', '--directory=' + str(ecDirectory),
+ 'BOARD=stm32l476g-eval', 'CTS_MODULE=' + module, '-j'])
+
+ sp.call(['make', '--directory=' + str(ecDirectory),
+ 'BOARD=' + dut_board, 'CTS_MODULE=' + module, '-j'])
+
+def openocd_cmd(command_list, board_cfg):
+ args = ['openocd', '-s', ocd_script_dir,
+ '-f', board_cfg]
+ for c in command_list:
+ args.append('-c')
+ args.append(c)
+ args.append('-c')
+ args.append('shutdown')
+ sp.call(args)
+
+def get_stlink_serial_numbers():
+ usb_args = ['lsusb', '-v', '-d', '0x0483:0x374b']
+ usb_process = sp.Popen(usb_args, stdout=sp.PIPE, shell=False)
+ st_link_info = usb_process.communicate()[0]
+ st_serials = []
+ for line in st_link_info.split('\n'):
+ if 'iSerial' in line:
+ st_serials.append(line.split()[2])
+ return st_serials
+
+# This function is necessary because the dut might be using an st-link debugger
+# params: th_hla_serial is your personal th board's serial
+def identify_dut(th_hla_serial):
+ stlink_serials = get_stlink_serial_numbers()
+ if len(stlink_serials) == 1:
+ return None
+ # If 2 st-link devices connected, find dut's serial number
+ elif len(stlink_serials) == 2:
+ dut = [s for s in stlink_serials if th_hla_serial not in s]
+ if len(dut) != 1:
+ print 'ERROR: Check your TH hla_serial'
+ return None
+ else:
+ return dut[0] # Found your other st-link device serial!
+ else:
+ print 'ERROR: Please connect TH and your DUT and remove all other st-link devices'
+ return None
+
+def update_th_serial(dest_dir):
+ serial = get_stlink_serial_numbers()
+ if len(serial) != 1:
+ print 'Connect your TH and remove other st-link devices'
+ else:
+ ser = serial[0]
+ f = open(os.path.join(dest_dir, th_serial_filename), mode='w')
+ f.write(ser)
+ f.close()
+ return ser
+
+def get_board_config_name(board):
+ board_config_locs = {
+ 'stm32l476g-eval' : 'board/stm32l4discovery.cfg',
+ 'nucleo-f072rb' : 'board/st_nucleo_f0.cfg'
+ }
+ return board_config_locs[board]
+
+def flash_boards(dut_board, th_serial_loc):
+ th_hla = None
+ dut_hla = None
+ try:
+ th_hla = open(th_serial_loc).read()
+ except:
+ print 'Your th hla_serial may not have been saved.'
+ print 'Connect only your th and run ./cts --th, then try again.'
+ print sys.exc_info()[0]
+ return
+ dut_hla = identify_dut(th_hla)
+ th_cfg = get_board_config_name(th_board)
+ dut_cfg = get_board_config_name(dut_board)
+
+ if(th_cfg == None or dut_cfg == None):
+ print 'Board cfg files not found'
+ return
+
+ th_flash_cmds = ['hla_serial ' + th_hla,
+ 'reset_config connect_assert_srst',
+ 'init',
+ 'reset init',
+ 'flash write_image erase build/' + th_board + '/ec.bin 0x08000000',
+ 'reset halt']
+
+ dut_flash_cmds = ['reset_config connect_assert_srst',
+ 'init',
+ 'reset init',
+ 'flash write_image erase build/' + dut_board + '/ec.bin 0x08000000',
+ 'reset halt']
+
+ if dut_hla != None:
+ dut_flash_cmds.insert(0, 'hla_serial ' + dut_hla)
+
+ openocd_cmd(th_flash_cmds, th_cfg)
+ openocd_cmd(dut_flash_cmds, dut_cfg)
+ openocd_cmd(['init', 'reset init', 'resume'], th_cfg)
+ openocd_cmd(['init', 'reset init', 'resume'], dut_cfg)
+
+def main():
+ global ocd_script_dir
+ path = os.path.abspath(__file__)
+ ec_dir = os.path.join(os.path.dirname(path), '..')
+ os.chdir(ec_dir)
+ th_serial_dir = os.path.join(ec_dir, 'build', th_board)
+ dut_board = 'nucleo-f072rb' #nucleo by default
+ module = 'gpio' #gpio by default
+
+ parser = argparse.ArgumentParser(description='Used to build/flash boards')
+ parser.add_argument('-d',
+ '--dut',
+ help='Specify DUT you want to build/flash')
+ parser.add_argument('-m',
+ '--module',
+ help='Specify module you want to build/flash')
+ parser.add_argument('-t',
+ '--th',
+ action='store_true',
+ help='Connect only the th to save its serial')
+ parser.add_argument('-b',
+ '--build',
+ action='store_true',
+ help='Build test suite (no flashing)')
+ parser.add_argument('-f',
+ '--flash',
+ action='store_true',
+ help='Flash boards with last image built for them')
+
+ args = parser.parse_args()
+ args = parser.parse_args()
+
+ if args.th:
+ serial = update_th_serial(th_serial_dir)
+ if(serial != None):
+ print 'Your th hla_serial # has been saved as: ' + serial
+ return
+
+ if args.module:
+ module = args.module
+
+ if args.dut:
+ dut_board = args.dut
+
+ elif args.build:
+ make(module, dut_board, ec_dir)
+
+ elif args.flash:
+ flash_boards(dut_board, os.path.join(th_serial_dir, th_serial_filename))
+
+ else:
+ make(module, dut_board, ec_dir)
+ flash_boards(dut_board, os.path.join(th_serial_dir, th_serial_filename))
+
+if __name__ == "__main__":
+ main() \ No newline at end of file
diff --git a/cts/gpio/dut.c b/cts/gpio/dut.c
new file mode 100644
index 0000000000..bdcd4938f7
--- /dev/null
+++ b/cts/gpio/dut.c
@@ -0,0 +1,15 @@
+/* Copyright 2016 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.
+ */
+
+#include "timer.h"
+#include "watchdog.h"
+
+void cts_task(void)
+{
+ while (1) {
+ watchdog_reload();
+ sleep(1);
+ }
+}
diff --git a/cts/gpio/th.c b/cts/gpio/th.c
new file mode 100644
index 0000000000..bdcd4938f7
--- /dev/null
+++ b/cts/gpio/th.c
@@ -0,0 +1,15 @@
+/* Copyright 2016 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.
+ */
+
+#include "timer.h"
+#include "watchdog.h"
+
+void cts_task(void)
+{
+ while (1) {
+ watchdog_reload();
+ sleep(1);
+ }
+}
diff --git a/include/task_id.h b/include/task_id.h
index db9ef7b3b1..34f24f097d 100644
--- a/include/task_id.h
+++ b/include/task_id.h
@@ -17,6 +17,12 @@
#define CONFIG_TEST_TASK_LIST
#endif
+#ifdef CTS_MODULE
+#define TASK_CTS TASK
+#else
+#define TASK_CTS(n, r, d, s)
+#endif
+
#define TASK_ALWAYS TASK
/* define the name of the header containing the list of tasks */