xref: /base/update/updater/services/main.cpp (revision fb299fa2)
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include "fs_manager/mount.h"
16#include "log/log.h"
17#include "misc_info/misc_info.h"
18#include "updater/updater.h"
19#include "updater/updater_const.h"
20#include "updater_main.h"
21#include "utils.h"
22
23using namespace Updater;
24
25int main(int argc, char **argv)
26{
27    // prepare modes vector by macro DEFINE_MODE which subscribe UPDATER_MAIN_PRE_EVENT event
28    UpdaterInit::GetInstance().InvokeEvent(UPDATER_MAIN_PRE_EVENT);
29
30    struct UpdateMessage boot {};
31    if (!ReadUpdaterMiscMsg(boot)) {
32        // read misc failed, default enter updater mode
33        LOG(WARNING) << "read misc message failed";
34    }
35
36    // select modes by bootMode.cond which would check misc message
37    auto bootMode = SelectMode(boot).value_or(BOOT_MODE(Updater, "updater.hdc.configfs"));
38
39    // execute mode initialization
40    bootMode.InitMode();
41
42    LOG(INFO) << "################################";
43    // mode entry
44    return bootMode.entryFunc(argc, argv);
45}
46