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