My expectation was that when nandsim is passed the cache_file argument that nandsim would use the cache file to back the simulated memory instead of RAM. What I am observing though when I dd create files on a volume mounted against the nandsim mtd device is that Free RAM is being consumed that is at least as large as the file created. The cache_file grows by the expected amount with each dd file write. And the cache_file contains the contents of the files that are created.
I first experienced this when using nandsim on a ZC706 board and using yaffs2 as the file system.
To help diagnose this was not a issue with the ZC706 setup I was able to recreate the issue using a lab machine with a old version of linux on it and using ubifs instead of yaffs2. The behavior was the same.
Has anyone experienced this and have any advice – it would be appreciated?
The setup I will describe is what I performed on the lab machine with a old linux version.
uname -r
2.6.32-754.24.3.el6.x86_64
Found the linux source for it online and downloaded it.
Then uncompressed it using.
rpm2cpio kernel-2.6.32-754.24.3.el6.src.rpm | cpio –idmv
Then untar.
tar xvf kernel.tar.bz2
If I tried to only build the nandsim ko I had signature issues trying to load it. It would fail to insert and using dmesg indicated signature issue. modprobe -f didn’t help.
(with make drivers/mtd/nandsim.ko)
To work around that I needed to do the following:
Tried doing a full compile of linux and it reported key.h was missing.
run make menuconfig.
- Select “Enable loadable module support”, then “Module signature verification (EXPERIMENTAL)”. Disable it.
- Then go back to the main menu, select “Cryptographic API” then “In-kernel signature checker (EXPERIMENTAL)” and disable that one too.
Then go back again, save your config and make your kernel. At least, it will pass this phase successfully.
modprobe would still not insert for me. what I found to work was this sequence:
sudo insmod nand_ids.ko
sudo insmod nand_ecc.ko
sudo insmod nand.ko
sudo insmod nandsim.ko first_id_byte=0x01 second_id_byte=0xd5 third_id_byte=0x80 fourth_id_byte=0x1d cache_file=/home/user/cache_file
(I think I needed to use abs path for this instead of ~ but not sure – just beware) (creates 2GB device)
The first byte is the manufacturer ID.
The second byte is the chip ID.
The third byte is the bus width.
The other bytes I think are optional.
(to see the chips that nandsim knows about look at the nand_ids.c file – and you can google for listing of nand parameters for chips) The chip ID parameter is hardcoded in that file for each device.
cat /proc/mtd shows the simulated mtd device.
cache_file will be empty until files are put on the device.
My computer did not have ubifs in /proc/filesystems.
I was able to get it to appear by insmod the ubi.ko and ubifs.ko that were produced when I built the linux kernel.
Next I need the ubi userspace apps from mtd-utils.
git clone https://git.infraroot.at/mtd-utils.git
When running autogen.sh on old linux version the configure script had problems with fi’s in it.
To get around that I ran autogen.sh on my desktop machine and then tarred the mtd-utils up and put it on the lab machine.
configure would then run – but mkdir path was incorrect. I edited that in configure.
then did make. and sys/random.h was missing. found that I could avoid building the heavy mtd parts by specifying just the apps I wanted by doing these:
make ubiformat
make ubiattach
make flash_erase
make ubidetach
make ubimkvol
My simulated device appeared as mtd0 be careful with your setup as it might not be mtd0 in your case.
The following steps get it to where ubifs is mounted on nandsim.
flash_erase /dev/mtd0 0 0
ubiformat /dev/mtd0
ubiattach -p /dev/mtd0
mkdir -p ~/mnt/nandsim
mount -t ubifs /dev/ubi0 ~/mnt/nandsim
(this would fail with wrong fs type)
dmesg said it couldnt find /dev/ubi0 but it is there for sure.
I detached to be sure I wasn’t fooling myself and that worked.
ubidetach –d 0
Made /dev/ubi0 go away.
I attached again.
ubiattach -p /dev/mtd0
Googling around I found this step to create a volume.
ubimkvol /dev/ubi0 -N test_volume -s 1GiB
mount -t ubifs ubi0:test_volume ~/mnt/nandsim
Whew ok so now it will exist.
Here’s the part where the memory leaking happens. Or maybe it’s just that nandsim uses RAM always even when the cache_file option is specified.
cd ~/mnt/nandsim
Run this command over and over and you will notice the Free memory drops by at least the size of the file created.
dd if=/dev/urandom of=test1.bin bs=1M count=1 ; cat /proc/meminfo | grep MemFree
The reason I am going through all this is because I want to simulate a very large nand device on a ZC706 and it does not have enough RAM. It does however have a large SDCARD which I point the cache_file at – and I used ext2 to mount the SDCARD so that one very large file is possible that can represent the very large nand device.
Because of the memory leaking or nandsim using the cache_file and RAM – I run out of RAM before I am able to fill up the file system mount with data that would be the same size as the large nand device. If I keep writing and let the Free memory keep going down eventually a crash will occur and the backtrace will be point back to dd and nandsim.
Sorry it is so long and if I made any mistakes in describing the setup.
If anyone has any advice on this it would be appreciated.
Thank you.
jonzerStyle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1