您尚未登录。

楼主 # 2025-04-14 22:13:08

memory
会员
注册时间: 2021-08-11
已发帖子: 582
积分: 554

F133 测试 SPI NAND

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00180000 00010000 "uboot"
mtd1: 00020000 00010000 "boot-resource"
mtd2: 00020000 00010000 "env"
mtd3: 00020000 00010000 "env-redund"
mtd4: 00780000 00010000 "boot"
mtd5: 007e0000 00010000 "rootfs"
mtd6: 00ec0000 00010000 "UDISK"
mtd7: 08000000 00020000 "spi0.1"
#
#
# ubiformat /dev/mtd7
ubiformat: mtd7 (nand), size 134217728 bytes (128.0 MiB), 1024 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 byt                                 es
libscan: scanning eraseblock 1023 -- 100 % complete
ubiformat: 1024 eraseblocks are supposedly empty
ubiformat: formatting eraseblock 1023 -- 100 % complete
#
#
# ubiattach -m 7
ubi0: attaching mtd7
ubi0: scanning is finished
ubi0: attached mtd7 (name "spi0.1", size 128 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 1024, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 1346078118
ubi0: available PEBs: 1000, total reserved PEBs: 24, PEBs reserved for bad PEB handling: 20
ubi0: background thread "ubi_bgt0d" started, PID 1306
UBI device number 0, total 1024 LEBs (130023424 bytes, 124.0 MiB), available 1000 LEBs (126976000 bytes, 121.0 MiB), LEB size                                  126976 bytes (124.0 KiB)
#
#
# ubimkvol /dev/ubi0 -N my_volume -s 120MiB
Volume ID 0, size 991 LEBs (125833216 bytes, 120.0 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "my_volume", alignment 1
#
#
# mkdir /mnt/addon
#
# mount -t ubifs ubi0:my_volume /mnt/addon
UBIFS (ubi0:0): default file-system created
UBIFS (ubi0:0): Mounting in unauthenticated mode
UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1556
UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "my_volume"
UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
UBIFS (ubi0:0): FS size: 124436480 bytes (118 MiB, 980 LEBs), journal size 6221824 bytes (5 MiB, 49 LEBs)
UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
UBIFS (ubi0:0): media format: w5/r0 (latest is w5/r0), UUID 9052DCCC-6CB7-46AC-8C19-D7589BB974F3, small LPT model
#
# dd if=/dev/urandom of=/mnt/addon/x1.bin bs=1M count=20
20+0 records in
20+0 records out
#
# dd if=/dev/urandom of=/mnt/addon/x2.bin bs=1M count=20
20+0 records in
20+0 records out
#
#
# dd if=/dev/urandom of=/mnt/addon/x3.bin bs=1M count=70
70+0 records in
70+0 records out
#
# md5sum /mnt/addon/*
e6b65f9c308d919a9fd15df47ce8f938  /mnt/addon/x1.bin
ec0d0d20e1ca4937638570313959467d  /mnt/addon/x2.bin
875826b16155aed227790c07d0bcee66  /mnt/addon/x3.bin
#

离线

楼主 #1 2025-04-14 22:16:33

memory
会员
注册时间: 2021-08-11
已发帖子: 582
积分: 554

Re: F133 测试 SPI NAND

modprobe spinand

ubiattach -m 7

mount -t ubifs ubi0:my_volume /mnt/addon

离线

楼主 #2 昨天 09:49:14

memory
会员
注册时间: 2021-08-11
已发帖子: 582
积分: 554

Re: F133 测试 SPI NAND

可惜了,ubifs 不支持swap:A failed attempt:ubifs+swap

# dd if=/dev/zero of=/mnt/swap/swapfile bs=1M count=32
32+0 records in
32+0 records out
33554432 bytes (32.0MB) copied, 0.341635 seconds, 93.7MB/s

# mkswap /mnt/swap/swapfile
Setting up swapspace version 1, size = 33550336 bytes
UUID=79052343-2d79-4423-925b-455c7e328917
# chmod 0600 //mnt/swap/swapfile
# swapon /mnt/swap/swapfile
[ 1984.581859] swapon: swapfile has holes
swapon: /root/swapfile: swapon failed: Invalid argument

能想到的方法都想到了,最后一招就只能是看内核的代码了。其中过程略过,只讲最后的发现。

本次遇到的"swapfile has holes"这个错误信息是由下述代码导致的!

int bmap(struct inode *inode, sector_t *block)
{
	if (!inode->i_mapping->a_ops->bmap)
		return -EINVAL;

	*block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block);
	return 0;
}
EXPORT_SYMBOL(bmap);

-EINVAL就是invalid argument!,看来是没有bmap操作!进一步阅读内核UBIFS的代码,得到如下:

const struct address_space_operations ubifs_file_address_operations = {
	.readpage       = ubifs_readpage,
	.writepage      = ubifs_writepage,
	.write_begin    = ubifs_write_begin,
	.write_end      = ubifs_write_end,
	.invalidatepage = ubifs_invalidatepage,
	.set_page_dirty = ubifs_set_page_dirty,
#ifdef CONFIG_MIGRATION
	.migratepage	= ubifs_migrate_page,
#endif
	.releasepage    = ubifs_releasepage,
};

可见,这里的确没有设置bmap操作,所以无论如何都会返回EINVAL。



UBIFS不支持文件方式的swap功能。同时,因为UBI本身(注意和UBIFS的区别)不是块设备(/dev/ubix是字符设备),因此也不能支持块设备的swap功能!

为了在使用UBI/UBIFS的系统里面支持swap功能,需要单独一个MTD分区(MTD有块设备支持),通过块设备的方式来支持swap功能!

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn