Commit af79e18e authored by lbernstone's avatar lbernstone Committed by Me No Dev

Added ESP:: functions for sketch size (#2028)

* Added ESP:: functions for sketch size

* Fixed free space name to match ESP8266
parent 273196d7
......@@ -25,20 +25,11 @@
#include <memory>
#include <soc/soc.h>
#include <soc/efuse_reg.h>
/* Main header of binary image */
typedef struct {
uint8_t magic;
uint8_t segment_count;
uint8_t spi_mode; /* flash read mode (esp_image_spi_mode_t as uint8_t) */
uint8_t spi_speed: 4; /* flash frequency (esp_image_spi_freq_t as uint8_t) */
uint8_t spi_size: 4; /* flash chip size (esp_image_flash_size_t as uint8_t) */
uint32_t entry_addr;
uint8_t encrypt_flag; /* encrypt flag */
uint8_t extra_header[15]; /* ESP32 additional header, unused by second bootloader */
} esp_image_header_t;
#define ESP_IMAGE_HEADER_MAGIC 0xE9
#include <esp_partition.h>
#include <esp_ota_ops.h>
extern "C" {
#include <esp_image_format.h>
}
/**
* User-defined Literals
......@@ -156,6 +147,31 @@ uint32_t EspClass::getMaxAllocPsram(void)
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
}
static uint32_t sketchSize(sketchSize_t response) {
esp_image_metadata_t data;
const esp_partition_t *running = esp_ota_get_running_partition();
if (!running) return 0;
const esp_partition_pos_t running_pos = {
.offset = running->address,
.size = running->size,
};
data.start_addr = running_pos.offset;
esp_image_load(ESP_IMAGE_VERIFY, &running_pos, &data);
if (response) {
return running_pos.size - data.image_len;
} else {
return data.image_len;
}
}
uint32_t EspClass::getSketchSize () {
return sketchSize(SKETCH_SIZE_TOTAL);
}
uint32_t EspClass::getFreeSketchSpace () {
return sketchSize(SKETCH_SIZE_FREE);
}
uint8_t EspClass::getChipRevision(void)
{
esp_chip_info_t chip_info;
......
......@@ -50,6 +50,11 @@ typedef enum {
FM_UNKNOWN = 0xff
} FlashMode_t;
typedef enum {
SKETCH_SIZE_TOTAL = 0,
SKETCH_SIZE_FREE = 1
} sketchSize_t;
class EspClass
{
public:
......@@ -84,6 +89,9 @@ public:
uint32_t magicFlashChipSpeed(uint8_t byte);
FlashMode_t magicFlashChipMode(uint8_t byte);
uint32_t getSketchSize();
uint32_t getFreeSketchSpace();
bool flashEraseSector(uint32_t sector);
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment