espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.5k stars 7.26k forks source link

How can I create a fat image in cmakelists.txt from file (IDFGH-9763) #11095

Closed waruqi closed 1 year ago

waruqi commented 1 year ago

Answers checklist.

General issue report

I am porting https://github.com/espressif/esp-skainet/blob/master/examples/chinese_tts to my project.

but it use flash_voicedata.sh to flash voice data to partition.

https://github.com/espressif/esp-skainet/blob/master/examples/chinese_tts/flash_voicedata.sh#L19

I want to use cmake to create and flash it when I run idy.py flash

I found fatfs_create_rawflash_image api but it does not support to create partiton from data file. just support base directory.

fatfs_create_rawflash_image(<partition> <base_dir> [FLASH_IN_PROJECT])

but I want to use

fatfs_create_rawflash_image(voice_data ../esp_tts_voice_data_xiaole.dat FLASH_IN_PROJECT)
igrr commented 1 year ago

@waruqi Can you explain what you would like to see in the resulting partition? A root directory with that single file? If yes, you can simply move the file into a subdirectory and point fatfs_create_rawflash_image to that subdirectory. If you want to keep the file where it currently is in your project, simply create that subdirectory at build time somewhere under CMAKE_CURRENT_BINARY_DIR and then copy the file there. Then point fatfs_create_rawflash_image to that generated directory.

waruqi commented 1 year ago

I think esp_tts_voice_data_xiaoxin.dat should be a whole partition data file, not a plain file in fs.

because it will be flashed to the given partition directly.

python ${IDF_PATH}/components/esptool_py/esptool/esptool.py \
        --port $port --baud $baud --before default_reset --after hard_reset write_flash \
        --flash_mode dio --flash_freq 40m --flash_size detect 0x410000 esp_tts_voice_data_xiaoxin.dat

https://github.com/espressif/esp-skainet/blob/master/examples/chinese_tts/esp_tts_voice_data_xiaoxin.dat

# Name,  Type, SubType, Offset,  Size
factory, app,  factory, 0x010000, 4M
voice_data, data,  fat, 0x410000, 3890K <---- esp_tts_voice_data_xiaoxin.dat
igrr commented 1 year ago

I see. In that case, looks like there is no FAT filesystem at all, you just need to flash the file to the partition. You can refer to what esp-sr already does with models: https://github.com/espressif/esp-sr/blob/1f3692bbd947bb5a6263929155f0f7264f52b71d/CMakeLists.txt#L115

waruqi commented 1 year ago

Thanks!