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

Storage improvements #2263

Merged
merged 10 commits into from
Mar 14, 2021
10 changes: 10 additions & 0 deletions Sming/Arch/Esp32/Components/spi_flash/flashmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <soc/dport_reg.h>
#include <esp_app_format.h>
#include <esp_flash_partitions.h>
#include <esp_flash.h>

/*
* Physical <-> Virtual address mapping is handled in `$IDF_COMPONENTS/spi_flash/flash_mmap.c`.
Expand Down Expand Up @@ -115,3 +116,12 @@ uint32_t flashmem_get_sector_of_address(uint32_t addr)
{
return flashmem_find_sector(addr, NULL, NULL);
}

uint32_t spi_flash_get_id(void)
{
uint32_t id{0};
if(esp_flash_read_id(esp_flash_default_chip, &id) != ESP_OK) {
id = 0;
}
return id;
}
2 changes: 2 additions & 0 deletions Sming/Arch/Esp32/Components/spi_flash/include/esp_spi_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ uint32_t flashmem_get_sector_of_address(uint32_t addr);

/** @} */

uint32_t spi_flash_get_id(void);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion Sming/Arch/Esp32/standard.hw
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"factory": {
"address": "0x010000",
"size": "0x1f0000",
"size": "0x180000",
"type": "app",
"subtype": "factory",
"filename": "$(TARGET_BIN)"
Expand Down
7 changes: 7 additions & 0 deletions Sming/Arch/Host/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ $(RUN_SCRIPT)::
$(foreach id,$(ENABLE_HOST_UARTID),echo '$(call RunHostTerminal,$(id))' >> $@;) \
echo '$(TARGET_OUT_0) $(CLI_TARGET_OPTIONS) -- $(HOST_PARAMETERS)' >> $@; \
chmod a+x $@

##@Flashing

.PHONY: flashconfig
flashconfig: kill_term ##Erase the rBoot config sector
$(info Erasing rBoot config sector)
$(call WriteFlash,$(FLASH_RBOOT_ERASE_CONFIG_CHUNKS))
2 changes: 1 addition & 1 deletion Sming/Components/Storage/Tools/hwconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def findConfig(name):
dirs = os.environ['HWCONFIG_DIRS'].split(' ')
for d in dirs:
path = os.path.join(fixpath(d), name + '.hw')
path = fixpath(d) + '/' + name + '.hw'
if os.path.exists(path):
return path
raise InputError("Config '%s' not found" % name)
Expand Down
1 change: 0 additions & 1 deletion Sming/Components/Storage/src/Iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "include/Storage/Iterator.h"
#include "include/Storage/SpiFlash.h"
#include <debug_progmem.h>

namespace Storage
{
Expand Down
5 changes: 5 additions & 0 deletions Sming/Components/Storage/src/SpiFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ String SpiFlash::getName() const
return FS_SPIFLASH;
}

uint32_t SpiFlash::getId() const
{
return spi_flash_get_id();
}

size_t SpiFlash::getBlockSize() const
{
return SPI_FLASH_SEC_SIZE;
Expand Down
9 changes: 9 additions & 0 deletions Sming/Components/Storage/src/include/Storage/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class Device : public LinkedObjectTemplate<Device>
*/
virtual String getName() const = 0;

/**
* @brief Obtain device ID
* @retval uint32_t typically flash chip ID
*/
virtual uint32_t getId() const
{
return 0;
}

/**
* @brief Obtain smallest allocation unit for erase operations
*/
Expand Down
2 changes: 2 additions & 0 deletions Sming/Components/Storage/src/include/Storage/SpiFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SpiFlash : public Device
return Type::flash;
}

uint32_t getId() const;

bool read(uint32_t address, void* dst, size_t size) override;
bool write(uint32_t address, const void* src, size_t size) override;
bool erase_range(uint32_t address, size_t size) override;
Expand Down
3 changes: 2 additions & 1 deletion Sming/Components/rboot/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ COMPONENT_CXXFLAGS += \

ifdef RBOOT_EMULATION
FLASH_BOOT_CHUNKS = 0x00000=$(BLANK_BIN)
FLASH_RBOOT_ERASE_CONFIG_CHUNKS := 0x01000=$(BLANK_BIN)
else
export RBOOT_ROM0_ADDR
export RBOOT_ROM1_ADDR
Expand All @@ -151,7 +152,7 @@ endif

# Define our flash chunks
FLASH_BOOT_CHUNKS := 0x00000=$(RBOOT_BIN)
FLASH_RBOOT_ERASE_CONFIG_CHUNKS := 0x01000=$(SDK_BASE)/bin/blank.bin
FLASH_RBOOT_ERASE_CONFIG_CHUNKS := 0x01000=$(BLANK_BIN)

# => Automatic linker script generation from template
# $1 -> application target
Expand Down
19 changes: 19 additions & 0 deletions samples/Basic_Storage/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@

IMPORT_FSTR(FS_app, PROJECT_DIR "/app/application.cpp")

void listDevices()
{
Serial.println();
Serial.println(_F("Registered storage devices:"));
for(auto& dev : Storage::getDevices()) {
Serial.print(" name = '");
Serial.print(dev.getName());
Serial.print(_F("', type = "));
Serial.print(toString(dev.getType()));
Serial.print(_F(", size = 0x"));
Serial.print(dev.getSize(), HEX);
Serial.print(_F(", ID = 0x"));
Serial.println(dev.getId), HEX);
}
Serial.println();
}

