From 0efa0b54374e3ea0cbaf455c41945800479b5bc8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 28 Jan 2021 15:46:02 +1100 Subject: [PATCH] stm32/mboot: Add ELEM_TYPE_STATUS element so application can get status. This new element takes the form: (ELEM_TYPE_STATUS, 4,
). If this element is present in the mboot command then mboot will store to the given address the result of the filesystem firmware update process. The address can for example be an RTC backup register. Signed-off-by: Damien George --- ports/stm32/boards/stm32f4xx_hal_conf_base.h | 1 + ports/stm32/boards/stm32f7xx_hal_conf_base.h | 1 + ports/stm32/boards/stm32h7xx_hal_conf_base.h | 1 + ports/stm32/mboot/main.c | 9 ++++++++- ports/stm32/mboot/mboot.h | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ports/stm32/boards/stm32f4xx_hal_conf_base.h b/ports/stm32/boards/stm32f4xx_hal_conf_base.h index 91f064835e..057a9e81e4 100644 --- a/ports/stm32/boards/stm32f4xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32f4xx_hal_conf_base.h @@ -54,6 +54,7 @@ #include "stm32f4xx_hal_usart.h" #include "stm32f4xx_hal_wwdg.h" #include "stm32f4xx_ll_adc.h" +#include "stm32f4xx_ll_pwr.h" #include "stm32f4xx_ll_rtc.h" // Enable various HAL modules diff --git a/ports/stm32/boards/stm32f7xx_hal_conf_base.h b/ports/stm32/boards/stm32f7xx_hal_conf_base.h index 1a3fca3ac8..6e7dff3042 100644 --- a/ports/stm32/boards/stm32f7xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32f7xx_hal_conf_base.h @@ -54,6 +54,7 @@ #include "stm32f7xx_hal_usart.h" #include "stm32f7xx_hal_wwdg.h" #include "stm32f7xx_ll_adc.h" +#include "stm32f7xx_ll_pwr.h" #include "stm32f7xx_ll_rtc.h" // Enable various HAL modules diff --git a/ports/stm32/boards/stm32h7xx_hal_conf_base.h b/ports/stm32/boards/stm32h7xx_hal_conf_base.h index 231f1ac7f4..a451cfde76 100644 --- a/ports/stm32/boards/stm32h7xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32h7xx_hal_conf_base.h @@ -54,6 +54,7 @@ #include "stm32h7xx_hal_usart.h" #include "stm32h7xx_hal_wwdg.h" #include "stm32h7xx_ll_adc.h" +#include "stm32h7xx_ll_pwr.h" #include "stm32h7xx_ll_rtc.h" // Enable various HAL modules diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 0846d97cf3..1395949f2e 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -1443,7 +1443,14 @@ enter_bootloader: // Application passed through elements, validate then process them const uint8_t *elem_end = elem_search(ELEM_DATA_START, ELEM_TYPE_END); if (elem_end != NULL && elem_end[-1] == 0) { - fsload_process(); + int ret = fsload_process(); + // If there is a valid ELEM_TYPE_STATUS element then store the status in the given location. + const uint8_t *elem_status = elem_search(ELEM_DATA_START, ELEM_TYPE_STATUS); + if (elem_status != NULL && elem_status[-1] == 4) { + uint32_t *status_ptr = (uint32_t *)get_le32(&elem_status[0]); + LL_PWR_EnableBkUpAccess(); // In case status_ptr points to backup registers + *status_ptr = ret; + } } // Always reset because the application is expecting to resume led_state_all(0); diff --git a/ports/stm32/mboot/mboot.h b/ports/stm32/mboot/mboot.h index e4ed3cecc7..853a86968e 100644 --- a/ports/stm32/mboot/mboot.h +++ b/ports/stm32/mboot/mboot.h @@ -43,6 +43,7 @@ enum { ELEM_TYPE_END = 1, ELEM_TYPE_MOUNT, ELEM_TYPE_FSLOAD, + ELEM_TYPE_STATUS, }; enum {