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 {
23 {
24 public:
25  static constexpr uint8_t SLOT_NONE{255};
26 
28 
29  virtual ~UpgraderBase()
30  {
31  }
32 
41  virtual bool begin(Partition partition, size_t size = 0) = 0;
42 
50  virtual size_t write(const uint8_t* buffer, size_t size) = 0;
51 
55  virtual bool end() = 0;
56 
60  virtual bool abort()
61  {
62  return false;
63  }
64 
72  virtual bool setBootPartition(Partition partition, bool save = true) = 0;
73 
80  virtual Partition getBootPartition() = 0;
81 
89 
96  virtual Partition getNextBootPartition(Partition startFrom = {}) = 0;
97 
104  {
106  }
107 
108  // utility functions
109 
116  uint8_t getSlot(Partition partition)
117  {
118  if(partition.type() != Partition::Type::app) {
119  return SLOT_NONE;
120  }
121 
122  using App = Partition::SubType::App;
123  auto subtype = App(partition.subType());
124  if(subtype < App::ota_min || subtype > App::ota_max) {
125  return SLOT_NONE;
126  }
127 
128  return uint8_t(subtype) - uint8_t(App::ota_min);
129  }
130 };
131 
132 } // namespace Ota
Each supported architecture implements this interface to support OTA updates.
Definition: UpgraderBase.h:23
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:116
virtual ~UpgraderBase()
Definition: UpgraderBase.h:29
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:103
virtual bool abort()
Aborts a partition upgrade.
Definition: UpgraderBase.h:60
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:25
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:311
uint8_t subType() const
Obtain partition sub-type.
Definition: Partition.h:319
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