一个flash能否挂两个系统

发布于 2021-03-19 13:42:51

我将flash分成了两部分,分别为A和B,现在在device中能够把A和B定义为两种设备,能否把A和B挂载成两种系统,怎么操作?

查看更多

关注者
0
被浏览
202
Thread_Liu
Thread_Liu 2021-03-19

参考 ART-PI 代码:

/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author        Notes
 * 2018-12-13     balanceTWK    add sdcard port file
 * 2019-06-11     WillianChan   Add SD card hot plug detection
 */

#include <rtthread.h>

#ifdef BSP_USING_FS
#if DFS_FILESYSTEMS_MAX < 4
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
#endif
#if DFS_FILESYSTEM_TYPES_MAX < 4
#error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4"
#endif

#ifdef BSP_USING_SPI_FLASH_FS
#include "fal.h"
#endif

#include <dfs_fs.h>
#include "dfs_romfs.h"
#include "drv_sdio.h"

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

static const struct romfs_dirent _romfs_root[] = {
    {ROMFS_DIRENT_DIR, "flash1", RT_NULL, 0},
    {ROMFS_DIRENT_DIR, "flash2", RT_NULL, 0},
    {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}};

const struct romfs_dirent romfs_root = {
    ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])};

#ifdef BSP_USING_SDCARD_FS

/* SD Card hot plug detection pin */
#define SD_CHECK_PIN GET_PIN(D, 5)

static void _sdcard_mount(void)
{
    rt_device_t device;

    device = rt_device_find("sd0");
    if (device == NULL)
    {
        mmcsd_wait_cd_changed(0);
        sdcard_change();
        mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
        device = rt_device_find("sd0");
    }
    if (device != RT_NULL)
    {
        if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
        {
            LOG_I("sd card mount to '/sdcard'");
        }
        else
        {
            LOG_W("sd card mount to '/sdcard' failed!");
        }
    }
}

static void _sdcard_unmount(void)
{
    rt_thread_mdelay(200);
    dfs_unmount("/sdcard");
    LOG_I("Unmount \"/sdcard\"");

    mmcsd_wait_cd_changed(0);
    sdcard_change();
    mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
}

static void sd_mount(void *parameter)
{
    rt_uint8_t re_sd_check_pin = 1;
    rt_thread_mdelay(200);
    if (rt_pin_read(SD_CHECK_PIN))
    {
        _sdcard_mount();
    }
    while (1)
    {
        rt_thread_mdelay(200);
        if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) != 0)
        {
            _sdcard_mount();
        }

        if (re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) == 0)
        {
            _sdcard_unmount();
        }
    }
}

#endif /* BSP_USING_SDCARD_FS */

#ifdef BSP_USING_FASTFS_FOMAT
extern int lpm_init(void);
#endif


int mount_init(void)
{
#ifdef RT_USING_DFS_ROMFS
    if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0)
    {
        LOG_E("rom mount to '/' failed!");
    }
#endif
#ifdef BSP_USING_SPI_FLASH_FS
    struct rt_device *flash1_dev = RT_NULL;
    struct rt_device *flash2_dev = RT_NULL;

#ifndef RT_USING_WIFI
    fal_init();
#endif

    flash1_dev = fal_mtd_nor_device_create("filesystem");

    if (flash1_dev)
    {
        //mount filesystem
        if (dfs_mount(flash1_dev->parent.name, "/flash1", "elm", 0, 0) != 0)
        {
            LOG_W("mount to '/flash1' failed! try to mkfs %s", flash1_dev->parent.name);
            dfs_mkfs("lfs", flash1_dev->parent.name);
            if (dfs_mount(flash1_dev->parent.name, "/flash1", "lfs", 0, 0) == 0)
            {
                LOG_I("mount to '/flash1' success!");
            }
        }
        else
        {
            LOG_I("mount to '/flash1' success!");
        }
    }

    flash2_dev = fal_mtd_nor_device_create("easyflash");
    if (flash2_dev)
    {
        //mount filesystem
        if (dfs_mount(flash2_dev->parent.name, "/flash2", "elm", 0, 0) != 0)
        {
            LOG_W("mount to '/flash2' failed! try to mkfs %s", flash2_dev->parent.name);
            dfs_mkfs("lfs", flash2_dev->parent.name);
            if (dfs_mount(flash2_dev->parent.name, "/flash2", "lfs", 0, 0) == 0)
            {
                LOG_I("mount to '/flash2' success!");
            }
        }
        else
        {
            LOG_I("mount to '/flash2' success!");
        }
    }

