Add modularity to the build

You can now enable/disable tasks more easily.
To conditionally compile a C file depending on the task FOO activation,
just write something like that in the build.mk file :
common-$(CONFIG_TASK_FOO)+=foo_source.o

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BUG=None
TEST=make all BOARD=link && make qemu-tests

Change-Id: I760fb248e1599d13190ccd937a68ef47da17b510
This commit is contained in:
Vincent Palatin
2012-01-24 21:15:26 +00:00
parent 396a94c43f
commit d356dea61e
19 changed files with 70 additions and 64 deletions

View File

@@ -12,6 +12,19 @@ PROJECT?=ec
# output directory for build objects
out?=build/$(BOARD)
include Makefile.toolchain
# Get CHIP name
include board/$(BOARD)/build.mk
# Transform the configuration into make variables
_tsk_lst:=$(shell echo "CONFIG_TASK_LIST" | $(CPP) -P -Iboard/$(BOARD) -Itest \
-D"TASK(n, r, d)=n" -imacros $(PROJECT).tasklist)
_tsk_cfg:=$(foreach t,$(_tsk_lst),CONFIG_TASK_$(t))
_flag_cfg:=$(shell $(CPP) -P -dN chip/$(CHIP)/config.h | grep -o "CONFIG_.*")
$(foreach c,$(_tsk_cfg) $(_flag_cfg),$(eval $(c)=y))
CPPFLAGS+=$(foreach t,$(_tsk_cfg),-D$(t))
# Get build configuration from sub-directories
include board/$(BOARD)/build.mk
include chip/$(CHIP)/build.mk
@@ -22,12 +35,11 @@ include util/build.mk
objs_from_dir=$(foreach obj,$(2), $(out)/$(1)/$(obj))
# Get all sources to build
all-objs=$(call objs_from_dir,chip/$(CHIP),$(chip-objs))
all-objs+=$(call objs_from_dir,board/$(BOARD),$(board-objs))
all-objs+=$(call objs_from_dir,common,$(common-objs))
all-objs+=$(call objs_from_dir,test,$($(PROJECT)-objs))
all-y=$(call objs_from_dir,chip/$(CHIP),$(chip-y))
all-y+=$(call objs_from_dir,board/$(BOARD),$(board-y))
all-y+=$(call objs_from_dir,common,$(common-y))
all-y+=$(call objs_from_dir,test,$($(PROJECT)-y))
dirs=chip/$(CHIP) board/$(BOARD) common test util
includes=include $(dirs)
include Makefile.toolchain
include Makefile.rules

View File

@@ -5,7 +5,7 @@
# Embedded Controller firmware build system - common targets
#
objs := $(all-objs)
objs := $(all-y)
deps := $(objs:%.o=%.o.d)
build-utils := $(foreach u,$(build-util-bin),$(out)/util/$(u))
host-utils := $(foreach u,$(host-util-bin),$(out)/util/$(u))

View File

@@ -4,4 +4,4 @@
# the IC is TI Stellaris LM4
CHIP:=lm4
board-objs=board.o
board-y=board.o

View File

@@ -14,7 +14,7 @@
* 'd' in an opaque parameter passed to the routine at startup
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(POWERBTN, power_button_task, NULL) \
TASK(X86POWER, x86_power_task, NULL) \

View File

@@ -8,4 +8,4 @@
# the IC is TI Stellaris LM4
CHIP:=lm4
board-objs=board.o
board-y=board.o

View File

@@ -14,7 +14,7 @@
* 'd' in an opaque parameter passed to the routine at startup
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(POWERBTN, power_button_task, NULL) \
TASK(X86POWER, x86_power_task, NULL) \

View File

