diff --git a/Makefile b/Makefile index 7be4e6a6d2..dfb9bcf8d0 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,11 @@ CFLAGS_DISABLED := FORKNAME = betaflight # Working directories +# ROOT_DIR is the full path to the directory containing this Makefile +ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +# ROOT is the relative path to the directory containing this Makefile ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) + PLATFORM_DIR := $(ROOT)/src/platform SRC_DIR := $(ROOT)/src/main LIB_MAIN_DIR := $(ROOT)/lib/main @@ -90,12 +94,16 @@ MAKE_PARALLEL = $(if $(filter -j%, $(MAKEFLAGS)),$(EMPTY),-j$(DEFAULT_PAR # pre-build sanity checks include $(MAKE_SCRIPT_DIR)/checks.mk -# list of targets that are executed on host (using exe as goal) -EXE_TARGETS := SITL - # basic target list PLATFORMS := $(sort $(notdir $(patsubst /%,%, $(wildcard $(PLATFORM_DIR)/*)))) -BASE_TARGETS := $(filter-out $(EXE_TARGETS),$(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/target.mk)))))) +BASE_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/target.mk))))) + +# list of targets that are executed on host - using exe as goal recipe +EXE_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/.exe))))) +# list of targets using uf2 as goal recipe +UF2_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/.uf2))))) +# list of targets using hex as goal recipe (default) +HEX_TARGETS := $(filter-out $(EXE_TARGETS) $(UF2_TARGETS),$(BASE_TARGETS)) # configure some directories that are relative to wherever ROOT_DIR is located TOOLS_DIR ?= $(ROOT)/tools @@ -134,7 +142,7 @@ HSE_VALUE ?= 8000000 CI_EXCLUDED_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/.exclude))))) CI_COMMON_TARGETS := STM32F4DISCOVERY CRAZYBEEF4SX1280 CRAZYBEEF4FR MATEKF405TE AIRBOTG4AIO TBS_LUCID_FC IFLIGHT_BLITZ_F722 NUCLEOF446 SPRACINGH7EXTREME SPRACINGH7RF -CI_TARGETS := $(filter-out $(CI_EXCLUDED_TARGETS), $(BASE_TARGETS) $(EXE_TARGETS)) $(filter $(CI_COMMON_TARGETS), $(BASE_CONFIGS)) +CI_TARGETS := $(filter-out $(CI_EXCLUDED_TARGETS), $(BASE_TARGETS) $(filter $(CI_COMMON_TARGETS), $(BASE_CONFIGS))) PREVIEW_TARGETS := MATEKF411 AIKONF4V2 AIRBOTG4AIO ZEEZF7V3 FOXEERF745V4_AIO KAKUTEH7 TBS_LUCID_FC SITL SPRACINGH7EXTREME SPRACINGH7RF TARGET_PLATFORM := $(notdir $(patsubst %/,%,$(subst target/$(TARGET)/,, $(dir $(wildcard $(PLATFORM_DIR)/*/target/$(TARGET)/target.mk))))) @@ -227,17 +235,15 @@ endif # TARGET specified # openocd specific includes include $(MAKE_SCRIPT_DIR)/openocd.mk -ifeq ($(CONFIG),) -ifeq ($(TARGET),) +ifeq ($(CONFIG)$(TARGET),) .DEFAULT_GOAL := all else ifneq ($(filter $(TARGET),$(EXE_TARGETS)),) .DEFAULT_GOAL := exe +else ifneq ($(filter $(TARGET),$(UF2_TARGETS)),) +.DEFAULT_GOAL := uf2 else .DEFAULT_GOAL := hex endif -else # ifeq ($(CONFIG),) -.DEFAULT_GOAL := hex -endif INCLUDE_DIRS := $(INCLUDE_DIRS) \ $(ROOT)/lib/main/MAVLink @@ -378,21 +384,22 @@ TARGET_FULLNAME = $(FORKNAME)_$(FC_VER)_$(TARGET_NAME) # # Things we will build # -TARGET_BIN = $(BIN_DIR)/$(TARGET_FULLNAME).bin -TARGET_HEX = $(BIN_DIR)/$(TARGET_FULLNAME).hex -TARGET_EXE = $(BIN_DIR)/$(TARGET_FULLNAME) -TARGET_DFU = $(BIN_DIR)/$(TARGET_FULLNAME).dfu -TARGET_ZIP = $(BIN_DIR)/$(TARGET_FULLNAME).zip -TARGET_OBJ_DIR = $(OBJECT_DIR)/$(TARGET_NAME) -TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).elf -TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_EXST.elf -TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_UNPATCHED.bin -TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).lst -TARGET_OBJS = $(addsuffix .o,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC)))) -TARGET_DEPS = $(addsuffix .d,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC)))) -TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).map +TARGET_BIN := $(BIN_DIR)/$(TARGET_FULLNAME).bin +TARGET_HEX := $(BIN_DIR)/$(TARGET_FULLNAME).hex +TARGET_UF2 := $(BIN_DIR)/$(TARGET_FULLNAME).uf2 +TARGET_EXE := $(BIN_DIR)/$(TARGET_FULLNAME) +TARGET_DFU := $(BIN_DIR)/$(TARGET_FULLNAME).dfu +TARGET_ZIP := $(BIN_DIR)/$(TARGET_FULLNAME).zip +TARGET_OBJ_DIR := $(OBJECT_DIR)/$(TARGET_NAME) +TARGET_ELF := $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).elf +TARGET_EXST_ELF := $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_EXST.elf +TARGET_UNPATCHED_BIN := $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_UNPATCHED.bin +TARGET_LST := $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).lst +TARGET_OBJS := $(addsuffix .o,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC)))) +TARGET_DEPS := $(addsuffix .d,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC)))) +TARGET_MAP := $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).map -TARGET_EXST_HASH_SECTION_FILE = $(TARGET_OBJ_DIR)/exst_hash_section.bin +TARGET_EXST_HASH_SECTION_FILE := $(TARGET_OBJ_DIR)/exst_hash_section.bin ifeq ($(DEBUG_MIXED),yes) TARGET_EF_HASH := $(shell echo -n -- "$(EXTRA_FLAGS)" "$(OPTIONS)" "$(DEVICE_FLAGS)" "$(TARGET_FLAGS)" | openssl dgst -md5 -r | awk '{print $$1;}') @@ -426,6 +433,10 @@ $(TARGET_HEX): $(TARGET_ELF) @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)" $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@ +$(TARGET_UF2): $(TARGET_ELF) + @echo "Creating UF2 $(TARGET_UF2)" "$(STDOUT)" + $(V1) $(PICOTOOL) uf2 convert $< $@ || { echo "Failed to convert ELF to UF2 format"; exit 1; } + $(TARGET_DFU): $(TARGET_HEX) @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)" $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@ @@ -539,17 +550,22 @@ $(TARGET_OBJ_DIR)/%.o: %.S ## all : Build all currently built targets all: $(CI_TARGETS) -$(BASE_TARGETS): - $(V0) @echo "Building target $@" && \ +$(HEX_TARGETS): + $(V0) @echo "Building hex target $@" && \ $(MAKE) hex TARGET=$@ && \ echo "Building $@ succeeded." +$(UF2_TARGETS): + $(V0) @echo "Building uf2 target $@" && \ + $(MAKE) uf2 TARGET=$@ && \ + echo "Building $@ succeeded." + $(EXE_TARGETS): $(V0) @echo "Building executable target $@" && \ $(MAKE) exe TARGET=$@ && \ echo "Building $@ succeeded." -TARGETS_CLEAN = $(addsuffix _clean,$(BASE_TARGETS) $(EXE_TARGETS)) +TARGETS_CLEAN = $(addsuffix _clean,$(HEX_TARGETS) $(UF2_TARGETS) $(EXE_TARGETS)) CONFIGS_CLEAN = $(addsuffix _clean,$(BASE_CONFIGS)) @@ -584,7 +600,7 @@ preview: $(PREVIEW_TARGETS) test ## all_configs : Build all configs all_configs: $(BASE_CONFIGS) -TARGETS_FLASH = $(addsuffix _flash,$(BASE_TARGETS)) +TARGETS_FLASH = $(addsuffix _flash,$(HEX_TARGETS)) ## _flash : build and flash a target $(TARGETS_FLASH): @@ -622,26 +638,33 @@ openocd-gdb: $(TARGET_ELF) $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load" endif -TARGETS_ZIP = $(addsuffix _zip,$(BASE_TARGETS)) +TARGETS_ZIP = $(addsuffix _zip,$(HEX_TARGETS)) ## _zip : build target and zip it (useful for posting to GitHub) $(TARGETS_ZIP): $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@) $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@) +.PHONY: zip zip: $(V0) zip $(TARGET_ZIP) $(TARGET_HEX) +.PHONY: binary binary: $(V0) $(MAKE) $(MAKE_PARALLEL) $(TARGET_BIN) +.PHONY: hex hex: $(V0) $(MAKE) $(MAKE_PARALLEL) $(TARGET_HEX) -.phony: exe +.PHONY: uf2 +uf2: + $(V0) $(MAKE) $(MAKE_PARALLEL) $(TARGET_UF2) + +.PHONY: exe exe: $(TARGET_EXE) -TARGETS_REVISION = $(addsuffix _rev,$(BASE_TARGETS)) +TARGETS_REVISION = $(addsuffix _rev,$(HEX_TARGETS)) ## _rev : build target and add revision to filename $(TARGETS_REVISION): $(V0) $(MAKE) hex REV=yes TARGET=$(subst _rev,,$@) @@ -675,6 +698,12 @@ $(DIRECTORIES): version: @echo $(FC_VER) +.PHONY: submodules +submodules: + @echo "Updating submodules" + $(V1) git submodule update --init --recursive || { echo "Failed to update submodules"; exit 1; } + @echo "Submodules updated" + ## help : print this help message and exit help: Makefile mk/tools.mk @echo "" @@ -690,7 +719,7 @@ help: Makefile mk/tools.mk @echo "To populate configuration targets:" @echo " make configs" @echo "" - @echo "Valid TARGET values are: $(EXE_TARGETS) $(BASE_TARGETS)" + @echo "Valid TARGET values are: $(BASE_TARGETS)" @echo "" @sed -n 's/^## //p' $? @@ -699,6 +728,7 @@ targets: @echo "Platforms: $(PLATFORMS)" @echo "Valid targets: $(BASE_TARGETS)" @echo "Executable targets: $(EXE_TARGETS)" + @echo "UF2 targets: $(UF2_TARGETS)" @echo "Built targets: $(CI_TARGETS)" @echo "Default target: $(TARGET)" @echo "CI common targets: $(CI_COMMON_TARGETS)" diff --git a/mk/tools.mk b/mk/tools.mk index 3dc42ab47a..5ecf7c79ab 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -331,3 +331,48 @@ breakpad_clean: $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR) @echo " CLEAN $(BREAKPAD_DL_FILE)" $(V1) $(RM) -f $(BREAKPAD_DL_FILE) + +# Raspberry Pi Pico tools +PICOTOOL_REPO := https://github.com/raspberrypi/picotool.git +PICOTOOL_DL_DIR := $(DL_DIR)/picotool +PICOTOOL_BUILD_DIR := $(PICOTOOL_DL_DIR)/build +PICOTOOL_DIR := $(TOOLS_DIR)/picotool +PICO_SDK_PATH ?= $(ROOT_DIR)/lib/main/pico-sdk +PICOTOOL ?= $(PICOTOOL_DIR)/picotool + +ifeq ($(filter picotool_install,$(MAKECMDGOALS)), picotool_install) + ifneq ($(wildcard $(PICO_SDK_PATH)/CMakeLists.txt),$(PICO_SDK_PATH)/CMakeLists.txt) + $(error "PICO_SDK_PATH ($(PICO_SDK_PATH)) does not point to a valid Pico SDK. Please 'make submodules' to hydrate the Pico SDK.") + endif +endif + +ifeq ($(filter uf2,$(MAKECMDGOALS)), uf2) + ifeq (,$(wildcard $(PICOTOOL))) + ifeq (,$(shell which picotool 2>/dev/null)) + $(error "picotool not in the PATH or setup in tools. Run 'make picotool_install' to install in the tools folder.") + else + PICOTOOL := picotool + endif + endif +endif + +.PHONY: picotool_install +picotool_install: | $(DL_DIR) $(TOOLS_DIR) +picotool_install: picotool_clean + @echo "\n CLONE $(PICOTOOL_REPO)" + $(V1) git clone --depth 1 $(PICOTOOL_REPO) "$(PICOTOOL_DL_DIR)" || { echo "Failed to clone picotool repository"; exit 1; } + @echo "\n BUILD $(PICOTOOL_BUILD_DIR)" + $(V1) [ -d "$(PICOTOOL_DIR)" ] || mkdir -p $(PICOTOOL_DIR) + $(V1) [ -d "$(PICOTOOL_BUILD_DIR)" ] || mkdir -p $(PICOTOOL_BUILD_DIR) + $(V1) cmake -S $(PICOTOOL_DL_DIR) -B $(PICOTOOL_BUILD_DIR) -D PICO_SDK_PATH=$(PICO_SDK_PATH) || { echo "CMake configuration failed"; exit 1; } + $(V1) $(MAKE) -C $(PICOTOOL_BUILD_DIR) || { echo "picotool build failed"; exit 1; } + $(V1) cp $(PICOTOOL_BUILD_DIR)/picotool $(PICOTOOL_DIR)/picotool || { echo "Failed to install picotool binary"; exit 1; } + @echo "\n VERSION:" + $(V1) $(PICOTOOL_DIR)/picotool version + +.PHONY: picotool_clean +picotool_clean: + @echo " CLEAN $(PICOTOOL_DIR)" + $(V1) [ ! -d "$(PICOTOOL_DIR)" ] || $(RM) -rf $(PICOTOOL_DIR) + @echo " CLEAN $(PICOTOOL_DL_DIR)" + $(V1) [ ! -d "$(PICOTOOL_DL_DIR)" ] || $(RM) -rf $(PICOTOOL_DL_DIR) diff --git a/src/platform/PICO/target/RP2350/.uf2 b/src/platform/PICO/target/RP2350/.uf2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/platform/SIMULATOR/target/SITL/.exe b/src/platform/SIMULATOR/target/SITL/.exe new file mode 100644 index 0000000000..e69de29bb2