Skip to content

Commit

Permalink
add remove custom part
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Aug 28, 2024
1 parent 973e871 commit 17eb8ba
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 52 deletions.
12 changes: 6 additions & 6 deletions lib/libesp32/berry/generate/be_const_bytes.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* extern binary arrays */
extern const binstance_arg3 be_const_instance_;
extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010002FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD;
12 changes: 6 additions & 6 deletions lib/libesp32/berry/generate/be_const_bytes_def.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* binary arrays */
be_define_const_bytes_empty();
be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010002FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x0F, 0x00, 0x11, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x0B, 0x40, 0x0C, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x09, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x01, 0x40, 0x0A, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
2 changes: 1 addition & 1 deletion tasmota/Plugins/xdrv_42_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define USE_MP3
#define USE_WEBRADIO
// select a codec
#define USE_WM8960
//#define USE_WM8960
#endif

//#define USE_MP3
Expand Down
115 changes: 76 additions & 39 deletions tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2213,12 +2213,13 @@ void LinkModule(uint8_t *mp, uint32_t size, char *name) {
return;
}

/*
if (fm->revision < CURR_MINREV ) {
free(mp);
AddLog(LOG_LEVEL_INFO,PSTR("plugin hander revision to old"));
AddLog(LOG_LEVEL_INFO,PSTR("plugin handler revision to old"));
return;
}

*/

Unlink_Named_Module(name);

