Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·227 lines (195 loc) · 6.47 KB
/
Copy pathMakefile
File metadata and controls
executable file
·227 lines (195 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# This file is part of the OpenMV project.
#
# Copyright (c) 2013-2024 Ibrahim Abdelkader <iabdalkader@openmv.io>
# Copyright (c) 2013-2024 Kwabena W. Agyeman <kwagyeman@openmv.io>
#
# This work is licensed under the MIT license, see the file LICENSE for details.
#
# Top level Makefile
# Set verbosity
ifeq ($(V), 1)
export Q =
else
export Q = @
MAKEFLAGS += --silent
endif
# Debug configuration
DEBUGGER ?= JLINK
# Dummy target to run sdk/clean
ifeq ($(TARGET),)
ifeq ($(filter sdk,$(MAKECMDGOALS)),)
$(error Invalid or no TARGET specified)
else
TARGET=OPENMV4
endif
endif
# OpenMV SDK configuration
SDK_VERSION := $(shell cat $(CURDIR)/SDK_VERSION)
SDK_DIR ?= $(HOME)/openmv-sdk-$(SDK_VERSION)
SDK_STAMP = $(SDK_DIR)/sdk.version
# Check if the SDK is downloaded
ifeq ($(filter sdk clean,$(MAKECMDGOALS)),)
ifeq ($(wildcard $(SDK_STAMP)),)
OLD_SDK_STAMPS := $(wildcard $(dir $(SDK_DIR))openmv-sdk-*/sdk.version)
ifneq ($(OLD_SDK_STAMPS),)
SDK_INSTALLED := $(shell cat $(OLD_SDK_STAMPS) 2>/dev/null | sort -u | tr '\n' ' ')
endif
else
SDK_INSTALLED := $(shell cat $(SDK_STAMP))
endif
ifeq ($(SDK_INSTALLED),)
$(error OpenMV SDK not found. Run 'make sdk' to install it.)
else ifneq ($(SDK_INSTALLED),$(SDK_VERSION))
$(error OpenMV SDK version mismatch (installed: $(SDK_INSTALLED), required: $(SDK_VERSION)). Run 'make sdk' to update.)
endif
endif
# Targets
export OPENMV ?= openmv
export FIRMWARE ?= firmware
OMV_DEBUG_ELF ?= $(FIRMWARE)
export BOOTLOADER ?= bootloader
# Commands (use := to avoid repeated expansion overhead in parallel builds)
export CC := $(Q)arm-none-eabi-gcc
export CLANG := $(Q)clang
export CXX := $(Q)arm-none-eabi-g++
export AS := $(Q)arm-none-eabi-as
export LD := $(Q)arm-none-eabi-ld
export AR := $(Q)arm-none-eabi-ar
export RM := $(Q)rm
export CPP := $(Q)arm-none-eabi-cpp
export SIZE := $(Q)arm-none-eabi-size
export STRIP := $(Q)arm-none-eabi-strip -s
export OBJCOPY := $(Q)arm-none-eabi-objcopy
export OBJDUMP := $(Q)arm-none-eabi-objdump
export PYTHON := $(Q)python3
export MKDIR := $(Q)mkdir
export ECHO := $(Q)@echo
export MAKE := $(Q)make
export CAT := $(Q)cat
export MKROMFS := mkromfs.py
export GENLINK := gen_linker.py
export MACHINE := $(shell uname -m)
# Directories
export TOP_DIR:=$(shell pwd)
export BUILD:=$(TOP_DIR)/build/$(TARGET)
export TOOLS_DIR:=$(TOP_DIR)/tools
export FW_DIR:=$(BUILD)/bin
export BOOT_DIR=boot
export PORTS_DIR=ports
export CUBEAI_DIR=cubeai
export CMSIS_DIR=lib/cmsis
export MICROPY_DIR=lib/micropython
export NEMA_DIR=drivers/nema
export VC8000_DIR=drivers/vc8000
export LIBPDM_DIR=lib/libpdm
export TENSORFLOW_DIR=lib/tflm
export COMMON_DIR=common
export CYW4343_FW_DIR=drivers/cyw4343/firmware/
export OMV_BOARD_CONFIG_DIR:=$(TOP_DIR)/boards/$(TARGET)/
export OMV_LIB_DIR:=$(TOP_DIR)/scripts/libraries
export FROZEN_MANIFEST:=$(OMV_BOARD_CONFIG_DIR)/manifest.py
# Prepend SDK bin directories to PATH.
STEDGEAI_CORE := $(SDK_DIR)/stedgeai
STEDGEAI_UTIL := Utilities/$(if $(filter Darwin,$(shell uname -s)),macarm,linux)
export PATH := $(SDK_DIR)/gcc/bin:$(SDK_DIR)/llvm/bin:$(SDK_DIR)/cmake/bin:$(SDK_DIR)/python/bin:$(SDK_DIR)/stcubeprog/bin:$(STEDGEAI_CORE)/$(STEDGEAI_UTIL):$(SDK_DIR)/bin:$(SDK_DIR)/fvp/bin:$(PATH)
# Debugging/Optimization
ifeq ($(DEBUG), 1)
ROM_TEXT_COMPRESSION = 0
CFLAGS += -Og -ggdb3
else
DEBUG=0
ROM_TEXT_COMPRESSION = 1
CFLAGS += -O2 -DNDEBUG
USERMOD_OPT = -O2
MPY_CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1
endif
# Enable debug printf
ifeq ($(DEBUG_PRINTF), 1)
CFLAGS += -DOMV_DEBUG_PRINTF
endif
# Enable stack protection
ifeq ($(STACK_PROTECTOR), 1)
CFLAGS += -fstack-protector-all -DSTACK_PROTECTOR
endif
# Enable debug printf
ifeq ($(FB_ALLOC_STATS), 1)
CFLAGS += -DFB_ALLOC_STATS
endif
# Enable timing for some functions.
ifeq ($(PROFILE_ENABLE), 1)
$(info ===================================)
$(info ======= Profiling Enabled =======)
$(info ===================================)
# Enable profiling in IRQ context (default: enabled)
PROFILE_IRQ ?= 0
# Default profiler hash table size (must be power of 2)
ifeq ($(PROFILE_HASH),)
PROFILE_HASH=256
endif
CFLAGS += -DOMV_PROFILER_ENABLE=1
CFLAGS += -DOMV_PROFILER_HASH_SIZE=$(PROFILE_HASH)
CFLAGS += -DOMV_PROFILER_IRQ_ENABLE=$(PROFILE_IRQ)
CFLAGS += -finstrument-functions-exclude-file-list=lib/cmsis,lib/stm32,/lib/mimxrt,lib/alif,simd.h
endif
# Include OpenMV board config first to set the port.
include $(OMV_BOARD_CONFIG_DIR)/board_config.mk
# Include MicroPython board config.
#include $(MP_BOARD_CONFIG_DIR)/mpconfigboard.mk
# Additional qstr definitions for OpenMV
#OMV_SRC_QSTR := $(wildcard $(TOP_DIR)/modules/*.c)
export OMV_PORT_DIR:=$(TOP_DIR)/ports/$(PORT)
export MP_BOARD_CONFIG_DIR:=$(TOP_DIR)/$(MICROPY_DIR)/ports/$(PORT)/boards/$(TARGET)/
# The following command line args are passed to MicroPython's top Makefile.
MPY_MKARGS = PORT=$(PORT) BOARD=$(TARGET) DEBUG=$(DEBUG) MICROPY_MANIFEST_OMV_LIB_DIR=$(OMV_LIB_DIR)\
FROZEN_MANIFEST=$(FROZEN_MANIFEST) OMV_SRC_QSTR="$(OMV_SRC_QSTR)"\
MICROPY_ROM_TEXT_COMPRESSION=$(ROM_TEXT_COMPRESSION) USER_C_MODULES=$(TOP_DIR)
# Include the port Makefile.
include $(OMV_PORT_DIR)/port_config.mk
# Check GCC toolchain version.
ifeq ($(CPU),cortex-m55)
include $(TOP_DIR)/common/check_toolchain.mk
endif
# Freeze recursively-expanded variables into simply-expanded ones.
# Without this, make re-evaluates all sub-variable references every
# time it constructs the environment for each recipe fork
CFLAGS := $(CFLAGS)
LDFLAGS := $(LDFLAGS)
MPY_CFLAGS := $(MPY_CFLAGS)
MPY_MKARGS := $(MPY_MKARGS)
AFLAGS := $(AFLAGS)
TOP_DIR := $(TOP_DIR)
BUILD := $(BUILD)
TOOLS_DIR := $(TOOLS_DIR)
FW_DIR := $(FW_DIR)
OMV_BOARD_CONFIG_DIR := $(OMV_BOARD_CONFIG_DIR)
OMV_PORT_DIR := $(OMV_PORT_DIR)
MP_BOARD_CONFIG_DIR := $(MP_BOARD_CONFIG_DIR)
OMV_LIB_DIR := $(OMV_LIB_DIR)
FROZEN_MANIFEST := $(FROZEN_MANIFEST)
# Export variables for sub-make.
export PORT
export MCU
export TARGET
export CFLAGS
export AFLAGS
export LDFLAGS
export MPY_CFLAGS
export MPY_MKARGS
export USERMOD_OPT
clean:
$(RM) -fr $(BUILD)
size:
ifeq ($(OMV_ENABLE_BL), 1)
$(SIZE) --format=SysV $(FW_DIR)/$(BOOTLOADER).elf
endif
$(SIZE) --format=SysV $(FW_DIR)/$(FIRMWARE).elf
.PHONY: sdk
sdk:
$(Q)bash -c "source tools/ci.sh && ci_install_sdk"
submodules:
$(MAKE) -C $(MICROPY_DIR)/ports/$(PORT) BOARD=$(TARGET) submodules
debug: $(ROMFS_IMAGE)
ifeq ($(DEBUGGER),NONE)
$(error This target does not support debugging)
endif
gdbrunner $(DEBUGGER) $(OMV_$(DEBUGGER)_ARGS) $(FW_DIR)/$(OMV_DEBUG_ELF).elf