Using a custom sdkconfig.defaults file

I am using AWS FreeRTOS with the Espressif ESP32. I have mulitple configuration keys that do not match the default sdkconfig.defaults. They can be set using idf.py menuconfig, but this is manual and error-prone for more than one or two changes. Even more important, these customizations must be non-manually applied so that automated builds will work.

The documentation here: Getting started with the Espressif ESP32-DevKitC and the ESP-WROVER-KIT - FreeRTOS, says to supply a custom sdkconfig.default by using the -DIDF_SDKCONFIG_DEFAULTS=path/to/sdkconfig.default flag.

This does not work. When I start with a clean build, and use the command

cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -S . -B build -GNinja -DCMAKE_BUILD_TYPE=release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DIDF_SDKCONFIG_DEFAULTS=/home/me/tryagain/sdkconfig.defaults

the build fails like this:

Loading defaults file /home/ian/wwork/firefly/tryagain/build/sdkconfig.defaults...
Traceback (most recent call last):
  File "/home/ian/work/firefly/tryagain/vendors/espressif/esp-idf/tools/kconfig_new    /confgen.py", line 641, in <module>
    main()
  File "/home/ian/work/firefly/tryagain/vendors/espressif/esp-idf/tools/kconfig_new        /confgen.py", line 285, in main
    raise RuntimeError("Defaults file not found: %s" % name)
RuntimeError: Defaults file not found: /home/ian/work/firefly/tryagain/build/sdkconfig.defaults
CMake Error at vendors/espressif/esp-idf/tools/cmake/kconfig.cmake:225 (message):
  Failed to run confgen.py

Indeed, looking in the build directory, no sdkconfig.defaults or sdkconfig file has been generated. The named file does exist, so it is not a typo issue.

When I do a build without the -DIDF_SDKCONFIG_DEFAULTS flag set, the build completes successfully.

I’ve also tried:

  • cmake ... without the flag, then idf.py build with the flag
  • cmake ... without the flag, then with the flag
  • cmake ... without the flag, then overwriting the generated sdkconfig.defaults
  • etc

In every combination there is either an error in either the cmake build, or the idf.py build caused by a missing config key.

What is the proper approach to solve this problem?

Hi Ian,

This looks similar to ESP32 - Cannot use sdkconfig.defaults from custom location · Issue #3026 · aws/amazon-freertos · GitHub. Can you try the patch proposed there, and see if it resolves this issue?

Thanks,

Carl

Yes, that does work with caveats. I’m working from the project root directory called example_ulp1.
When I pass the complete path to the defaults file, like so:
cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -DIDF_SDKCONFIG_DEFAULTS=/home/ian/work/firefly/example_ulp1/sdkconfig.minimal -S . -B build -GNinja -DCMAKE_BUILD_TYPE=release -DCMAKE_EXPORT_COMPILE_COMMANDS=1
followed by
idf.py build
everything works as expected.

But using a relative path like this (executing in the example_ulp1 directory):
cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -DIDF_SDKCONFIG_DEFAULTS=sdkconfig.minimal -S . -B build -GNinja -DCMAKE_BUILD_TYPE=release -DCMAKE_EXPORT_COMPILE_COMMANDS=1
followed by
idf.py build
will fail when running confgen.

I think the CMake system needs a tiny bit more tweaking before this is a robust solution.

Ian

Moving to the Espressif category so that the @Espressif team can have better visibility as well.

Hi Ian,

I was able to reproduce this, and will forward this to the Espressif team.

Thanks,

Carl

Hi Ian,

Thanks for reporting this issue.

I’m attaching a patch that should fix the issue. Please try applying the patch and check if it works with relative path of custom sdkconfig.defaults as well.

Thanks,
Shubham

0001-esp32-Fix-issue-with-custom-sdkconfig.defaults.patch.zip (1015 Bytes)

The patch works.

After removing the build directory, I can run the initial cmake command with the -DIDF_SDKCONFIG_DEFAULTS=filename flag to build a target with my configuration.

This method does have the disadvantage that you can no longer simply run

idf.py menuconfig

after the cmake any more.
Thank you,
Ian

Hi Ian,

Can you share error log when you run idf.py menuconfig?
Running idf.py menuconfig works fine at my end.

Thanks,
Shubham

Hi @shubhamkulkarni97

I haven’t seen that error since, and I have been using the patch for the last 8 days.

I suspect the error was mine - most likely I moved the default file because I wanted to be sure menuconfig was running based on the build/sdkconfig.

That indeed causes an error, and I had looked in the fairly verbose trace, I would have seen it. I saw

CMake Error at vendors/espressif/esp-idf/tools/cmake/kconfig.cmake:225 (message):
  Failed to run confgen.py

which I had been seeing a lot of, so I stopped looking. Had I read one more line up:

RuntimeError: Defaults file not found:   home/ian/work/fiddle/example_ulp2/sdkconfig.prx

Sorry for the misinformation.

Ian