#endif

#ifdef BSP_USING_SDCARD_FS
    rt_thread_t tid;

    rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP);

    tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
                           2048, RT_THREAD_PRIORITY_MAX - 2, 20);
    if (tid != RT_NULL)
    {
        rt_thread_startup(tid);
    }
    else
    {
        LOG_E("create sd_mount thread err!");
    }
#endif
    return RT_EOK;
}
INIT_APP_EXPORT(mount_init);

#endif /* BSP_USING_FS */

 \ | /
- RT -     Thread Operating System
 / | \     4.0.3 build Mar 19 2021
 2006 - 2020 Copyright by rt-thread team
[I/SDIO] SD card capacity 123008 KB.
[I/SDIO] switching card to high speed failed!
[I/SFUD] Find a Winbond flash chip. Size is 16777216 bytes.
[I/SFUD] norflash0 flash device is initialize success.
[I/SFUD] Probe SPI flash norflash0 by SPI device spi10 success.
[D/FAL] (fal_flash_init:63) Flash device |                norflash0 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name       | flash_dev |   offset   |    length  |
[I/FAL] -------------------------------------------------------------
[I/FAL] | wifi_image | norflash0 | 0x00000000 | 0x00080000 |
[I/FAL] | bt_image   | norflash0 | 0x00080000 | 0x00080000 |
[I/FAL] | download   | norflash0 | 0x00100000 | 0x00200000 |
[I/FAL] | easyflash  | norflash0 | 0x00300000 | 0x00100000 |
[I/FAL] | filesystem | norflash0 | 0x00400000 | 0x00c00000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer (V0.5.0) initialize success.
[I/FAL] The FAL MTD NOR device (filesystem) created successfully
The sector size of device is greater than the sector size of FAT.
[W/app.filesystem] mount to '/flash1' failed! try to mkfs filesyst
msh />[I/app.filesystem] mount to '/flash1' success!
[I/FAL] The FAL MTD NOR device (easyflash) created successfully
The sector size of device is greater than the sector size of FAT.
[W/app.filesystem] mount to '/flash2' failed! try to mkfs easyflas
[I/app.filesystem] sd card mount to '/sdcard'

msh />
msh />ls
Directory /:
flash1              <DIR>
flash2              <DIR>
sdcard              <DIR>
4 个回答
HeFeng123
HeFeng123 2021-03-19

多谢flashman2002,多谢yangjie,多谢Thread_Liu.我也挂载成功了,一个为elm,一个rom。
代码分享如下:

 rt_sfud_flash_probe(SPI_FLASH_NAME, SPI_FLASH_USING_SPIBUS_NAME "0");

fal_init();
fal_blk_device_create("para");
if(dfs_mount("para", "/", "elm", 0, 0) == 0)
{
  rt_kprintf("para fatfs filesystem mount is successful\r\n");
}

else
{
  
  dfs_mkfs("elm", "para");
  dfs_mount("para", "/", "elm", 0, 0);
  rt_kprintf("para fatfs filesystem mount again!");
  
}
 mkdir("data", 0x777);
 
 
 fal_blk_device_create("data");
 dfs_mount("data", "/data", "rom", 0, &(romfs_root));
flashman2002
flashman2002 2021-03-19

你是指挂载2种不同的文件系统吗?可以的,你使用FAL分成不同的区partition后可以使用不同的文件系统初始化后挂载的。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览