This commit is contained in:
2026-02-27 12:27:26 +01:00
parent 74dc8642c7
commit f70ef5c259
6 changed files with 98 additions and 10 deletions

View File

@@ -267,6 +267,26 @@ int rm(const char *path) {
return rc;
}
int confirm_firmware() {
int rc = boot_write_img_confirmed();
if (rc < 0)
{
LOG_ERR("Failed to confirm firmware: %d", rc);
return rc;
}
LOG_INF("Firmware confirmed successfully");
return 0;
}
int reboot_device() {
LOG_INF("Rebooting device as requested by host...");
send_ok();
k_sleep(K_MSEC(100)); // Kurze Pause, damit die OK-Antwort noch rausgeht
while (log_process());
sys_reboot(SYS_REBOOT_COLD);
return 0; // Dieser Code wird nie erreicht, aber wir geben ihn der Vollständigkeit halber zurück
}
void execute_current_command(void)
{
int rc;
@@ -346,6 +366,24 @@ void execute_current_command(void)
send_error(rc);
}
break;
case CMD_CONFIRM:
LOG_DBG("Executing CONFIRM command");
rc = confirm_firmware();
if (rc == 0)
{ send_ok();
}
else
{
send_error(rc);
}
break;
case CMD_REBOOT:
LOG_DBG("Executing REBOOT command");
rc = reboot_device();
if (rc != 0) {
send_error(rc);
}
break;
default:
LOG_ERR("No execution logic for command %d", current_command);
send_error(ENOSYS);
@@ -396,6 +434,14 @@ protocol_state_t reading_command(uint8_t byte)
{
LOG_DBG("Received RM command");
current_command = CMD_RM;
} else if (strcmp((char *)buffer, "confirm") == 0)
{
LOG_DBG("Received CONFIRM command");
current_command = CMD_CONFIRM;
} else if (strcmp((char *)buffer, "reboot") == 0)
{
LOG_DBG("Received REBOOT command");
current_command = CMD_REBOOT;
}
else
{