Sysprogs forums › Forums › VisualGDB › ESP32: Modifying flash settings for writing binary to partition
Tagged: ESP32 Flash Settings Partition
- This topic has 4 replies, 3 voices, and was last updated 3 months, 2 weeks ago by AnatoliKrassavine.
-
AuthorPosts
-
June 28, 2022 at 03:50 #32791tonicodeParticipant
Hello,
in our project we need to write a binary to the OTA0 partition when executing right-click on project – “Program FLASH memory” but we could not find a way to modify the flash settings.
We tried to right-click on the partition and select “Program from File”, but the flash command does not change:
“esptool.py esp32s3 -b 115200 –before=default_reset –after=hard_reset write_flash –flash_mode dio –flash_freq 80m –flash_size 8MB 0x0 bootloader/bootloader.bin 0x10000 main.bin 0x8000 partition_table/partition-table.bin”
We also tried modifying the file “Debug\flash_args” but this file is overwritten, when recompiling the project.
We need the flash command to look like:
“esptool.py esp32s3 -b 115200 –before=default_reset –after=hard_reset write_flash –flash_mode dio –flash_freq 80m –flash_size 8MB 0x0 bootloader/bootloader.bin 0x10000 main.bin 0x110000 oat.bin 0x8000 partition_table/partition-table.bin”
so that the main.bin is written to 0x10000 and the ota.bin is written to 0x110000.Is there a way to modify the flash settings to flash an additional binary to the OTA0 partition?
Thanks in advance,
ToniJune 28, 2022 at 08:00 #32792supportKeymasterHi,
The exact FLASH command line is not directly under VisualGDB’s control, however we can explain what parts are involved in computing it so that you can pinpoint the correct setting:
- ESP-IDF enumerates all KConfig files referenced by the project and stores them in the project_description.json file.
- VisualGDB scans the KConfig files referenced there and shows the ESP-IDF-specific settings based on them.
- When you change those settings in the GUI, VisualGDB updates the sdkconfig file.
- When you build the project using ESP-IDF scripts, they pick up the settings from sdkconfig, and compute various command lines based on them.
- Some command lines are saved to intermediate files such as flash_args
Modifying flash_args manually will indeed not work, since the build scripts will overwrite it. Instead you would need to find the ESP-IDF setting that controls its content and change it (either by editing sdkconfig directly, or via VisualGDB Project Properties that will let VisualGDB edit it for you). Searching ESP-IDF build scripts for flash_args or parts of the command line shown there could be a good starting point.
June 29, 2022 at 05:48 #32795tonicodeParticipantHi,
thank you for that information, unfortunately we could not find any way to modify the flash_args via sdkconfig or in the ESP-IDF build scripts.
What is the option “Program from File” when right-clicking on a Partion intended to do? See screenshot attached.
It does not seem to do anything, but according to the name it should set the File that is programmed to that partition.
Thanks
ToniAttachments:
You must be logged in to view attached files.June 29, 2022 at 08:13 #32798supportKeymasterHi,
You can try contacting Espressif for help, or patching the ESP-IDF build scripts yourself. VisualGDB works on top of the existing scripts and cannot do it for you.
The “program from file” option programs the specified file into the bounds of the partition reported by ESP-IDF. This is done once and does not change the ESP-IDF project properties, or override the regular ESP-IDF programming logic.
August 14, 2024 at 05:48 #35863AnatoliKrassavineParticipantHad a similar problem – here is a solution.
PROBLEM
First of all – it is an ESP-IDF defaults problem – not VisualGDB. Albeit, I would argue that for something like that VisualGDB could have provided a user-friendly configuration override
- The way partition writing logic is controlled is first esptool_py tool creates partition command skeleton using a fixed template
- Then, individual components which are interested in adding to partitions (eg spiffs, nvs, etc), add their own entries
- To support various tools within toolchain, the logic is then used to generate a number of configuration files overlapping in functionality
- To add rules for writing to partition, one typically usesĀ either esptool_py_flash_target_image() or esptool_py_flash_to_partition() CMAKE functions. The two functions do the same thing, except that the first one expects you to provide all details (offset, etc), while the second one tries to extract those details from configuration
CONCEPTUAL FIX
So, to fix the problem, we need to do two things:
- We need to disable the default partition logic which writes the project main binary to the first ‘app’ partition which happened to be mentioned in partition table – which is typically ‘factory’
- Add explicit partition writing rules to write binaries we want to each project directory
This has the benefit that we keep core ESP-IDF project-neutral and allow each project to define what it likes
STEP-BY-STEP FIX
The default partition logic is located in %ESP_IDF_HOME%\components\esptool_py\CMakeLists.txt
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
partition_table_get_partition_info(app_partition_offset “–partition-boot-default” “offset”)
esptool_py_custom_target(app-flash app “app”)`</div># esptool_py_flash_target_image(app-flash app “${app_partition_offset}” “${build_dir}/${PROJECT_BIN}”)
# esptool_py_flash_target_image(flash app “${app_partition_offset}” “${build_dir}/${PROJECT_BIN}”)
endif()to disable it – comment out the last two lines, as shown</div>
To add your own rules, create a new cmake file – lets call it “custom.flash.config.cmake”
Inside, specify something like that (I am using “esptool_py_flash_to_partition”, as it is cleaner)esptool_py_flash_to_partition(flash “factory” “${CMAKE_BINARY_DIR}/factory.bin”)
esptool_py_flash_to_partition(flash “app0” “${CMAKE_BINARY_DIR}/MyApp.bin”)
esptool_py_flash_to_partition(flash “app1” “${CMAKE_BINARY_DIR}/MyApp.bin”)Finally, reference the new CMAKE file from your add the following to your root CMakeLists.txt (assuming that your custom cmake file is in project root directory
include(custom.flash.config.cmake)
That is it.
- This reply was modified 3 months, 2 weeks ago by AnatoliKrassavine.
- This reply was modified 3 months, 2 weeks ago by AnatoliKrassavine.
-
AuthorPosts
- You must be logged in to reply to this topic.