nanohub: add support for specifying a variant map file

add new linker script rule that accepts full path to map file
add NANO_VARIANT_LKR_MAP to specify a map file instead of the default
tell make not to delete os.checked.elf

Bug: 68819698
Test: Set NANO_VARIANT_LKR_MAP to a different map file and build
Change-Id: Ia2bd2cb3b9194ca41c6cd2ae98b0d724287fc18b
Signed-off-by: Ben Fennema <fennema@google.com>
diff --git a/firmware/build/config.mk b/firmware/build/config.mk
index e7dbbe4..2776653 100644
--- a/firmware/build/config.mk
+++ b/firmware/build/config.mk
@@ -98,6 +98,17 @@
 $(eval $(call nano-gen-linker-script-from-list,$(1),$(NANOHUB_OS_PATH)/os/platform/$(5)/lkr/$(4).extra.lkr))
 endef
 
+# create linker script rule
+#
+# $(1) - target file
+# $(2) - { os | bl }
+# $(3) - full path to map file
+# $(4) - platform class
+# $(5) - platform dir
+define nano-gen-linker-script-map
+$(eval $(call nano-gen-linker-script-from-list,$(1),$(3) $(patsubst %,$(NANOHUB_OS_PATH)/os/platform/$(5)/lkr/%.lkr,$(4).$(2) $(4).common)))
+endef
+
 # variables that Android.mk or our config files may define per-cpu, per-arch etc;
 # must include all LOCAL* variables we modify in any place within the scope of for-each-variant.
 #
diff --git a/firmware/build/nanohub_executable.mk b/firmware/build/nanohub_executable.mk
index b474b92..4b99ccd 100644
--- a/firmware/build/nanohub_executable.mk
+++ b/firmware/build/nanohub_executable.mk
@@ -41,7 +41,11 @@
 ifeq ($(LOCAL_NANO_MODULE_TYPE),BL)
 ifeq ($(AUX_ARCH),stm32)
 linker_script := $(gen)/bl.lkr
+ifeq ($(NANO_VARIANT_LKR_MAP),)
 $(call nano-gen-linker-script,$(linker_script),bl,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
+else
+$(call nano-gen-linker-script-map,$(linker_script),bl,$(NANO_VARIANT_LKR_MAP),stm32f4xx,$(AUX_ARCH))
+endif
 endif
 endif
 
@@ -52,7 +56,11 @@
 endif
 ifeq ($(AUX_ARCH),stm32)
 linker_script := $(gen)/os.lkr
+ifeq ($(NANO_VARIANT_LKR_MAP),)
 $(call nano-gen-linker-script,$(linker_script),os,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
+else
+$(call nano-gen-linker-script-map,$(linker_script),os,$(NANO_VARIANT_LKR_MAP),stm32f4xx,$(AUX_ARCH))
+endif
 endif
 endif
 
diff --git a/firmware/firmware.mk b/firmware/firmware.mk
index 0c81072..8627748 100644
--- a/firmware/firmware.mk
+++ b/firmware/firmware.mk
@@ -117,3 +117,5 @@
 
 clean:
 	rm -rf $(OUT)
+
+.SECONDARY: $(OUT)/os.checked.elf