• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "los_config.h"
32 #include "ram_virt_flash.h"
33 
34 #if (LOSCFG_SUPPORT_LITTLEFS == 1)
35 #include "fs_lowlevel.h"
36 
37 struct fs_cfg {
38     CHAR *mount_point;
39     struct lfs_config lfs_cfg;
40 };
41 
42 STATIC struct fs_cfg fs[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
43 
LfsLowLevelInit()44 INT32 LfsLowLevelInit()
45 {
46     INT32 ret;
47 
48     fs[0].mount_point = "/littlefs";
49     fs[0].lfs_cfg.block_size = 4096; /* 4096, lfs block size */
50     fs[0].lfs_cfg.block_count = 2048; /* 2048, lfs block count */
51     fs[0].lfs_cfg.context = FLASH_PARTITION_DATA0;
52     fs[0].lfs_cfg.read = littlefs_block_read;
53     fs[0].lfs_cfg.prog = littlefs_block_write;
54     fs[0].lfs_cfg.erase = littlefs_block_erase;
55     fs[0].lfs_cfg.sync = littlefs_block_sync;
56 
57     fs[0].lfs_cfg.read_size = 256; /* 256, lfs read size */
58     fs[0].lfs_cfg.prog_size = 256; /* 256, lfs prog size */
59     fs[0].lfs_cfg.cache_size = 256; /* 256, lfs cache size */
60     fs[0].lfs_cfg.lookahead_size = 16; /* 16, lfs lookahead size */
61     fs[0].lfs_cfg.block_cycles = 1000; /* 1000, lfs block cycles */
62 
63     ret = mount(NULL, fs[0].mount_point, "littlefs", 0, &fs[0].lfs_cfg);
64     printf("%s: mount fs on '%s' %s\n", __func__, fs[0].mount_point, (ret == 0) ? "succeed" : "failed");
65     if (ret != 0) {
66         return -1;
67     }
68     ret = mkdir(fs[0].mount_point);
69     printf("%s: mkdir '%s' %s\n", __func__, fs[0].mount_point, (ret == 0) ? "succeed" : "failed");
70     if (ret != 0) {
71         return -1;
72     }
73     return 0;
74 }
75 #endif
76