Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files in the encrypted directory of the esp_littlefs file system are lost (IDFGH-14305) #15096

Open
3 tasks done
wolen666 opened this issue Dec 26, 2024 · 0 comments
Open
3 tasks done
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@wolen666
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

commit e3e112e (HEAD -> release/v5.1, origin/release/v5.1) Merge: c1f26c

Espressif SoC revision.

esp32c3

Operating System used.

macOS

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

esp32c3

Power Supply used.

USB

What is the expected behavior?

Files in the directory in developer mode should not be lost

What is the actual behavior?

I started nvs encryption in developer mode. This is my file system. The files in the directory existed after the first encryption, but when I used idf.py encrypted-flash monitor again, the files in the directory were lost.

Below is my specific file code information

file system files
LittleFS Configuration:
Block Size: 4096 / 0x1000
Image Size: 425984 / 0x68000
Block Count: 104
Name Max: 64
Image: /Users/ko_hon/matter1-2/connectedhomeip/examples/bridge-app3-0/esp32/build/storage.bin
Adding File: channel11.txt
Adding File: channel2.txt
Adding File: index.html
Adding File: .DS_Store
Adding File: channel1.txt
Adding File: hot16.txt
Adding File: cool18.txt
Adding File: cool30.txt
Adding File: cool24.txt
Adding File: cool25.txt
Adding File: cool19.txt
Adding File: hot17.txt
Adding File: hot29.txt
Adding File: cool27.txt
Adding File: cool26.txt
Adding File: hot28.txt
Adding File: cool22.txt
Adding File: cool23.txt
Adding File: air.txt
Adding File: onoff.txt
Adding File: cool21.txt
Adding File: cool20.txt
Adding File: hot23.txt
Adding File: hot22.txt
Adding File: hot20.txt
Adding File: hot21.txt
Adding File: hot19.txt
Adding File: hot25.txt
Adding File: cool17.txt
Adding File: cool16.txt
Adding File: hot24.txt
Adding File: hot30.txt
Adding File: hot18.txt
Adding File: hot26.txt
Adding File: cool28.txt
Adding File: cool29.txt
Adding File: hot27.txt
Adding File: channel22.txt

code:
#include "ir_file_system.h"
#include <dirent.h> // 提供 opendir, readdir, closedir 函数

#define SPIFFS_BASE_PATH "/littlefs"
#define SPIFFS_PARTITION_LABEL "storage"
static const char *TAG = "ir-spiffs";
nvs_handle_t Web_s; //网页状态句柄

void list_littlefs_files(const char *base_path)
{
DIR *dir = opendir(base_path);
if (dir == NULL) {
printf("Failed to open directory: %s\n", base_path);
return;
}

printf("Listing files in: %s\n", base_path);

struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
    printf("Found %s: %s\n", 
           (entry->d_type == DT_DIR) ? "directory" : "file", 
           entry->d_name);
    
    // 如果是目录,递归列出子目录中的内容
    if (entry->d_type == DT_DIR && 
        strcmp(entry->d_name, ".") != 0 && 
        strcmp(entry->d_name, "..") != 0) {
        
        char sub_path[512];
        snprintf(sub_path, sizeof(sub_path), "%s/%s", base_path, entry->d_name);
        list_littlefs_files(sub_path); // 递归调用
    }
}

closedir(dir);

}

// 初始化 LittleFS 文件系统
void ir_spiffs_init()
{
esp_vfs_littlefs_conf_t conf = {
.base_path = SPIFFS_BASE_PATH,
.partition_label = SPIFFS_PARTITION_LABEL, // 与分区表中的标签匹配
.format_if_mount_failed = false,
.dont_mount = false,
};

// 挂载 LittleFS 文件系统
esp_err_t ret = esp_vfs_littlefs_register(&conf);
if (ret != ESP_OK) {
    printf("Failed to mount or format filesystem (%s)\n", esp_err_to_name(ret));
    return;
}

printf("LittleFS mounted successfully!\n");

// 获取 LittleFS 分区信息
size_t total = 0, used = 0;
ret = esp_littlefs_info(conf.partition_label, &total, &used);
if (ret != ESP_OK) {
    printf("Failed to get LittleFS partition information (%s)\n", esp_err_to_name(ret));
} else {
        printf("LittleFS partition size: total: %d, used: %d\n", total, used);

    // 列出文件
    list_littlefs_files("/littlefs");
}

// 检查加密后的文件系统是否正常工作
FILE* file = fopen("/littlefs/index.html", "rb");
if (file == NULL) {
            printf("Failed to open index.html for reading\n");

} else {
    fclose(file);
    printf("Successfully opened index.html\n");
}

}

When I decrypt the firmware, the code exists without modifying the files in the directory.
Below is my encrypted partition.This problem will not occur if you use spiffs

Name, Type, SubType, Offset, Size, Flags

nvs, data, nvs, , 0x8000,
fctry1, data, nvs_keys,, 0x1000, encrypted
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x2000,
ota_0, app, ota_0, , 0x1B2000,
ota_1, app, ota_1, , 0x1B2000,
storage, data, littlefs,, 0x68000,
fctry, data, nvs, , 0x6000,

meuconfig setup
image
image
image
image

Steps to reproduce.

1.Initialize the esp_littlefs file system
2.Encryption developer mode

Debug Logs.

run log
LittleFS mounted successfully!
Failed to open index.html for reading

More Information.

No response

@wolen666 wolen666 added the Type: Bug bugs in IDF label Dec 26, 2024
@github-actions github-actions bot changed the title Files in the encrypted directory of the esp_littlefs file system are lost Files in the encrypted directory of the esp_littlefs file system are lost (IDFGH-14305) Dec 26, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

2 participants