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
17include $(BUILD_SYSTEM)/aux_toolchain.mk
18
19ifeq ($(AUX_BUILD_NOT_COMPATIBLE),)
20
21include $(NANO_BUILD)/config_internal.mk
22
23intermediates := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX)
24
25nanohub_linked_map := $(intermediates)/LINKED/$(LOCAL_MODULE).map
26nanohub_unchecked_elf := $(intermediates)/UNCHECKED/$(LOCAL_MODULE).elf
27nanohub_checked_elf := $(intermediates)/CHECKED/$(LOCAL_MODULE).elf
28nanohub_checked_bin := $(intermediates)/CHECKED/$(LOCAL_MODULE).bin
29
30LOCAL_CUSTOM_BUILD_STEP_INPUT := $(nanohub_unchecked_elf)
31
32
33gen := $(call generated-sources-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX)
34
35linker_script:=
36
37ifeq ($(LOCAL_NANO_MODULE_TYPE),APP)
38linker_script := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/lkr/app.lkr
39endif
40
41ifeq ($(LOCAL_NANO_MODULE_TYPE),BL)
42ifeq ($(AUX_ARCH),stm32)
43linker_script := $(gen)/bl.lkr
44$(call nano-gen-linker-script,$(linker_script),bl,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
45endif
46endif
47
48ifeq ($(LOCAL_NANO_MODULE_TYPE),OS)
49ifeq ($(AUX_ARCH),native)
50linker_script := $(gen)/os.lkr
51$(call nano-gen-linker-script-native,$(linker_script),os,$(AUX_SUBARCH),native,$(AUX_ARCH))
52endif
53ifeq ($(AUX_ARCH),stm32)
54linker_script := $(gen)/os.lkr
55$(call nano-gen-linker-script,$(linker_script),os,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
56endif
57endif
58
59ifeq ($(linker_script),)
60$(error $(LOCAL_PATH): $(LOCAL_MODULE): linker script is not defined for ARCH=$(AUX_ARCH) TYPE=$(LOCAL_NANO_MODULE_TYPE))
61endif
62
63LOCAL_ADDITIONAL_DEPENDENCIES += $(linker_script)
64LOCAL_LDFLAGS += -T $(linker_script)
65
66ifneq ($(LOCAL_NANO_APP_VERSION),)
67LOCAL_NANO_APP_POSTPROCESS_FLAGS += -e $(LOCAL_NANO_APP_VERSION)
68endif
69
70$(nanohub_checked_elf): $(nanohub_unchecked_elf)
71	$(hide)echo "nanohub Symcheck $@ <= $<"
72	$(copy-file-to-target)
73nanohub_output := $(nanohub_checked_elf)
74
75# objcopy is per-cpu only
76objcopy_params:=
77
78# optional objcopy step
79ifneq ($(strip $(LOCAL_OBJCOPY_SECT)),)
80
81objcopy_params := $(GLOBAL_NANO_OBJCOPY_FLAGS) $(GLOBAL_NANO_OBJCOPY_FLAGS_$(AUX_CPU)) $(foreach sect,$(LOCAL_OBJCOPY_SECT), -j $(sect))
82
83$(nanohub_checked_bin): PRIVATE_OBJCOPY_ARGS := $(objcopy_params)
84$(nanohub_checked_bin): PRIVATE_MODULE := $(LOCAL_MODULE)
85$(nanohub_checked_bin): PRIVATE_OBJCOPY := $(AUX_OBJCOPY)
86$(nanohub_checked_bin): $(nanohub_output)
87	$(hide)echo "nanohub OBJCOPY $(PRIVATE_MODULE) ($@)"
88	$(hide)$(PRIVATE_OBJCOPY) $(PRIVATE_OBJCOPY_ARGS) $< $@
89nanohub_output := $(nanohub_checked_bin)
90
91objcopy_params :=
92objcopy_sect :=
93else
94LOCAL_NANO_APP_NO_POSTPROCESS := true
95LOCAL_NANO_APP_UNSIGNED := true
96endif
97
98ifeq ($(LOCAL_NANO_MODULE_TYPE),APP)
99
100nanohub_napp := $(intermediates)/CHECKED/$(LOCAL_MODULE).napp
101nanohub_signed_napp := $(intermediates)/CHECKED/$(LOCAL_MODULE).signed.napp
102
103# postprocess only works on BIN; if it is used, objcopy must be used as well
104ifneq ($(LOCAL_NANO_APP_NO_POSTPROCESS),true)
105$(if $(LOCAL_OBJCOPY_SECT),,\
106    $(error $(LOCAL_PATH): $(LOCAL_MODULE): nanoapp postprocess step requires LOCAL_OBJCOPY_SECT defined))
107
108$(nanohub_napp): PRIVATE_NANO_APP_ID  := $(LOCAL_NANO_APP_ID)
109$(nanohub_napp): PRIVATE_NANO_APP_VER := $(LOCAL_NANO_APP_VERSION)
110$(nanohub_napp): PRIVATE_NANO_APP_POSTPROCESS_FLAGS := $(LOCAL_NANO_APP_POSTPROCESS_FLAGS)
111
112$(nanohub_napp): $(nanohub_output) $(NANOAPP_POSTPROCESS)
113	$(hide)echo "nanoapp POSTPROCESS $@ <= $<"
114	$(hide)$(NANOAPP_POSTPROCESS) -a $(PRIVATE_NANO_APP_ID) $(PRIVATE_NANO_APP_POSTPROCESS_FLAGS) $< $@
115nanohub_output := $(nanohub_napp)
116endif # NO_POSTPROCESS
117
118ifneq ($(LOCAL_NANO_APP_UNSIGNED),true)
119$(if $(filter true,$(LOCAL_NANO_APP_NO_POSTPROCESS)),\
120    $(error $(LOCAL_PATH): $(LOCAL_MODULE): nanoapp sign step requires nanoapp postprocess))
121
122nanohub_pvt_key := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/misc/debug.privkey
123nanohub_pub_key := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/misc/debug.pubkey
124
125$(nanohub_signed_napp): PRIVATE_PVT_KEY := $(nanohub_pvt_key)
126$(nanohub_signed_napp): PRIVATE_PUB_KEY := $(nanohub_pub_key)
127
128$(nanohub_signed_napp): $(nanohub_napp) $(NANOAPP_SIGN)
129	$(hide)echo "nanoapp SIGN $@ <= $<"
130	$(hide)$(NANOAPP_SIGN) -s -e $(PRIVATE_PVT_KEY) -m $(PRIVATE_PUB_KEY) $< $@
131
132nanohub_output := $(nanohub_signed_napp)
133endif # !UNSIGNED
134
135endif # TYPE == APP
136
137LOCAL_CUSTOM_BUILD_STEP_OUTPUT := $(nanohub_output)
138LOCAL_LDFLAGS += -Wl,-Map,$(nanohub_linked_map)
139
140###############################
141include $(BUILD_AUX_EXECUTABLE)
142###############################
143
144LOCAL_CUSTOM_BUILD_STEP_INPUT :=
145LOCAL_CUSTOM_BUILD_STEP_OUTPUT :=
146
147endif # AUX_BUILD_NOT_COMPATIBLE
148