uboot中yaffs2命令使用

  • 硬件平台
    • 君正x1000 halley2

uboot中yaffs2文件系统的支持

yaffs2文件系统,是针对nand的的文件系统,在uboot原生代码库中就有支持,yaffs2文件系统源码相对独立,方便移植。

uboot对yaffs2的支持可以通过以下宏来控制

#define CONFIG_YAFFS2

uboot中使用yaffs2的相关命令如下

ydevconfig- configure yaffs mount point
ydevls - list yaffs mount points
yls - yaffs ls
ymkdir - YAFFS mkdir
ymount - mount yaffs
ymv - YAFFS mv
yrd - read file from yaffs
yrdm - read file to memory from yaffs
yrm - YAFFS rm
yrmdir - YAFFS rmdir
ytrace - show/set yaffs trace mask
yumount - unmount yaffs
ywr - write file to yaffs
ywrm - write file from memory to yaffs

yaffs2命令的使用

配置mount点,和nand的起始结束块地址,注意是块地址(通常nand的一个块为64*2048大小)

例如:

1. 通过以下命令获取分区信息

halley2-sfcnand# nand info

Device 0: nand0, sector size 128 KiB
Page size 2048 b
OOB size 128 b
Erase size 131072 b
halley2-sfcnand# mtdpart default
halley2-sfcnand# mtdparts

device nand0 <nand>, # parts = 4
#: name size offset mask_flags
0: boot 0x00100000 0x00000000 0
1: kernel 0x00800000 0x00100000 0
2: rootfs 0x02800000 0x00900000 0
3: data 0x0cf00000 0x03100000 0

active partition: nand0,0 - (boot) 0x00100000 @ 0x00000000

defaults:
mtdids : nand0=nand
mtdparts: mtdparts=nand:1M(boot),8M(kernel),40M(rootfs),-(data)

2. 将rootfs分区配置为mnt挂载点的yaffs2文件系统

halley2-sfcnand# ydevconfig mnt 0 0x48 0x188
Configures yaffs mount mnt: dev 0 start block 72, end block 392 using inband tags

其中 ydevconfig参数解释如下:

第一个参数为 挂载点的名字,可以随意取。

第二个参数是nand device的索引,通常我们只有一个nand, 所以从0开始

第三个参数控制起始 block, 0x900000 / (2048 * 64) = 0x48

第四个参数控制结束block, (0x900000 + 0x2800000) / (2048 * 64) = 0x188

想配置其他挂载点,依次类推。

扫描二维码关注公众号,回复: 2937829 查看本文章

重点注意 using inband tags,表示使用数据区存储tag而非使用oob,这种方式对于不同的nand支持比较友好,不用每个nand都去更改oob的位置(如果将tag存放在oob区,针对不同的nand, oob的排布不一样,所以在制作竟像时比较麻烦)。具体如何实现的,需要在制作镜像文件的时候加以控制

3.  挂载yaffs2文件系统

第二步配置了挂载点mnt,现在需要挂在文件系统到mnt,执行如下命令

halley2-sfcnand# ymount mnt
Mounting yaffs2 mount point mnt

4.  对文件系统文件进行访问

挂载完文件系统之后,就可以对文件系统文件进行读写操作了,uboot提供的命令举例说明如下:

4.1 查看文件
halley2-sfcnand# yls mnt
u-boot
README.txt
yaffs_osglue.h
yaffscfg.h
yaffs_hweight.h
yaffsfs.c
lost+found

halley2-sfcnand# yls -l mnt
optional_sort 2032 829 directory
u-boot 2032 832 directory
README.txt 671 848 regular file
yaffs_osglue.h 932 849 regular file
yaffscfg.h 769 850 regular file
yaffs_hweight.h 600 851 regular file
yaffsfs.c 85890 852 regular file
lost+found 2032 2 directory
4.2 创建删除文件夹
halley2-sfcnand# ymkdir mnt/test
halley2-sfcnand# yls mnt
test

halley2-sfcnand# yrmdir mnt/test
halley2-sfcnand# yls mnt
4.3 移动文件
halley2-sfcnand# yls mnt
README.txt
halley2-sfcnand# ymv mnt/README.txt mnt/README.TXT
halley2-sfcnand# yls mnt
README.TXT
4.5 读写文件内容

从文件系统读数据到内存

halley2-sfcnand# yrdm mnt/README.TXT 0x80600000
Copy mnt/README.TXT to 0x80600000... [DONE]
halley2-sfcnand# md 0x80600000
80600000: 2077654e 646e6148 676e696c 726f6620 New Handling for
80600010: 66615920 43207366 2065726f 65646f43 Yaffs Core Code
80600020: 206e6920 66666159 69442073 74636572 in Yaffs Direct
80600030: 6e490a0a 65687420 73617020 74202c74 ..In the past, t

从内存写数据到文件

halley2-sfcnand# mm 0x80600000 # 创建数据
80600000: 2077654e ? 01234567
80600004: 646e6148 ? 89abcdef
80600008: 676e696c ? 01234567
8060000c: 726f6620 ? 89abcdef

halley2-sfcnand# ywrm mnt/mytest 0x80600000 10
halley2-sfcnand# yrd mnt/mytest
Reading file mnt/mytest 67 45 23 01 ef cd ab 89 67 45 23 01 ef cd ab 89
done
4.6 卸载文件系统
yumount - unmount yaffs

halley2-sfcnand# yumount mnt
Unmounting yaffs2 mount point mnt
4.7 其他命令

yrd - 读文件并打印内容

ywr - 写固定的值到文件

ytrace - show/set yaffs trace mask

总结

主要描述了uboot中yaffs2命令的使用,其中文件系统是已经烧录好的,所以能直接看到里面的内容。此处的支持yaffs2文件系统,也是为了后续将该文件系统移植到小系统上做准备。

猜你喜欢

转载自blog.csdn.net/boysic/article/details/82153454