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 
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 
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:
65  rboot_write_status status{};
66  size_t maxSize{0};
67  size_t writtenSoFar{0};
68 };
69 
70 } // namespace Ota
const PartitionTable & partitions() const
Provide read-only access to partition table.
Definition: Components/Storage/src/include/Storage/Device.h:62
bool rboot_write_end(rboot_write_status *status)
Complete flash write process.
bool setBootPartition(Partition partition, bool save=true) override
Sets the default partition from where the application will be booted on next restart.
static Partition getPartitionForSlot(uint8_t slot)
Definition: RbootUpgrader.h:59
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:38
uint8_t subType() const
Obtain partition sub-type.
Definition: Partition.h:318
uint8_t rboot_get_current_rom(void)
Get index of current ROM.
Partition getRunningPartition() override
Gets information about the partition from which the current application is running.
Definition: IdfUpgrader.h:17
ESP8266 rBoot OTA Upgrader implementation.
Definition: RbootUpgrader.h:22
Partition findOta(uint8_t index) const
Find the n&#39;th OTA partition.
Definition: PartitionTable.h:79
Structure defining flash write status.
Definition: rboot-api.h:26
static uint8_t getSlotForPartition(Partition partition)
Definition: RbootUpgrader.h:54
SpiFlash * spiFlash
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:19
Represents a flash partition.
Definition: Partition.h:85
bool end() override
Finalizes the partition upgrade.
Definition: RbootUpgrader.h:31
bool begin(Partition partition, size_t size=0) override
Prepare the partition for.