Expand Down Expand Up @@ -2538,23 +2539,32 @@ void Module_dump(void) {
#ifdef ESP32
#include <MD5Builder.h>


bool scan_ptable(uint8_t *mp, uint32_t num) {
int num_partitions = num;
esp_partition_info_t *peptr = (esp_partition_info_t*)mp;
for (uint32_t cnt = 0; cnt < num_partitions; cnt++) {
AddLog(LOG_LEVEL_INFO,PSTR("partition addr: 0x%06x; size: 0x%06x; label: %s"), peptr->pos.offset, peptr->pos.size, peptr->label);
peptr++;
}
esp_err_t ret = esp_partition_table_verify((const esp_partition_info_t *)mp, false, &num_partitions);
AddLog(LOG_LEVEL_INFO, "partition table status: err: %d - entries: %d", ret, num_partitions);
return ret;
}

// show or add(aX) or remove(r) custom partition (X 1..4, optional size extender time 64k)
// we steel the size from the spiffs partition
void Check_partition(void) {
const esp_partition_t *pptr;

pptr = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_TEST, "custom");
if (pptr) {
AddLog(LOG_LEVEL_INFO,PSTR("custom plugin partition already there!"));
ResponseCmndDone();
return;
}

uint32_t custom_size = 0x10000; // 64k default size
uint8_t update = 0;
uint8_t add = 0;
uint8_t remove = 0;
if (XdrvMailbox.data_len) {
char *cp = XdrvMailbox.data;
while (*cp == ' ') cp++;
if (*cp == 'u') {
update = 1;
if (*cp == 'a') {
add = 1;
cp++;
uint32_t fac = strtol(cp, &cp, 10);
if (fac > 4) {
Expand All @@ -2565,7 +2575,24 @@ void Check_partition(void) {
}
custom_size *= fac;
} else if (*cp == 'r') {
// remove not yet
remove = 1;
}
}

if (add || remove) {
pptr = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_TEST, "custom");
if (pptr) {
if (add) {
AddLog(LOG_LEVEL_INFO,PSTR("custom plugin partition already there!"));
ResponseCmndDone();
return;
}
} else {
if (remove) {
AddLog(LOG_LEVEL_INFO,PSTR("custom plugin partition already removed!"));
ResponseCmndDone();
return;
}
}
}

Expand Down Expand Up @@ -2607,11 +2634,11 @@ typedef struct {
for (uint32_t cnt = 0; cnt < num_partitions; cnt++) {
AddLog(LOG_LEVEL_INFO,PSTR("partition addr: 0x%06x; size: 0x%06x; label: %s"), peptr->pos.offset, peptr->pos.size, peptr->label);
if (!strcmp((char*)peptr->label, "spiffs")) {
AddLog(LOG_LEVEL_INFO,PSTR("spiffs partition found!"));
//AddLog(LOG_LEVEL_INFO,PSTR("spiffs partition found!"));
hasspiffs = cnt;
}
if (!strcmp((char*)peptr->label, "custom")) {
AddLog(LOG_LEVEL_INFO,PSTR("custom partition found!"));
//AddLog(LOG_LEVEL_INFO,PSTR("custom partition found!"));
custom = true;
}
peptr++;
Expand All @@ -2620,13 +2647,23 @@ typedef struct {
}
}
if (custom == true) {
AddLog(LOG_LEVEL_INFO,PSTR("custom already there!"));
if (remove && hasspiffs > 0) {
AddLog(LOG_LEVEL_INFO,PSTR("may remove custom!"));
// assuming custom directly after spiffs
esp_partition_info_t *peptr = (esp_partition_info_t*)mp;
peptr += hasspiffs;
esp_partition_info_t *peptr_custom = peptr + 1;
peptr->pos.size += peptr_custom->pos.size;
memset(peptr_custom, 0, sizeof(esp_partition_info_t));
memset(peptr_custom + 1, 0xff, sizeof(esp_partition_info_t));
num_partitions--;
}
} else {
if (hasspiffs < 0) {
AddLog(LOG_LEVEL_INFO,PSTR("no spiffs partition found!"));
} else {
// we may patch spiffs
AddLog(LOG_LEVEL_INFO,PSTR("spiffs may be patched!"));
AddLog(LOG_LEVEL_INFO,PSTR("may add custom!"));
// reiterate
esp_partition_info_t *peptr = (esp_partition_info_t*)mp;
for (uint32_t cnt = 0; cnt < num_partitions; cnt++) {
Expand All @@ -2644,16 +2681,7 @@ typedef struct {
peptr->type = PART_TYPE_APP;
peptr->subtype = PART_SUBTYPE_TEST;
strcpy((char*)peptr->label,"custom");
num_partitions++;

// scan again
esp_partition_info_t *peptr = (esp_partition_info_t*)mp;
for (uint32_t cnt = 0; cnt < num_partitions; cnt++) {
AddLog(LOG_LEVEL_INFO,PSTR("partition addr: 0x%06x; size: 0x%06x; label: %s"), peptr->pos.offset, peptr->pos.size, peptr->label);
peptr++;
}
ret = esp_partition_table_verify((const esp_partition_info_t *)mp, false, &num_partitions);
AddLog(LOG_LEVEL_INFO, "partition table status: %d entries : %d", num_partitions, ret);
num_partitions++;
break;
}
}
Expand All @@ -2665,23 +2693,32 @@ typedef struct {
}
}

if (update) {
MD5Builder md5;
md5.begin();
md5.add(mp, num_partitions * sizeof(esp_partition_info_t));
md5.calculate();
uint8_t result[16];
md5.getBytes(result);
uint8_t *end_offset = mp + (num_partitions * sizeof(esp_partition_info_t));
end_offset[0] = 0xeb;
end_offset[1] = 0xeb;
memmove(end_offset + 16, result, 16);
MD5Builder md5;
md5.begin();
md5.add(mp, num_partitions * sizeof(esp_partition_info_t));
md5.calculate();
uint8_t result[16];
md5.getBytes(result);
uint8_t *end_offset = mp + (num_partitions * sizeof(esp_partition_info_t));
end_offset[0] = 0xeb;
end_offset[1] = 0xeb;
memmove(end_offset + 16, result, 16);

#if 0
File wf = ufsp->open("/partition.bin", FS_FILE_WRITE);
wf.write(mp, SPI_FLASH_SEC_SIZE);
wf.close();
#endif

if (add || remove) {
scan_ptable(mp, num_partitions);
}

if (add || remove) {
// ESP_PARTITION_MAGIC_MD5
// esp_partition_is_flash_region_writable
ret = esp_flash_erase_region(NULL, PART_OFFSET, SPI_FLASH_SEC_SIZE);
ret = esp_flash_write(NULL, mp, PART_OFFSET, SPI_FLASH_SEC_SIZE);

// restart immediately
ESP_Restart();
}
Expand Down

0 comments on commit 17eb8ba

Please sign in to comment.