1#
2# Copyright (C) 2016 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17PLATFORM?=stm32
18CPU?=cortexm4
19CHIP?=stm32f411
20
21# SRC_PATH points to "firmware"; TOP_PATH is the abs path to top of android tree
22TOP_RELPATH := ../../../..
23TOP_ABSPATH := $(realpath $(SRC_PATH)/$(TOP_RELPATH))
24VARIANT_ABSPATH := $(TOP_ABSPATH)/$(VARIANT_PATH)
25VARIANT_PATH := $(TOP_RELPATH)/$(VARIANT_PATH)
26
27ifndef OUT
28OUT:=out/nanohub/$(VARIANT)
29MAKE_OUT=$(VARIANT_PATH)/$(OUT)
30else
31ifneq ($(filter $(TOP_ABSPATH)/out/target/product/%,$(OUT)),)
32# this looks like Android OUT env var; update it
33OUT:=$(OUT)/nanohub/$(VARIANT)
34IMAGE_TARGET_OUT:=vendor/firmware/nanohub.full.bin
35endif
36MAKE_OUT:=$(OUT)
37endif
38
39ifdef IMAGE_TARGET_OUT
40DIR_TMP := $(dir $(IMAGE_TARGET_OUT))
41IMAGE_TARGET_OUT_ELF := $(DIR_TMP)nanohub.os.$(TARGET_PRODUCT).elf
42endif
43
44ifdef IMAGE_OUT
45DIR_TMP := $(dir $(IMAGE_OUT))
46IMAGE_OUT_ELF := $(DIR_TMP)nanohub.os.$(TARGET_PRODUCT).elf
47endif
48
49.PHONY: all clean sync
50
51all:
52	make -C $(SRC_PATH) -f firmware.mk VARIANT=$(VARIANT) VARIANT_PATH=$(VARIANT_PATH) OUT=$(MAKE_OUT) PLATFORM=$(PLATFORM) CPU=$(CPU) CHIP=$(CHIP) $(EXTRA_ARGS)
53ifdef IMAGE_OUT
54	cd $(VARIANT_ABSPATH) && \
55	cp $(OUT)/full.bin $(IMAGE_OUT) && \
56	cp $(OUT)/os.unchecked.elf $(IMAGE_OUT_ELF) && \
57	chmod -x $(IMAGE_OUT_ELF)
58endif
59ifdef IMAGE_TARGET_OUT
60	cd $(VARIANT_ABSPATH) && \
61	mkdir -p $(dir $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT)) && \
62	cp $(OUT)/full.bin $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT) && \
63	cp $(OUT)/os.unchecked.elf $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT_ELF) && \
64	chmod -x $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT_ELF)
65endif
66
67clean:
68	rm -rf $(OUT)
69ifdef IMAGE_OUT
70	rm $(VARIANT_ABSPATH)/$(IMAGE_OUT)
71	rm $(VARIANT_ABSPATH)/$(IMAGE_OUT_ELF)
72endif
73ifdef IMAGE_TARGET_OUT
74	rm $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT)
75	rm $(TOP_ABSPATH)/$(IMAGE_TARGET_OUT_ELF)
76endif
77
78sync:
79	adb push $(OUT)/full.bin /vendor/firmware/nanohub.full.bin
80