diff --git a/Sming/Components/Storage/README.rst b/Sming/Components/Storage/README.rst index 4b86403ff0..ef4a5cccd9 100644 --- a/Sming/Components/Storage/README.rst +++ b/Sming/Components/Storage/README.rst @@ -189,7 +189,7 @@ To customise the hardware configuration for a project, for example 'my_project': To rebuild these manually type:: - make partbuild + make buildpart These will be removed when ``make clean`` is run, but you can also clean them separately thus:: @@ -338,14 +338,13 @@ This is a C++ interface. Some examples:: } // Enumerate all partitions - for(auto it = Storage::findPartition(); it; ++it) { - auto part = *it; + for(auto part: Storage::findPartition()) { debugf("Found '%s' at 0x%08x, size 0x%08x", part.name().c_str(), part.address(), part.size()); } // Enumerate all SPIFFS partitions - for(auto it = Storage::findPartition(Partition::SubType::Data::spiffs; it; it++) { - debugf("Found '%s' at 0x%08x, size 0x%08x", it->name().c_str(), it->address(), it->size()); + for(auto part: Storage::findPartition(Storage::Partition::SubType::Data::spiffs)) { + debugf("Found '%s' at 0x%08x, size 0x%08x", part.name().c_str(), part.address(), part.size()); } diff --git a/Sming/Components/Storage/Tools/hwconfig/config.py b/Sming/Components/Storage/Tools/hwconfig/config.py index 2056c49461..fb5ebe9277 100644 --- a/Sming/Components/Storage/Tools/hwconfig/config.py +++ b/Sming/Components/Storage/Tools/hwconfig/config.py @@ -176,7 +176,7 @@ def dict(self): res['name'] = self.name if hasattr(self, 'comment'): res['comment'] = self.comment - res['arch'] = self.arch; + res['arch'] = self.arch res['options'] = self.options res['bootloader_size'] = size_format(self.bootloader_size) res['partition_table_offset'] = addr_format(self.partition_table_offset) diff --git a/Sming/Components/Storage/Tools/hwconfig/partition.py b/Sming/Components/Storage/Tools/hwconfig/partition.py index 6585d81544..51549d4e0d 100644 --- a/Sming/Components/Storage/Tools/hwconfig/partition.py +++ b/Sming/Components/Storage/Tools/hwconfig/partition.py @@ -395,6 +395,8 @@ def parse_dict(self, data, devices): def resolve_expressions(self): try: + SMING_ARCH = os.environ['SMING_ARCH'] + SMING_SOC = os.environ['SMING_SOC'] self.address = eval(str(self.address)) except Exception: self.address = parse_int(self.address) diff --git a/Sming/Components/Storage/component.mk b/Sming/Components/Storage/component.mk index b1691e2aaf..24967d8da7 100644 --- a/Sming/Components/Storage/component.mk +++ b/Sming/Components/Storage/component.mk @@ -39,6 +39,8 @@ PARTITION_TOOLS := $(PARTITION_PATH)/Tools HWCONFIG_SCHEMA := $(PARTITION_PATH)/schema.json HWCONFIG_VARS := \ SMING_HOME \ + SMING_ARCH \ + SMING_SOC \ OUT_BASE \ HWCONFIG_DIRS \ HWCONFIG_OPTS \ diff --git a/Sming/Components/Storage/src/Debug.cpp b/Sming/Components/Storage/src/Debug.cpp index 37d261ecea..422c0573b1 100644 --- a/Sming/Components/Storage/src/Debug.cpp +++ b/Sming/Components/Storage/src/Debug.cpp @@ -26,9 +26,9 @@ void listPartitions(Print& out) { out.println(); out.println(_F("Registered partitions:")); - for(auto it = Storage::findPartition(); it; ++it) { + for(auto part : Storage::findPartition()) { out.print("- "); - printPartition(out, *it); + printPartition(out, part); } out.println(); } diff --git a/Sming/Components/Storage/src/Iterator.cpp b/Sming/Components/Storage/src/Iterator.cpp index e7a4e2a2ab..8abc2a6c5b 100644 --- a/Sming/Components/Storage/src/Iterator.cpp +++ b/Sming/Components/Storage/src/Iterator.cpp @@ -13,19 +13,8 @@ namespace Storage { -Iterator::Iterator(Device& device, uint8_t partitionIndex) - : mSearch{&device, Partition::Type::any, Partition::SubType::any}, mDevice(&device), mPos(partitionIndex) - -{ - if(partitionIndex >= device.partitions().count()) { - mDevice = nullptr; - mPos = afterEnd; - } -} - -Iterator::Iterator(Partition::Type type, uint8_t subtype) : mSearch{nullptr, type, subtype} +Iterator::Iterator(Partition::Type type, uint8_t subtype) : mSearch{nullptr, type, subtype}, mDevice(spiFlash) { - mDevice = spiFlash; next(); } @@ -46,9 +35,7 @@ bool Iterator::next() return true; } - mPos = afterEnd; if(mSearch.device != nullptr) { - mDevice = nullptr; break; } @@ -56,6 +43,8 @@ bool Iterator::next() mPos = beforeStart; } + mDevice = nullptr; + mPos = afterEnd; return false; } diff --git a/Sming/Components/Storage/src/Partition.cpp b/Sming/Components/Storage/src/Partition.cpp index d66c128fbb..4b08654b17 100644 --- a/Sming/Components/Storage/src/Partition.cpp +++ b/Sming/Components/Storage/src/Partition.cpp @@ -206,7 +206,7 @@ bool Partition::allowWrite() return true; } -bool Partition::read(size_t offset, void* dst, size_t size) +bool Partition::read(uint32_t offset, void* dst, size_t size) { if(!allowRead()) { return false; @@ -220,7 +220,7 @@ bool Partition::read(size_t offset, void* dst, size_t size) return mDevice ? mDevice->read(addr, dst, size) : false; } -bool Partition::write(size_t offset, const void* src, size_t size) +bool Partition::write(uint32_t offset, const void* src, size_t size) { if(!allowWrite()) { return false; @@ -234,7 +234,7 @@ bool Partition::write(size_t offset, const void* src, size_t size) return mDevice ? mDevice->write(addr, src, size) : false; } -bool Partition::erase_range(size_t offset, size_t size) +bool Partition::erase_range(uint32_t offset, size_t size) { if(!allowWrite()) { return false; diff --git a/Sming/Components/Storage/src/include/Storage/Iterator.h b/Sming/Components/Storage/src/include/Storage/Iterator.h index dcd3b7ca88..028090278a 100644 --- a/Sming/Components/Storage/src/include/Storage/Iterator.h +++ b/Sming/Components/Storage/src/include/Storage/Iterator.h @@ -18,11 +18,13 @@ class Device; class Iterator : public std::iterator { public: - Iterator(Device& device, uint8_t partitionIndex); + Iterator(Device& device) : mSearch{&device, Partition::Type::any, Partition::SubType::any}, mDevice(&device) + { + next(); + } - Iterator(Device& device, Partition::Type type, uint8_t subtype) : mSearch{&device, type, subtype} + Iterator(Device& device, Partition::Type type, uint8_t subtype) : mSearch{&device, type, subtype}, mDevice(&device) { - mDevice = &device; next(); } @@ -58,10 +60,24 @@ class Iterator : public std::iterator Partition operator*() const; + Iterator begin() + { + return mSearch.device ? Iterator(*mSearch.device) : Iterator(mSearch.type, mSearch.subType); + } + + Iterator end() + { + return Iterator(); + } + private: static constexpr int8_t beforeStart{-1}; static constexpr int8_t afterEnd{0x7f}; + Iterator() : mPos(afterEnd) + { + } + bool seek(uint8_t pos); bool next(); diff --git a/Sming/Components/Storage/src/include/Storage/Partition.h b/Sming/Components/Storage/src/include/Storage/Partition.h index c101b3bfd3..834e3126af 100644 --- a/Sming/Components/Storage/src/include/Storage/Partition.h +++ b/Sming/Components/Storage/src/include/Storage/Partition.h @@ -209,9 +209,9 @@ class Partition * @param size Size of data to be read, in bytes. * @retval bool true on success, false on error */ - bool read(size_t offset, void* dst, size_t size); + bool read(uint32_t offset, void* dst, size_t size); - template typename std::enable_if::value, bool>::type read(size_t offset, T& value) + template typename std::enable_if::value, bool>::type read(uint32_t offset, T& value) { return read(offset, &value, sizeof(value)); } @@ -224,7 +224,7 @@ class Partition * @retval bool true on success, false on error * @note Flash region must be erased first */ - bool write(size_t offset, const void* src, size_t size); + bool write(uint32_t offset, const void* src, size_t size); /** * @brief Erase part of the partition @@ -233,7 +233,7 @@ class Partition * @retval bool true on success, false on error * @note Both offset and size must be aligned to flash sector size (4Kbytes) */ - bool erase_range(size_t offset, size_t size); + bool erase_range(uint32_t offset, size_t size); /** * @brief Obtain partition type diff --git a/Sming/Components/Storage/src/include/Storage/PartitionTable.h b/Sming/Components/Storage/src/include/Storage/PartitionTable.h index 49cd59bf10..06033d6640 100644 --- a/Sming/Components/Storage/src/include/Storage/PartitionTable.h +++ b/Sming/Components/Storage/src/include/Storage/PartitionTable.h @@ -81,12 +81,12 @@ class PartitionTable Iterator begin() const { - return Iterator(mDevice, 0); + return Iterator(mDevice); } Iterator end() const { - return Iterator(mDevice, mCount); + return Iterator(mDevice).end(); } uint8_t count() const diff --git a/docs/source/information/rboot-ota.rst b/docs/source/information/rboot-ota.rst index 6cbe1e17fc..7b2c657e4e 100644 --- a/docs/source/information/rboot-ota.rst +++ b/docs/source/information/rboot-ota.rst @@ -77,9 +77,9 @@ To mount your SPIFFS at boot time add the following code to init: .. code-block:: c++ - int slot = rboot_get_current_rom(); - // Find the n'th SPIFFS partition - auto part = PartitionTable().find(Partition::SubType::Data::spiffs, slot); + String name = F("spiffs"); + name += rboot_get_current_rom(); + auto part = Storage::findPartition(name); if(part) { //debugf("trying to mount SPIFFS at %x, length %d", part.address(), part.size()); spiffs_mount(part); diff --git a/samples/Basic_Ota/app/application.cpp b/samples/Basic_Ota/app/application.cpp index 7d8283b18a..d3df87054a 100644 --- a/samples/Basic_Ota/app/application.cpp +++ b/samples/Basic_Ota/app/application.cpp @@ -14,10 +14,10 @@ Ota::Network::HttpUpgrader* otaUpdater; Storage::Partition spiffsPartition; OtaUpgrader ota; -Storage::Partition findSpiffsPartition(Storage::Partition partition) +Storage::Partition findSpiffsPartition(Storage::Partition appPart) { String name = F("spiffs"); - name += ota.getSlot(partition); + name += ota.getSlot(appPart); auto part = Storage::findPartition(name); if(!part) { debug_w("Partition '%s' not found", name.c_str()); diff --git a/samples/Basic_Ota/ota.hw b/samples/Basic_Ota/ota.hw index c5d71daa72..a6a64f6186 100644 --- a/samples/Basic_Ota/ota.hw +++ b/samples/Basic_Ota/ota.hw @@ -6,6 +6,15 @@ }, "rom1": { "subtype": "ota_1" + }, + "spiffs0": { + "size": "512K" + }, + "spiffs1": { + "address": "0x380000 if SMING_ARCH == 'Esp32' else 0x280000", + "size": "512K", + "type": "data", + "subtype": "spiffs" } } } \ No newline at end of file diff --git a/samples/Basic_Storage/app/application.cpp b/samples/Basic_Storage/app/application.cpp index a1ba039d47..0c3a2dcf14 100644 --- a/samples/Basic_Storage/app/application.cpp +++ b/samples/Basic_Storage/app/application.cpp @@ -8,11 +8,11 @@ IMPORT_FSTR(FS_app, PROJECT_DIR "/app/application.cpp") void listSpiffsPartitions() { Serial.println(_F("** Enumerate registered SPIFFS partitions")); - for(auto it = Storage::findPartition(Storage::Partition::SubType::Data::spiffs); it; ++it) { + for(auto part : Storage::findPartition(Storage::Partition::SubType::Data::spiffs)) { Serial.print(F(">> Mounting '")); - Serial.print((*it).name()); + Serial.print(part.name()); Serial.println("' ..."); - bool ok = spiffs_mount(*it); + bool ok = spiffs_mount(part); Serial.println(ok ? "OK, listing files:" : "Mount failed!"); if(ok) { Directory dir; diff --git a/tests/HostTests/modules/Storage.cpp b/tests/HostTests/modules/Storage.cpp index 06cd99c4cd..7579dd8999 100644 --- a/tests/HostTests/modules/Storage.cpp +++ b/tests/HostTests/modules/Storage.cpp @@ -63,8 +63,7 @@ class PartitionTest : public TestGroup void listPartitions() { - for(auto it = Storage::findPartition(); it; ++it) { - auto part = *it; + for(auto part : Storage::findPartition()) { Serial.print("* "); Storage::Debug::printPartition(Serial, part);