How to access nand or emmc storage from linux

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to access nand or emmc storage from linux

Jump to solution
16,121 Views
mrigendra_chaub
Contributor III

I have a i.mx6 based board running using buildroot and linux.

I am trying to access nand and emmc storages from sd card's rootfs but the underlying subsystem and commands are not very clear to me.


This board have two storages nand and emmc. The nand has full rootfs and bootimage on itself.

Booting from SD card gives below log.
From the boot logs I can see the nand and emmc partition getting detected

[ 3.440294] 5 ofpart partitions found on MTD device gpmi-nand
[ 3.446084] Creating 5 MTD partitions on "gpmi-nand":
[ 3.451148] 0x000000000000-0x000000200000 : "boot"
[ 3.456431] 0x000000200000-0x000000500000 : "scratch"
[ 3.461632] 0x000000500000-0x000000b00000 : "kernel"
[ 3.467091] 0x000000b00000-0x000001100000 : "recovery"
[ 3.472521] 0x000001100000-0x000010000000 : "rootfs"
[ 3.481312] gpmi-nand 112000.gpmi-nand: driver registered.

and emmc

[ 4.318175] mmcblk0: p1 p2

I can see the devices for nand are registered and shown in `/dev/mtd*` but not mounted.
Now I am using `nand and mmc-utils` provided by buildroot.
I am trying to write some data on nand like this

nandwrite -b 1 -n /dev/mtd0 -p /test.txt

error log

https:/pastebin.com/raw/FZdk2hUT

Tried flash erase command, 

flash_erase /dev/mtd0

flash_erase: error!: no start erase block specified
flash_erase: error!: no erase block count specified
flash_erase: error!: Try `--help' for more information

Can anyone tell the correct way/steps to be followed in case of nand, sd interaction. I followed this thread

https://unix.stackexchange.com/questions/99476/how-can-i-flash-erase-mtd0

Similarly I am not able to flash, or do anything with emmc.

mmc status get /dev/mmcblk0
SEND_STATUS response: 0x00000900

This looks ok, but how to really write or erase mmc? There are many commands associated with mmc , and not know which should I use,

https://manpages.debian.org/unstable/mmc-utils/mmc.1.en.html

What are the prerequisites for this?

Any hint or direction would be helpful.

0 Kudos
1 Solution
12,191 Views
jimmychan
NXP TechSupport
NXP TechSupport

Which BSP are you using?

Basically, the device name of mmc/SD in Linux is /dev/mmcblkx. The NAND is /dev/mtdx. The "x" is the 0,1,2,3.

You can take the script in mfgtool for reference because it is using the Linux commands to program the images to the storage media. For example: attached is the ucl2.xml in L4.1.15_2.0.0-ga_mfg-tools. You can get the tool from here : i.MX Software|NXP 

For the eMMC part of the script is under "<LIST name="eMMC" desc="Choose eMMC as media">" in the ucl2.xml.

For the NAND part of the script is under "<LIST name="NAND Flash" desc="Choose NAND as media">" in the ucl2.xml.

In the script, there are two parts. One is “BootStrap" and the other part is "Updater".

The "BootStrap" part is loading the firmware to the DDR. The firmware is a small linux system which include bootloader, kernel and ramfs. So you can ignore this part of script.

The "Updater" part is the script to program the images to the media. So, you can read this part of script for reference.

View solution in original post

3 Replies
12,187 Views
mrigendra_chaub
Contributor III

Hi JimmyChan

Thanks for your response and I got the relevant information.

I have a question though.

Does emmc version affects its flashing? I have emmc version 5 as reported by u-boot and it already have two partitions written on it mmcblk0bootp0 and mmcblk0bootp1. 

I flashed whole android on emmc using fsl script, tried to boot from nand and read partition table but u-boot cannot identify 'boot' gpt partition table (how ever it is there on doing mmc part).

I tried to change the permission to write and then overwriting mmcblk0bootp0 and mmcblk0bootp1 partitions but still they are intact. 

Is it a know issue or probably I am doing something wrong.

0 Kudos
12,187 Views
jimmychan
NXP TechSupport
NXP TechSupport

Sorry, I don't understand your question. Would you show me the steps or more details about the issue you met? Thanks.

0 Kudos
12,192 Views
jimmychan
NXP TechSupport
NXP TechSupport

Which BSP are you using?

Basically, the device name of mmc/SD in Linux is /dev/mmcblkx. The NAND is /dev/mtdx. The "x" is the 0,1,2,3.

You can take the script in mfgtool for reference because it is using the Linux commands to program the images to the storage media. For example: attached is the ucl2.xml in L4.1.15_2.0.0-ga_mfg-tools. You can get the tool from here : i.MX Software|NXP 

For the eMMC part of the script is under "<LIST name="eMMC" desc="Choose eMMC as media">" in the ucl2.xml.

For the NAND part of the script is under "<LIST name="NAND Flash" desc="Choose NAND as media">" in the ucl2.xml.

In the script, there are two parts. One is “BootStrap" and the other part is "Updater".

The "BootStrap" part is loading the firmware to the DDR. The firmware is a small linux system which include bootloader, kernel and ramfs. So you can ignore this part of script.

The "Updater" part is the script to program the images to the media. So, you can read this part of script for reference.