add ota command to reboot into factory partition
This commit is contained in:
parent
ed19a5758d
commit
dd4f29b8e5
4 changed files with 49 additions and 0 deletions
|
@ -12,6 +12,7 @@ void cmd_preamble_register();
|
||||||
void cmd_send_register();
|
void cmd_send_register();
|
||||||
void cmd_dump_register();
|
void cmd_dump_register();
|
||||||
void cmd_hostname_register();
|
void cmd_hostname_register();
|
||||||
|
void cmd_ota_register();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ set(COMPONENT_SRCS "\
|
||||||
cmd_send.c\
|
cmd_send.c\
|
||||||
cmd_dump.c\
|
cmd_dump.c\
|
||||||
cmd_hostname.c\
|
cmd_hostname.c\
|
||||||
|
cmd_ota.c\
|
||||||
")
|
")
|
||||||
set(COMPONENT_ADD_INCLUDEDIRS ". ../include")
|
set(COMPONENT_ADD_INCLUDEDIRS ". ../include")
|
||||||
|
|
||||||
|
|
46
main/cmd_ota.c
Normal file
46
main/cmd_ota.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#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));
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ void console_task(void *args) {
|
||||||
cmd_send_register(lorcomm_cfg.lora);
|
cmd_send_register(lorcomm_cfg.lora);
|
||||||
cmd_dump_register(lorcomm_cfg.lora);
|
cmd_dump_register(lorcomm_cfg.lora);
|
||||||
cmd_hostname_register(lorcomm_cfg.lora);
|
cmd_hostname_register(lorcomm_cfg.lora);
|
||||||
|
cmd_ota_register(lorcomm_cfg.lora);
|
||||||
|
|
||||||
char *prompt;
|
char *prompt;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue