feat(fatfs): modify FATFS for ESP8266

This commit is contained in:
Dong Heng
2020-02-27 11:46:10 +08:00
parent 3bbadfa6de
commit 3690eab433
14 changed files with 166 additions and 17 deletions

View File

@ -19,7 +19,7 @@
#include "esp_err.h" #include "esp_err.h"
#include "sdmmc_types.h" #include "sdmmc_types.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/spi_master.h" // #include "driver/spi_master.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -32,7 +32,7 @@ extern "C" {
* *
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST. * 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
*/ */
#define SDSPI_HOST_DEFAULT() {\ /*#define SDSPI_HOST_DEFAULT() {\
.flags = SDMMC_HOST_FLAG_SPI, \ .flags = SDMMC_HOST_FLAG_SPI, \
.slot = HSPI_HOST, \ .slot = HSPI_HOST, \
.max_freq_khz = SDMMC_FREQ_DEFAULT, \ .max_freq_khz = SDMMC_FREQ_DEFAULT, \
@ -47,7 +47,7 @@ extern "C" {
.io_int_enable = &sdspi_host_io_int_enable, \ .io_int_enable = &sdspi_host_io_int_enable, \
.io_int_wait = &sdspi_host_io_int_wait, \ .io_int_wait = &sdspi_host_io_int_wait, \
.command_timeout_ms = 0, \ .command_timeout_ms = 0, \
} }*/
/** /**
* Extra configuration for SPI host * Extra configuration for SPI host

View File

@ -1,6 +1,5 @@
set(srcs "diskio/diskio.c" set(srcs "diskio/diskio.c"
"diskio/diskio_rawflash.c" "diskio/diskio_rawflash.c"
"diskio/diskio_sdmmc.c"
"diskio/diskio_wl.c" "diskio/diskio_wl.c"
"src/ff.c" "src/ff.c"
"port/freertos/ffsystem.c" "port/freertos/ffsystem.c"
@ -14,5 +13,5 @@ endif()
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
INCLUDE_DIRS diskio vfs src INCLUDE_DIRS diskio vfs src
REQUIRES wear_levelling sdmmc REQUIRES wear_levelling
) )

View File

@ -1,3 +1,3 @@
COMPONENT_ADD_INCLUDEDIRS := diskio vfs src COMPONENT_ADD_INCLUDEDIRS := diskio vfs src
COMPONENT_SRCDIRS := diskio vfs port/freertos src COMPONENT_SRCDIRS := diskio vfs port/freertos src
COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o diskio/diskio_sdmmc.o vfs/vfs_fat_sdmmc.o

View File

@ -694,7 +694,7 @@ static void read_write_task(void* param)
srand(args->seed); srand(args->seed);
for (size_t i = 0; i < args->word_count; ++i) { for (size_t i = 0; i < args->word_count; ++i) {
uint32_t val = rand(); uint32_t val = i * 77;
if (args->write) { if (args->write) {
int cnt = fwrite(&val, sizeof(val), 1, f); int cnt = fwrite(&val, sizeof(val), 1, f);
if (cnt != 1) { if (cnt != 1) {

View File

@ -41,13 +41,30 @@ static void test_setup(size_t max_files)
}; };
const esp_partition_t* part = get_test_data_partition(); const esp_partition_t* part = get_test_data_partition();
TEST_ASSERT(part->size == (fatfs_end - fatfs_start - 1)); TEST_ASSERT(part->size >= (fatfs_end - fatfs_start - 1));
spi_flash_mmap_handle_t mmap_handle; // spi_flash_mmap_handle_t mmap_handle;
const void* mmap_ptr; // const void* mmap_ptr;
TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle)); // TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0; // bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
spi_flash_munmap(mmap_handle); // spi_flash_munmap(mmap_handle);
size_t max_space_size = MIN(part->size, fatfs_end - fatfs_start - 1);
bool content_valid = true;
char *buf = malloc(4096);
TEST_ASSERT_NOT_NULL(buf);
for (size_t i = 0; i < max_space_size; i += 4096) {
size_t bytes = MIN(4096, max_space_size - i);
TEST_ESP_OK(esp_partition_read(part, i, buf, bytes));
if (memcmp(fatfs_start + i, buf, bytes)) {
content_valid = false;
break;
}
}
free(buf);
if (!content_valid) { if (!content_valid) {
printf("Copying fatfs.img into test partition...\n"); printf("Copying fatfs.img into test partition...\n");

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#if 0
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -297,4 +299,6 @@ TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected using UTF-
} }
#endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936 #endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936
#endif #endif
#endif

View File

@ -11,7 +11,7 @@ else ifdef CONFIG_NEWLIB_LIBRARY_LEVEL_FLOAT_NANO
LIB_PATH := $(COMPONENT_PATH)/newlib/lib/libc_fnano.a $(COMPONENT_PATH)/newlib/lib/libm.a LIB_PATH := $(COMPONENT_PATH)/newlib/lib/libc_fnano.a $(COMPONENT_PATH)/newlib/lib/libm.a
endif endif
COMPONENT_ADD_INCLUDEDIRS += newlib/port/include newlib/include COMPONENT_ADD_INCLUDEDIRS := newlib/port/include newlib/include
COMPONENT_SRCDIRS += newlib/port COMPONENT_SRCDIRS += newlib/port
COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib
COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH) COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH)

View File

@ -110,7 +110,7 @@ typedef _fpos64_t fpos64_t;
#ifdef __FOPEN_MAX__ #ifdef __FOPEN_MAX__
#define FOPEN_MAX __FOPEN_MAX__ #define FOPEN_MAX __FOPEN_MAX__
#else #else
#define FOPEN_MAX 20 #define FOPEN_MAX 10
#endif #endif
#ifdef __FILENAME_MAX__ #ifdef __FILENAME_MAX__

View File

@ -0,0 +1,31 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ESP_SYS_UNISTD_H
#define _ESP_SYS_UNISTD_H
#ifdef __cplusplus
extern "C" {
#endif
#include_next <sys/unistd.h>
int truncate(const char *, off_t __length);
int gethostname(char *__name, size_t __len);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_UNISTD_H */

