diff --git a/esp8266/Makefile b/esp8266/Makefile
index 7db5a76d35070e48b59c6ac81ec0738995efd8d4..d930a255596848ad177495b729c44ab8cf3f66e5 100644
--- a/esp8266/Makefile
+++ b/esp8266/Makefile
@@ -68,7 +68,6 @@ SRC_C = \
 
 STM_SRC_C = $(addprefix stmhal/,\
 	printf.c \
-	pyexec.c \
 	pybstdio.c \
 	)
 
@@ -77,6 +76,7 @@ LIB_SRC_C = $(addprefix lib/,\
 	mp-readline/readline.c \
 	netutils/netutils.c \
 	timeutils/timeutils.c \
+	utils/pyexec.c \
 	)
 
 SRC_S = \
diff --git a/stmhal/pyexec.c b/lib/utils/pyexec.c
similarity index 100%
rename from stmhal/pyexec.c
rename to lib/utils/pyexec.c
diff --git a/minimal/Makefile b/minimal/Makefile
index 619d24952650d7f61521722e41b3ff08030c201a..1fe7b9dbc1138d04a042ad234ba253aa1b2e1854 100644
--- a/minimal/Makefile
+++ b/minimal/Makefile
@@ -45,7 +45,7 @@ SRC_C = \
 	uart_core.c \
 	uart_extra.c \
 	stmhal/printf.c \
-	stmhal/pyexec.c \
+	lib/utils/pyexec.c \
 	lib/libc/string0.c \
 	lib/mp-readline/readline.c \
 
diff --git a/pic16bit/Makefile b/pic16bit/Makefile
index 309b47b79763df5f97c773af4d0d8a156e6a886a..a16a26386eb552d65ff22bbb1b202d14229b45e2 100644
--- a/pic16bit/Makefile
+++ b/pic16bit/Makefile
@@ -41,7 +41,7 @@ SRC_C = \
 	modpybled.c \
 	modpybswitch.c \
 	stmhal/pybstdio.c \
-	stmhal/pyexec.c \
+	lib/utils/pyexec.c \
 	lib/mp-readline/readline.c \
 
 SRC_S = \
diff --git a/stmhal/Makefile b/stmhal/Makefile
index 8c0cd2175faa9566e56d66f52c2b8f2ee2eb1ee8..ab1c345afab4fed1d26d8a34131799af7c1823c4 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -103,6 +103,7 @@ SRC_LIB = $(addprefix lib/,\
 	mp-readline/readline.c \
 	netutils/netutils.c \
 	timeutils/timeutils.c \
+	utils/pyexec.c \
 	)
 
 SRC_C = \
@@ -132,7 +133,6 @@ SRC_C = \
 	printf.c \
 	gccollect.c \
 	pybstdio.c \
-	pyexec.c \
 	help.c \
 	input.c \
 	modmachine.c \
diff --git a/teensy/Makefile b/teensy/Makefile
index 32f753b3eb1d8ee520486e5ae073d2bfbc08dfd1..42cb5123e556efe872a74d6fcf9dac492378aff6 100644
--- a/teensy/Makefile
+++ b/teensy/Makefile
@@ -99,7 +99,6 @@ STM_SRC_C = $(addprefix stmhal/,\
 	pin.c \
 	pin_named_pins.c \
 	printf.c \
-	pyexec.c \
 	pybstdio.c \
 	)
 
@@ -110,6 +109,7 @@ STM_SRC_S = $(addprefix stmhal/,\
 LIB_SRC_C = $(addprefix lib/,\
 	libc/string0.c \
 	mp-readline/readline.c \
+	utils/pyexec.c \
 	)
 
 SRC_TEENSY = $(addprefix core/,\