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 17 include $(BUILD_SYSTEM)/aux_toolchain.mk 18 19 ifeq ($(AUX_BUILD_NOT_COMPATIBLE),) 20 21 include $(NANO_BUILD)/config_internal.mk 22 23 intermediates := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX) 24 25 nanohub_linked_map := $(intermediates)/LINKED/$(LOCAL_MODULE).map 26 nanohub_unchecked_elf := $(intermediates)/UNCHECKED/$(LOCAL_MODULE).elf 27 nanohub_checked_elf := $(intermediates)/CHECKED/$(LOCAL_MODULE).elf 28 nanohub_checked_bin := $(intermediates)/CHECKED/$(LOCAL_MODULE).bin 29 30 LOCAL_CUSTOM_BUILD_STEP_INPUT := $(nanohub_unchecked_elf) 31 32 33 gen := $(call generated-sources-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX) 34 35 linker_script:= 36 37 ifeq ($(LOCAL_NANO_MODULE_TYPE),APP) 38 linker_script := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/lkr/app.lkr 39 endif 40 41 ifeq ($(LOCAL_NANO_MODULE_TYPE),BL) 42 ifeq ($(AUX_ARCH),stm32) 43 linker_script := $(gen)/bl.lkr 44 ifeq ($(NANO_VARIANT_LKR_MAP),) 45 $(call nano-gen-linker-script,$(linker_script),bl,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH)) 46 else 47 $(call nano-gen-linker-script-map,$(linker_script),bl,$(NANO_VARIANT_LKR_MAP),stm32f4xx,$(AUX_ARCH)) 48 endif 49 endif 50 endif 51 52 ifeq ($(LOCAL_NANO_MODULE_TYPE),OS) 53 ifeq ($(AUX_ARCH),native) 54 linker_script := $(gen)/os.lkr 55 $(call nano-gen-linker-script-native,$(linker_script),os,$(AUX_SUBARCH),native,$(AUX_ARCH)) 56 endif 57 ifeq ($(AUX_ARCH),stm32) 58 linker_script := $(gen)/os.lkr 59 ifeq ($(NANO_VARIANT_LKR_MAP),) 60 $(call nano-gen-linker-script,$(linker_script),os,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH)) 61 else 62 $(call nano-gen-linker-script-map,$(linker_script),os,$(NANO_VARIANT_LKR_MAP),stm32f4xx,$(AUX_ARCH)) 63 endif 64 endif 65 endif 66 67 ifeq ($(linker_script),) 68 $(error $(LOCAL_PATH): $(LOCAL_MODULE): linker script is not defined for ARCH=$(AUX_ARCH) TYPE=$(LOCAL_NANO_MODULE_TYPE)) 69 endif 70 71 LOCAL_ADDITIONAL_DEPENDENCIES += $(linker_script) 72 LOCAL_LDFLAGS += -T $(linker_script) 73 74 ifneq ($(LOCAL_NANO_APP_VERSION),) 75 LOCAL_NANO_APP_POSTPROCESS_FLAGS += -e $(LOCAL_NANO_APP_VERSION) 76 endif 77 78 $(nanohub_checked_elf): $(nanohub_unchecked_elf) 79 $(hide)echo "nanohub Symcheck $@ <= $<" 80 $(copy-file-to-target) 81 nanohub_output := $(nanohub_checked_elf) 82 83 # objcopy is per-cpu only 84 objcopy_params:= 85 86 # optional objcopy step 87 ifneq ($(strip $(LOCAL_OBJCOPY_SECT)),) 88 89 objcopy_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) $< $@ 97 nanohub_output := $(nanohub_checked_bin) 98 99 objcopy_params := 100 objcopy_sect := 101 else 102 LOCAL_NANO_APP_NO_POSTPROCESS := true 103 LOCAL_NANO_APP_UNSIGNED := true 104 endif 105 106 ifeq ($(LOCAL_NANO_MODULE_TYPE),APP) 107 108 nanohub_napp := $(intermediates)/CHECKED/$(LOCAL_MODULE).napp 109 nanohub_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 112 ifneq ($(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) $< $@ 123 nanohub_output := $(nanohub_napp) 124 endif # NO_POSTPROCESS 125 126 ifneq ($(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 130 nanohub_pvt_key := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/misc/debug.privkey 131 nanohub_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 140 nanohub_output := $(nanohub_signed_napp) 141 endif # !UNSIGNED 142 143 endif # TYPE == APP 144 145 LOCAL_CUSTOM_BUILD_STEP_OUTPUT := $(nanohub_output) 146 LOCAL_LDFLAGS += -Wl,-Map,$(nanohub_linked_map) 147 148 ############################### 149 include $(BUILD_AUX_EXECUTABLE) 150 ############################### 151 152 LOCAL_CUSTOM_BUILD_STEP_INPUT := 153 LOCAL_CUSTOM_BUILD_STEP_OUTPUT := 154 155 endif # AUX_BUILD_NOT_COMPATIBLE 156