From c4e9c913b02f33f878be89b4f9d78fbe8ac3796e Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Thu, 3 Aug 2023 01:55:03 +0200 Subject: [PATCH] revovery: POC writing an image --- recovery/main/rec_main.c | 32 +++++++++++++++++++++++++++++++- recovery/sdkconfig.defaults | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/recovery/main/rec_main.c b/recovery/main/rec_main.c index 3993a0bd22..5b2b4b238e 100644 --- a/recovery/main/rec_main.c +++ b/recovery/main/rec_main.c @@ -17,6 +17,7 @@ #include "esp_app_desc.h" #include "esp_app_format.h" +#include "esp_partition.h" #include <dirent.h> #include <errno.h> @@ -91,6 +92,35 @@ static void _list_select(void) { // TODO: copy selected image over to app partition _cur_menu = &_main_menu; _cur_menu->selected = 0; + + // app, app, ota_0, 0x90000, 0x300000, + const esp_partition_t *p = esp_partition_find_first( + ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, "app"); + + if (p == NULL) { + ESP_LOGE(TAG, "app partition not found"); + return; + } + + printf("erase size: %lu\n", p->erase_size); + uint8_t buf[p->erase_size]; + size_t n; + size_t offset = 0; + + char path[128] = "/flash/hello.bin"; + FILE *f = fopen(path, "rb"); + + do { + n = fread(buf, 1, sizeof(buf), f); + if (n > 0) { + esp_partition_erase_range(p, offset, sizeof(buf)); + esp_partition_write(p, offset, buf, n); + offset += n; + printf("wrote %u bytes\n", offset); + } + } while (n == sizeof(buf)); + + fclose(f); } typedef struct { @@ -162,7 +192,7 @@ static void _main_list(void) { } static menu_entry_t _main_menu_entries[] = { - { .label = "List Images", .enter = _main_list }, + { .label = "Flash Firmware Image", .enter = _main_list }, { .label = "Reboot", .enter = _main_reboot }, { .label = "Disk Mode (Flash)", .enter = _main_disk_mode_flash }, { .label = "Disk Mode (SD)", .enter = _main_disk_mode_sd }, diff --git a/recovery/sdkconfig.defaults b/recovery/sdkconfig.defaults index c8f6427fa1..3f4555a544 100644 --- a/recovery/sdkconfig.defaults +++ b/recovery/sdkconfig.defaults @@ -12,6 +12,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB=y CONFIG_ESP32S3_DATA_CACHE_64KB=y CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y CONFIG_FATFS_LFN_HEAP=y CONFIG_FATFS_API_ENCODING_UTF_8=y -- GitLab