• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <iostream>
16 #include "fs_manager/mount.h"
17 #include "misc_info/misc_info.h"
18 #include "securec.h"
19 #include "updater/updater_const.h"
20 
21 using namespace std;
22 using namespace Updater;
23 
main(int argc,char ** argv)24 int main(int argc, char **argv)
25 {
26     if (argc == 1) {
27         cout << "Please input correct command, examples :" << endl;
28         cout << "updater       :  write_updater updater /data/updater/updater.zip" << endl;
29         cout << "factory_reset :  write_updater user_factory_reset" << endl;
30         cout << "clear command :  write_updater clear" << endl;
31         return -1;
32     }
33 
34     const std::string miscFile = "/dev/block/by-name/misc";
35     struct UpdateMessage boot {};
36     if (strcmp(argv[1], "updater") == 0) {
37         if (argc < BINARY_MAX_ARGS) {
38             cout << "Please input correct updater command!" << endl;
39             return -1;
40         }
41         if (argv[WRITE_SECOND_CMD] != nullptr) {
42             if (snprintf_s(boot.update, sizeof(boot.update), sizeof(boot.update) - 1, "--update_package=%s",
43                 argv[WRITE_SECOND_CMD]) == -1) {
44                 cout << "WriteUpdaterMessage snprintf_s failed!" << endl;
45                 return -1;
46             }
47         }
48     } else if (strcmp(argv[1], "user_factory_reset") == 0) {
49         if (strncpy_s(boot.update, sizeof(boot.update), "--user_wipe_data", sizeof(boot.update) - 1) != 0) {
50             cout << "strncpy_s failed!" << endl;
51             return -1;
52         }
53     } else if (strcmp(argv[1], "boot_flash") == 0) {
54         if (strncpy_s(boot.update, sizeof(boot.update), "boot_flash", sizeof(boot.update) - 1) != 0) {
55             cout << "strncpy_s failed!" << endl;
56             return -1;
57         }
58     } else if (strcmp(argv[1], "clear") == 0) {
59         cout << "clear misc" << endl;
60     } else {
61         cout << "Please input correct command!" << endl;
62         return -1;
63     }
64     bool ret = WriteUpdaterMessage(miscFile, boot);
65     if (!ret) {
66         cout << "WriteUpdaterMessage failed!" << endl;
67         return -1;
68     }
69     return 0;
70 }
71