diff options
author | Che-yu Wu <cheyuw@google.com> | 2017-07-19 15:51:40 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-14 05:54:35 -0700 |
commit | 1bf7abdc206a177c0b8a8d6b541cc4250a8f0026 (patch) | |
tree | 8df82e09233db620054d2a3cc8de7ceeb34febf0 /Makefile.rules | |
parent | 041b90bcac4b03b484d6e5530e297100a7ff76f5 (diff) | |
download | chrome-ec-1bf7abdc206a177c0b8a8d6b541cc4250a8f0026.tar.gz |
ec: Add analysis tool for firmware stack usage.
Add a static analysis tool for firmware stack usage.
Add an new Makefile rule to analyze the stack usages of firmwares.
Details about the tool can be found in extra/stack_analyzer/README.md.
BUG=chromium:648840
BRANCH=none
TEST=extra/stack_analyzer/stack_analyzer_unittest.py
make BOARD=elm && make BOARD=elm build/elm/RW/ec.RW.taskinfo && \
extra/stack_analyzer/stack_analyzer.py \
--objdump=arm-none-eabi-objdump \
--addr2line=arm-none-eabi-addr2line \
./build/elm/RW/ec.RW.elf ./build/elm/RW/ec.RW.taskinfo
make BOARD=${BOARD} SECTION=${SECTION} analyzestack
Change-Id: Ifb1b5f5ad6be8f8b125b14d6ee03e25cb385895b
Signed-off-by: Che-yu Wu <cheyuw@google.com>
Reviewed-on: https://chromium-review.googlesource.com/576411
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'Makefile.rules')
-rw-r--r-- | Makefile.rules | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Makefile.rules b/Makefile.rules index 2dae63a26e..3be6a64582 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -94,6 +94,10 @@ cmd_sharedlib_elf = $(CC) $(libsharedobjs_deps) \ -Wl,-T,common/ec.$(SHOBJLIB).ld $(LDFLAGS) \ -o $(out)/$(SHOBJLIB)/$(SHOBJLIB).elf \ -Wl,-Map,$(out)/$(SHOBJLIB)/$(SHOBJLIB).map +cmd_taskinfo = $(CPP) -P -DSECTION_IS_$(3) \ + -I$(BDIR) -DBOARD_$(UC_BOARD) -D_MAKEFILE_DUMP_INFO \ + -imacros $(PROJECT).tasklist include/task_filter.h \ + -o $@ # commands for RSA signature: rwsig does not need to sign the whole image # (it signs the RW part separately). usbpd1 type needs to sign the final image. @@ -423,6 +427,13 @@ $(npcx-flash-fw-bin): -Wl,-Map,$(out)/$(npcx-flash-fw).map -@ $(OBJCOPY) -O binary $(out)/$(npcx-flash-fw).elf $@ +# Update taskinfo when the ec.tasklist is modified. +$(out)/RO/%.taskinfo: $(BDIR)/$(PROJECT).tasklist + $(call quiet,taskinfo,TSKINFO,RO) + +$(out)/RW/%.taskinfo: $(BDIR)/$(PROJECT).tasklist + $(call quiet,taskinfo,TSKINFO,RW) + .PHONY: xrefs xrefs: $(call targ_if_prog,etags,$(out)/TAGS) \ $(call targ_if_prog,ctags,$(out)/tags) @@ -532,6 +543,24 @@ newsizes: "$$((FILE_SIZE_CHANGE / FILES_CHANGED))"; \ fi +# The reason why don't add elf files as dependencies, but ask users to build +# them first is because elf dependencies will cause the elf files be rebuilt for +# updating date, which shouldn't happen when analyzing the existing firmwares. +.PHONY: analyzestack +analyzestack: $(out)/RO/ec.RO.taskinfo $(out)/RW/ec.RW.taskinfo + @if [ "$(SECTION)" != "RO" ] && [ "$(SECTION)" != "RW" ]; then \ + echo "Please specify SECTION=RO or RW. The default is RW."; \ + SECTION="RW"; \ + fi; \ + ELF=$(out)/$$SECTION/ec.$$SECTION.elf; \ + TASKLIST=$(out)/$$SECTION/ec.$$SECTION.taskinfo; \ + if [ ! -f "$$ELF" ]; then \ + echo "Some files are missing. Are they built?"; \ + exit 1; \ + fi; \ + extra/stack_analyzer/stack_analyzer.py --objdump "$(OBJDUMP)" \ + --addr2line "$(ADDR2LINE)" "$$ELF" "$$TASKLIST" + .SECONDARY: -include $(deps) |