Skip to content

Commit 86c466b

Browse files
nmaggionixiaoxiang781216
authored andcommitted
tools/rp{2040,23xx}: Ensure that picotool is found or built
The current logic failed silently on some systems, maybe because of a different default shell? This resulted in builds that completed successfully but generated invalid UF2 files, which were refused by the uC bootloader. Now the check is properly enforced and picotool is either found in the $PATH or built from the pico-sdk source. Signed-off-by: Niccolò Maggioni <nicco.maggioni+nuttx@gmail.com>
1 parent 3e70a7e commit 86c466b

2 files changed

Lines changed: 42 additions & 30 deletions

File tree

tools/rp2040/Config.mk

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
# POSTBUILD -- Perform post build operations
2828

29-
PICOTOOL_BIN_PATH?=$(PICO_SDK_PATH)$(DELIM)_deps$(DELIM)picotool$(DELIM)picotool
29+
PICOTOOL_FOUND := $(shell command -v picotool 2> /dev/null)
30+
31+
PICOTOOL_BIN_PATH ?= $(PICO_SDK_PATH)$(DELIM)_deps$(DELIM)picotool$(DELIM)picotool
3032

3133
define GEN_PICO_UF2
3234
$(Q)echo "Generating: nuttx.uf2"; \
@@ -36,23 +38,26 @@ define GEN_PICO_UF2
3638
endef
3739

3840
ifeq ($(CONFIG_RP2040_UF2_BINARY),y)
39-
ifneq ($(shell which picotool),)
41+
ifdef PICOTOOL_FOUND
4042
define POSTBUILD
4143
$(call GEN_PICO_UF2, picotool)
4244
endef
43-
else ifdef PICO_SDK_PATH
44-
define POSTBUILD
45-
$(Q)(if ! $(PICOTOOL_BIN_PATH) help >&/dev/null; then \
46-
echo "Building: picotool"; \
47-
cd $(PICO_SDK_PATH); \
48-
cmake . >&/dev/null; \
49-
make picotoolBuild >&/dev/null; \
50-
fi;)
51-
$(call GEN_PICO_UF2, $(PICOTOOL_BIN_PATH))
52-
endef
5345
else
54-
define POSTBUILD
55-
$(Q) echo "PICO_SDK_PATH/picotool must be specified/installed for flash boot"
56-
endef
46+
ifdef PICO_SDK_PATH
47+
define POSTBUILD
48+
$(warning "picotool not found in $$PATH, it will be sourced from pico-sdk")
49+
$(Q)if [[ ! -x "$(PICOTOOL_BIN_PATH)" ]]; then \
50+
echo "Warning: building picotool from pico-sdk will skip USB support! See https://github.com/raspberrypi/pico-sdk/issues/1827" >&2; \
51+
cd $(PICO_SDK_PATH); \
52+
cmake . >&/dev/null; \
53+
make picotoolBuild >/dev/null; \
54+
fi
55+
$(call GEN_PICO_UF2, $(PICOTOOL_BIN_PATH))
56+
endef
57+
else
58+
define POSTBUILD
59+
$(error "Generating UF2 files requires picotool to be available in $$PATH, or $$PICO_SDK_PATH must be specified")
60+
endef
61+
endif
5762
endif
5863
endif

tools/rp23xx/Config.mk

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
############################################################################
22
# tools/rp23xx/Config.mk
33
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
46
# Licensed to the Apache Software Foundation (ASF) under one or more
57
# contributor license agreements. See the NOTICE file distributed with
68
# this work for additional information regarding copyright ownership. The
@@ -24,7 +26,9 @@
2426

2527
# POSTBUILD -- Perform post build operations
2628

27-
PICOTOOL_BIN_PATH?=$(PICO_SDK_PATH)$(DELIM)_deps$(DELIM)picotool$(DELIM)picotool
29+
PICOTOOL_FOUND := $(shell command -v picotool 2> /dev/null)
30+
31+
PICOTOOL_BIN_PATH ?= $(PICO_SDK_PATH)$(DELIM)_deps$(DELIM)picotool$(DELIM)picotool
2832

2933
define GEN_PICO_UF2
3034
$(Q)echo "Generating: nuttx.uf2"; \
@@ -34,23 +38,26 @@ define GEN_PICO_UF2
3438
endef
3539

3640
ifeq ($(CONFIG_RP23XX_UF2_BINARY),y)
37-
ifneq ($(shell which picotool),)
41+
ifdef PICOTOOL_FOUND
3842
define POSTBUILD
3943
$(call GEN_PICO_UF2, picotool)
4044
endef
41-
else ifdef PICO_SDK_PATH
42-
define POSTBUILD
43-
$(Q)(if ! $(PICOTOOL_BIN_PATH) help >&/dev/null; then \
44-
echo "Building: picotool"; \
45-
cd $(PICO_SDK_PATH); \
46-
cmake . >&/dev/null; \
47-
make picotoolBuild >&/dev/null; \
48-
fi;)
49-
$(call GEN_PICO_UF2, $(PICOTOOL_BIN_PATH))
50-
endef
5145
else
52-
define POSTBUILD
53-
$(Q) echo "PICO_SDK_PATH/picotool must be specified/installed for flash boot"
54-
endef
46+
ifdef PICO_SDK_PATH
47+
define POSTBUILD
48+
$(warning "picotool not found in $$PATH, it will be sourced from pico-sdk")
49+
$(Q)if [[ ! -x "$(PICOTOOL_BIN_PATH)" ]]; then \
50+
echo "Warning: building picotool from pico-sdk will skip USB support! See https://github.com/raspberrypi/pico-sdk/issues/1827" >&2; \
51+
cd $(PICO_SDK_PATH); \
52+
cmake . >&/dev/null; \
53+
make picotoolBuild >/dev/null; \
54+
fi
55+
$(call GEN_PICO_UF2, $(PICOTOOL_BIN_PATH))
56+
endef
57+
else
58+
define POSTBUILD
59+
$(error "Generating UF2 files requires picotool to be available in $$PATH, or $$PICO_SDK_PATH must be specified")
60+
endef
61+
endif
5562
endif
5663
endif

0 commit comments

Comments
 (0)