From 01857dd1bd717912d536c0b36d33302b0eda340a Mon Sep 17 00:00:00 2001 From: Bartosz Date: Fri, 18 Nov 2022 14:19:25 +0100 Subject: [PATCH] [MOS-786] Added support for A/B boot codes in OS Further implementation of A/B booting --- image/user/boot.json | 6 ++--- .../ApplicationDesktop.cpp | 16 ----------- module-bsp/CMakeLists.txt | 1 + module-bsp/board/linux/lpm/LinuxLPM.cpp | 5 +--- module-bsp/board/linux/lpm/LinuxLPM.h | 3 +-- .../board/rt1051/bsp/lpm/RT1051LPMCommon.cpp | 27 +++++++------------ .../board/rt1051/bsp/lpm/RT1051LPMCommon.hpp | 1 - module-bsp/board/rt1051/common/board.cpp | 17 ++++++++++-- .../board/rt1051/common/reboot_codes.hpp | 25 ----------------- module-bsp/bsp/lpm/bsp_lpm.hpp | 1 - module-sys/CMakeLists.txt | 1 + module-sys/SystemManager/PowerManager.cpp | 5 ---- .../SystemManager/SystemManagerCommon.cpp | 6 +++-- .../include/SystemManager/PowerManager.hpp | 1 - 14 files changed, 36 insertions(+), 79 deletions(-) delete mode 100644 module-bsp/board/rt1051/common/reboot_codes.hpp diff --git a/image/user/boot.json b/image/user/boot.json index af20e239f5b8a8a08d886efdccbe8a82a372117b..f010155a7d9fb544c71f30a2b517a379922b63eb 100644 --- a/image/user/boot.json +++ b/image/user/boot.json @@ -3,13 +3,13 @@ "slots": { "a": { "bootable": true, - "successful": true, - "boot_attempts_left": "1", + "successful": false, + "boot_attempts_left": "10", "prefix" : "/system_a" }, "b": { "bootable": true, - "successful": true, + "successful": false, "boot_attempts_left": "10", "prefix" : "/system_b" }, diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index b6904e1ff0e0ed52696920b3c57146639842eae0..4621d6cf1aacb40f3d5e9a966ba6504eb5b00c7b 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -4,35 +4,19 @@ #include "ApplicationDesktop.hpp" #include "ChargingBatteryWindow.hpp" #include "DeadBatteryWindow.hpp" -#include "DesktopData.hpp" #include "DesktopMainWindow.hpp" #include "ClosingWindow.hpp" #include "MenuWindow.hpp" #include "MmiInternalMsgWindow.hpp" #include "MmiPullWindow.hpp" -#include "MmiPushWindow.hpp" -#include "Reboot.hpp" #include "WindowsPopupFilter.hpp" #include -#include -#include -#include -#include -#include #include -#include -#include #include #include -#include #include -#include #include -#include -#include - -#include namespace app { diff --git a/module-bsp/CMakeLists.txt b/module-bsp/CMakeLists.txt index 586dcbc231115b6a1ac9c6b8b705d72ae9622c5f..bf10e23a038a02a9292a9fcace2ddffa188c1ad0 100644 --- a/module-bsp/CMakeLists.txt +++ b/module-bsp/CMakeLists.txt @@ -78,6 +78,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE purefs-paths time-constants + pure-core ) if (${ENABLE_TESTS}) diff --git a/module-bsp/board/linux/lpm/LinuxLPM.cpp b/module-bsp/board/linux/lpm/LinuxLPM.cpp index f340914b5eb434e9d9ce8859d0774aa6f9149916..a2788b00c3784dc3f868e181a69e6894a8cee873 100644 --- a/module-bsp/board/linux/lpm/LinuxLPM.cpp +++ b/module-bsp/board/linux/lpm/LinuxLPM.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md // @@ -36,9 +36,6 @@ namespace bsp void LinuxLPM::SwitchOscillatorSource(bsp::LowPowerMode::OscillatorSource source) {} - void LinuxLPM::SetBootSuccess() - {} - void LinuxLPM::EnableDcdcPowerSaveMode() {} diff --git a/module-bsp/board/linux/lpm/LinuxLPM.h b/module-bsp/board/linux/lpm/LinuxLPM.h index 8bcdc96e9461c76aa9d8b57acf7ad8083609dace..94e13266768c2eb52c9c4432e3c72983424df4e6 100644 --- a/module-bsp/board/linux/lpm/LinuxLPM.h +++ b/module-bsp/board/linux/lpm/LinuxLPM.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #ifndef PUREPHONE_LINUXLPM_H @@ -18,7 +18,6 @@ namespace bsp void SetHighestCoreVoltage() final; [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final; void SwitchOscillatorSource(OscillatorSource source) final; - void SetBootSuccess() override; void EnableDcdcPowerSaveMode() final; void DisableDcdcPowerSaveMode() final; diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp index 4e72089302e1c13ada2fa27d9adfae66df6812fc..d0aa7e61d6b4ce053863ecbfb39d416c9ff384be 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp @@ -3,17 +3,13 @@ #include "RT1051LPMCommon.hpp" -#include "board.h" -#include "reboot_codes.hpp" #include -#include "bsp/watchdog/watchdog.hpp" -#include #include #include -#include "ClockState.hpp" #include "Oscillator.hpp" #include "critical.hpp" #include "drivers/semc/DriverSEMC.hpp" +#include namespace bsp { @@ -36,26 +32,28 @@ namespace bsp { switch (reason) { case RebootType::GoToUpdaterUpdate: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToUpdaterCode; + set_boot_reason(boot_reason_code_update); break; case RebootType::GoToUpdaterRecovery: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToRecoveryCode; + set_boot_reason(boot_reason_code_recovery); break; case RebootType::GoToUpdaterFactoryReset: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToFactoryRstCode; + set_boot_reason(boot_reason_code_factory); break; case RebootType::GoToUpdaterBackup: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToBackupCode; + set_boot_reason(boot_reason_code_backup); break; case RebootType::GoToUpdaterRestore: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToRestoreCode; + set_boot_reason(boot_reason_code_restore); break; case RebootType::GoToUsbMscMode: - SNVS->LPGPR[0] = bsp::rebootCode::rebootToUsbMscModeCode; + set_boot_reason(boot_reason_code_usb_mc_mode); break; case RebootType::NormalRestart: - SNVS->LPGPR[0] = bsp::rebootCode::rebootNormalCode; + set_boot_reason(boot_reason_code_os); break; + default: + set_boot_reason(boot_reason_code_unknown); } board_restart(); return 0; @@ -170,11 +168,6 @@ namespace bsp } } - void RT1051LPMCommon::SetBootSuccess() - { - SNVS->LPGPR[0] = bsp::rebootCode::rebootNormalCode; - } - void RT1051LPMCommon::DisconnectInternalLoadResistor() { DCDC->REG1 &= ~DCDC_REG1_REG_RLOAD_SW_MASK; diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp index 5abe254c92ad2818667e4108d19bacb4d99d05d4..64d0e456b24780af8f1d7e6008bd79ca2a68005e 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp @@ -19,7 +19,6 @@ namespace bsp void SetHighestCoreVoltage() final; [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final; void SwitchOscillatorSource(OscillatorSource source) final; - void SetBootSuccess() override; void DisconnectInternalLoadResistor() final; void ConnectInternalLoadResistor() final; diff --git a/module-bsp/board/rt1051/common/board.cpp b/module-bsp/board/rt1051/common/board.cpp index f7992870857a4cdcaed9c71193afd8715140ac88..6614b2c384d810293ea222fccde8bab5eb9766a2 100644 --- a/module-bsp/board/rt1051/common/board.cpp +++ b/module-bsp/board/rt1051/common/board.cpp @@ -17,13 +17,25 @@ extern "C" } #include "chip.hpp" #include "board/irq_gpio.hpp" -#include "reboot_codes.hpp" #include #include extern std::uint32_t __sdram_cached_start[]; +extern "C" +{ + uint32_t boot_reason_get_raw() + { + return SNVS->LPGPR[0]; + } + + void boot_reason_set_raw(uint32_t raw) + { + SNVS->LPGPR[0] = raw; + } +} + namespace bsp { namespace @@ -163,7 +175,8 @@ namespace bsp SNVS_HP_ChangeSSMState(SNVS); // Default flag set on start in non-volatile memory to detect boot fault - SNVS->LPGPR[0] = rebootCode::rebootFailedToBoot; + // SNVS->LPGPR[0] = rebootCode::rebootFailedToBoot; + // TODO: Here we can implement boot-time fail detection // Set internal DCDC to DCM mode. Switching between DCM and CCM mode will be done automatically. DCDC_BootIntoDCM(DCDC); diff --git a/module-bsp/board/rt1051/common/reboot_codes.hpp b/module-bsp/board/rt1051/common/reboot_codes.hpp deleted file mode 100644 index 6ba3a96066fc1136274fd8fe6fa3369e25127e00..0000000000000000000000000000000000000000 --- a/module-bsp/board/rt1051/common/reboot_codes.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -// Copyright (c) 2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include - -namespace bsp -{ - enum rebootCode : std::uint32_t - { - rebootNormalCode = std::uint32_t{0}, - rebootToUpdaterCode = std::uint32_t{0xdead0000}, - rebootToRecoveryCode = std::uint32_t{0xdead0001}, - rebootToFactoryRstCode = std::uint32_t{0xdead0002}, - // 0xdead0003 is reserved for eco_factory_pgm_keys - rebootToUsbMscModeCode = std::uint32_t{0x00000004}, - rebootToBackupCode = std::uint32_t{0xdead0005}, - rebootToRestoreCode = std::uint32_t{0xdead0006}, - rebootFailedToBoot = std::uint32_t{0xdeadFFFF} - }; -} // namespace bsp diff --git a/module-bsp/bsp/lpm/bsp_lpm.hpp b/module-bsp/bsp/lpm/bsp_lpm.hpp index 418d0c8e81ca67cb2c86afd1440be80bc6fa823d..d33742cd8dbcde836d369649c771a14224ef3b34 100644 --- a/module-bsp/bsp/lpm/bsp_lpm.hpp +++ b/module-bsp/bsp/lpm/bsp_lpm.hpp @@ -49,7 +49,6 @@ namespace bsp [[nodiscard]] virtual uint32_t GetCpuFrequency() const noexcept = 0; virtual void SwitchOscillatorSource(OscillatorSource source) = 0; - virtual void SetBootSuccess() = 0; virtual void EnableDcdcPowerSaveMode() = 0; virtual void DisableDcdcPowerSaveMode() = 0; diff --git a/module-sys/CMakeLists.txt b/module-sys/CMakeLists.txt index 86b91b5e3dc0855c7301bd2f9bc7def75e83a79d..b7b28d73cc361b6e877b4ea7f93bc86d4575ef7f 100644 --- a/module-sys/CMakeLists.txt +++ b/module-sys/CMakeLists.txt @@ -15,4 +15,5 @@ target_link_libraries(module-sys sys-phonemodes sys-watchdog sys-manager + pure-core ) diff --git a/module-sys/SystemManager/PowerManager.cpp b/module-sys/SystemManager/PowerManager.cpp index 5c0ed704ffb4b3163440c9514024eb67d88dc6cb..03155917b2fbe2c7b9e314bbb32d74589b78f4f9 100644 --- a/module-sys/SystemManager/PowerManager.cpp +++ b/module-sys/SystemManager/PowerManager.cpp @@ -222,9 +222,4 @@ namespace sys taskStatistics.Update(); taskStatistics.LogCpuUsage(); } - - void PowerManager::SetBootSuccess() - { - lowPowerControl->SetBootSuccess(); - } } // namespace sys diff --git a/module-sys/SystemManager/SystemManagerCommon.cpp b/module-sys/SystemManager/SystemManagerCommon.cpp index 6e2c12345d4bec174773a366ff9bc4a035251e9f..4f6ff6e4904594c33c8ddc79072fafd3de80536a 100644 --- a/module-sys/SystemManager/SystemManagerCommon.cpp +++ b/module-sys/SystemManager/SystemManagerCommon.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -222,8 +223,6 @@ namespace sys if (userInit) { userInit(); } - - powerManager->SetBootSuccess(); } void SystemManagerCommon::StartSystemServices() @@ -529,6 +528,9 @@ namespace sys } return sys::MessageNone{}; }); + + LOG_INFO("Post-start routine - assuming successful boot"); + mark_as_successful(); } void SystemManagerCommon::batteryCriticalLevelAction(bool charging) diff --git a/module-sys/SystemManager/include/SystemManager/PowerManager.hpp b/module-sys/SystemManager/include/SystemManager/PowerManager.hpp index 04e042007ac8742b72dbe04e15167db567650d3d..519c56bee9dab88a9bae671891170de699913a0d 100644 --- a/module-sys/SystemManager/include/SystemManager/PowerManager.hpp +++ b/module-sys/SystemManager/include/SystemManager/PowerManager.hpp @@ -72,7 +72,6 @@ namespace sys void ResetPernamentFrequency(); void LogPowerManagerStatistics(); - void SetBootSuccess(); private: void ResetFrequencyShiftCounter();