RbootUpgrader.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Ota.h
8  *
9  * This header includes all unified Over-The-Air functions.
10  *
11 */
12 
13 #pragma once
14 #include <Ota/UpgraderBase.h>
15 #include <rboot-api.h>
16 
17 namespace Ota
18 {
22 class RbootUpgrader : public UpgraderBase
23 {
24 public:
28  bool begin(Partition partition, size_t size = 0) override;
29  size_t write(const uint8_t* buffer, size_t size) override;
30 
31  bool end() override
32  {
33  return rboot_write_end(&status);
34  }
35 
36  bool setBootPartition(Partition partition, bool save = true) override;
37 
38  Partition getBootPartition() override
39  {
41  }
42 
43  Partition getRunningPartition() override;
44 
45  Partition getNextBootPartition(Partition startFrom = {}) override
46  {
47  uint8_t currentSlot = rboot_get_current_rom();
48  if(startFrom) {
49  currentSlot = getSlotForPartition(startFrom);
50  }
51  return getPartitionForSlot(currentSlot ? 0 : 1);
52  }
53 
54  static uint8_t getSlotForPartition(Partition partition)
55  {
56  return (partition.subType() == uint8_t(Partition::SubType::App::ota1)) ? 1 : 0;
57  }
58 
60  {
61  return Storage::spiFlash->partitions().findOta(slot);
62  }
63 
64 private:
66  size_t maxSize{0};
67  size_t writtenSoFar{0};
68 };
69 
70 } // namespace Ota
Represents a flash partition.
Definition: Partition.h:85
Storage::Partition Partition
Definition: UpgraderBase.h:44
const PartitionTable & partitions() const
Provide read-only access to partition table.
Definition: Components/Storage/src/include/Storage/Device.h:62
bool setBootPartition(Partition partition, bool save=true) override
Sets the default partition from where the application will be booted on next restart.
bool end() override
Finalizes the partition upgrade.
Definition: RbootUpgrader.h:51
Partition findOta(uint8_t index) const
Find the n'th OTA partition.
Definition: PartitionTable.h:95
bool rboot_write_end(rboot_write_status *status)
Complete flash write process.
Partition getRunningPartition() override
Gets information about the partition from which the current application is running.
Partition getNextBootPartition(Partition startFrom={}) override
Gets the next bootable partition that can be used after successful OTA upgrade.
Definition: RbootUpgrader.h:65
Definition: HttpUpgrader.h:21
uint8_t rboot_get_current_rom(void)
Get index of current ROM.
SpiFlash * spiFlash
bool begin(Partition partition, size_t size=0) override
Prepare the partition for.
Structure defining flash write status.
Definition: rboot-api.h:26
static uint8_t getSlotForPartition(Partition partition)
Definition: RbootUpgrader.h:74
static Partition getPartitionForSlot(uint8_t slot)
Definition: RbootUpgrader.h:79
size_t write(const uint8_t *buffer, size_t size) override
Writes chunk of data to the partition set in begin().
Partition getBootPartition() override
Gets information about the partition that is set as the default one to boot.
Definition: RbootUpgrader.h:58