From 7ce71f4c8dacc84497e879482fcf27b4dc4dc3ce Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 17 Mar 2026 23:55:44 +0100 Subject: [PATCH] Fix macOS locale env for adafruit-nrfutil invocations Arduino IDE v2 invokes tools in an environment where `LANG=""` and `LC_ALL=` are not set to a specific encoding, as described in: https://github.com/arduino/arduino-ide/issues/1513#issuecomment-1293383639 The bundled adafruit-nrfutil binary is a PyInstaller-frozen app using Click, which expects the encoding to be set to UTF-8, and throws the following error on macOS: Traceback (most recent call last): File "__main__.py", line 317, in File "click/core.py", line 1134, in __call__ File "click/core.py", line 1040, in main File "click/_unicodefun.py", line 100, in _verify_python_env RuntimeError: Click will abort further execution because Python was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/unicode-support/ for mitigation steps. This system supports the C.UTF-8 locale which is recommended. You might be able to resolve your issue by exporting the following environment variables: export LC_ALL=C.UTF-8 export LANG=C.UTF-8 So, prepends `env LANG=C.UTF-8 LC_ALL=C.UTF-8` to each invokation in macOS, via a `.macosx` override, to force a valid locale. To avoid duplication, the tool arguments have been moved into a `.args` variable that is included in the normal call and the `.macosx` override. --- platform.txt | 8 ++++++-- programmers.txt | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/platform.txt b/platform.txt index f749ebd2..e7d24146 100644 --- a/platform.txt +++ b/platform.txt @@ -106,7 +106,9 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" ## Create dfu package zip file -recipe.objcopy.zip.pattern="{tools.nrfutil.cmd}" dfu genpkg --dev-type 0x0052 --sd-req {build.sd_fwid} --application "{build.path}/{build.project_name}.hex" "{build.path}/{build.project_name}.zip" +recipe.objcopy.zip.args=dfu genpkg --dev-type 0x0052 --sd-req {build.sd_fwid} --application "{build.path}/{build.project_name}.hex" "{build.path}/{build.project_name}.zip" +recipe.objcopy.zip.pattern="{tools.nrfutil.cmd}" {recipe.objcopy.zip.args} +recipe.objcopy.zip.pattern.macosx=env LANG=C.UTF-8 LC_ALL=C.UTF-8 "{tools.nrfutil.cmd}" {recipe.objcopy.zip.args} ## Create uf2 file #recipe.objcopy.uf2.pattern=python "{runtime.platform.path}/tools/uf2conv/uf2conv.py" -f {build.uf2_family} -c -o "{build.path}/{build.project_name}.uf2" "{build.path}/{build.project_name}.hex" @@ -139,7 +141,9 @@ tools.nrfutil.cmd.macosx={runtime.platform.path}/tools/adafruit-nrfutil/macos/ad tools.nrfutil.upload.params.verbose=--verbose tools.nrfutil.upload.params.quiet= -tools.nrfutil.upload.pattern="{cmd}" {upload.verbose} dfu serial -pkg "{build.path}/{build.project_name}.zip" -p {serial.port} -b 115200 --singlebank +tools.nrfutil.upload.args={upload.verbose} dfu serial -pkg "{build.path}/{build.project_name}.zip" -p {serial.port} -b 115200 --singlebank +tools.nrfutil.upload.pattern="{cmd}" {tools.nrfutil.upload.args} +tools.nrfutil.upload.pattern.macosx=env LANG=C.UTF-8 LC_ALL=C.UTF-8 "{tools.nrfutil.cmd}" {tools.nrfutil.upload.args} # --------------------------------------------------- # Burning bootloader with either jlink or nrfutil diff --git a/programmers.txt b/programmers.txt index 98b6effb..d736f90c 100644 --- a/programmers.txt +++ b/programmers.txt @@ -31,7 +31,9 @@ nrfutil_boot.program.cmd.windows={runtime.platform.path}/tools/adafruit-nrfutil/ nrfutil_boot.program.cmd.macosx={runtime.platform.path}/tools/adafruit-nrfutil/macos/adafruit-nrfutil # Burn bootloader pattern -nrfutil_boot.program.burn_pattern="{program.cmd}" --verbose dfu serial -pkg "{bootloader.file}.zip" -p {serial.port} -b 115200 --touch 1200 +nrfutil_boot.program.burn_pattern.args=--verbose dfu serial -pkg "{bootloader.file}.zip" -p {serial.port} -b 115200 --touch 1200 +nrfutil_boot.program.burn_pattern="{program.cmd}" {nrfutil_boot.program.burn_pattern.args} +nrfutil_boot.program.burn_pattern.macosx=env LANG=C.UTF-8 LC_ALL=C.UTF-8 "{program.cmd}" {nrfutil_boot.program.burn_pattern.args} # Remind user to select Jlink when used to upload sketch nrfutil_boot.program.params.quiet=