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

@@ -48,10 +48,17 @@ int main(void)
LOG_INF("All subsystems initialized. Starting application threads.");
audio_system_ready();
k_sleep(K_SECONDS(5)); // Kurze Pause, damit die READY-Antworten der Subsysteme noch rausgehen
volatile uint32_t *invalid_pointer = (volatile uint32_t *)0xFFFFFFFF;
*invalid_pointer = 0xDEADBEEF;
while (1) {
if (!boot_is_img_confirmed())
{
LOG_INF("Confirmation of firmware image pending. Inform user...");
audio_play("/lfs/sys/update");
}
else
{
LOG_INF("Firmware image already confirmed. No need to confirm again.");
}
while (1)
{
k_sleep(K_FOREVER);
}
}

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
{

View File

@@ -15,6 +15,8 @@ typedef enum {
CMD_PUT_BINARY_FILE,
CMD_MKDIR,
CMD_RM,
CMD_CONFIRM,
CMD_REBOOT,
/* Weitere Kommandos folgen hier */
} protocol_cmd_t;