Selecting "partition.csv" filename in sdkconfig depending on sdkconfig config option

eriksl
Posts: 116
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Selecting "partition.csv" filename in sdkconfig depending on sdkconfig config option

Postby eriksl » Fri Sep 06, 2024 6:58 pm

Hi this may sound a bit complex, but it's not really, I think.

At this moment I am doing work on supporting multiple boards with one set of source files. Before I did this with multiple project directories that symlinked to selected source files and therefore each board would have it's own sdkconfig. This had some drawbacks.

Now I have only one project directory, with the source files residing under "main" as usual and additionally a file Kconfig.projbuild there that has kconfig statements to enable the user to select one board type. When a board is selected, some config options are automatically set, e.g. the amount of flash and spiram, which are required to be known during compile time.

This works. No problem there.

Now what I am bumping into: various boards have various flash chip sizes e.g. need different partition tables. I'd thought I solve this by setting the existing Kconfig symbol PARTITION_TABLE_CUSTOM_FILENAME in my own piece of additional Kconfig statements in Kconfig.projbuild. But it doesn't work. At least I can't get it to work. PARTITION_TABLE_CUSTOM_FILENAME already has a "default" value set by ESP-IDF and I cannot overwrite it in my own kconfig file. I've tried various methods and either I get errors from Kconfig or the value I set is ignored.

Anyone a thought on how to solve this? How do you tackle this if you have multiple boards (with different flash sizes) you want to support?

Thanks!

nopnop2002
Posts: 111
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Selecting "partition.csv" filename in sdkconfig depending on sdkconfig config option

Postby nopnop2002 » Thu Sep 19, 2024 2:33 am

You can replace the partition definition (CSV) according to CONFIG values.

partitions_example_64k.csv

Code: Select all

nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
storage,  data, spiffs,  ,        64K,

partitions_example_128k.csv

Code: Select all

nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
storage,  data, spiffs,  ,        128K,
main/Kconfig.projbuild

Code: Select all

menu "Application Configuration"

        choice PARTITION
                prompt "Select storage partitions size"
                default 64K
                help
                        Select storage partition sizey.
                config 64K
                        bool "storage is 64K"
                        help
                                storage is 64K
                config 128K
                        bool "storage is 128K"
                        help
                                storage is 128K
        endchoice

endmenu

main/CMakeLists.txt

Code: Select all

set(TARGET_FILE "${CMAKE_SOURCE_DIR}/partitions_example.csv")
if(CONFIG_64K)
        message(STATUS "CONFIG_64K")
        set(SOURCE_FILE "${CMAKE_SOURCE_DIR}/partitions_example_64k.csv")
        message(STATUS ${SOURCE_FILE})
        file(COPY_FILE ${SOURCE_FILE} ${TARGET_FILE})
elseif(CONFIG_128K)
        message(STATUS "CONFIG_128K")
        set(SOURCE_FILE "${CMAKE_SOURCE_DIR}/partitions_example_128k.csv")
        message(STATUS ${SOURCE_FILE})
        file(COPY_FILE ${SOURCE_FILE} ${TARGET_FILE})
endif()
sdkconfig.defaults

Code: Select all

CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv"

This is the main/CMakeLists.txt I'm using.

Code: Select all

set(TARGET_FILE "${CMAKE_SOURCE_DIR}/partitions_example.csv")
message(STATUS ${TARGET_FILE})
if(CONFIG_ESPTOOLPY_FLASHSIZE_2MB)
    message(STATUS "CONFIG_ESPTOOLPY_FLASHSIZE_2MB")
    set(SOURCE_FILE "${CMAKE_SOURCE_DIR}/partitions_example_2M.csv")
    message(STATUS ${SOURCE_FILE})
    file(COPY_FILE ${SOURCE_FILE} ${TARGET_FILE})
elseif(CONFIG_ESPTOOLPY_FLASHSIZE_4MB)
    message(STATUS "CONFIG_ESPTOOLPY_FLASHSIZE_4MB")
    set(SOURCE_FILE "${CMAKE_SOURCE_DIR}/partitions_example_4M.csv")
    message(STATUS ${SOURCE_FILE})
    file(COPY_FILE ${SOURCE_FILE} ${TARGET_FILE})
endif()
idf_component_register(SRCS "main.c" INCLUDE_DIRS ".")

eriksl
Posts: 116
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Re: Selecting "partition.csv" filename in sdkconfig depending on sdkconfig config option

Postby eriksl » Thu Sep 19, 2024 6:51 am

Thank you!

This is almost exactly as I did it, after a tip from an Espressif employee, see here: https://github.com/espressif/esp-idf/is ... 2337608491

Apparently I am not the only one that needs this, after all :)

I merged this with a few other board-specific settings, to have "CONFIG_*" values too.

The crux appears to be:
- start with making a sdkconfig.defaults file (so you can remove the sdkconfig file completely)
- create a directory for each board to be supported (not really required)
- make a Kconfig.projbuild file in your sources directory with the required config values, including the name of the partitions file
- create a sdkconfig.defaults file for each board separately from the generic sdkconfig.defaults file, make sure there are no overlapping options
- create a build directory for each board (this IS required)

call idf with idf.py -B "${IDF_BUILD}" -D "${IDF_DEFAULTS}", where
- IDF_BUILD is the relevant build directory per board
- IDF_DEFAULTS is the generic and the board specific defaults file, separated by a semicolon.

Anyway, it's explained pretty nicely in the article which is referred to in the link.

Works like a charm!

Enables you to work on several boards at the same time, and retaining all temporary work in the meantime (compilation objects, image files...)

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 190 guests