1d6aed566Sopenharmony_ci/*
2d6aed566Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3d6aed566Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d6aed566Sopenharmony_ci * you may not use this file except in compliance with the License.
5d6aed566Sopenharmony_ci * You may obtain a copy of the License at
6d6aed566Sopenharmony_ci *
7d6aed566Sopenharmony_ci *    http://www.apache.org/licenses/LICENSE-2.0
8d6aed566Sopenharmony_ci *
9d6aed566Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d6aed566Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d6aed566Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d6aed566Sopenharmony_ci * See the License for the specific language governing permissions and
13d6aed566Sopenharmony_ci * limitations under the License.
14d6aed566Sopenharmony_ci */
15d6aed566Sopenharmony_ci
16d6aed566Sopenharmony_ci#include <sys/stat.h>
17d6aed566Sopenharmony_ci#include "stdlib.h"
18d6aed566Sopenharmony_ci#include "ohos_mem_pool.h"
19d6aed566Sopenharmony_ci#include "hiview_log.h"
20d6aed566Sopenharmony_ci#include "los_debug.h"
21d6aed566Sopenharmony_ci#if (LOSCFG_SUPPORT_FATFS == 1)
22d6aed566Sopenharmony_ci#include "fatfs.h"
23d6aed566Sopenharmony_ci#endif /* LOSCFG_SUPPORT_FATFS == 1 */
24d6aed566Sopenharmony_ci#if (LOSCFG_SUPPORT_LITTLEFS == 1)
25d6aed566Sopenharmony_ci#include "lfs.h"
26d6aed566Sopenharmony_ci#endif /* LOSCFG_SUPPORT_LITTLEFS == 1 */
27d6aed566Sopenharmony_ci
28d6aed566Sopenharmony_ci/**
29d6aed566Sopenharmony_ci * @brief implement for hilog_lite featured/mini
30d6aed566Sopenharmony_ci * @notice hilog_lite mini converts '%s' to '%p'
31d6aed566Sopenharmony_ci */
32d6aed566Sopenharmony_ciboolean HilogProc_Impl(const HiLogContent *hilogContent, uint32 len)
33d6aed566Sopenharmony_ci{
34d6aed566Sopenharmony_ci    char tempOutStr[LOG_FMT_MAX_LEN] = {0};
35d6aed566Sopenharmony_ci    if (LogContentFmt(tempOutStr, sizeof(tempOutStr), hilogContent) > 0) {
36d6aed566Sopenharmony_ci        printf(tempOutStr);
37d6aed566Sopenharmony_ci    }
38d6aed566Sopenharmony_ci    return TRUE;
39d6aed566Sopenharmony_ci}
40d6aed566Sopenharmony_ci
41d6aed566Sopenharmony_ci#if (LOSCFG_SUPPORT_FATFS == 1)
42d6aed566Sopenharmony_civoid SetupDefaultVolToPartTable(void)
43d6aed566Sopenharmony_ci{
44d6aed566Sopenharmony_ci    int i = 0;
45d6aed566Sopenharmony_ci    PARTITION defaultVToP[FF_VOLUMES] = {
46d6aed566Sopenharmony_ci        {0, 1, 1},     /* "0:" ==> Physical drive 1, 1st partition */
47d6aed566Sopenharmony_ci        {1, 1, 2},     /* "1:" ==> Physical drive 1, 2nd partition */
48d6aed566Sopenharmony_ci        {2, 1, 3},     /* "2:" ==> Physical drive 1, 3rd partition */
49d6aed566Sopenharmony_ci        {3, 1, 4}      /* "3:" ==> Physical drive 1, 4th partition */
50d6aed566Sopenharmony_ci    };
51d6aed566Sopenharmony_ci
52d6aed566Sopenharmony_ci    for (i = 0; i < FF_VOLUMES; i++) {
53d6aed566Sopenharmony_ci        SetupVolToPartTable(i, defaultVToP[i], GetCfiBlkOps());
54d6aed566Sopenharmony_ci    }
55d6aed566Sopenharmony_ci}
56d6aed566Sopenharmony_ci#endif /* LOSCFG_SUPPORT_FATFS == 1 */
57d6aed566Sopenharmony_ci
58d6aed566Sopenharmony_civoid _init(void) {}
59d6aed566Sopenharmony_civoid _fini(void) {}
60d6aed566Sopenharmony_ciextern void __libc_fini_array (void);
61d6aed566Sopenharmony_ci
62d6aed566Sopenharmony_civoid SystemAdapterInit(void)
63d6aed566Sopenharmony_ci{
64d6aed566Sopenharmony_ci    UINT32 ret = 0;
65d6aed566Sopenharmony_ci
66d6aed566Sopenharmony_ci    /* _start in crt0.S have been replaced by los_start.S in riscv32_virt,
67d6aed566Sopenharmony_ci     * so call this functions here for initialization and destruction of c++ global var
68d6aed566Sopenharmony_ci     */
69d6aed566Sopenharmony_ci    if (atexit(__libc_fini_array) != 0) {
70d6aed566Sopenharmony_ci        PRINT_ERR("register exit proc error!\n");
71d6aed566Sopenharmony_ci    };
72d6aed566Sopenharmony_ci    __libc_init_array();
73d6aed566Sopenharmony_ci
74d6aed566Sopenharmony_ci#if (LOSCFG_SUPPORT_LITTLEFS == 1)
75d6aed566Sopenharmony_ci    if (LittlefsDriverInit(1) == 0) {
76d6aed566Sopenharmony_ci        struct lfs_config *littlefsConfig = GetCfiLfsCfg();
77d6aed566Sopenharmony_ci        ret = mount(NULL, "/data", "littlefs", 0, littlefsConfig);
78d6aed566Sopenharmony_ci        if (ret != LOS_OK) {
79d6aed566Sopenharmony_ci            PRINT_ERR("Mount Littlefs error:0x%x\n", ret);
80d6aed566Sopenharmony_ci        }
81d6aed566Sopenharmony_ci    }
82d6aed566Sopenharmony_ci#elif (LOSCFG_SUPPORT_FATFS == 1)
83d6aed566Sopenharmony_ci    SetupDefaultVolToPartTable();
84d6aed566Sopenharmony_ci    /* mount fs in fat.img,for font.ttf used by graphic */
85d6aed566Sopenharmony_ci    if (ret = mount("p0", "/data", "vfat", 0, NULL)) {
86d6aed566Sopenharmony_ci        PRINT_ERR("Mount Fatfs error:0x%x\n", ret);
87d6aed566Sopenharmony_ci    }
88d6aed566Sopenharmony_ci#endif /* LOSCFG_SUPPORT_FATFS == 1 */
89d6aed566Sopenharmony_ci
90d6aed566Sopenharmony_ci    /* bootstrap init */
91d6aed566Sopenharmony_ci    OHOS_SystemInit();
92d6aed566Sopenharmony_ci
93d6aed566Sopenharmony_ci    /* register hilog output func for mini */
94d6aed566Sopenharmony_ci    HiviewRegisterHilogProc(HilogProc_Impl);
95d6aed566Sopenharmony_ci}
96d6aed566Sopenharmony_ci
97d6aed566Sopenharmony_ci/**
98d6aed566Sopenharmony_ci * @brief implement for ohos_mem_pool.h
99d6aed566Sopenharmony_ci */
100d6aed566Sopenharmony_civoid *OhosMalloc(MemType type, uint32 size)
101d6aed566Sopenharmony_ci{
102d6aed566Sopenharmony_ci    if (size == 0) {
103d6aed566Sopenharmony_ci        return NULL;
104d6aed566Sopenharmony_ci    }
105d6aed566Sopenharmony_ci    return malloc(size);
106d6aed566Sopenharmony_ci}
107d6aed566Sopenharmony_ci
108d6aed566Sopenharmony_civoid OhosFree(void *ptr)
109d6aed566Sopenharmony_ci{
110d6aed566Sopenharmony_ci    free(ptr);
111d6aed566Sopenharmony_ci}
112d6aed566Sopenharmony_ci
113d6aed566Sopenharmony_ci/* implementation for js_app_host.h: LP_TaskBegin */
114d6aed566Sopenharmony_civoid LP_TaskBegin(void)
115d6aed566Sopenharmony_ci{
116d6aed566Sopenharmony_ci}
117d6aed566Sopenharmony_ci
118d6aed566Sopenharmony_ci/* implementation for js_app_host.h: LP_TaskEnd */
119d6aed566Sopenharmony_civoid LP_TaskEnd(void)
120d6aed566Sopenharmony_ci{
121d6aed566Sopenharmony_ci}
122d6aed566Sopenharmony_ci
123d6aed566Sopenharmony_ci/**
124d6aed566Sopenharmony_ci * @brief adapter for js_ability.cpp
125d6aed566Sopenharmony_ci * #ifdef OHOS_ACELITE_PRODUCT_WATCH
126d6aed566Sopenharmony_ci */
127d6aed566Sopenharmony_civoid RestoreSystemWrapper(const char *crashMessage)
128d6aed566Sopenharmony_ci{
129d6aed566Sopenharmony_ci    printf("%s\n", crashMessage);
130d6aed566Sopenharmony_ci}
131