~aleteoryx/muditaos

01857dd1bd717912d536c0b36d33302b0eda340a — Bartosz 3 years ago fab9068
[MOS-786] Added support for A/B boot codes in OS

Further implementation of A/B booting
M image/user/boot.json => image/user/boot.json +3 -3
@@ 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"
            },

M module-apps/application-desktop/ApplicationDesktop.cpp => module-apps/application-desktop/ApplicationDesktop.cpp +0 -16
@@ 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 <apps-common/messages/AppMessage.hpp>
#include <AppWindow.hpp>
#include <Dialog.hpp>
#include <magic_enum.hpp>
#include <messages/DialogMetadataMessage.hpp>
#include <MessageType.hpp>
#include <module-gui/gui/widgets/status-bar/SIM.hpp>
#include <service-desktop/Constants.hpp>
#include <popups/presenter/PowerOffPresenter.hpp>
#include <popups/TetheringOffPopup.hpp>
#include <service-appmgr/Controller.hpp>
#include <service-cellular-api>
#include <service-db/DBNotificationMessage.hpp>
#include <service-db/QueryMessage.hpp>
#include <system/messages/SystemManagerMessage.hpp>
#include <windows/Dialog.hpp>
#include <windows/DialogMetadata.hpp>

#include <cassert>

namespace app
{

M module-bsp/CMakeLists.txt => module-bsp/CMakeLists.txt +1 -0
@@ 78,6 78,7 @@ target_link_libraries(${PROJECT_NAME}
    PRIVATE
        purefs-paths
        time-constants
        pure-core
)

if (${ENABLE_TESTS})

M module-bsp/board/linux/lpm/LinuxLPM.cpp => module-bsp/board/linux/lpm/LinuxLPM.cpp +1 -4
@@ 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()
    {}


M module-bsp/board/linux/lpm/LinuxLPM.h => module-bsp/board/linux/lpm/LinuxLPM.h +1 -2
@@ 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;

M module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp +10 -17
@@ 3,17 3,13 @@

#include "RT1051LPMCommon.hpp"

#include "board.h"
#include "reboot_codes.hpp"
#include <log/log.hpp>
#include "bsp/watchdog/watchdog.hpp"
#include <board/clock_config.h>
#include <fsl_clock.h>
#include <bsp/bsp.hpp>
#include "ClockState.hpp"
#include "Oscillator.hpp"
#include "critical.hpp"
#include "drivers/semc/DriverSEMC.hpp"
#include <hal/boot_reason.h>

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;

M module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp +0 -1
@@ 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;

M module-bsp/board/rt1051/common/board.cpp => module-bsp/board/rt1051/common/board.cpp +15 -2
@@ 17,13 17,25 @@ extern "C"
}
#include "chip.hpp"
#include "board/irq_gpio.hpp"
#include "reboot_codes.hpp"
#include <board/debug_console.hpp>

#include <cstdint>

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);

D module-bsp/board/rt1051/common/reboot_codes.hpp => module-bsp/board/rt1051/common/reboot_codes.hpp +0 -25
@@ 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 <cstdint>

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

M module-bsp/bsp/lpm/bsp_lpm.hpp => module-bsp/bsp/lpm/bsp_lpm.hpp +0 -1
@@ 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;

M module-sys/CMakeLists.txt => module-sys/CMakeLists.txt +1 -0
@@ 15,4 15,5 @@ target_link_libraries(module-sys
        sys-phonemodes
        sys-watchdog
        sys-manager
        pure-core
    )

M module-sys/SystemManager/PowerManager.cpp => module-sys/SystemManager/PowerManager.cpp +0 -5
@@ 222,9 222,4 @@ namespace sys
        taskStatistics.Update();
        taskStatistics.LogCpuUsage();
    }

    void PowerManager::SetBootSuccess()
    {
        lowPowerControl->SetBootSuccess();
    }
} // namespace sys

M module-sys/SystemManager/SystemManagerCommon.cpp => module-sys/SystemManager/SystemManagerCommon.cpp +4 -2
@@ 33,6 33,7 @@
#include <service-db/DBServiceName.hpp>
#include <module-gui/gui/Common.hpp>
#include <service-eink/Common.hpp>
#include <hal/boot_control.h>

#include <algorithm>



@@ 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)

M module-sys/SystemManager/include/SystemManager/PowerManager.hpp => module-sys/SystemManager/include/SystemManager/PowerManager.hpp +0 -1
@@ 72,7 72,6 @@ namespace sys
        void ResetPernamentFrequency();

        void LogPowerManagerStatistics();
        void SetBootSuccess();

      private:
        void ResetFrequencyShiftCounter();