IDE preferences LevelDB

On Arduino 1.8.19 there was preferences.txt where the IDE preferences were stored.

Now there is a LevelDB in Local Storage which is not easy to read by external tools. I want to read current esp32 board config from external script.

How can I read Arduino IDE 2.x preferences such as board config options from arduino-cli?

Hi @alecxs.

You definitely can't use Arduino CLI for this purpose.

It is possible to read it from a VS Code extension installed in Arduino IDE 2.x. The data is provided by this extension, which is bundled with the Arduino IDE installation:

In case they will be useful as a reference, here are some extensions that access this data:

Yes I am aware of VS Code extension, I have already asked for this.

My goal was to run a script from esp32 platform.txt

Then the information in the Arduino Platform Specification will be useful to you:

https://arduino.github.io/arduino-cli/latest/platform-specification/#custom-board-options

The Arduino boards platform framework doesn't provide the capability to determine which option is selected for each custom board option menu. However, it does allow you to use the values of the properties that are set via that option.

For example, if the user has selected from the Arduino IDE menus:

  • Tools > Board > esp32 > ESP32 Dev Module
  • Tools > Partition Scheme > RainMaker 8MB

Then according to the configuration of that custom board option:

  • The build.partitions property will be set to the value rainmaker_8MB
  • The upload.maximum_size property will be set to the value 4116480

You can reference those properties in platform.txt using this syntax:

  • {build.partitions}
  • {upload.maximum_size}

You can pass those values to an arbitrary external command, application, or script. You will find the "Pre and post build hooks" feature useful for that purpose:

https://arduino.github.io/arduino-cli/latest/platform-specification/#pre-and-post-build-hooks-since-arduino-ide-165

I think there is a good chance that this will allow you to accomplish the equivalent of your stated goal:

You are welcome to add additional arbitrary properties to the custom board options if the existing properties are insufficient. For example, if I added this line to boards.txt:

esp32.menu.PartitionScheme.rainmaker_8MB.foo=bar

Then the foo property will be set to the value bar when compiling or uploading while Tools > Partition Scheme > RainMaker 8MB is selected from the Arduino IDE menus.

If you are patching the "esp32" boards platform installation (as opposed to submitting your changes to be distributed to the users in the platform), then you will find it convenient to make your patches via the platform.local.txt and boards.local.txt files instead of modifying the platform.txt and boards.txt files:

1 Like

Thank you for linking the docs to this! I tried creating my own platform.local.txt and the script is executed (for testing purposes only Windows for Partition Scheme: "Custom").

platform.local.txt
tools.cust_app_partsize.cmd.windows="{runtime.platform.path}\tools\cust_app_partsize.bat"
recipe.hooks.prebuild.8.pattern.windows=cmd /c if exist "{build.source.path}\partitions.csv" {tools.cust_app_partsize.cmd} "{build.source.path}\partitions.csv" "{build.partitions}" "{build.fqbn}"
cust_app_partsize.bat
@echo off
setlocal enabledelayedexpansion
set "parent_dir=%~dp0"

if "%~3"=="" (
    echo Error: %~nx0: usage: partitions.csv {build.partitions} {build.fqbn}
    goto :EOF
)

rem todo: arguments are somehow not processed correctly
set "csv_file=%~1"
set "build.partitions=%~2"
set "build.fqbn=%~3"

for /f "usebackq tokens=1-6 delims=," %%a in ("%csv_file%") do (
rem todo: for some reason regex won't work inside batch file
rem    echo %%a | findstr /r /c:"\<app\>" > nul
    echo %%a | findstr /c:"app" > nul
    if !errorlevel! == 0 (
        set hex_value=%%e
        set /a upload.maximum_size=!hex_value!
        goto :mod
    )
)
goto :EOF

:mod
for %%i in ("%parent_dir:~0,-1%") do set "runtime.platform.path=%%~dpi"

for /f "tokens=3 delims=:" %%a in ("%build.fqbn%") do (
    for /f "tokens=1 delims=:" %%b in ("%%a") do (
        set "build.variant=%%b"
    )
)

rem todo: update file instead of deleting boards.local.txt
if "%build.partitions%" == "custom" (
    echo %~nx0: upload.maximum_size=!upload.maximum_size! %csv_file%
	echo %build.variant%.upload.maximum_size=!upload.maximum_size!> "%runtime.platform.path%\boards.local.txt"
    echo %build.variant%.menu.PartitionScheme.%build.partitions%=%build.partitions%>> "%runtime.platform.path%\boards.local.txt"
    echo %build.variant%.menu.PartitionScheme.%build.partitions%.build.partitions=%build.partitions%>> "%runtime.platform.path%\boards.local.txt"
    echo %build.variant%.menu.PartitionScheme.%build.partitions%.upload.maximum_size=!upload.maximum_size!>> "%runtime.platform.path%\boards.local.txt"
)

I can confirm the boards.local.txt is created from script.

boards.local.txt
esp32.upload.maximum_size=1441792
esp32.menu.PartitionScheme.custom=custom
esp32.menu.PartitionScheme.custom.build.partitions=custom
esp32.menu.PartitionScheme.custom.upload.maximum_size=1441792

However, still uploading failes with error; it seems the boards.local.txt is only processed once, when starting IDE.

Sketch uses 1349205 bytes (102%) of program storage space. Maximum is 1310720 bytes.

If I close the Arduino IDE, restart and compile again, the values are now updated and uploading Sketch is successful.

Sketch uses 1349205 bytes (93%) of program storage space. Maximum is 1441792 bytes.

Is there a chance to not just read, but set/update {upload.maximum_size} property in place during runtime? Or is this approach a dead end.

There is a known bug in IDE 2.x; any change to platform.txt (even the normal one) is not picked up on the fly; will probably apply to the other text files as well.

I think that it's this one on github: Changes to custom board option definitions in `boards.txt` are not picked up · Issue #1030 · arduino/arduino-ide · GitHub but not 100% sure; there might be another one.

That is correct.

Which version of Arduino IDE are you using? A feature was added in Arduino IDE 2.3.3 that should communicate to you when changes have been made to the platform configuration files, but not loaded by Arduino IDE.

I'm not aware of a specific way to do this. It is theoretically possible that you could somehow trigger an Init request from Arduino CLI via its gRPC interface. Or perhaps make a custom VS Code extension that will trigger an initialization via Arduino IDE.

However, I think a better approach would be to create a custom sketch size tool (which can be a batch file if you like):

https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-compute-binary-sketch-size-for-more-complex-systems-since-arduino-cli-0210

The only changes you would make to the platform is configuring platform.txt/platform.local.txt to use the custom size tool via recipe.advanced_size.pattern. Then you would do everything else in the tool.

1 Like

That is the solution I am looking for. Not what I have asked in the question but way better approach. I have successfully tested and created a batch file that outputs the JSON structure, it works as described in documents.

Now all that's left is, find a platform developer who will add this to the platform.txt soon.

I will prepare the windows batch file and some linux shell script as proof of concept and open new issue on the espressif arduino-esp32 core.

:slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.