Can't open "/dev/block/mmcblk0" in kernel

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't open "/dev/block/mmcblk0" in kernel

11,398 Views
xrz_lam
Contributor I

I  use below codes to open "/dev/block/mmcblk0" in android kernel:

static const char *filename = "/dev/block/mmcblk0";
static const int  offset = 26623 * 512;

static int emmc_read(void)
{
mm_segment_t fs;
struct file *fp = NULL;
loff_t pos = 0;
u8 header[512], *data=NULL, *udata=NULL, *vp;
int len, outlen=0, n, i, ret = -1;
char *p;

printk("loading  file: %s\n", filename);

fs = get_fs();
set_fs(KERNEL_DS);

fp = filp_open(filename, O_RDONLY, 0);
if (IS_ERR(fp)) {
  fp = NULL;
  ERR("Could not open  file\n");
  goto err2;
}

....

}

but it failed,it shows below error:

loading file: /dev/block/mmcblk0

Could not open file

Can you tell me how to open "/dev/block/mmcblk0"  in android kernel ?

Thanks.

Labels (2)
Tags (2)
0 Kudos
15 Replies

3,893 Views
PeterChan
NXP Employee
NXP Employee

I used similar code but I don't experience such problem in Android. However, the Android BSP release is r13.5.


Please add the below lines to imx50_rdp/init.rc and try again.


    # enable mmcblk0 read by system

    chmod 0660 /dev/block/mmcblk0

0 Kudos

3,893 Views
wallyyeh
Contributor V

your question interests me.

mmcblk0 is a block device, if you doesn't have mmcblk0pX means this emmc block even not been partitioned.

and I'm curious, is it possible that user space program could/should do operations on this block device?

0 Kudos

3,893 Views
xrz_lam
Contributor I

  I stored the files in address "26623 * 512",so I only need to open the "/dev/block/mmcblk0" for read the file contents,

  I had made the  following  test.

1.Add the node of drivers;

   

static int emmcvalue=0;

static ssize_t show_emmc(struct device *dev,

  struct device_attribute *attr, char *buf)

{

  return snprintf(buf, PAGE_SIZE, "%d\n", emmcvalue);

}

static ssize_t set_emmc(struct device *dev,

  struct device_attribute *attr, char *buf, size_t count)

{

  int value = simple_strtol(buf,NULL,0);

  printk(" value =%d\n",value);

  ///check the value

  if(value ==1)

      emmc_read();

  emmcvalue = value;

  return count;

}

static DEVICE_ATTR(emmc, S_IWUSR | S_IRUGO, show_emmc, set_emmc);

2.When the devices bootup, I call the "emmc" in serial port:

bash-3.2# echo 1 > emmc
[ 53.799949] value =1
[ 53.802239] loading waveform file: /dev/block/mmcblk0
[ 53.808659] emmc_read,i=4
[ 53.813369] waveform name: V220_C175_50_WN5331_ED050SC5_BTC.wbf
[ 53.819297] waveform size: 38853


it works well,but I call it in kernel,it can't open. Thanks.




0 Kudos

3,893 Views
wallyyeh
Contributor V

I'll suggest using command "dd" to try that if you can retrieve your file or not

.

0 Kudos

3,893 Views
xrz_lam
Contributor I

"dd" command is for write,and I sure the file had been wrote to emmc,because in uboot,I can read the file contents from this address in emmc.

0 Kudos

3,893 Views
wallyyeh
Contributor V

if you change your if=, dd can be read, too.

such like "dd if=/dev/mmcblk0 of=/tmp/V220_C175_50_WN5331_ED050SC5_BTC.wbf bs=X seek=X skip=X"

0 Kudos

3,893 Views
xrz_lam
Contributor I

your mean, we can use the dd command to verify whether the file contents exist?but I sure the file is exist,because I can read the file contents in uboot.

0 Kudos

3,893 Views
wallyyeh
Contributor V

this also test user space program can access /dev/mmcblk0 or not.

