summaryrefslogtreecommitdiff
path: root/bsp/cvitek/drivers/port/mnt_cromfs.c
blob: 5ca7416215ee8fe8f8f69757f434e2577d9df54b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-06-18     Shell        add cromfs support
 */

#define DBG_TAG "app.filesystem"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

#include <dfs_cromfs.h>
#include <dfs_posix.h>
#include <dfs_fs.h>
#include <ioremap.h>
#include <mmu.h>
#include <rtthread.h>

#include <unistd.h>

struct _mount_table
{
    char *dev_name;
    char *mount_point;
    char *fs_name;
    long rwflag;
    void *data;
};

struct _mount_table _mount_table[] = {
    [0] = {NULL, "/", "crom", 0, 0},

};

static int _wait_device_ready(const char* devname)
{
    int k;

    for(k = 0; k < 10; k++)
    {
        if (rt_device_find(devname) != RT_NULL)
        {
            return 1;
        }
        rt_thread_mdelay(50);
    }

    return 0;
}

int mnt_init(void)
{
    int i;
    uint32_t crom_data_len = 0;
    uint32_t length;

    _mount_table[0].data = cromfs_get_partition_data(&length);
    crom_data_len = length;

    if (_mount_table[0].data && (crom_data_len > 0))
    {
        for (i = 0; i < sizeof(_mount_table) / sizeof(_mount_table[0]); i++)
        {
            if (_mount_table[i].dev_name && !_wait_device_ready(_mount_table[i].dev_name))
            {
                LOG_E("device %s find timeout", _mount_table[i].dev_name);
                continue;
            }

            if (dfs_mount(_mount_table[i].dev_name, _mount_table[i].mount_point,
                        _mount_table[i].fs_name, _mount_table[i].rwflag, _mount_table[i].data) != 0)
            {
                LOG_E("Dir %s %s mount failed!", _mount_table[i].mount_point,
                    _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name);
            }
            else
            {
                LOG_I("Dir %s %s mount ok!", _mount_table[i].mount_point,
                    _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name);
            }
        }
    }
    else
    {
        LOG_E("No mount data found!");
    }

    mkdir("/dev/shm", 0777);

    if (dfs_mount(NULL, "/dev/shm", "tmp", 0, 0) != 0)
    {
        LOG_E("Dir %s %s mount failed!", "/dev/shm", "tmp");
    }
    else
    {
        LOG_I("Dir %s %s mount ok!", "/dev/shm", "tmp");
    }

    LOG_I("file system initialization done!\n");

    return 0;
}
INIT_ENV_EXPORT(mnt_init);