• 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 
16 #ifndef UPDATER_FLASHING_H
17 #define UPDATER_FLASHING_H
18 #include <functional>
19 #include <iostream>
20 
21 namespace flashd {
22 enum {
23     FLASHING_SYSTEM_ERROR = 100,
24     FLASHING_ARG_INVALID,
25     FLASHING_IMAGE_INVALID,
26     FLASHING_PART_NOEXIST,
27     FLASHING_NOPERMISSION,
28     FLASHING_PART_WRITE_ERROR,
29     FLASHING_PACKAGE_INVALID,
30     FLASHING_SPACE_NOTENOUGH,
31     FLASHING_INVALID_SPACE,
32     FLASHING_FSTYPE_NOT_SUPPORT,
33 };
34 
35 enum UpdateModType {
36     UPDATEMOD_UPDATE,
37     UPDATEMOD_FLASH,
38     UPDATEMOD_ERASE,
39     UPDATEMOD_FORMAT,
40     UPDATEMOD_MAX
41 };
42 
43 static constexpr uint16_t MAX_SIZE_BUF = 1024;
44 static constexpr uint32_t PERCENT_FINISH = 100;
45 static constexpr uint32_t PERCENT_CLEAR = (uint32_t)-1;
46 
47 const std::string FORMAT_TOOL_FOR_EXT4 = "/bin/mke2fs";
48 const std::string FORMAT_TOOL_FOR_F2FS = "/bin/make_f2fs";
49 const std::string RESIZE_TOOL = "/bin/resize2fs";
50 
51 #ifndef UPDATER_UT
52 const std::string FLASHD_FILE_PATH = "/data/updater/";
53 const std::string FLASHD_HDC_LOG_PATH = "/tmp/flashd_hdc.log";
54 #else
55 const std::string FLASHD_FILE_PATH = "/data/updater/updater/";
56 const std::string FLASHD_HDC_LOG_PATH = "/data/updater/flashd_hdc.log";
57 #endif
58 static constexpr uint32_t MIN_BLOCKS_FOR_UPDATE = 1024 * 1024;
59 static constexpr uint32_t DEFAULT_BLOCK_SIZE = 2048;
60 static constexpr uint32_t DEFAULT_SIZE_UNIT = 1024 * 1024;
61 
62 using FlashHandle = void *;
63 int flashd_main(int argc, char **argv);
64 using ProgressFunction = std::function<void(uint32_t type, size_t dataLen, const void *context)>;
65 
66 int CreateFlashInstance(FlashHandle *handle, std::string &errorMsg, ProgressFunction progressor);
67 int DoUpdaterPrepare(FlashHandle handle, uint8_t type, const std::string &cmdParam, std::string &filePath);
68 int DoUpdaterFlash(FlashHandle handle, uint8_t type, const std::string &cmdParam, const std::string &filePath);
69 int DoUpdaterFinish(FlashHandle handle, uint8_t type, const std::string &partition);
70 
71 #ifdef __cplusplus
72 #if __cplusplus
73 extern "C" {
74 #endif
75 #endif
76 int SetParameter(const char *key, const char *value);
77 #ifdef __cplusplus
78 #if __cplusplus
79 }
80 #endif
81 #endif
82 } // namespace flashd
83 #endif /* UPDATER_FLASHING_H */
84