Text file reading and writing based on QEMU file system

Text file reading and writing based on QEMU file system

Create and mount virtual SD card

env/tools/fatdisk/Create the sd folder in the ENV installation directory
insert image description here
and modify the parameters in fatdisk.xml, as shown in the figure below.
insert image description here
Use the ENV tool in this directory to input the fatdiskgenerated sd.binfile . Copy
insert image description here
the above figure sd.binto the relevant directory of the rt-thread source code, and replace the corresponding sd.binfile, as shown in the figure below.
insert image description here
The source code for mounting filesystems is in qemu-vexpress-a9\applications\mnt.c. In the actual code, the file system in the block device sd0 will be mounted to the root directory /, and you can also make some modifications according to your needs.

#include <rtthread.h>

#ifdef RT_USING_DFS
#include <dfs_fs.h>

int mnt_init(void)
{
    
    
    rt_thread_delay(RT_TICK_PER_SECOND);

    if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
    {
    
    
        rt_kprintf("file system initialization done!\n");
    }

    return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif

File creation sample program writing

insert image description here

insert image description here

insert image description here

ENV configuration

Open ENV in this directory and
insert image description here
open the following directory
insert image description here
Open the example
insert image description here

insert image description here
After exiting, update and scons compile
insert image description here

test


insert image description here
Open the ENV input in the following directory .\qemu.bat
insert image description here
and the following effect will appear
insert image description here

Use the example to generate directories and files (the error occurred because of the original operation), and the cat will display hello world after printing!
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43058521/article/details/106318880