From f26ae0ef9254c974917f9b3721cc1a57087d9970 Mon Sep 17 00:00:00 2001 From: blckmn Date: Fri, 23 May 2025 18:44:43 +1000 Subject: [PATCH] Adding picotool build recipe in makefiles. --- Makefile | 49 +++++++++++++++++++++++++++++++++++-------------- mk/tools.mk | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7be4e6a6d2..2e591ccf3e 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ CFLAGS_DISABLED := FORKNAME = betaflight # Working directories +ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) PLATFORM_DIR := $(ROOT)/src/platform SRC_DIR := $(ROOT)/src/main @@ -92,10 +93,13 @@ include $(MAKE_SCRIPT_DIR)/checks.mk # list of targets that are executed on host (using exe as goal) EXE_TARGETS := SITL +UF2_TARGETS := RP2350 # 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))))) + +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 +138,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 +231,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 @@ -380,6 +382,7 @@ TARGET_FULLNAME = $(FORKNAME)_$(FC_VER)_$(TARGET_NAME) # 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 @@ -426,6 +429,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 $< $@ + $(TARGET_DFU): $(TARGET_HEX) @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)" $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@ @@ -539,17 +546,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 +596,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,7 +634,7 @@ 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): @@ -638,10 +650,13 @@ binary: hex: $(V0) $(MAKE) $(MAKE_PARALLEL) $(TARGET_HEX) +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 +690,11 @@ $(DIRECTORIES): version: @echo $(FC_VER) +submodules: + @echo "Updating submodules" + $(V1) git submodule update --init --recursive + @echo "Submodules updated" + ## help : print this help message and exit help: Makefile mk/tools.mk @echo "" @@ -690,7 +710,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 +719,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..664f48c6c4 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -331,3 +331,43 @@ 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 uf2,$(MAKECMDGOALS)), uf2) + ifeq (,$(wildcard $(PICOTOOL))) + PICOTOOL_VERSION := $(shell picotool version) + ifneq ($(PICOTOOL_VERSION),) + PICOTOOL := picotool + else + $(error **ERROR** picotool not in the PATH or setup in tools. Run 'make picotool_install' to install automatically in the tools folder) + 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 "\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) + $(V1) $(MAKE) -C $(PICOTOOL_BUILD_DIR) + $(V1) cp $(PICOTOOL_BUILD_DIR)/picotool $(PICOTOOL_DIR)/picotool + @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)