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

* Added ESP:: functions for sketch size

* Fixed free space name to match ESP8266
This commit is contained in:
lbernstone 2018-11-19 08:03:36 -08:00 committed by Me No Dev
parent 273196d7e6
commit af79e18ecb
2 changed files with 38 additions and 14 deletions

View File

@ -25,20 +25,11 @@
#include <memory> #include <memory>
#include <soc/soc.h> #include <soc/soc.h>
#include <soc/efuse_reg.h> #include <soc/efuse_reg.h>
#include <esp_partition.h>
/* Main header of binary image */ #include <esp_ota_ops.h>
typedef struct { extern "C" {
uint8_t magic; #include <esp_image_format.h>
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
/** /**
* User-defined Literals * User-defined Literals
@ -156,6 +147,31 @@ uint32_t EspClass::getMaxAllocPsram(void)
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); 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) uint8_t EspClass::getChipRevision(void)
{ {
esp_chip_info_t chip_info; esp_chip_info_t chip_info;

View File

@ -50,6 +50,11 @@ typedef enum {
FM_UNKNOWN = 0xff FM_UNKNOWN = 0xff
} FlashMode_t; } FlashMode_t;
typedef enum {
SKETCH_SIZE_TOTAL = 0,
SKETCH_SIZE_FREE = 1
} sketchSize_t;
class EspClass class EspClass
{ {
public: public:
@ -84,6 +89,9 @@ public:
uint32_t magicFlashChipSpeed(uint8_t byte); uint32_t magicFlashChipSpeed(uint8_t byte);
FlashMode_t magicFlashChipMode(uint8_t byte); FlashMode_t magicFlashChipMode(uint8_t byte);
uint32_t getSketchSize();
uint32_t getFreeSketchSpace();
bool flashEraseSector(uint32_t sector); bool flashEraseSector(uint32_t sector);
bool flashWrite(uint32_t offset, uint32_t *data, size_t size); bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
bool flashRead(uint32_t offset, uint32_t *data, size_t size); bool flashRead(uint32_t offset, uint32_t *data, size_t size);