From f41b0d00fdcdec27a688a149b0eeb676140d59ab Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Sat, 9 Nov 2024 22:12:32 +0800 Subject: [PATCH] tools/rp2040: Building picotool if necessary Improved 1. The pre-installed "picotool" should not depend on `PICO_SDK_PATH` 2. Perhaps we should compile "picotool" from `PICO_SDK_PATH` if it was not found in $PATH Tests 1. The "picotool" is pre-installed or built from `PICO_SDK_PATH` LD: nuttx Generating: nuttx.uf2 Done. 2. `PICO_SDK_PATH` is specified but "picotool" is not installed LD: nuttx Building: picotool Generating: nuttx.uf2 Done. 3. Neither "picotool" nor `PICO_SDK_PATH` are installed/specified LD: nuttx PICO_SDK_PATH/picotool must be specified/installed for flash boot Signed-off-by: wangjianyu3 --- tools/rp2040/Config.mk | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/tools/rp2040/Config.mk b/tools/rp2040/Config.mk index 2d3faa7fd86ee..51bafdf6f409a 100644 --- a/tools/rp2040/Config.mk +++ b/tools/rp2040/Config.mk @@ -26,17 +26,33 @@ # POSTBUILD -- Perform post build operations -ifeq ($(CONFIG_RP2040_UF2_BINARY),y) -ifdef PICO_SDK_PATH -define POSTBUILD - $(Q)echo "Generating: nuttx.uf2"; \ +PICOTOOL_BIN_PATH?=$(PICO_SDK_PATH)$(DELIM)_deps$(DELIM)picotool$(DELIM)picotool - picotool$(HOSTEXEEXT) uf2 convert --quiet -t elf nuttx nuttx.uf2; - $(Q)([ $$? -eq 0 ] && echo nuttx.uf2 >> nuttx.manifest && echo "Done.") -endef -else -define POSTBUILD - $(Q) echo "PICO_SDK_PATH must be specified for flash boot" +define GEN_PICO_UF2 + $(Q)echo "Generating: nuttx.uf2"; \ + + $(Q)$1 uf2 convert --quiet -t elf nuttx nuttx.uf2; + $(Q)([ $$? -eq 0 ] && echo nuttx.uf2 >> nuttx.manifest && echo "Done.") endef -endif + +ifeq ($(CONFIG_RP2040_UF2_BINARY),y) + ifneq ($(shell which picotool),) + define POSTBUILD + $(call GEN_PICO_UF2, picotool) + endef + else ifdef PICO_SDK_PATH + define POSTBUILD + $(Q)(if ! $(PICOTOOL_BIN_PATH) help >&/dev/null; then \ + echo "Building: picotool"; \ + cd $(PICO_SDK_PATH); \ + cmake . >&/dev/null; \ + make picotoolBuild >&/dev/null; \ + fi;) + $(call GEN_PICO_UF2, $(PICOTOOL_BIN_PATH)) + endef + else + define POSTBUILD + $(Q) echo "PICO_SDK_PATH/picotool must be specified/installed for flash boot" + endef + endif endif