From dd4f29b8e573937e5ddf84adc0a472e31fb24d10 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Tue, 28 Apr 2020 22:41:02 -0700 Subject: [PATCH] add ota command to reboot into factory partition --- include/cmd_lora.h | 1 + main/CMakeLists.txt | 1 + main/cmd_ota.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ main/console.c | 1 + 4 files changed, 49 insertions(+) create mode 100644 main/cmd_ota.c diff --git a/include/cmd_lora.h b/include/cmd_lora.h index acb4d93..485e5a0 100644 --- a/include/cmd_lora.h +++ b/include/cmd_lora.h @@ -12,6 +12,7 @@ void cmd_preamble_register(); void cmd_send_register(); void cmd_dump_register(); void cmd_hostname_register(); +void cmd_ota_register(); #ifdef __cplusplus } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ebf5145..e60b552 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -10,6 +10,7 @@ set(COMPONENT_SRCS "\ cmd_send.c\ cmd_dump.c\ cmd_hostname.c\ + cmd_ota.c\ ") set(COMPONENT_ADD_INCLUDEDIRS ". ../include") diff --git a/main/cmd_ota.c b/main/cmd_ota.c new file mode 100644 index 0000000..673df32 --- /dev/null +++ b/main/cmd_ota.c @@ -0,0 +1,46 @@ +#include +#include +#include "esp_log.h" +#include "esp_console.h" +#include "esp_partition.h" +#include "esp_ota_ops.h" +#include "argtable3/argtable3.h" + +#include "esp32-lora.h" + +static struct { + struct arg_end *end; + lora32_cfg_t *lora; +} ota_args; + +int ota(int argc, char **argv) { + esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, "factory"); + + if(factory != NULL) { + ESP_LOGI("cmd_ota", "found partition: addr: 0x%02X size: %d", factory->address, factory->size); + + esp_ota_set_boot_partition(factory); + + esp_restart(); + } else { + ESP_LOGE("cmd_ota", "failed to find factory partition"); + } + + return 0; +} + +void cmd_ota_register(lora32_cfg_t *lora) { + + ota_args.end = arg_end(1); + ota_args.lora = lora; + + const esp_console_cmd_t ota_cmd = { + .command = "ota", + .help = "Reboots into WiFi OTA mode", + .hint = NULL, + .func = &ota, + .argtable = &ota_args + }; + + ESP_ERROR_CHECK(esp_console_cmd_register(&ota_cmd)); +} diff --git a/main/console.c b/main/console.c index 10498ee..4718094 100644 --- a/main/console.c +++ b/main/console.c @@ -57,6 +57,7 @@ void console_task(void *args) { cmd_send_register(lorcomm_cfg.lora); cmd_dump_register(lorcomm_cfg.lora); cmd_hostname_register(lorcomm_cfg.lora); + cmd_ota_register(lorcomm_cfg.lora); char *prompt;