if dd can retrieve your file successfully, that indicate your program might be wrong, or your program just not have the right permission to access /dev/mmcblk0(in this case, sudo sounds a good answer).

0 Kudos

3,893 Views
xrz_lam
Contributor I

I had tested the "dd" command, I think it can't retrieve the file successfully,because when I ran this command in serial port,it didn't have any response:

   bash-3.2#  dd if=/dev/block/mmcblk0 of=/mnt/sdcard/001.wbf bs=512 seek=26624

Is this command right? How to let dd stop at address ?

0 Kudos

3,893 Views
wallyyeh
Contributor V

it won't stop. unless it reach /dev/mmcblk0's end.

you may append count=X to let dd know when it should stop.

for example, bs=512 count=4, dd will dump 512 * 4 = 2048 byte

0 Kudos

3,893 Views
xrz_lam
Contributor I

Can you tell me how to use the dd command to transferred below file contents?

1).When I upgrade the firmware,I use below command to write:

     <CMD type="push" body="send" file="files/android/wfname">Sending SoftWare Version</CMD>

    <CMD type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=512 seek=26623 conv=fsync">write software version file to sd card</CMD>   

 

     <CMD type="push" body="send" file="files/android/V220_C175_50_WN5331_ED050SC5_BTC.wbf">Sending SoftWare Version</CMD>

    <CMD type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=512 seek=26624 conv=fsync">write software version file to sd card</CMD>   

    

2),After the devices bootup, I use below command to  transferred ,but the results is not the same :

bash-3.2#dd if=/dev/block/mmcblk0 of=/mnt/sdcard/002.txt bs=512 seek=26623 count=1                   

1+0 records in

1+0 records out

512 bytes transferred in 0.002 secs (256000 bytes/sec)

bash-3.2#

0 Kudos

3,893 Views
wallyyeh
Contributor V

dd will dump raw data from input source, and the data you dump is not a "file", it's just a combination of binary strings.

you may need hex editor/viewer to peek the contents of dd's dump file.

on linux, I often using hexdump.

if you using Windows, ultra editor can do this trick.

So, if you wanna retrieve the file you write in mmcblk0, you need:

    1. remove the garbage data append in your dd dump. you have to calculate the size, and write a program to retrieve (wait a sec, why not using your previous program, just replace dd file instead /dev/mmcblk0 ? ).

    2. or you just format your mmcblk0, and put the file in the file system.

after you get into your system, just mount this mmcblk0pX in /mnt, then get the file

  I believe the second one is lot easier.

0 Kudos

3,893 Views
xrz_lam
Contributor I

Thanks for your help,I think we can get the file content from your method,but,it still can't solve my problem,because I need read the wbf file in Eink driver,in  funtion "mxc_epdc_fb_init_hw".

   If I can't read the wbf file,the Eink driver can't register successful.

   From my test,we can run "dd" in serial port,it means,we had the permission to open the "/dev/block/mmcblk0" ?

   In android filesystem,the emmc will be divided six partition,and the "/dev/block/mmcblk0" will be stored uboot,kernel, and so on.

bash-3.2# cat /proc/partitions

major minor  #blocks  name

179        0    3870720 mmcblk0

179        1    2744320 mmcblk0p1

179        2     358400 mmcblk0p2

179        3          1 mmcblk0p3

179        4      40960 mmcblk0p4

179        5     307199 mmcblk0p5

179        6     358399 mmcblk0p6

bash-3.2#

0 Kudos

3,893 Views
Wlodek_D_
Senior Contributor II

Hello,

Thank you for your post, however please consider moving it to the right community place (e.g. i.MX Community ) to get it visible for active members.

For details please see general advice Where to post a Discussion?

Thank you for using Freescale Community. 

0 Kudos

3,893 Views
xrz_lam
Contributor I

Thanks for your reminder, I had selected the location as the  "i.MX Community",and had selected the catrgory "Android .I.MX50".

0 Kudos