void listSpiffsPartitions()
{
Serial.println(_F("** Enumerate registered SPIFFS partitions"));
Expand Down Expand Up @@ -63,6 +80,8 @@ void init()
Serial.begin(SERIAL_BAUD_RATE);
Serial.systemDebugOutput(true);

listDevices();

listSpiffsPartitions();

printPart(F("user0"));
Expand Down
1 change: 0 additions & 1 deletion samples/Basic_Storage/basic_storage.hw
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"devices": {
// Override default (conservative) flash settings for maximum performance
"spiFlash": {
"mode": "qio",
"speed": 80
}
},
Expand Down
9 changes: 5 additions & 4 deletions samples/Basic_rBoot/app/application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <SmingCore.h>
#include <Network/RbootHttpUpdater.h>
#include <Storage/SpiFlash.h>

// download urls, set appropriately
#define ROM_0_URL "http://192.168.7.5:80/rom0.bin"
Expand Down Expand Up @@ -114,16 +115,16 @@ void ShowInfo()
Serial.printf("Free Heap: %d\r\n", system_get_free_heap_size());
Serial.printf("CPU Frequency: %d MHz\r\n", system_get_cpu_freq());
Serial.printf("System Chip ID: %x\r\n", system_get_chip_id());
Serial.printf("SPI Flash ID: %x\r\n", spi_flash_get_id());
Serial.printf("SPI Flash ID: %x\r\n", Storage::spiFlash->getId());
//Serial.printf("SPI Flash Size: %d\r\n", (1 << ((spi_flash_get_id() >> 16) & 0xff)));

rboot_config conf;
conf = rboot_get_config();

debugf("Count: %d", conf.count);
debugf("ROM 0: %d", conf.roms[0]);
debugf("ROM 1: %d", conf.roms[1]);
debugf("ROM 2: %d", conf.roms[2]);
debugf("ROM 0: 0x%08x", conf.roms[0]);
debugf("ROM 1: 0x%08x", conf.roms[1]);
debugf("ROM 2: 0x%08x", conf.roms[2]);
debugf("GPIO ROM: %d", conf.gpio_rom);
}

Expand Down
2 changes: 0 additions & 2 deletions samples/Basic_rBoot/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ ifeq ($(SMING_ARCH),Esp8266)
HWCONFIG := basic_rboot
else
HWCONFIG := spiffs
# Emulate UART 0
ENABLE_HOST_UARTID := 0
endif
4 changes: 2 additions & 2 deletions tests/HostTests/modules/Spiffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SpiffsTest : public TestGroup
*/
void cycleFlash()
{
spiffs_unmount();
fileFreeFileSystem();
if(!spiffs_mount()) {
debug_e("SPIFFS mount failed");
return;
Expand Down Expand Up @@ -68,7 +68,7 @@ class SpiffsTest : public TestGroup
debug_i("Sector #0 erased after %u writes", writeCount);

// Re-mount file system and confirm test file is still present
spiffs_unmount();
fileFreeFileSystem();
spiffs_mount();
auto content = fileGetContent(testFile);
REQUIRE(testContent == content);
Expand Down