View File

@ -0,0 +1,35 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _UTIME_H_
#define _UTIME_H_
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
struct utimbuf {
time_t actime; // access time
time_t modtime; // modification time
};
int utime(const char *path, const struct utimbuf *times);
#ifdef __cplusplus
};
#endif
#endif /* _UTIME_H_ */

View File

@ -0,0 +1,21 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <unistd.h>
#include "esp_vfs.h"
ssize_t pread(int fd, void *dst, size_t size, off_t offset)
{
return esp_vfs_pread(fd, dst, size, offset);
}

View File

@ -0,0 +1,21 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <unistd.h>
#include "esp_vfs.h"
ssize_t pwrite(int fd, const void *src, size_t size, off_t offset)
{
return esp_vfs_pwrite(fd, src, size, offset);
}

View File

@ -0,0 +1,21 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <utime.h>
#include "esp_vfs.h"
int utime(const char *path, const struct utimbuf *times)
{
return esp_vfs_utime(path, times);
}

View File

@ -9,6 +9,6 @@ factory, 0, 0, 0x10000, 0xF0000
ota_0, 0, ota_0, , 64K ota_0, 0, ota_0, , 64K
ota_1, 0, ota_1, , 64K ota_1, 0, ota_1, , 64K
# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests # flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests
flash_test, data, fat, , 528K flash_test, data, fat, , 896K
# Note: still 1MB of a 4MB flash left free for some other purpose # Note: still 1MB of a 4MB flash left free for some other purpose

1 # Special partition table for unit test app
9 ota_0, 0, ota_0, , 64K
10 ota_1, 0, ota_1, , 64K
11 # flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests
12 flash_test, data, fat, , 528K flash_test, data, fat, , 896K
13 # Note: still 1MB of a 4MB flash left free for some other purpose
14