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

Made spiffs_mount() compatible with rBoot. #1292

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sming/Makefile-rboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ endif
# define your custom directories in the project's own Makefile before including this one
MODULES ?= app # default to app if not set by user
MODULES += $(THIRD_PARTY_DIR)/rboot/appcode
MODULES += $(SMING_HOME)/appspecific/rboot
EXTRA_INCDIR ?= include # default to include if not set by user

ENABLE_CUSTOM_LWIP ?= 1
Expand Down Expand Up @@ -313,7 +314,7 @@ ifeq ($(DISABLE_SPIFFS), 1)
endif

# linker flags used to generate the main object file
LDFLAGS = -nostdlib -u call_user_start -u Cache_Read_Enable_New -Wl,-static -Wl,--gc-sections -Wl,-Map=$(basename $@).map -Wl,-wrap,system_restart_local
LDFLAGS = -nostdlib -u call_user_start -u Cache_Read_Enable_New -u spiffs_get_storage_config -Wl,-static -Wl,--gc-sections -Wl,-Map=$(basename $@).map -Wl,-wrap,system_restart_local

ifeq ($(SPI_SPEED), 26)
flashimageoptions = -ff 26m
Expand Down
40 changes: 1 addition & 39 deletions Sming/Services/SpifFS/spiffs_sming.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "spiffs_sming.h"

#define LOG_PAGE_SIZE 256

spiffs _filesystemStorageHandle;

static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
Expand Down Expand Up @@ -39,7 +37,7 @@ the entire chip (chip erase). The W25Q32BV has 1,024 erasable sectors and 64 era
The small 4KB sectors allow for greater flexibility in applications that require data and parameter storage.
********************/

spiffs_config spiffs_get_storage_config()
spiffs_config __attribute__((weak)) spiffs_get_storage_config()
{
spiffs_config cfg = {0};
cfg.phys_addr = ( u32_t )flashmem_get_first_free_block_address();
Expand Down Expand Up @@ -185,39 +183,3 @@ bool spiffs_format_manual(u32_t phys_addr, u32_t phys_size)
spiffs_mount_manual(phys_addr, phys_size);
return true;
}

//int spiffs_check( void )
//{
// ets_wdt_disable();
// int res = (int)SPIFFS_check(&_filesystemStorageHandle);
// ets_wdt_enable();
// return res;
//}

void test_spiffs()
{
char buf[12] = {0};

// Surely, I've mounted spiffs before entering here

spiffs_file fd;
spiffs_stat st = {0};
SPIFFS_stat(&_filesystemStorageHandle, "my_file.txt", &st);
if (st.size <= 0)
{
fd = SPIFFS_open(&_filesystemStorageHandle, "my_file.txt", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
if (SPIFFS_write(&_filesystemStorageHandle, fd, (u8_t *)"Hello world", 11) < 0)
debugf("errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
SPIFFS_close(&_filesystemStorageHandle, fd);
debugf("file created");
}
else
debugf("file %s exist :)", st.name);


fd = SPIFFS_open(&_filesystemStorageHandle, "my_file.txt", SPIFFS_RDWR, 0);
if (SPIFFS_read(&_filesystemStorageHandle, fd, (u8_t *)buf, 11) < 0) debugf("errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
SPIFFS_close(&_filesystemStorageHandle, fd);

debugf("--> %s <--\n", buf);
}
3 changes: 2 additions & 1 deletion Sming/Services/SpifFS/spiffs_sming.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ extern "C" {

#include "spiffs.h"

#define LOG_PAGE_SIZE 256

void spiffs_mount();
void spiffs_mount_manual(u32_t phys_addr, u32_t phys_size);
void spiffs_unmount();
bool spiffs_format();
bool spiffs_format_internal(spiffs_config *cfg);
bool spiffs_format_manual(u32_t phys_addr, u32_t phys_size);
spiffs_config spiffs_get_storage_config();
extern void test_spiffs();

extern spiffs _filesystemStorageHandle;

Expand Down
23 changes: 23 additions & 0 deletions Sming/appspecific/rboot/overrides.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "spiffs_sming.h"

/*
* rBoot uses different spiffs organization and we need to override this method
* during application compile time in order to make automatic
* mounting with `spiffs_mount()` work as expected.
*/
spiffs_config spiffs_get_storage_config()
{
spiffs_config cfg = {0};
#ifdef RBOOT_SPIFFS_0
cfg.phys_addr = RBOOT_SPIFFS_0;
#elif RBOOT_SPIFFS_1
cfg.phys_addr = RBOOT_SPIFFS_1;
#else
#error "Define either RBOOT_SPIFFS_0 or RBOOT_SPIFFS_1"
#endif
cfg.phys_size = SPIFF_SIZE;
cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet
cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 2; // Important to make large
cfg.log_page_size = LOG_PAGE_SIZE; // as we said
return cfg;
}
2 changes: 1 addition & 1 deletion samples/Basic_WebClient/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void init()

#ifndef DISABLE_SPIFFS
debugf("trying to mount spiffs at 0x%08x, length %d", RBOOT_SPIFFS_0, SPIFF_SIZE);
spiffs_mount_manual(RBOOT_SPIFFS_0, SPIFF_SIZE);
spiffs_mount();
#endif

// Setup the WIFI connection
Expand Down