build: Android build for nanohub FW
Bug: 29635686
Change-Id: I5225d027a22c23ea175445e2cdc6ffd30891aece
Signed-off-by: Alexey Polyudov <[email protected]>
diff --git a/firmware/Android.mk b/firmware/Android.mk
new file mode 100644
index 0000000..4bdab2f
--- /dev/null
+++ b/firmware/Android.mk
@@ -0,0 +1,98 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+ifneq ($(NANOHUB_OS_PATH),)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ os/core/appSec.c \
+ os/core/eventQ.c \
+ os/core/floatRt.c \
+ os/core/heap.c \
+ os/core/hostIntf.c \
+ os/core/hostIntfI2c.c \
+ os/core/hostIntfSpi.c \
+ os/core/nanohubCommand.c \
+ os/core/nanohub_chre.c \
+ os/core/osApi.c \
+ os/core/printf.c \
+ os/core/sensors.c \
+ os/core/seos.c \
+ os/core/simpleQ.c \
+ os/core/syscall.c \
+ os/core/slab.c \
+ os/core/spi.c \
+ os/core/timer.c \
+ os/core/trylock.c \
+
+LOCAL_C_INCLUDES := \
+ $(NANOHUB_OS_PATH)/external/freebsd/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES)
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
+
+########################################################
+# BOOT LOADER BINARY
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := nanohub_bl
+
+LOCAL_SRC_FILES := \
+ os/core/bl.c \
+
+LOCAL_STATIC_LIBRARIES := \
+ libnanohub_common_bl \
+ libnanohub_os \
+ libnanolibc_os \
+
+LOCAL_OBJCOPY_SECT_cortexm4 := .bl .blrodata .eedata
+
+include $(BUILD_NANOHUB_BL_EXECUTABLE)
+
+########################################################
+# NANOHUB OS BINARY
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := nanohub_os
+
+LOCAL_CFLAGS := \
+ -DPLATFORM_HW_VER=0 \
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+ libnanohub_os \
+
+LOCAL_STATIC_LIBRARIES := \
+ libnanomath_os \
+ libnanolibc_os \
+
+LOCAL_OBJCOPY_SECT_cortexm4 := .data .text
+
+include $(BUILD_NANOHUB_OS_EXECUTABLE)
+
+include $(call first-makefiles-under,$(NANOHUB_OS_PATH))
+
+endif # NANOHUB_OS_PATH
diff --git a/firmware/app/Android.mk b/firmware/app/Android.mk
index e69de29..e6bbbc1 100644
--- a/firmware/app/Android.mk
+++ b/firmware/app/Android.mk
@@ -0,0 +1,18 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+subdirs := test0.app test1.app chre
+include $(call all-named-subdir-makefiles,$(subdirs))
diff --git a/firmware/app/chre/Android.mk b/firmware/app/chre/Android.mk
new file mode 100644
index 0000000..54d18ee
--- /dev/null
+++ b/firmware/app/chre/Android.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/firmware/app/chre/chre_test0.app/Android.mk b/firmware/app/chre/chre_test0.app/Android.mk
new file mode 100644
index 0000000..c34123f
--- /dev/null
+++ b/firmware/app/chre/chre_test0.app/Android.mk
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := chre_test0
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x9000
+LOCAL_NANO_APP_ID := 476f6f676c549000
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+ libnanochre \
+
+LOCAL_STATIC_LIBRARIES := \
+ libnanolibc \
+ libnanolibm \
+
+LOCAL_SRC_FILES := main.c
+
+include $(BUILD_NANOHUB_APP_EXECUTABLE)
diff --git a/firmware/app/chre/common/Android.mk b/firmware/app/chre/common/Android.mk
new file mode 100644
index 0000000..f82d699
--- /dev/null
+++ b/firmware/app/chre/common/Android.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanochre
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ chre_app.c \
+ chre_app_syscalls.c \
+
+include $(BUILD_NANOHUB_APP_STATIC_LIBRARY)
diff --git a/firmware/app/test0.app/Android.mk b/firmware/app/test0.app/Android.mk
new file mode 100644
index 0000000..3e7d649
--- /dev/null
+++ b/firmware/app/test0.app/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := test0
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x8000
+LOCAL_NANO_APP_ID := 476f6f676c548000
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := test_app0.c
+
+include $(BUILD_NANOHUB_APP_EXECUTABLE)
diff --git a/firmware/app/test1.app/Android.mk b/firmware/app/test1.app/Android.mk
new file mode 100644
index 0000000..7d04e3c
--- /dev/null
+++ b/firmware/app/test1.app/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := test1
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x8000
+LOCAL_NANO_APP_ID := 476f6f676c548001
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := test_app1.c
+
+include $(BUILD_NANOHUB_APP_EXECUTABLE)
diff --git a/firmware/build/app_config.mk b/firmware/build/app_config.mk
new file mode 100644
index 0000000..1bb4177
--- /dev/null
+++ b/firmware/build/app_config.mk
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANO_BUILD)/common_config.mk
+
+LOCAL_CFLAGS_cortexm4 += \
+ -fpic \
+ -mno-pic-data-is-text-relative \
+ -msingle-pic-base \
+ -mpic-register=r9 \
+
+LOCAL_NANO_MODULE_TYPE := APP
+LOCAL_OBJCOPY_SECT_cortexm4 := .flash .data .relocs .dynsym
+LOCAL_FORCE_STATIC_EXECUTABLE := false
+
+LOCAL_CFLAGS += \
+ -DAPP_ID=$(LOCAL_NANO_APP_ID) \
+ -DAPP_VERSION=$(LOCAL_NANO_APP_VERSION) \
+ -D__NANOHUB__ \
+
+# Optimization/debug
+LOCAL_CFLAGS += \
+ -Os \
+ -g \
diff --git a/firmware/build/app_executable.mk b/firmware/build/app_executable.mk
new file mode 100644
index 0000000..bfd031d
--- /dev/null
+++ b/firmware/build/app_executable.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_MODULE_SUFFIX := .napp
+include $(NANOHUB_APP_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),APP,$(BUILD_NANOHUB_EXECUTABLE))
diff --git a/firmware/build/app_static_library.mk b/firmware/build/app_static_library.mk
new file mode 100644
index 0000000..0eed67a
--- /dev/null
+++ b/firmware/build/app_static_library.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANOHUB_APP_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),,$(NANO_BUILD)/nanohub_static_library.mk)
diff --git a/firmware/build/bl_config.mk b/firmware/build/bl_config.mk
new file mode 100644
index 0000000..60af389
--- /dev/null
+++ b/firmware/build/bl_config.mk
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANO_BUILD)/common_config.mk
+
+LOCAL_CFLAGS += \
+ -g \
+ -ggdb3 \
+ -D_OS_BUILD_ \
+ -O2
+
+LOCAL_CFLAGS_x86 += \
+ -m32
+
+LOCAL_NANO_MODULE_TYPE := BL
+LOCAL_FORCE_STATIC_EXECUTABLE := true
diff --git a/firmware/build/bl_executable.mk b/firmware/build/bl_executable.mk
new file mode 100644
index 0000000..4cbcfb2
--- /dev/null
+++ b/firmware/build/bl_executable.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_MODULE_SUFFIX := .bin
+
+include $(NANOHUB_BL_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),BL,$(NANO_BUILD)/bl_executable_internal.mk)
diff --git a/firmware/build/bl_executable_internal.mk b/firmware/build/bl_executable_internal.mk
new file mode 100644
index 0000000..23f685f
--- /dev/null
+++ b/firmware/build/bl_executable_internal.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifeq ($(strip $(NANO_VARIANT_NO_BOOTLOADER_$(AUX_OS_VARIANT))),)
+
+LOCAL_WHOLE_STATIC_LIBRARIES += libnanohub_bl_$(AUX_CPU)
+LOCAL_WHOLE_STATIC_LIBRARIES += libnanohub_bl_$(AUX_ARCH)
+LOCAL_WHOLE_STATIC_LIBRARIES += $(NANO_VARIANT_BLCFG_STATIC_LIBRARIES_$(AUX_OS_VARIANT))
+
+LOCAL_SRC_FILES += $(NANO_VARIANT_BLCFG_SRC_FILES_$(AUX_OS_VARIANT))
+
+include $(BUILD_NANOHUB_EXECUTABLE)
+
+endif
diff --git a/firmware/build/bl_static_library.mk b/firmware/build/bl_static_library.mk
new file mode 100644
index 0000000..ead85c6
--- /dev/null
+++ b/firmware/build/bl_static_library.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANOHUB_BL_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),BL,$(NANO_BUILD)/nanohub_static_library.mk)
diff --git a/firmware/build/clear_vars.mk b/firmware/build/clear_vars.mk
new file mode 100644
index 0000000..aaf106e
--- /dev/null
+++ b/firmware/build/clear_vars.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# used by NANOAPP and NANOHUB OS
+LOCAL_NANO_MODULE_TYPE :=
+LOCAL_NANO_IS_VARIANT :=
+
+# used by NANOAPP only
+LOCAL_NANO_APP_ID :=
+LOCAL_NANO_APP_VERSION :=
+LOCAL_NANO_APP_NO_POSTPROCESS :=
+LOCAL_NANO_APP_UNSIGNED :=
+
+include $(CLEAR_VARS)
diff --git a/firmware/build/common_config.mk b/firmware/build/common_config.mk
new file mode 100644
index 0000000..e00fb7d
--- /dev/null
+++ b/firmware/build/common_config.mk
@@ -0,0 +1,72 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_CFLAGS += \
+ -Wall \
+ -Werror \
+ \
+ -Waddress \
+ -Wempty-body \
+ -Wenum-compare \
+ -Wlogical-op \
+ -Wmissing-declarations \
+ -Wpointer-arith \
+ -Wshadow \
+ \
+ -fdata-sections \
+ -ffunction-sections \
+ -fno-strict-aliasing \
+ -fno-unwind-tables \
+ -fstack-reuse=all \
+ -fvisibility=hidden \
+
+LOCAL_CPPFLAGS += \
+ -std=c++11 \
+ -fno-exceptions \
+ -fno-rtti \
+
+LOCAL_LDFLAGS += \
+ -nostartfiles \
+ -Wl,--gc-sections \
+ -Wl,--no-undefined \
+ -Wl,--no-allow-shlib-undefined \
+
+LOCAL_CFLAGS_cortexm4 += \
+ -mthumb \
+ -mcpu=cortex-m4 \
+ -march=armv7e-m \
+ -mfloat-abi=softfp \
+ -mfpu=fpv4-sp-d16 \
+ -mno-thumb-interwork \
+ -ffast-math \
+ -fshort-double \
+ -fsingle-precision-constant \
+ -DARM \
+ -DUSE_NANOHUB_FLOAT_RUNTIME \
+ -DARM_MATH_CM4 \
+ -D__FPU_PRESENT \
+ -DCPU_NUM_PERSISTENT_RAM_BITS=32 \
+
+LOCAL_CFLAGS_x86 += \
+ -march=core2 \
+ -msse2 \
+ -DSYSCALL_VARARGS_PARAMS_PASSED_AS_PTRS \
+
+LOCAL_CFLAGS_stm32 += \
+ -DPLATFORM_HW_VER=0 \
+
+# CHRE-specific
+LOCAL_CFLAGS += -DCHRE_MESSAGE_TO_HOST_MAX_SIZE=128
diff --git a/firmware/build/config.mk b/firmware/build/config.mk
new file mode 100644
index 0000000..f1b921b
--- /dev/null
+++ b/firmware/build/config.mk
@@ -0,0 +1,216 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+NANO_BUILD := $(NANOHUB_OS_PATH)/build
+
+NANO_OS := nanohub
+NANO_ALL_CLASSES := phone watch
+NANO_ALL_TARGETS := APP BL OS
+
+NANO_ALL_ALL := $(AUX_ALL_VARIANTS) $(AUX_ALL_OSES) $(AUX_ALL_ARCHS) $(AUX_ALL_SUBARCHS) $(AUX_ALL_CPUS) $(NANO_ALL_CLASSES) $(NANO_ALL_TARGETS)
+
+GLOBAL_NANO_OBJCOPY_FLAGS_cortexm4 := -I elf32-littlearm -O binary
+
+CLEAR_NANO_VARS := $(NANO_BUILD)/clear_vars.mk
+NANOHUB_BL_CONFIG := $(NANO_BUILD)/bl_config.mk
+NANOHUB_OS_CONFIG := $(NANO_BUILD)/os_config.mk
+NANOHUB_APP_CONFIG := $(NANO_BUILD)/app_config.mk
+
+BUILD_NANOHUB_BL_STATIC_LIBRARY := $(NANO_BUILD)/bl_static_library.mk
+BUILD_NANOHUB_OS_STATIC_LIBRARY := $(NANO_BUILD)/os_static_library.mk
+BUILD_NANOHUB_APP_STATIC_LIBRARY := $(NANO_BUILD)/app_static_library.mk
+BUILD_NANOHUB_EXECUTABLE := $(NANO_BUILD)/nanohub_executable.mk
+BUILD_NANOHUB_BL_EXECUTABLE := $(NANO_BUILD)/bl_executable.mk
+BUILD_NANOHUB_OS_EXECUTABLE := $(NANO_BUILD)/os_executable.mk
+BUILD_NANOHUB_OS_IMAGE := $(NANO_BUILD)/os_image.mk
+BUILD_NANOHUB_APP_EXECUTABLE := $(NANO_BUILD)/app_executable.mk
+
+NANOAPP_POSTPROCESS := $(HOST_OUT_EXECUTABLES)/nanoapp_postprocess
+NANOAPP_SIGN := $(HOST_OUT_EXECUTABLES)/nanoapp_sign
+
+# $(1) - optional value to assign to
+# pass empty to clear for repeated includes
+# pass some definitive invalid value otherwise (after last repeat)
+define nano-reset-built-env
+$(eval OVERRIDE_BUILT_MODULE_PATH:=$(1)) \
+$(eval LOCAL_BUILT_MODULE:=$(1)) \
+$(eval LOCAL_INSTALLED_MODULE:=$(1)) \
+$(eval LOCAL_INTERMEDIATE_TARGETS:=$(1))
+endef
+
+# variant may declare it's class; default is phone
+define nano-variant-class
+$(if $(filter $(NANO_ALL_CLASSES),$(NANO_CLASS_$(AUX_OS_VARIANT))),$(NANO_CLASS_$(AUX_OS_VARIANT)),phone)
+endef
+
+# $(1) - target file
+# $(2) - list of dependencies
+define nano-gen-linker-script-from-list-body
+ mkdir -p $(dir $(1)) && \
+ rm -f $(1).tmp && \
+ touch $(1).tmp && \
+ $(foreach file,$(2),echo "INCLUDE $(file)" >> $(1).tmp &&) \
+ mv -f $(1).tmp $(1)
+endef
+
+# $(1) - target file
+# $(2) - list of dependencies
+define nano-gen-linker-script-from-list
+$(1): $(2)
+ $(call nano-gen-linker-script-from-list-body,$(1),$(2))
+endef
+
+# create linker script rule
+#
+# $(1) - target file
+# $(2) - { os | bl }
+# $(3) - platform name
+# $(4) - platform class
+# $(5) - platform dir
+define nano-gen-linker-script
+$(eval $(call nano-gen-linker-script-from-list,$(1),$(patsubst %,$(NANOHUB_OS_PATH)/os/platform/$(5)/lkr/%.lkr,$(3).map $(4).$(2) $(4).common)))
+endef
+
+# create linker script rule
+#
+# $(1) - target file
+# $(2) - bl|os
+# $(3) - platform name
+# $(4) - platform class
+# $(5) - platform dir
+#
+# NOTE: ($(2), $(3) - unused; keep for argument compatibility with nano-gen-linker-script
+define nano-gen-linker-script-native
+$(eval $(call nano-gen-linker-script-from-list,$(1),$(NANOHUB_OS_PATH)/os/platform/$(5)/lkr/$(4).extra.lkr))
+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.
+#
+# workflow is as follows:
+# before starting iterations:
+# all the LOCAL_<var> and LOCAL_<var>_<cpu,arch,subarch,variant,os,class> from NANO_VAR_LIST
+# are copied to LOCAL_NANO_*; original LOCAL_* are erased to avoid conflicts fith underlaying build which also does suffix handling.
+# this part is performed by nano-user-vars-save-all
+# on every iteration, before includeing file:
+# all the LOCAL_NANO_<var>_<cpu,arch,subarch,variant,os,class> vars are loaded for the current variant,
+# and then concatenated all toghether and also with
+# NANO_VARIANT_<target>_<var>_<variant> (where target is OS or BL for system builds, or APP for nanoapp builds) and
+# NANO_VARIANT_<var>_<variant>; result is stored in LOCAL_<var>
+# this var is used by underlaying build infrastructure as usual
+# this part is performed by nano-user-vars-load-all
+# on every iteration, after includeing file:
+# reset "BUILT" variables in order to let next iteration going
+# after all iterations done:
+# erase all volatile AUX* enviraonment, cleanup all the LOCAL* and LOCAL_NANO* vars
+NANO_VAR_LIST := \
+ C_INCLUDES \
+ CFLAGS \
+ ASFLAGS \
+ CPPFLAGS \
+ SRC_FILES \
+ STATIC_LIBRARIES \
+ WHOLE_STATIC_LIBRARIES \
+ LDFLAGS \
+ OBJCOPY_SECT \
+
+# collect anything that user might define per-cpu, per-arch etc
+# $(1) - one of $(NANO_VAR_LIST)
+# $(2) - optional: one of { APP,BL,OS }
+define nano-user-var-load
+$(eval LOCAL_$(1) := \
+ $(LOCAL_NANO_$(1)) \
+ $(NANO_VARIANT_$(1)_$(AUX_OS_VARIANT)) \
+ $(NANO_VARIANT_$(2)_$(1)_$(AUX_OS_VARIANT)) \
+ $(LOCAL_NANO_$(1)_$(AUX_OS_VARIANT)) \
+ $(LOCAL_NANO_$(1)_$(AUX_CPU)) \
+ $(LOCAL_NANO_$(1)_$(AUX_ARCH)) \
+ $(LOCAL_NANO_$(1)_$(AUX_SUBARCH)) \
+ $(LOCAL_NANO_$(1)_$(AUX_OS)) \
+ $(LOCAL_NANO_$(1)_$(call nano-variant-class,$(AUX_OS_VARIANT))) \
+ $(LOCAL_NANO_$(1)_$(LOCAL_NANO_MODULE_TYPE)) \
+)
+endef
+
+define nano-user-var-reset-final
+$(eval LOCAL_$(1):=) \
+$(eval LOCAL_NANO_$(1):=) \
+$(foreach v,$(NANO_ALL_ALL),\
+ $(eval LOCAL_NANO_$(1)_$(v):=) \
+ $(eval LOCAL_$(1)_$(v):=) \
+)
+endef
+
+define nano-user-vars-reset-final
+$(foreach _nuvrf_var,$(NANO_VAR_LIST),$(call nano-user-var-reset-final,$(_nuvrf_var)))
+endef
+
+# $(1) - optional: one of APP,BL,OS
+define nano-user-vars-load-all
+$(foreach _nuvla_var,$(NANO_VAR_LIST),$(call nano-user-var-load,$(_nuvla_var),$(1)))
+endef
+
+define nano-user-vars-save-all
+$(foreach _nuvsa_var,$(NANO_VAR_LIST),\
+ $(eval LOCAL_NANO_$(_nuvsa_var) := $(LOCAL_$(_nuvsa_var))) \
+ $(eval LOCAL_$(_nuvsa_var):=) \
+ $(foreach v,$(NANO_ALL_ALL),\
+ $(eval LOCAL_NANO_$(_nuvsa_var)_$(v):=$(LOCAL_$(_nuvsa_var)_$(v))) \
+ $(eval LOCAL_$(_nuvsa_var)_$(v):=) \
+ ) \
+)
+endef
+
+# $(1) - variant list
+# $(2) - optional: one of APP,BL,OS
+# $(3) - path to makefile which has to be included for each variant
+define for-each-variant-unchecked
+ $(eval AUX_RECURSIVE_VARIANT_LIST:=$(1)) \
+ $(call nano-user-vars-save-all) \
+ $(foreach _fev_variant,$(1),\
+ $(call aux-variant-load-env,$(_fev_variant)) \
+ $(call nano-user-vars-load-all,$(2)) \
+ $(info $(LOCAL_PATH): $(LOCAL_MODULE): OS=$(AUX_OS) ARCH=$(AUX_ARCH) SUBARCH=$(AUX_SUBARCH) CPU=$(AUX_CPU)) \
+ $(eval include $(3)) \
+ $(call nano-reset-built-env,) \
+ ) \
+ $(eval AUX_RECURSIVE_VARIANT_LIST:=) \
+ $(call aux-variant-load-env,) \
+ $(call nano-reset-built-env,$(LOCAL_MODULE)-module-is-poisoned) \
+ $(call nano-user-vars-reset-final) \
+
+endef
+
+# $(1),$(2) - two sets to compare for equality
+# returns true, if sets have the same items (not necessarily in the same order)
+# returns empty string on mismatch
+define equal-sets
+$(if $(strip $(filterout $(1),$(2))$(filterout $(2),$(1))),,true)
+endef
+
+# this call would include a given makefile in the loop,
+# and would iterate through available variants from $(1)
+# $(1) - variant list
+# $(2) - optional: one of APP,BL,OS
+# $(3) - path to makefile to include for each variant
+define for-each-variant
+$(if $(AUX_RECURSIVE_VARIANT_LIST),$(if \
+ $(call equal-sets,$(AUX_RECURSIVE_VARIANT_LIST),$(1)),,\
+ $(error $(LOCAL_PATH): Recursive variant list mismatch: "$(AUX_RECURSIVE_VARIANT_LIST)" and "$(1))),\
+ $(call for-each-variant-unchecked,$(1),$(2),$(3)))
+endef
+
+$(info NANOHUB OS config loaded)
diff --git a/firmware/build/config_internal.mk b/firmware/build/config_internal.mk
new file mode 100644
index 0000000..533d38f
--- /dev/null
+++ b/firmware/build/config_internal.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_C_INCLUDES += \
+ $(NANOHUB_OS_PATH)/os/inc \
+ $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/inc \
+ $(NANOHUB_OS_PATH)/os/cpu/$(AUX_CPU)/inc \
+ $(NANOHUB_OS_PATH)/../lib/include \
+ $(NANOHUB_OS_PATH)/../inc \
+
+LOCAL_WHOLE_STATIC_LIBRARIES_BL += libnanohub_bl_$(AUX_CPU)
+LOCAL_WHOLE_STATIC_LIBRARIES_BL += libnanohub_bl_$(AUX_ARCH)
+
+LOCAL_WHOLE_STATIC_LIBRARIES_OS += libnanohub_os_$(AUX_CPU)
+LOCAL_WHOLE_STATIC_LIBRARIES_OS += libnanohub_os_$(AUX_ARCH)
diff --git a/firmware/build/nanohub_executable.mk b/firmware/build/nanohub_executable.mk
new file mode 100644
index 0000000..b71f8c6
--- /dev/null
+++ b/firmware/build/nanohub_executable.mk
@@ -0,0 +1,140 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(BUILD_SYSTEM)/aux_toolchain.mk
+
+ifeq ($(AUX_BUILD_NOT_COMPATIBLE),)
+
+include $(NANO_BUILD)/config_internal.mk
+
+intermediates := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX)
+
+nanohub_unchecked_elf := $(intermediates)/UNCHECKED/$(LOCAL_MODULE).elf
+nanohub_checked_elf := $(intermediates)/CHECKED/$(LOCAL_MODULE).elf
+nanohub_checked_bin := $(intermediates)/CHECKED/$(LOCAL_MODULE).bin
+
+LOCAL_CUSTOM_BUILD_STEP_INPUT := $(nanohub_unchecked_elf)
+
+
+gen := $(call generated-sources-dir-for,EXECUTABLES,$(LOCAL_MODULE),AUX)
+
+linker_script:=
+
+ifeq ($(LOCAL_NANO_MODULE_TYPE),APP)
+linker_script := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/lkr/app.lkr
+endif
+
+ifeq ($(LOCAL_NANO_MODULE_TYPE),BL)
+ifeq ($(AUX_ARCH),stm32)
+linker_script := $(gen)/bl.lkr
+$(call nano-gen-linker-script,$(linker_script),bl,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
+endif
+endif
+
+ifeq ($(LOCAL_NANO_MODULE_TYPE),OS)
+ifeq ($(AUX_ARCH),native)
+linker_script := $(gen)/os.lkr
+$(call nano-gen-linker-script-native,$(linker_script),os,$(AUX_SUBARCH),native,$(AUX_ARCH))
+endif
+ifeq ($(AUX_ARCH),stm32)
+linker_script := $(gen)/os.lkr
+$(call nano-gen-linker-script,$(linker_script),os,$(AUX_SUBARCH),stm32f4xx,$(AUX_ARCH))
+endif
+endif
+
+ifeq ($(linker_script),)
+$(error $(LOCAL_PATH): $(LOCAL_MODULE): linker script is not defined for ARCH=$(AUX_ARCH) TYPE=$(LOCAL_NANO_MODULE_TYPE))
+endif
+
+LOCAL_ADDITIONAL_DEPENDENCIES += $(linker_script)
+LOCAL_LDFLAGS += -T $(linker_script)
+
+$(nanohub_checked_elf): $(nanohub_unchecked_elf)
+ $(hide)echo "nanohub Symcheck $@ <= $<"
+ $(copy-file-to-target)
+nanohub_output := $(nanohub_checked_elf)
+
+# objcopy is per-cpu only
+objcopy_params:=
+
+# optional objcopy step
+ifneq ($(strip $(LOCAL_OBJCOPY_SECT)),)
+
+objcopy_params := $(GLOBAL_NANO_OBJCOPY_FLAGS) $(GLOBAL_NANO_OBJCOPY_FLAGS_$(AUX_CPU)) $(foreach sect,$(LOCAL_OBJCOPY_SECT), -j $(sect))
+
+$(nanohub_checked_bin): PRIVATE_OBJCOPY_ARGS := $(objcopy_params)
+$(nanohub_checked_bin): PRIVATE_MODULE := $(LOCAL_MODULE)
+$(nanohub_checked_bin): PRIVATE_OBJCOPY := $(AUX_OBJCOPY)
+$(nanohub_checked_bin): $(nanohub_output)
+ $(hide)echo "nanohub OBJCOPY $(PRIVATE_MODULE) ($@)"
+ $(hide)$(PRIVATE_OBJCOPY) $(PRIVATE_OBJCOPY_ARGS) $< $@
+nanohub_output := $(nanohub_checked_bin)
+
+objcopy_params :=
+objcopy_sect :=
+else
+LOCAL_NANO_APP_NO_POSTPROCESS := true
+LOCAL_NANO_APP_UNSIGNED := true
+endif
+
+ifeq ($(LOCAL_NANO_MODULE_TYPE),APP)
+
+nanohub_napp := $(intermediates)/CHECKED/$(LOCAL_MODULE).napp
+nanohub_signed_napp := $(intermediates)/CHECKED/$(LOCAL_MODULE).signed.napp
+
+# postprocess only works on BIN; if it is used, objcopy must be used as well
+ifneq ($(LOCAL_NANO_APP_NO_POSTPROCESS),true)
+$(if $(LOCAL_OBJCOPY_SECT),,\
+ $(error $(LOCAL_PATH): $(LOCAL_MODULE): nanoapp postprocess step requires LOCAL_OBJCOPY_SECT defined))
+
+$(nanohub_napp): PRIVATE_NANO_APP_ID := $(LOCAL_NANO_APP_ID)
+$(nanohub_napp): PRIVATE_NANO_APP_VER := $(LOCAL_NANO_APP_VERSION)
+
+$(nanohub_napp): $(nanohub_output) $(NANOAPP_POSTPROCESS)
+ $(hide)echo "nanoapp POSTPROCESS $@ <= $<"
+ $(hide)$(NANOAPP_POSTPROCESS) -a $(PRIVATE_NANO_APP_ID) $< $@
+nanohub_output := $(nanohub_napp)
+endif # NO_POSTPROCESS
+
+ifneq ($(LOCAL_NANO_APP_UNSIGNED),true)
+$(if $(filter true,$(LOCAL_NANO_APP_NO_POSTPROCESS)),\
+ $(error $(LOCAL_PATH): $(LOCAL_MODULE): nanoapp sign step requires nanoapp postprocess))
+
+nanohub_pvt_key := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/misc/debug.privkey
+nanohub_pub_key := $(NANOHUB_OS_PATH)/os/platform/$(AUX_ARCH)/misc/debug.pubkey
+
+$(nanohub_signed_napp): PRIVATE_PVT_KEY := $(nanohub_pvt_key)
+$(nanohub_signed_napp): PRIVATE_PUB_KEY := $(nanohub_pub_key)
+
+$(nanohub_signed_napp): $(nanohub_napp) $(NANOAPP_SIGN)
+ $(hide)echo "nanoapp SIGN $@ <= $<"
+ $(hide)$(NANOAPP_SIGN) -s -e $(PRIVATE_PVT_KEY) -m $(PRIVATE_PUB_KEY) $< $@
+
+nanohub_output := $(nanohub_signed_napp)
+endif # !UNSIGNED
+
+endif # TYPE == APP
+
+LOCAL_CUSTOM_BUILD_STEP_OUTPUT := $(nanohub_output)
+
+###############################
+include $(BUILD_AUX_EXECUTABLE)
+###############################
+
+LOCAL_CUSTOM_BUILD_STEP_INPUT :=
+LOCAL_CUSTOM_BUILD_STEP_OUTPUT :=
+
+endif # AUX_BUILD_NOT_COMPATIBLE
diff --git a/firmware/build/nanohub_static_library.mk b/firmware/build/nanohub_static_library.mk
new file mode 100644
index 0000000..8421b6b
--- /dev/null
+++ b/firmware/build/nanohub_static_library.mk
@@ -0,0 +1,24 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(BUILD_SYSTEM)/aux_toolchain.mk
+
+ifeq ($(AUX_BUILD_NOT_COMPATIBLE),)
+
+include $(NANO_BUILD)/config_internal.mk
+include $(BUILD_AUX_STATIC_LIBRARY)
+
+endif # AUX_BUILD_NOT_COMPATIBLE
diff --git a/firmware/build/os_config.mk b/firmware/build/os_config.mk
new file mode 100644
index 0000000..2415711
--- /dev/null
+++ b/firmware/build/os_config.mk
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANO_BUILD)/common_config.mk
+
+LOCAL_CFLAGS += \
+ -g \
+ -ggdb3 \
+ -D_OS_BUILD_ \
+ -O2
+
+LOCAL_CFLAGS_x86 += \
+ -m32
+
+LOCAL_NANO_MODULE_TYPE := OS
+LOCAL_FORCE_STATIC_EXECUTABLE := true
diff --git a/firmware/build/os_executable.mk b/firmware/build/os_executable.mk
new file mode 100644
index 0000000..1478664
--- /dev/null
+++ b/firmware/build/os_executable.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_MODULE_SUFFIX := .bin
+
+include $(NANOHUB_OS_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),OS,$(NANO_BUILD)/os_executable_internal.mk)
diff --git a/firmware/build/os_executable_internal.mk b/firmware/build/os_executable_internal.mk
new file mode 100644
index 0000000..3acd8ad
--- /dev/null
+++ b/firmware/build/os_executable_internal.mk
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_WHOLE_STATIC_LIBRARIES += libnanohub_os_$(AUX_CPU)
+LOCAL_WHOLE_STATIC_LIBRARIES += libnanohub_os_$(AUX_ARCH)
+LOCAL_WHOLE_STATIC_LIBRARIES += $(NANO_VARIANT_OSCFG_STATIC_LIBRARIES_$(AUX_OS_VARIANT))
+
+LOCAL_SRC_FILES += $(NANO_VARIANT_OSCFG_SRC_FILES_$(AUX_OS_VARIANT))
+
+include $(BUILD_NANOHUB_EXECUTABLE)
+
+ifeq ($(AUX_BUILD_NOT_COMPATIBLE),)
+
+INSTALLED_AUX_TARGETS += $(AUX_OUT_EXECUTABLES_$(AUX_OS_VARIANT))/nanohub.full.bin
+
+nano_bl_bin := $(AUX_OUT_EXECUTABLES_$(AUX_OS_VARIANT))/nanohub_bl.bin
+nano_os_bin := $(AUX_OUT_EXECUTABLES_$(AUX_OS_VARIANT))/nanohub_os.bin
+
+nano_os_components :=
+
+ifneq ($(NANO_VARIANT_NO_BOOTLOADER_$(AUX_OS_VARIANT)),true)
+nano_os_components += $(nano_bl_bin)
+endif
+
+nano_os_components += $(nano_os_bin)
+
+$(AUX_OUT_EXECUTABLES_$(AUX_OS_VARIANT))/nanohub.full.bin: $(nano_os_components)
+ @echo "$(AUX_DISPLAY) GEN NANOHUB OS IMAGE: $(notdir $@) <= $(foreach f,$^,$(notdir $(f))")
+ $(hide) cat $^ > $@
+
+endif
diff --git a/firmware/build/os_static_library.mk b/firmware/build/os_static_library.mk
new file mode 100644
index 0000000..0299a25
--- /dev/null
+++ b/firmware/build/os_static_library.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(NANOHUB_OS_CONFIG)
+
+my_variants := $(LOCAL_NANO_VARIANT_LIST)
+
+ifeq ($(strip $(my_variants)),)
+# default is to use all variants supported by this OS
+my_variants := $(AUX_OS_VARIANT_LIST_$(NANO_OS))
+endif
+
+$(call for-each-variant,$(my_variants),OS,$(NANO_BUILD)/nanohub_static_library.mk)
diff --git a/firmware/external/Android.mk b/firmware/external/Android.mk
new file mode 100644
index 0000000..31baa2b
--- /dev/null
+++ b/firmware/external/Android.mk
@@ -0,0 +1,70 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanomath_os
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ arm/arm_sin_cos_f32.c \
+ freebsd/lib/msun/src/e_atan2f.c \
+ freebsd/lib/msun/src/e_expf.c \
+ freebsd/lib/msun/src/s_atanf.c \
+
+
+LOCAL_CFLAGS := \
+ -DFLT_EVAL_METHOD=0 \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/freebsd/lib/msun/src \
+ $(NANOHUB_OS_PATH)/inc \
+ $(NANOHUB_OS_PATH)/src/platform/$(AUX_ARCH)/inc \
+ $(NANOHUB_OS_PATH)/src/platform/$(AUX_ARCH)/inc/plat/cmsis \
+ $(NANOHUB_OS_PATH)/src/cpu/$(AUX_CPU)/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_PATH)/freebsd/inc \
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanomath
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ arm/arm_sin_cos_f32.c \
+ freebsd/lib/msun/src/e_atan2f.c \
+ freebsd/lib/msun/src/e_expf.c \
+ freebsd/lib/msun/src/s_atanf.c \
+
+LOCAL_CFLAGS := \
+ -DFLT_EVAL_METHOD=0 \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/freebsd/lib/msun/src \
+ $(NANOHUB_OS_PATH)/inc \
+ $(NANOHUB_OS_PATH)/src/platform/$(AUX_ARCH)/inc \
+ $(NANOHUB_OS_PATH)/src/platform/$(AUX_ARCH)/inc/plat/cmsis \
+ $(NANOHUB_OS_PATH)/src/cpu/$(AUX_CPU)/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_PATH)/freebsd/inc \
+
+include $(BUILD_NANOHUB_APP_STATIC_LIBRARY)
diff --git a/firmware/lib/lib.mk b/firmware/lib/lib.mk
index c31b289..e2a9ae6 100644
--- a/firmware/lib/lib.mk
+++ b/firmware/lib/lib.mk
@@ -1,3 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
################################################################################
#
# Nanoapp Libc/Libm build helper script
diff --git a/firmware/lib/libc/Android.mk b/firmware/lib/libc/Android.mk
new file mode 100644
index 0000000..0b299ba
--- /dev/null
+++ b/firmware/lib/libc/Android.mk
@@ -0,0 +1,48 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+src_files := \
+ bcopy.c \
+ memcmp.c \
+ memmove.c \
+ memset.c \
+ strcasecmp.c \
+ strlen.c \
+ strncpy.c \
+
+LOCAL_MODULE := libnanolibc_os
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(src_files)
+
+LOCAL_SRC_FILES_cortexm4 += memcpy-armv7m.S
+LOCAL_SRC_FILES_x86 += memcpy.c
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanolibc
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(src_files)
+LOCAL_SRC_FILES += memcpy.c
+
+include $(BUILD_NANOHUB_APP_STATIC_LIBRARY)
diff --git a/firmware/lib/libm/Android.mk b/firmware/lib/libm/Android.mk
new file mode 100644
index 0000000..b91366a
--- /dev/null
+++ b/firmware/lib/libm/Android.mk
@@ -0,0 +1,50 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanolibm
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ ef_asin.c \
+ ef_atan2.c \
+ ef_fmod.c \
+ ef_pow.c \
+ ef_rem_pio2.c \
+ ef_sqrt.c \
+ kf_cos.c \
+ kf_rem_pio2.c \
+ kf_sin.c \
+ sf_atan.c \
+ sf_cos.c \
+ sf_floor.c \
+ sf_fpclassify.c \
+ sf_round.c \
+ sf_scalbn.c \
+ sf_sin.c \
+ wf_asin.c \
+ wf_atan2.c \
+ wf_fmod.c \
+ wf_pow.c \
+
+LOCAL_CFLAGS := \
+ -DARM_MATH_CM4 \
+ -D__FPU_PRESENT\
+
+include $(BUILD_NANOHUB_APP_STATIC_LIBRARY)
diff --git a/firmware/linux_aux_variant_config.mk b/firmware/linux_aux_variant_config.mk
new file mode 100644
index 0000000..d3559a8
--- /dev/null
+++ b/firmware/linux_aux_variant_config.mk
@@ -0,0 +1,49 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# only locally defined variables can be used at this time
+
+my_variant := linux
+
+AUX_OS_$(my_variant) := nanohub
+AUX_ARCH_$(my_variant) := native
+AUX_SUBARCH_$(my_variant) := native
+AUX_CPU_$(my_variant) := x86
+
+# variant supports building OS bootloader, main OS image and application as targets
+# target should one of the following:
+# "" (empty) -- applies to all (OS, BL, APP)
+# _BL -- applies to OS bootloader target build only
+# _OS -- applies to OS image target build only
+# _APP -- applies to application target build only
+#
+# the following variables may be defined in variant script for any target:
+# NANO_VARIANT<target>_CFLAGS_<variant>
+# NANO_VARIANT<target>_C_INCLUDES_<variant>
+# NANO_VARIANT<target>_STATIC_LIBRARIRES_<variant>
+# NANO_VARIANT<target>_WHOLE_STATIC_LIBRARIRES_<variant>
+#
+# the following may be defined for _OS and _BL only, to control
+# what additional source files need to be included in the build;
+# the file paths in this list are relative to the target (_OS or _BL) LOCAL_PATH;
+# NANO_VARIANT<target>_SRC_FILES_<variant>
+
+# 100K heap
+NANO_VARIANT_CFLAGS_$(my_variant) := -DHEAP_SIZE=102400
+
+NANO_VARIANT_C_INCLUDES_$(my_variant) := device/google/contexthub/firmware/variant/linux/inc
+
+NANO_VARIANT_NO_BOOTLOADER_$(my_variant) := true
diff --git a/firmware/lunchbox_aux_variant_config.mk b/firmware/lunchbox_aux_variant_config.mk
new file mode 100644
index 0000000..b9043dd
--- /dev/null
+++ b/firmware/lunchbox_aux_variant_config.mk
@@ -0,0 +1,82 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# only locally defined variables can be used at this time
+
+my_variant := lunchbox
+
+AUX_OS_$(my_variant) := nanohub
+AUX_ARCH_$(my_variant) := stm32
+AUX_SUBARCH_$(my_variant) := stm32f411
+AUX_CPU_$(my_variant) := cortexm4
+
+# variant supports building OS bootloader, main OS image and application as targets
+# target should one of the following:
+# "" (empty) -- applies to all targets
+# _BL -- applies to OS bootloader target build only
+# _OS -- applies to OS image target build only
+# _APP -- applies to application target build only
+#
+# special targets:
+# _OSCFG - apply only at build stage of OS binary image
+# _BLCFG - apply only at build stage of BL binary image
+#
+# the following variables may be defined in variant script for any target:
+# NANO_VARIANT<target>_CFLAGS_<variant>
+# NANO_VARIANT<target>_C_INCLUDES_<variant>
+# NANO_VARIANT<target>_STATIC_LIBRARIRES_<variant>
+# NANO_VARIANT<target>_WHOLE_STATIC_LIBRARIRES_<variant>
+#
+# the following may be defined for _OS and _BL only, to control
+# what additional source files need to be included in the build;
+# the file paths in this list are relative to the target (_OS or _BL) LOCAL_PATH;
+# NANO_VARIANT<target>_SRC_FILES_<variant>
+
+NANO_VARIANT_OSCFG_STATIC_LIBRARIES_$(my_variant) := libnanohub_os_$(my_variant)
+
+NANO_VARIANT_OS_CFLAGS_$(my_variant) :=
+
+NANO_VARIANT_OS_CFLAGS_$(my_variant) += \
+ -DUSE_BMM150 \
+ -DMAG_SLAVE_PRESENT \
+
+#GPIOB0 is debug uart at 2MBps
+NANO_VARIANT_OS_CFLAGS_$(my_variant) += -DDEBUG_UART_PIN=16
+
+#'Lu' -> lunchbox
+NANO_VARIANT_CFLAGS_$(my_variant) += -DPLATFORM_HW_TYPE=0x4C75
+
+NANO_VARIANT_C_INCLUDES_$(my_variant) := \
+ device/google/contexthub/firmware/variant/lunchbox/inc \
+
+# this is relative to NANOHUB_OS_PATH
+NANO_VARIANT_OSCFG_SRC_FILES_$(my_variant) := \
+ os/algos/fusion.c \
+ os/algos/mag_cal.c \
+ os/algos/mat.c \
+ os/algos/quat.c \
+ os/algos/time_sync.c \
+ os/algos/vec.c \
+ os/drivers/ams_tmd2772/ams_tmd2772.c \
+ os/drivers/bosch_bmi160/bosch_bmi160.c \
+ os/drivers/bosch_bmi160/bosch_bmm150_slave.c \
+ os/drivers/bosch_bmp280/bosch_bmp280.c \
+ os/drivers/hall/hall.c \
+ os/drivers/orientation/orientation.c \
+ os/drivers/rohm_rpr0521/rohm_rpr0521.c \
+ os/drivers/tilt_detection/tilt_detection.c \
+ os/drivers/vsync/vsync.c \
+ os/drivers/window_orientation/window_orientation.c \
diff --git a/firmware/nanohub_aux_os_config.mk b/firmware/nanohub_aux_os_config.mk
new file mode 100644
index 0000000..79cbdf0
--- /dev/null
+++ b/firmware/nanohub_aux_os_config.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+NANOHUB_OS_PATH := device/google/contexthub/firmware
+
+include $(NANOHUB_OS_PATH)/build/config.mk
diff --git a/firmware/nucleo_aux_variant_config.mk b/firmware/nucleo_aux_variant_config.mk
new file mode 100644
index 0000000..b5b8515
--- /dev/null
+++ b/firmware/nucleo_aux_variant_config.mk
@@ -0,0 +1,74 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# only locally defined variables can be used at this time
+
+my_variant := nucleo
+
+AUX_OS_$(my_variant) := nanohub
+AUX_ARCH_$(my_variant) := stm32
+AUX_SUBARCH_$(my_variant) := stm32f411
+AUX_CPU_$(my_variant) := cortexm4
+
+# variant supports building OS bootloader, main OS image and application as targets
+# target should one of the following:
+# "" (empty) -- applies to all targets
+# _BL -- applies to OS bootloader target build only
+# _OS -- applies to OS image target build only
+# _APP -- applies to application target build only
+#
+# the following variables may be defined in variant script for any target:
+# NANO_VARIANT<target>_CFLAGS_<variant>
+# NANO_VARIANT<target>_C_INCLUDES_<variant>
+# NANO_VARIANT<target>_STATIC_LIBRARIRES_<variant>
+# NANO_VARIANT<target>_WHOLE_STATIC_LIBRARIRES_<variant>
+#
+# the following may be defined for _OS and _BL only, to control
+# what additional source files need to be included in the build;
+# the file paths in this list are relative to the target (_OS or _BL) LOCAL_PATH;
+# NANO_VARIANT<target>_SRC_FILES_<variant>
+
+NANO_VARIANT_OSCFG_STATIC_LIBRARIES_$(my_variant) := libnanohub_os_$(my_variant)
+
+NANO_VARIANT_OS_CFLAGS_$(my_variant) := \
+ -DUSE_BMM150 \
+ -DMAG_SLAVE_PRESENT \
+ -DDEBUG_SWD \
+
+#'Nu' ->nucleo
+NANO_VARIANT_CFLAGS_$(my_variant) := -DPLATFORM_HW_TYPE=0x4E75
+
+NANO_VARIANT_C_INCLUDES_$(my_variant) := \
+ device/google/contexthub/firmware/variant/nucleo/inc \
+
+# this is relative to NANOHUB_OS_PATH
+NANO_VARIANT_OSCFG_SRC_FILES_$(my_variant) := \
+ os/algos/fusion.c \
+ os/algos/mag_cal.c \
+ os/algos/mat.c \
+ os/algos/quat.c \
+ os/algos/time_sync.c \
+ os/algos/vec.c \
+ os/drivers/ams_tmd2772/ams_tmd2772.c \
+ os/drivers/bosch_bmi160/bosch_bmi160.c \
+ os/drivers/bosch_bmi160/bosch_bmm150_slave.c \
+ os/drivers/bosch_bmp280/bosch_bmp280.c \
+ os/drivers/hall/hall.c \
+ os/drivers/orientation/orientation.c \
+ os/drivers/rohm_rpr0521/rohm_rpr0521.c \
+ os/drivers/tilt_detection/tilt_detection.c \
+ os/drivers/vsync/vsync.c \
+ os/drivers/window_orientation/window_orientation.c \
diff --git a/firmware/os/cpu/cortexm4/Android.mk b/firmware/os/cpu/cortexm4/Android.mk
new file mode 100644
index 0000000..a3c3875
--- /dev/null
+++ b/firmware/os/cpu/cortexm4/Android.mk
@@ -0,0 +1,47 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+########################################################
+# COMMON OS & BL defs
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_bl_cortexm4
+LOCAL_AUX_CPU := cortexm4
+
+LOCAL_SRC_FILES := \
+ atomic.c \
+ atomicBitset.c \
+
+include $(BUILD_NANOHUB_BL_STATIC_LIBRARY)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_cortexm4
+LOCAL_AUX_CPU := cortexm4
+
+LOCAL_SRC_FILES := \
+ appSupport.c \
+ atomic.c \
+ atomicBitset.c \
+ cpu.c \
+ cpuMath.c \
+ pendsv.c \
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/os/cpu/x86/Android.mk b/firmware/os/cpu/x86/Android.mk
new file mode 100644
index 0000000..6a9476b
--- /dev/null
+++ b/firmware/os/cpu/x86/Android.mk
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+########################################################
+# COMMON OS & BL defs
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_x86
+LOCAL_AUX_CPU := x86
+
+LOCAL_SRC_FILES := \
+ atomic.c \
+ atomicBitset.c \
+ cpu.c \
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/os/platform/native/Android.mk b/firmware/os/platform/native/Android.mk
new file mode 100644
index 0000000..54ed6f5
--- /dev/null
+++ b/firmware/os/platform/native/Android.mk
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+NANOHUB_PALTFORM_PATH := $(LOCAL_PATH)
+
+########################################################
+# NANOHUB OS BINARY
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_native
+LOCAL_AUX_ARCH := native
+
+LOCAL_SRC_FILES := \
+ hostIntf.c \
+ i2c.c \
+ platform.c \
+ rtc.c \
+ spi.c \
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/os/platform/stm32/Android.mk b/firmware/os/platform/stm32/Android.mk
new file mode 100644
index 0000000..b61dc3b
--- /dev/null
+++ b/firmware/os/platform/stm32/Android.mk
@@ -0,0 +1,69 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+########################################################
+# COMMON OS & BL defs
+########################################################
+
+NANOHUB_PALTFORM_PATH := $(LOCAL_PATH)
+
+########################################################
+# BOOT LOADER BINARY
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_bl_stm32
+LOCAL_AUX_ARCH := stm32
+
+LOCAL_SRC_FILES := \
+ bl.c \
+ gpio.c \
+ pwr.c \
+
+include $(BUILD_NANOHUB_BL_STATIC_LIBRARY)
+
+########################################################
+# NANOHUB OS BINARY
+########################################################
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_stm32
+LOCAL_AUX_ARCH := stm32
+
+LOCAL_SRC_FILES := \
+ apInt.c \
+ crc.c \
+ crt_stm32.c \
+ dma.c \
+ eeData.c \
+ exti.c \
+ gpio.c \
+ hostIntf.c \
+ i2c.c \
+ mpu.c \
+ platform.c \
+ pwr.c \
+ rtc.c \
+ spi.c \
+ syscfg.c \
+ usart.c \
+ wdt.c \
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/os/platform/stm32/lkr/stm32f4xx.bl.lkr b/firmware/os/platform/stm32/lkr/stm32f4xx.bl.lkr
index 501faf9..890fac7 100644
--- a/firmware/os/platform/stm32/lkr/stm32f4xx.bl.lkr
+++ b/firmware/os/platform/stm32/lkr/stm32f4xx.bl.lkr
@@ -74,4 +74,4 @@
} > ram
}
-ENTRY(__BL_VECTORS)
+ENTRY(_BL)
diff --git a/firmware/variant/Android.mk b/firmware/variant/Android.mk
index e69de29..558a505 100644
--- a/firmware/variant/Android.mk
+++ b/firmware/variant/Android.mk
@@ -0,0 +1,18 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+subdirs := nucleo lunchbox linux
+include $(call all-named-subdir-makefiles,$(subdirs))
diff --git a/firmware/variant/linux/Android.mk b/firmware/variant/linux/Android.mk
new file mode 100644
index 0000000..669b221
--- /dev/null
+++ b/firmware/variant/linux/Android.mk
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_linux
+LOCAL_MODULE_TAGS := optional
+LOCAL_AUX_OS_VARIANT := linux
+
+LOCAL_SRC_FILES := \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_C_INCLUDES)
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/variant/linux/Makefile b/firmware/variant/linux/Makefile
index 9d87a8f..4ba26a3 100644
--- a/firmware/variant/linux/Makefile
+++ b/firmware/variant/linux/Makefile
@@ -2,4 +2,4 @@
SRC_PATH=../..
-include $(SRC_PATH)/src/variant/variant.mk
+include $(SRC_PATH)/variant/variant.mk
diff --git a/firmware/variant/linux/inc/variant/variant.h b/firmware/variant/linux/inc/variant/variant.h
index 2e6c280..1d02d43 100644
--- a/firmware/variant/linux/inc/variant/variant.h
+++ b/firmware/variant/linux/inc/variant/variant.h
@@ -21,7 +21,6 @@
extern "C" {
#endif
-#define PLATFORM_HOST_INTF_I2C_BUS 0
#define PLATFORM_HW_TYPE 0x8086
#define PLAT_HAS_NO_U_TYPES_H
diff --git a/firmware/variant/linux/linux_conf.mk b/firmware/variant/linux/linux_conf.mk
index 5febed9..fac0d66 100644
--- a/firmware/variant/linux/linux_conf.mk
+++ b/firmware/variant/linux/linux_conf.mk
@@ -1,3 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
# settings that apps and OS both want to know about variant
VENDOR := google
diff --git a/firmware/variant/lunchbox/Android.mk b/firmware/variant/lunchbox/Android.mk
new file mode 100644
index 0000000..d743a54
--- /dev/null
+++ b/firmware/variant/lunchbox/Android.mk
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_lunchbox
+LOCAL_MODULE_TAGS := optional
+LOCAL_AUX_OS_VARIANT := lunchbox
+
+LOCAL_SRC_FILES := \
+ src/os/i2c.c \
+ src/os/spi.c \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_C_INCLUDES)
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/variant/lunchbox/lunchbox_conf.mk b/firmware/variant/lunchbox/lunchbox_conf.mk
index aac2014..248d673 100644
--- a/firmware/variant/lunchbox/lunchbox_conf.mk
+++ b/firmware/variant/lunchbox/lunchbox_conf.mk
@@ -1,3 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
# settings that apps and OS both want to know about variant
VENDOR := google
diff --git a/firmware/variant/nucleo/Android.mk b/firmware/variant/nucleo/Android.mk
new file mode 100644
index 0000000..1e00b25
--- /dev/null
+++ b/firmware/variant/nucleo/Android.mk
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_os_nucleo
+LOCAL_MODULE_TAGS := optional
+LOCAL_AUX_OS_VARIANT := nucleo
+
+LOCAL_SRC_FILES := \
+ src/os/i2c.c \
+ src/os/spi.c \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/inc \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_C_INCLUDES)
+
+include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
diff --git a/firmware/variant/nucleo/nucleo_conf.mk b/firmware/variant/nucleo/nucleo_conf.mk
index 33f7c98..e58aaff 100644
--- a/firmware/variant/nucleo/nucleo_conf.mk
+++ b/firmware/variant/nucleo/nucleo_conf.mk
@@ -1,3 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
# settings that apps and OS both want to know about variant
VENDOR := google
diff --git a/firmware/variant/variant.mk b/firmware/variant/variant.mk
index 5d9bb56..ef581f8 100644
--- a/firmware/variant/variant.mk
+++ b/firmware/variant/variant.mk
@@ -1,3 +1,19 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
PLATFORM?=stm32
CPU?=cortexm4
CHIP?=stm32f411
diff --git a/lib/Android.mk b/lib/Android.mk
index a39d13f..0caa123 100644
--- a/lib/Android.mk
+++ b/lib/Android.mk
@@ -25,6 +25,17 @@
src_includes := \
$(LOCAL_PATH)/include \
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanohub_common_bl
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(src_files)
+LOCAL_C_INCLUDES := $(src_includes)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(src_includes)
+
+include $(BUILD_NANOHUB_BL_STATIC_LIBRARY)
+
include $(CLEAR_VARS)
LOCAL_MODULE := libnanohub_common
diff --git a/util/nanoapp_cmd/Android.mk b/util/nanoapp_cmd/Android.mk
index 8dcd8ac..80af754 100644
--- a/util/nanoapp_cmd/Android.mk
+++ b/util/nanoapp_cmd/Android.mk
@@ -27,8 +27,7 @@
LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_OWNER := google
-LOCAL_LDLIBS := \
- -L$(SYSROOT)/usr/lib -llog
+LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := \
libutils \
diff --git a/util/nanoapp_postprocess/Android.mk b/util/nanoapp_postprocess/Android.mk
index dce1711..9b4539b 100644
--- a/util/nanoapp_postprocess/Android.mk
+++ b/util/nanoapp_postprocess/Android.mk
@@ -23,7 +23,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- postprocess.c \
+ postprocess_elf.c \
LOCAL_CFLAGS := -Wall -Werror -Wextra