@@ -8,6 +8,7 @@
# CPU specific compilation flags
CFLAGS_CPU=-mcpu=cortex-m4 -mthumb -Os -mno-sched-prolog
chip-objs=init.o panic.o switch.o task.o timer.o pwm.o i2c.o adc.o jtag.o
chip-objs+=clock.o gpio.o system.o lpc.o uart.o power_button.o
chip-objs+=flash.o watchdog.o eeprom.o keyboard_scan.o temp_sensor.o
chip-y=init.o panic.o switch.o task.o timer.o pwm.o i2c.o adc.o jtag.o
chip-y+=clock.o gpio.o system.o lpc.o uart.o power_button.o
chip-y+=flash.o watchdog.o eeprom.o temp_sensor.o
chip-$(CONFIG_TASK_KEYSCAN)+=keyboard_scan.o

View File

@@ -30,6 +30,7 @@ SECTIONS
__irqprio = .;
*(.rodata.irqprio)
__irqprio_end = .;
. = ALIGN(4);
__cmds = .;
*(.rodata.cmds)
__cmds_end = .;

View File

@@ -174,6 +174,7 @@ static void lpc_interrupt(void)
/* Clear the interrupt bits we're handling */
LM4_LPC_LPCIC = mis;
#ifdef CONFIG_TASK_HOSTCMD
/* Handle host kernel/user command writes */
if (mis & LM4_LPC_INT_MASK(LPC_CH_KERNEL, 4)) {
/* Set the busy bit and clear the status */
@@ -193,11 +194,13 @@ static void lpc_interrupt(void)
* This clears the FRMH bit in the status byte. */
host_command_received(1, LPC_POOL_USER[0]);
}
#endif
/* Handle port 80 writes (CH0MIS1) */
if (mis & LM4_LPC_INT_MASK(LPC_CH_PORT80, 2))
port_80_write(LPC_POOL_PORT80[0]);
#ifdef CONFIG_TASK_I8042CMD
/* Handle port 60 command (CH3MIS2) and data (CH3MIS1) */
if (mis & LM4_LPC_INT_MASK(LPC_CH_KEYBOARD, 2)) {
/* Read the data byte and pass to the i8042 handler.
@@ -213,6 +216,7 @@ static void lpc_interrupt(void)
/* Host picks up the data, try to send remaining bytes */
task_send_msg(TASK_ID_I8042CMD, TASK_ID_I8042CMD, 0);
}
#endif
/* Handle COMx */
if (mis & LM4_LPC_INT_MASK(LPC_CH_COMX, 2)) {

View File

@@ -11,7 +11,9 @@
#include "common.h"
#include "config.h"
#include "registers.h"
#include "gpio.h"
#include "task.h"
#include "timer.h"
#include "uart.h"
#include "util.h"
@@ -135,3 +137,20 @@ int watchdog_init(int period_ms)
return EC_SUCCESS;
}
/* Low priority task to reload the watchdog */
void watchdog_task(void)
{
while (1) {
#ifdef BOARD_bds
gpio_set_level(GPIO_DEBUG_LED, 1);
#endif
usleep(500000);
watchdog_reload();
#ifdef BOARD_bds
gpio_set_level(GPIO_DEBUG_LED, 0);
#endif
usleep(500000);
watchdog_reload();
}
}

View File

@@ -5,6 +5,9 @@
# Common files build
#
common-objs=main.o util.o console.o vboot.o x86_power.o pwm_commands.o
common-objs+=flash_commands.o host_command.o port80.o keyboard.o i8042.o
common-objs+=memory_commands.o shared_mem.o temp_sensor_commands.o usb_charge.o
common-y=main.o util.o console.o vboot.o pwm_commands.o
common-y+=flash_commands.o port80.o
common-y+=memory_commands.o shared_mem.o temp_sensor_commands.o usb_charge.o
common-$(CONFIG_TASK_HOSTCMD)+=host_command.o
common-$(CONFIG_TASK_I8042CMD)+=i8042.o keyboard.o
common-$(CONFIG_TASK_X86POWER)+=x86_power.o

View File

