• 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 FLASHING_UTILS_H
17 #define FLASHING_UTILS_H
18 #include <cstdlib>
19 
20 #include "flashd/flashd.h"
21 #include "log/log.h"
22 #include "securec.h"
23 
24 namespace flashd {
25 #define FLASHING_LOGE(format, ...) Logger(updater::ERROR, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
26 #define FLASHING_DEBUG(format, ...) Logger(updater::DEBUG, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
27 #define FLASHING_LOGI(format, ...) Logger(updater::INFO, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
28 #define FLASHING_LOGW(format, ...) Logger(updater::WARNING, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
29 
30 #define FLASHING_CHECK(retCode, exper, ...) \
31     if (!(retCode)) {                       \
32         FLASHING_LOGE(__VA_ARGS__);         \
33         exper;                              \
34     }
35 
36 static constexpr size_t BUFFER_SIZE = 64 * 1024;
37 static constexpr uint32_t LOOP_MAJOR = 7;
38 static constexpr uint32_t SCSI_CDROM_MAJOR = 11;
39 static constexpr uint32_t SCSI_DISK0_MAJOR = 8;
40 static constexpr uint32_t SDMMC_MAJOR = 179;
41 static constexpr uint32_t DEVICE_PATH_SIZE = 256;
42 static constexpr uint32_t LINE_BUFFER_SIZE = 256;
43 static constexpr size_t SECTOR_SIZE_DEFAULT = 512;
44 #define SCSI_BLK_MAJOR(M) ((M) == SCSI_DISK0_MAJOR)
45 
46 class FlashService;
47 using FlashingPtr = FlashService *;
48 } // namespace flashd
49 #endif // FLASHING_UTILS_H
50