UpgraderBase.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 <Storage.h>
15 #include <Storage/SpiFlash.h>
16 
17 namespace Ota
18 {
20 {
21 public:
22  static constexpr uint8_t SLOT_NONE{255};
23 
25 
26  virtual ~UpgraderBase()
27  {
28  }
29 
38  virtual bool begin(Partition partition, size_t size = 0) = 0;
39 
47  virtual size_t write(const uint8_t* buffer, size_t size) = 0;
48 
52  virtual bool end() = 0;
53 
57  virtual bool abort()
58  {
59  return false;
60  }
61 
69  virtual bool setBootPartition(Partition partition, bool save = true) = 0;
70 
77  virtual Partition getBootPartition() = 0;
78 
86 
93  virtual Partition getNextBootPartition(Partition startFrom = {}) = 0;
94 
101  {
103  }
104 
105  // utility functions
106 
113  uint8_t getSlot(Partition partition)
114  {
115  if(partition.type() != Partition::Type::app) {
116  return SLOT_NONE;
117  }
118 
119  using App = Partition::SubType::App;
120  auto subtype = App(partition.subType());
121  if(subtype < App::ota_min || subtype > App::ota_max) {
122  return SLOT_NONE;
123  }
124 
125  return uint8_t(subtype) - uint8_t(App::ota_min);
126  }
127 };
128 
129 } // namespace Ota
Definition: UpgraderBase.h:20
virtual Partition getRunningPartition()=0
Gets information about the partition from which the current application is running.
uint8_t getSlot(Partition partition)
Gets slot number for a partition.
Definition: UpgraderBase.h:113
virtual ~UpgraderBase()
Definition: UpgraderBase.h:26
virtual bool begin(Partition partition, size_t size=0)=0
Prepares a partition for an upgrade. The preparation is bootloader and architecture dependent.
Storage::Iterator getBootPartitions()
Gets information about all bootable partitions.
Definition: UpgraderBase.h:100
virtual bool abort()
Aborts a partition upgrade.
Definition: UpgraderBase.h:57
virtual bool end()=0
Finalizes the partition upgrade.
virtual size_t write(const uint8_t *buffer, size_t size)=0
Writes chunk of data to the partition set in begin().
virtual Partition getBootPartition()=0
Gets information about the partition that is set as the default one to boot.
static constexpr uint8_t SLOT_NONE
Definition: UpgraderBase.h:22
virtual Partition getNextBootPartition(Partition startFrom={})=0
Gets the next bootable partition that can be used after successful OTA upgrade.
virtual bool setBootPartition(Partition partition, bool save=true)=0
Sets the default partition from where the application will be booted on next restart.
Definition: Iterator.h:19
Represents a flash partition.
Definition: Partition.h:86
Partition::Type type() const
Obtain partition type.
Definition: Partition.h:319
uint8_t subType() const
Obtain partition sub-type.
Definition: Partition.h:327
Definition: IdfUpgrader.h:18
Partition findPartition(const String &name)
Find the first partition matching the given name.
App
Application partition type.
Definition: Partition.h:105