|
| 1 | +# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | +# Use of this source code is governed by a BSD-style license that can be |
| 3 | +# found in the LICENSE file. |
| 4 | +# |
| 5 | +# Embedded Controller firmware build system |
| 6 | +# |
| 7 | + |
| 8 | +BOARD ?= bds |
| 9 | + |
| 10 | +# Directory where the board is configured (includes /$(BOARD) at the end) |
| 11 | +BDIR:=$(wildcard board/$(BOARD) private-*/board/$(BOARD)) |
| 12 | +# There can be only one <insert exploding windows here> |
| 13 | +ifeq (,$(BDIR)) |
| 14 | +$(error unable to locate BOARD $(BOARD)) |
| 15 | +endif |
| 16 | +ifneq (1,$(words $(BDIR))) |
| 17 | +$(error multiple definitions for BOARD $(BOARD): $(BDIR)) |
| 18 | +endif |
| 19 | +ifneq ($(filter private-%,$(BDIR)),) |
| 20 | +PDIR=$(subst /board/$(BOARD),,$(BDIR)) |
| 21 | +endif |
| 22 | + |
| 23 | +PROJECT?=ec |
| 24 | + |
| 25 | +# Output directory for build objects |
| 26 | +ifdef CTS_MODULE |
| 27 | +# CTS builds need different directories per board per suite. |
| 28 | +out?=build/$(BOARD)/cts_$(CTS_MODULE) |
| 29 | +else |
| 30 | +out?=build/$(BOARD) |
| 31 | +endif |
| 32 | + |
| 33 | +# File containing configuration information |
| 34 | +config=$(out)/.config |
| 35 | + |
| 36 | +# If no key file is provided, use the default dev key |
| 37 | +PEM ?= $(BDIR)/dev_key.pem |
| 38 | + |
| 39 | +# If CONFIG_TOUCHPAD_HASH_FW is set, include hashes of a touchpad firmware in |
| 40 | +# the EC image (if no touchpad firmware is provided, just output blank hashes). |
| 41 | +TOUCHPAD_FW ?= |
| 42 | + |
| 43 | +include Makefile.toolchain |
| 44 | + |
| 45 | +# Define the traditional first target. The dependencies of this are near the |
| 46 | +# bottom as they can be altered by chip and board files. |
| 47 | +.PHONY: all |
| 48 | +all: |
| 49 | + |
| 50 | +# Returns the opposite of a configuration variable |
| 51 | +# y -> |
| 52 | +# ro -> rw |
| 53 | +# rw -> ro |
| 54 | +# -> y |
| 55 | +# usage: common-$(call not_cfg,$(CONFIG_FOO))+=bar.o |
| 56 | +not_cfg = $(subst ro rw,y,$(filter-out $(1:y=ro rw),ro rw)) |
| 57 | + |
| 58 | +# The board makefile sets $CHIP and the chip makefile sets $CORE. |
| 59 | +# Include those now, since they must be defined for _flag_cfg below. |
| 60 | +include $(BDIR)/build.mk |
| 61 | +# Baseboard directory |
| 62 | +ifneq (,$(BASEBOARD)) |
| 63 | +BASEDIR:=baseboard/$(BASEBOARD) |
| 64 | +CFLAGS_BASEBOARD=-DHAS_BASEBOARD -DBASEBOARD_$(UC_BASEBOARD) |
| 65 | +include $(BASEDIR)/build.mk |
| 66 | +else |
| 67 | +# If BASEBOARD is not defined, then assign BASEDIR to BDIR. This avoids |
| 68 | +# the need to have so many conditional checks wherever BASEDIR is used |
| 69 | +# below. |
| 70 | +BASEDIR:=$(BDIR) |
| 71 | +CFLAGS_BASEBOARD= |
| 72 | +endif |
| 73 | +include chip/$(CHIP)/build.mk |
| 74 | + |
| 75 | +# Create uppercase config variants, to avoid mixed case constants. |
| 76 | +# Also translate '-' to '_', so 'cortex-m' turns into 'CORTEX_M'. This must |
| 77 | +# be done before evaluating config.h. |
| 78 | +uppercase = $(shell echo $(1) | tr '[:lower:]-' '[:upper:]_') |
| 79 | +UC_BASEBOARD:=$(call uppercase,$(BASEBOARD)) |
| 80 | +UC_BOARD:=$(call uppercase,$(BOARD)) |
| 81 | +UC_CHIP:=$(call uppercase,$(CHIP)) |
| 82 | +UC_CHIP_FAMILY:=$(call uppercase,$(CHIP_FAMILY)) |
| 83 | +UC_CHIP_VARIANT:=$(call uppercase,$(CHIP_VARIANT)) |
| 84 | +UC_CORE:=$(call uppercase,$(CORE)) |
| 85 | +UC_PROJECT:=$(call uppercase,$(PROJECT)) |
| 86 | + |
| 87 | +# Transform the configuration into make variables. This must be done after |
| 88 | +# the board/baseboard/project/chip/core variables are defined, since some of |
| 89 | +# the configs are dependent on particular configurations. |
| 90 | +includes=include core/$(CORE)/include $(dirs) $(out) test |
| 91 | +ifdef CTS_MODULE |
| 92 | +includes+=cts/$(CTS_MODULE) cts |
| 93 | +endif |
| 94 | +ifeq "$(TEST_BUILD)" "y" |
| 95 | + _tsk_lst_file:=ec.tasklist |
| 96 | + _tsk_lst_flags:=-Itest -DTEST_BUILD -imacros $(PROJECT).tasklist |
| 97 | +else ifdef CTS_MODULE |
| 98 | + _tsk_lst_file:=ec.tasklist |
| 99 | + _tsk_lst_flags:=-I cts/$(CTS_MODULE) -Icts -DCTS_MODULE=$(CTS_MODULE) \ |
| 100 | + -imacros cts.tasklist |
| 101 | +else |
| 102 | + _tsk_lst_file:=$(PROJECT).tasklist |
| 103 | + _tsk_lst_flags:= |
| 104 | +endif |
| 105 | + |
| 106 | +_tsk_lst_flags+=-I$(BDIR) -DBOARD_$(UC_BOARD) -I$(BASEDIR) \ |
| 107 | + -DBASEBOARD_$(UC_BASEBOARD) -D_MAKEFILE \ |
| 108 | + -imacros $(_tsk_lst_file) |
| 109 | + |
| 110 | +_tsk_lst_ro:=$(shell $(CPP) -P -DSECTION_IS_RO \ |
| 111 | + $(_tsk_lst_flags) include/task_filter.h) |
| 112 | +_tsk_lst_rw:=$(shell $(CPP) -P -DSECTION_IS_RW \ |
| 113 | + $(_tsk_lst_flags) include/task_filter.h) |
| 114 | + |
| 115 | +_tsk_cfg_ro:=$(foreach t,$(_tsk_lst_ro) ,HAS_TASK_$(t)) |
| 116 | +_tsk_cfg_rw:=$(foreach t,$(_tsk_lst_rw) ,HAS_TASK_$(t)) |
| 117 | + |
| 118 | +_tsk_cfg:= $(filter $(_tsk_cfg_ro), $(_tsk_cfg_rw)) |
| 119 | +_tsk_cfg_ro:= $(filter-out $(_tsk_cfg), $(_tsk_cfg_ro)) |
| 120 | +_tsk_cfg_rw:= $(filter-out $(_tsk_cfg), $(_tsk_cfg_rw)) |
| 121 | + |
| 122 | +CPPFLAGS_RO+=$(foreach t,$(_tsk_cfg_ro),-D$(t)) \ |
| 123 | + $(foreach t,$(_tsk_cfg_rw),-D$(t)_RW) |
| 124 | +CPPFLAGS_RW+=$(foreach t,$(_tsk_cfg_rw),-D$(t)) \ |
| 125 | + $(foreach t,$(_tsk_cfg_ro),-D$(t)_RO) |
| 126 | +CPPFLAGS+=$(foreach t,$(_tsk_cfg),-D$(t)) |
| 127 | + |
| 128 | +# Get the CONFIG_ and VARIANT_ options that are defined for this target and make |
| 129 | +# them into variables available to this build script |
| 130 | +_flag_cfg_ro:=$(shell $(CPP) $(CPPFLAGS) -P -dM -Ichip/$(CHIP) \ |
| 131 | + -I$(BASEDIR) -I$(BDIR) -DSECTION_IS_RO include/config.h | \ |
| 132 | + grep -o "\#define \(CONFIG\|VARIANT\)_[A-Z0-9_]*" | cut -c9- | sort) |
| 133 | +_flag_cfg_rw:=$(_tsk_cfg_rw) $(shell $(CPP) $(CPPFLAGS) -P -dM -Ichip/$(CHIP) \ |
| 134 | + -I$(BASEDIR) -I$(BDIR) -DSECTION_IS_RW include/config.h | \ |
| 135 | + grep -o "\#define \(CONFIG\|VARIANT\)_[A-Z0-9_]*" | cut -c9- | sort) |
| 136 | + |
| 137 | +_flag_cfg:= $(filter $(_flag_cfg_ro), $(_flag_cfg_rw)) |
| 138 | +_flag_cfg_ro:= $(filter-out $(_flag_cfg), $(_flag_cfg_ro)) |
| 139 | +_flag_cfg_rw:= $(filter-out $(_flag_cfg), $(_flag_cfg_rw)) |
| 140 | + |
| 141 | +$(foreach c,$(_tsk_cfg_rw) $(_flag_cfg_rw),$(eval $(c)=rw)) |
| 142 | +$(foreach c,$(_tsk_cfg_ro) $(_flag_cfg_ro),$(eval $(c)=ro)) |
| 143 | +$(foreach c,$(_tsk_cfg) $(_flag_cfg),$(eval $(c)=y)) |
| 144 | + |
| 145 | +ifneq "$(CONFIG_COMMON_RUNTIME)" "y" |
| 146 | + _irq_list:=$(shell $(CPP) $(CPPFLAGS) -P -Ichip/$(CHIP) -I$(BASEDIR) \ |
| 147 | + -I$(BDIR) -D"ENABLE_IRQ(x)=EN_IRQ x" \ |
| 148 | + -imacros chip/$(CHIP)/registers.h \ |
| 149 | + $(BDIR)/ec.irqlist | grep "EN_IRQ .*" | cut -c8-) |
| 150 | + CPPFLAGS+=$(foreach irq,$(_irq_list),\ |
| 151 | + -D"irq_$(irq)_handler_optional=irq_$(irq)_handler") |
| 152 | +endif |
| 153 | + |
| 154 | +# Compute RW firmware size and offset |
| 155 | +_rw_off_str:=$(shell echo "CONFIG_RW_MEM_OFF" | $(CPP) $(CPPFLAGS) -P \ |
| 156 | + -Ichip/$(CHIP) -I$(BASEDIR) -I$(BDIR) -imacros include/config.h) |
| 157 | +_rw_off:=$(shell echo "$$(($(_rw_off_str)))") |
| 158 | +_rw_size_str:=$(shell echo "CONFIG_RW_SIZE" | $(CPP) $(CPPFLAGS) -P \ |
| 159 | + -Ichip/$(CHIP) -I$(BASEDIR) -I$(BDIR) -imacros include/config.h) |
| 160 | +_rw_size:=$(shell echo "$$(($(_rw_size_str)))") |
| 161 | +_program_memory_base_str:=$(shell echo "CONFIG_PROGRAM_MEMORY_BASE" | \ |
| 162 | + $(CPP) $(CPPFLAGS) -P \ |
| 163 | + -Ichip/$(CHIP) -I$(BDIR) -I$(BASEDIR) -imacros include/config.h) |
| 164 | +_program_memory_base=$(shell echo "$$(($(_program_memory_base_str)))") |
| 165 | + |
| 166 | +$(eval BASEBOARD_$(UC_BASEBOARD)=y) |
| 167 | +$(eval BOARD_$(UC_BOARD)=y) |
| 168 | +$(eval CHIP_$(UC_CHIP)=y) |
| 169 | +$(eval CHIP_VARIANT_$(UC_CHIP_VARIANT)=y) |
| 170 | +$(eval CHIP_FAMILY_$(UC_CHIP_FAMILY)=y) |
| 171 | + |
| 172 | +# Private subdirectories may call this from their build.mk |
| 173 | +# First arg is the path to be prepended to configured *.o files. |
| 174 | +# Second arg is the config variable (ie, "FOO" to select with $(FOO-$3)). |
| 175 | +# Third arg is the config variable value ("y" for configuration options |
| 176 | +# that are set for both RO and RW, "rw" for RW-only configuration options) |
| 177 | +objs_from_dir_p=$(foreach obj, $($(2)-$(3)), $(1)/$(obj)) |
| 178 | +objs_from_dir=$(call objs_from_dir_p,$(1),$(2),y) |
| 179 | + |
| 180 | +# Get build configuration from sub-directories |
| 181 | +# Note that this re-includes the board and chip makefiles |
| 182 | + |
| 183 | +ifdef CTS_MODULE |
| 184 | +include cts/build.mk |
| 185 | +endif |
| 186 | +include $(BASEDIR)/build.mk |
| 187 | +ifneq ($(BASEDIR),$(BDIR)) |
| 188 | +include $(BDIR)/build.mk |
| 189 | +endif |
| 190 | +include chip/$(CHIP)/build.mk |
| 191 | +include core/$(CORE)/build.mk |
| 192 | +include common/build.mk |
| 193 | +include driver/build.mk |
| 194 | +include power/build.mk |
| 195 | +-include private/build.mk |
| 196 | +ifneq ($(PDIR),) |
| 197 | +include $(PDIR)/build.mk |
| 198 | +endif |
| 199 | +include test/build.mk |
| 200 | +include util/build.mk |
| 201 | +include util/lock/build.mk |
| 202 | + |
| 203 | +includes+=$(includes-y) |
| 204 | + |
| 205 | +# Wrapper for fetching all the sources relevant to this build |
| 206 | +# target. |
| 207 | +# First arg is "y" indicating sources for all segments, |
| 208 | +# or "rw" indicating sources for rw segment. |
| 209 | +define get_sources = |
| 210 | +# Get sources to build for this target |
| 211 | +all-obj-$(1)+=$(call objs_from_dir_p,core/$(CORE),core,$(1)) |
| 212 | +all-obj-$(1)+=$(call objs_from_dir_p,chip/$(CHIP),chip,$(1)) |
| 213 | +all-obj-$(1)+=$(call objs_from_dir_p,$(BASEDIR),baseboard,$(1)) |
| 214 | +all-obj-$(1)+=$(call objs_from_dir_p,$(BDIR),board,$(1)) |
| 215 | +all-obj-$(1)+=$(call objs_from_dir_p,private,private,$(1)) |
| 216 | +ifneq ($(PDIR),) |
| 217 | +all-obj-$(1)+=$(call objs_from_dir_p,$(PDIR),$(PDIR),$(1)) |
| 218 | +endif |
| 219 | +all-obj-$(1)+=$(call objs_from_dir_p,common,common,$(1)) |
| 220 | +all-obj-$(1)+=$(call objs_from_dir_p,driver,driver,$(1)) |
| 221 | +all-obj-$(1)+=$(call objs_from_dir_p,power,power,$(1)) |
| 222 | +ifdef CTS_MODULE |
| 223 | +all-obj-$(1)+=$(call objs_from_dir_p,cts,cts,$(1)) |
| 224 | +endif |
| 225 | +all-obj-$(1)+=$(call objs_from_dir_p,test,$(PROJECT),$(1)) |
| 226 | +endef |
| 227 | + |
| 228 | +# Get all sources to build |
| 229 | +$(eval $(call get_sources,y)) |
| 230 | +$(eval $(call get_sources,ro)) |
| 231 | + |
| 232 | +dirs=core/$(CORE) chip/$(CHIP) $(BASEDIR) $(BDIR) common power test \ |
| 233 | + cts/common cts/$(CTS_MODULE) |
| 234 | +dirs+= private $(PDIR) |
| 235 | +dirs+=$(shell find common -type d) |
| 236 | +dirs+=$(shell find driver -type d) |
| 237 | +common_dirs=util |
| 238 | + |
| 239 | +ifeq ($(custom-ro_objs-y),) |
| 240 | +ro-common-objs := $(sort $(foreach obj, $(all-obj-y), $(out)/RO/$(obj))) |
| 241 | +ro-only-objs := $(sort $(foreach obj, $(all-obj-ro), $(out)/RO/$(obj))) |
| 242 | +ro-objs := $(sort $(ro-common-objs) $(ro-only-objs)) |
| 243 | +else |
| 244 | +ro-objs := $(sort $(foreach obj, $(custom-ro_objs-y), $(out)/RO/$(obj))) |
| 245 | +endif |
| 246 | + |
| 247 | +# Add RW-only sources to build |
| 248 | +$(eval $(call get_sources,rw)) |
| 249 | + |
| 250 | +rw-common-objs := $(sort $(foreach obj, $(all-obj-y), $(out)/RW/$(obj))) |
| 251 | +rw-only-objs := $(sort $(foreach obj, $(all-obj-rw), $(out)/RW/$(obj))) |
| 252 | +rw-objs := $(sort $(rw-common-objs) $(rw-only-objs)) |
| 253 | + |
| 254 | +# Don't include the shared objects in the RO/RW image if we're enabling |
| 255 | +# the shared objects library. |
| 256 | +ifeq ($(CONFIG_SHAREDLIB),y) |
| 257 | +ro-objs := $(filter-out %_sharedlib.o, $(ro-objs)) |
| 258 | +endif |
| 259 | +ro-deps := $(ro-objs:%.o=%.o.d) |
| 260 | +rw-deps := $(rw-objs:%.o=%.o.d) |
| 261 | +deps := $(ro-deps) $(rw-deps) $(deps-y) |
| 262 | + |
| 263 | +.PHONY: ro rw |
| 264 | +$(config): $(out)/$(PROJECT).bin |
| 265 | + @printf '%s=y\n' $(_tsk_cfg) $(_flag_cfg) > $@ |
| 266 | + |
| 267 | +def_all_deps:=utils ro rw notice $(config) $(PROJECT_EXTRA) size |
| 268 | +all_deps?=$(def_all_deps) |
| 269 | +all: $(all_deps) |
| 270 | + |
| 271 | +ro: override BLD:=RO |
| 272 | +ro: $(libsharedobjs_elf-y) $(out)/RO/$(PROJECT).RO.flat |
| 273 | + |
| 274 | +rw: override BLD:=RW |
| 275 | +rw: $(libsharedobjs_elf-y) $(out)/RW/$(PROJECT).RW.flat |
| 276 | + |
| 277 | +# Shared objects library |
| 278 | +SHOBJLIB := libsharedobjs |
| 279 | +sharedlib-objs := $(filter %_sharedlib.o, $(all-obj-y)) |
| 280 | +sharedlib-objs := $(foreach obj, $(sharedlib-objs), $(out)/$(SHOBJLIB)/$(obj)) |
| 281 | +sharedlib-deps := $(sharedlib-objs:%.o=%.o.d) |
| 282 | +deps += $(sharedlib-deps) |
| 283 | +def_libsharedobjs_deps := $(sharedlib-objs) |
| 284 | +libsharedobjs_deps ?= $(def_libsharedobjs_deps) |
| 285 | + |
| 286 | +libsharedobjs-$(CONFIG_SHAREDLIB) := $(out)/$(SHOBJLIB)/$(SHOBJLIB).flat |
| 287 | +libsharedobjs_elf-$(CONFIG_SHAREDLIB) := \ |
| 288 | + $(libsharedobjs-$(CONFIG_SHAREDLIB):%.flat=%.elf) |
| 289 | +libsharedobjs: $(libsharedobjs-y) |
| 290 | + |
| 291 | +include Makefile.rules |
| 292 | +export CROSS_COMPILE CFLAGS CC CPP LD NM AR OBJCOPY OBJDUMP |
0 commit comments