@@ -34,24 +34,6 @@
#include "watchdog.h"
#include "usb_charge.h"
/* example task blinking the user LED */
/* TODO: This also kicks the watchdog, so MUST be present! */
void UserLedBlink(void)
{
while (1) {
#ifdef BOARD_bds
gpio_set_level(GPIO_DEBUG_LED, 1);
#endif
usleep(500000);
watchdog_reload();
#ifdef BOARD_bds
gpio_set_level(GPIO_DEBUG_LED, 0);
#endif
usleep(500000);
watchdog_reload();
}
}
int main(void)
{
@@ -75,7 +57,9 @@ int main(void)
task_init();
#ifdef CONFIG_TASK_WATCHDOG
watchdog_init(1100);
#endif
timer_init();
uart_init();
system_init();

View File

@@ -5,7 +5,7 @@
test-list=hello pingpong timer_calib timer_dos
#disable: powerdemo
pingpong-objs=pingpong.o
powerdemo-objs=powerdemo.o
timer_calib-objs=timer_calib.o
timer_dos-objs=timer_dos.o
pingpong-y=pingpong.o
powerdemo-y=powerdemo.o
timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o

View File

@@ -7,7 +7,6 @@
def test(helper):
helper.wait_output("--- Chrome EC initialized! ---")
helper.wait_prompt()
helper.ec_command("version")
ro = helper.wait_output("RO version:\s*(?P<ro>\S+)", use_re=True)["ro"]
wa = helper.wait_output("RW-A version:\s*(?P<a>\S+)", use_re=True)["a"]

View File

@@ -14,9 +14,6 @@
* 'd' in an opaque parameter passed to the routine at startup
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(GPIOISR, gpio_task, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(CONSOLE, console_task, NULL) \
TASK(HOSTCMD, host_command_task, NULL) \
TASK(I8042CMD, i8042_command_task, NULL)
TASK(HOSTCMD, host_command_task, NULL)

View File

@@ -5,13 +5,9 @@
* The first one has the lowest priority.
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(GPIOISR, gpio_task, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(CONSOLE, console_task, NULL) \
TASK(TESTA, TaskAbc, (void *)'A') \
TASK(TESTB, TaskAbc, (void *)'B') \
TASK(TESTC, TaskAbc, (void *)'C') \
TASK(TESTT, TaskTick, (void *)'T')\
TASK(HOSTCMD, host_command_task, NULL) \
TASK(I8042CMD, i8042_command_task, NULL)
TASK(TESTT, TaskTick, (void *)'T')

View File

@@ -1,6 +1,4 @@
#define CONFIG_TASK_LIST \
TASK(CONSOLE, console_task, NULL) \
TASK(HOSTCMD, host_command_task, NULL) \
TASK(I8042CMD, i8042_command_task, NULL) \
TASK(POWERDEMO, power_demo_task, NULL)

View File

@@ -5,10 +5,6 @@
* The first one has the lowest priority.
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(GPIOISR, gpio_task, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(TESTTMR, timer_calib_task, (void *)'T')\
TASK(CONSOLE, console_task, NULL) \
TASK(HOSTCMD, host_command_task, NULL) \
TASK(I8042CMD, i8042_command_task, NULL)
TASK(CONSOLE, console_task, NULL)

View File

@@ -5,13 +5,9 @@
* The first one has the lowest priority.
*/
#define CONFIG_TASK_LIST \
TASK(BLINK, UserLedBlink, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(GPIOISR, gpio_task, NULL) \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(CONSOLE, console_task, NULL) \
TASK(TMRA, TaskTimer, (void *)1234) \
TASK(TMRB, TaskTimer, (void *)5678) \
TASK(TMRC, TaskTimer, (void *)8462) \
TASK(TMRD, TaskTimer, (void *)3719) \
TASK(HOSTCMD, host_command_task, NULL)\
TASK(I8042CMD, i8042_command_task, NULL)
TASK(TMRD, TaskTimer, (void *)3719)