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 {
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 
39  {
41  }
42 
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 
59  static Partition getPartitionForSlot(uint8_t slot)
60  {
61  return Storage::spiFlash->partitions().findOta(slot);
62  }
63 
64 private:
65  rboot_write_status status{};
66  size_t maxSize{0};
67  size_t writtenSoFar{0};
68 };
69 
70 } // namespace Ota
ESP8266 rBoot OTA Upgrader implementation.
Definition: RbootUpgrader.h:23
bool begin(Partition partition, size_t size=0) override
Prepare the partition for.
bool end() override
Finalizes the partition upgrade.
Definition: RbootUpgrader.h:31
static Partition getPartitionForSlot(uint8_t slot)
Definition: RbootUpgrader.h:59
Partition getRunningPartition() override
Gets information about the partition from which the current application is running.
size_t write(const uint8_t *buffer, size_t size) override
Writes chunk of data to the partition set in begin().
bool setBootPartition(Partition partition, bool save=true) override
Sets the default partition from where the application will be booted on next restart.
Partition getBootPartition() override
Gets information about the partition that is set as the default one to boot.
Definition: RbootUpgrader.h:38
static uint8_t getSlotForPartition(Partition partition)
Definition: RbootUpgrader.h:54
Partition getNextBootPartition(Partition startFrom={}) override
Gets the next bootable partition that can be used after successful OTA upgrade.
Definition: RbootUpgrader.h:45
Definition: UpgraderBase.h:20
const PartitionTable & partitions() const
Provide read-only access to partition table.
Definition: Components/Storage/src/include/Storage/Device.h:68
Partition findOta(uint8_t index) const
Find the n'th OTA partition.
Definition: PartitionTable.h:79
Represents a flash partition.
Definition: Partition.h:86
uint8_t subType() const
Obtain partition sub-type.
Definition: Partition.h:327
bool rboot_write_end(rboot_write_status *status)
Complete flash write process.
uint8_t rboot_get_current_rom(void)
Get index of current ROM.
Definition: IdfUpgrader.h:18
SpiFlash * spiFlash
Structure defining flash write status.
Definition: rboot-api.h:26