~aleteoryx/muditaos

5324fcc0a677f1733c2366990bc078901f49c1a1 — Lucjan Bryndza 4 years ago 3df2492
[CP-312] Add reboot to update function

Because update procedure it is splitted to the two stages
downloading and update throught separate binary we need
to pass ecoboot special flag to request reboot to updater
bin after update procedure.
This patch adds this functionality to the PureOS.

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>
M module-bsp/board/linux/lpm/LinuxLPM.cpp => module-bsp/board/linux/lpm/LinuxLPM.cpp +2 -3
@@ 15,7 15,7 @@ namespace bsp
        return 0;
    }

    int32_t LinuxLPM::Reboot()
    int32_t LinuxLPM::Reboot(RebootType)
    {
        return 0;
    }


@@ 31,7 31,6 @@ namespace bsp
    }

    void LinuxLPM::SwitchOscillatorSource(bsp::LowPowerMode::OscillatorSource source)
    {
    }
    {}

} // namespace bsp

M module-bsp/board/linux/lpm/LinuxLPM.h => module-bsp/board/linux/lpm/LinuxLPM.h +1 -1
@@ 13,7 13,7 @@ namespace bsp
    {
      public:
        int32_t PowerOff() override final;
        int32_t Reboot() override final;
        int32_t Reboot(RebootType reason) override final;
        void SetCpuFrequency(CpuFrequencyHz freq) final;
        [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final;
        void SwitchOscillatorSource(OscillatorSource source) final;

M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp +11 -1
@@ 39,8 39,18 @@ namespace bsp
        return 0;
    }

    int32_t RT1051LPM::Reboot()
    int32_t RT1051LPM::Reboot(RebootType reason)
    {
        constexpr uint32_t rebootToUpdaterCode{0xdeadbeaf};
        constexpr uint32_t rebootNormalCode{0};
        switch (reason) {
        case RebootType::GoToUpdater:
            SNVS->LPGPR[0] = rebootToUpdaterCode;
            break;
        case RebootType::NormalRestart:
            SNVS->LPGPR[0] = rebootNormalCode;
            break;
        }
        NVIC_SystemReset();
        return 0;
    }

M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp +1 -1
@@ 15,7 15,7 @@ namespace bsp
      public:
        RT1051LPM();
        int32_t PowerOff() override final;
        int32_t Reboot() override final;
        int32_t Reboot(RebootType reason) override final;
        void SetCpuFrequency(CpuFrequencyHz freq) final;
        [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final;
        void SwitchOscillatorSource(OscillatorSource source) final;

M module-bsp/bsp/lpm/bsp_lpm.hpp => module-bsp/bsp/lpm/bsp_lpm.hpp +9 -5
@@ 7,7 7,8 @@
#include <memory>
#include <bsp/common.hpp>

namespace bsp {
namespace bsp
{

    class LowPowerMode
    {


@@ 17,14 18,18 @@ namespace bsp {
            External,
            Internal
        };
        enum class RebootType {
            NormalRestart,
            GoToUpdater,
        };

        LowPowerMode()          = default;
        virtual ~LowPowerMode() = default;

        static std::optional<std::unique_ptr<LowPowerMode>> Create();

        virtual int32_t PowerOff() = 0;
        virtual int32_t Reboot() = 0;
        virtual int32_t PowerOff()              = 0;
        virtual int32_t Reboot(RebootType reason) = 0;

        virtual void SetCpuFrequency(CpuFrequencyHz freq) = 0;
        [[nodiscard]] CpuFrequencyHz GetCurrentFrequencyLevel() const noexcept;


@@ 32,8 37,7 @@ namespace bsp {

        virtual void SwitchOscillatorSource(OscillatorSource source) = 0;

    protected:
      protected:
        CpuFrequencyHz currentFrequency = CpuFrequencyHz::Level_6;
    };
} // namespace bsp


M module-sys/SystemManager/PowerManager.cpp => module-sys/SystemManager/PowerManager.cpp +7 -2
@@ 24,7 24,12 @@ namespace sys

    int32_t PowerManager::Reboot()
    {
        return lowPowerControl->Reboot();
        return lowPowerControl->Reboot(bsp::LowPowerMode::RebootType::NormalRestart);
    }

    int32_t PowerManager::RebootToUpdate()
    {
        return lowPowerControl->Reboot(bsp::LowPowerMode::RebootType::GoToUpdater);
    }

    void PowerManager::UpdateCpuFrequency(uint32_t cpuLoad)


@@ 58,7 63,7 @@ namespace sys

    void PowerManager::IncreaseCpuFrequency() const
    {
        const auto freq      = lowPowerControl->GetCurrentFrequencyLevel();
        const auto freq = lowPowerControl->GetCurrentFrequencyLevel();

        if (freq == bsp::CpuFrequencyHz::Level_1) {
            // switch osc source first

M module-sys/SystemManager/PowerManager.hpp => module-sys/SystemManager/PowerManager.hpp +1 -0
@@ 26,6 26,7 @@ namespace sys

        int32_t PowerOff();
        int32_t Reboot();
        int32_t RebootToUpdate();

        /// called periodically to calculate the CPU requirement
        ///

M module-sys/SystemManager/SystemManager.cpp => module-sys/SystemManager/SystemManager.cpp +17 -4
@@ 97,7 97,7 @@ namespace sys
        : Service(service::name::system_manager, "", systemManagerStack), systemServiceCreators{std::move(creators)}
    {
        // Specify list of channels which System Manager is registered to
        bus.channels = {BusChannel::SystemManagerRequests};
        bus.channels            = {BusChannel::SystemManagerRequests};
        lowBatteryShutdownDelay = sys::TimerFactory::createPeriodicTimer(
            this, "lowBatteryShutdownDelay", lowBatteryShutdownDelayTime, [this](sys::Timer &) {
                CloseSystemHandler(CloseReason::LowBattery);


@@ 155,6 155,10 @@ namespace sys
            LOG_INFO("  ---> SHUTDOWN <--- ");
            powerManager->PowerOff();
            break;
        case State::RebootToUpdate:
            LOG_INFO("  ---> REBOOT TO UPDATER <--- ");
            powerManager->RebootToUpdate();
            break;
        default:
            LOG_FATAL("State changed after reset/shutdown was requested to: %s! this is terrible failure!",
                      c_str(state));


@@ 271,6 275,12 @@ namespace sys
        return true;
    }

    bool SystemManager::RebootToUpdate(Service *s)
    {
        s->bus.sendUnicast(std::make_shared<SystemManagerCmd>(Code::RebootToUpdate), service::name::system_manager);
        return true;
    }

    bool SystemManager::SuspendService(const std::string &name, sys::Service *caller)
    {
        auto ret = caller->bus.sendUnicastSync(


@@ 501,7 511,10 @@ namespace sys
                    RestoreSystemHandler();
                    break;
                case Code::Reboot:
                    RebootHandler();
                    RebootHandler(State::Reboot);
                    break;
                case Code::RebootToUpdate:
                    RebootHandler(State::RebootToUpdate);
                    break;
                case Code::None:
                    break;


@@ 711,10 724,10 @@ namespace sys
        DestroyServices(sys::state::update::whitelist);
    }

    void SystemManager::RebootHandler()
    void SystemManager::RebootHandler(State state)
    {
        CloseSystemHandler(CloseReason::Reboot);
        set(State::Reboot);
        set(state);
    }

    void SystemManager::CpuStatisticsTimerHandler()

M module-sys/SystemManager/SystemManager.hpp => module-sys/SystemManager/SystemManager.hpp +10 -4
@@ 40,8 40,8 @@ namespace sys
        inline constexpr auto restoreTimeout{5000};
    } // namespace constants

    class PhoneModeRequest; // Forward declaration
    class TetheringStateRequest; // Forward declaration
    class PhoneModeRequest;         // Forward declaration
    class TetheringStateRequest;    // Forward declaration
    class TetheringEnabledResponse; // Forward declaration

    enum class Code


@@ 50,6 50,7 @@ namespace sys
        Update,
        Restore,
        Reboot,
        RebootToUpdate,
        None,
    };



@@ 81,7 82,8 @@ namespace sys
            Suspend,
            Shutdown,
            ShutdownReady,
            Reboot
            Reboot,
            RebootToUpdate
        } state = State::Running;

        explicit SystemManager(std::vector<std::unique_ptr<BaseServiceCreator>> &&creators);


@@ 102,6 104,8 @@ namespace sys

        static bool Reboot(Service *s);

        static bool RebootToUpdate(Service *s);

        static void storeOsVersion(Service *s, const std::string &updateOSVer, const std::string &currentOSVer);

        static bool SuspendService(const std::string &name, Service *caller);


@@ 176,7 180,7 @@ namespace sys

        void RestoreSystemHandler();

        void RebootHandler();
        void RebootHandler(State state);

        /// loop to handle prior to full system close
        /// for now for rt1051 we need to


@@ 234,6 238,8 @@ inline const char *c_str(sys::SystemManager::State state)
        return "Shutdown";
    case sys::SystemManager::State::Reboot:
        return "Reboot";
    case sys::SystemManager::State::RebootToUpdate:
        return "RebootToUpdate";
    case sys::SystemManager::State::ShutdownReady:
        return "ShutdownReady";
    }