Difference between revisions of "MultiMediaCard"

From ArmadeusWiki
Jump to: navigation, search
(Usage (as a removable mass storage))
(U-Boot usage)
 
(66 intermediate revisions by 8 users not shown)
Line 4: Line 4:
  
 
You can use standard MMC/SD/miniSD/microSD cards with your Armadeus board:
 
You can use standard MMC/SD/miniSD/microSD cards with your Armadeus board:
* with a DevLight V1 you must have [[MMC/SD | the corresponding connector attached to your development board.]] and use an adaptor for miniSD and microSD
+
* with an APF9328 DevLight V1, you must have [[MMC/SD | the corresponding connector attached to your development board.]] and use an adaptor for miniSD and microSD,
* with a DevLight V2 you can use the onboard microSD connector
+
* with an APF9328 DevLight V2, you can use the onboard microSD connector,
* with a DevFull you can use the MMC/SD onboard connector and an adaptor for miniSD and microSD
+
* with an [[APF9328DevFull]], you can use the MMC/SD onboard connector and an adaptor for miniSD and microSD,
 +
* with an [[APF27Dev]], an [[APF28Dev]], an [[APF51Dev]] or an [[APF6Dev]], you can use the onboard microSD connector.
  
All needed drivers are included in standard Armadeus Linux image.
+
All needed drivers are included in the standard Armadeus Linux image.
  
==Mounting the MMC/SD==
+
==Card insertion==
 +
You should see something like that on the Linux console:
 +
<pre class="apf">
 +
# imx-mmc imx-mmc.0: card inserted
 +
mmc0: host does not support reading read-only switch. assuming write-enable.
 +
mmc0: new SD card at address 01b0
 +
mmcblk0: mmc0:01b0 SD512 500224KiB
 +
  mmcblk0: p1
 +
</pre>
  
* Just mount the MMC like you will do on your PC, for example (FAT32 formatted card):
+
==Mounting the MMC/SD from Linux==
# mount -t vfat /dev/mmcblk0p1 /mnt/mmc
+
* Then, you can access the MMC's files from the ''/mnt/mmc'' directory
+
  
If you have problems with vfat code page [http://www.armadeus.com/wiki/index.php?title=MultiMediaCard#VFAT_Code_Page click here]
+
* Just mount the MMC like you will do on your PC:
 +
<pre class="apf">
 +
# mount /dev/mmcblk0p1 /media/mmc            (on all APF *except* APF6)
 +
</pre>
 +
<pre class="apf">
 +
# mount /dev/mmcblk1p1 /media/mmc            (on APF6)
 +
</pre>
 +
* Then, you can access the MMC's files from the ''/media/mmc'' directory. Filesystem should be automagically detected.
 +
* Of course if you have several partitions on your MMC/SD they will be named p1/p2/p3...
 +
* If you have problems with vfat code page, [[MultiMediaCard#VFAT_Code_Page|include the missing code page into the kernel]].
  
 
==Booting from MMC/SD==
 
==Booting from MMC/SD==
When your rootfs is too big to be put on the APF9328 FLASH, you can always use a MMC/SD like a Hard Drive and boot from it. '''To do that you must have MMC drivers compiled as builtin in your Linux kernel (done by default in standard Armadeus kernel)'''
+
When your rootfs is too big to be put on the APF Flash, you can always use a MMC/SD like a Hard Drive and boot from it (this is possible because standard Armadeus kernel is compiled with the MMC driver built in).
* Format your MMC with Ext2 filesystem:
+
 
  [armadeus] $ sudo mkfs.ext2 /dev/sdxx
+
===Prepare your card===
* Mount your MMC/SD on your Host filesystem, for example in ''/media/mmc''
+
* On your APF board (to avoid to crash your Host HD), create a good partition table on MMC (X is the id of the device, for example 1 on [[APF6]]):
  [armadeus] $ sudo mkdir -p /media/mmc
+
<pre class="apf">
  [armadeus] $ sudo mount /dev/sdxx /media/mmc
+
# /sbin/fdisk /dev/mmcblkX
* Then put your rootfs on this MMC/SD: in Buildroot configure rootfs to be tar-ed:
+
 
[armadeus] $ make menuconfig
+
Delete all existing partion with 'd'
'''Target filesystem options --->'''  
+
Create a primary partion: 'n' then 'p' then '1' then 2x'ENTER'
[[Image:Menuconfig_tar_rootfs.png]]
+
Change bootflag to Linux: 't' then '83'
[armadeus] $ make
+
Save partition table: 'w'
and then:
+
(To quit without saving: 'm')
[armadeus] $ sudo tar xvf ./buildroot/binaries/armadeus/rootfs.arm.tar -C /media/mmc
+
</pre>
[armadeus] $ sudo umount /media/mmc
+
* If your APF has the ''mkfs'' tools, then format your MMC:
* in U-Boot then use (with MMC/SD/microSD inserted):
+
<pre class="apf">
 +
# mkfs.ext4 -O ^64bit /dev/mmcblkXp1
 +
</pre>
 +
* Otherwise, on your PC, format your MMC with Ext2 or Ext3/4 filesystems (booting on FAT is bad :-) ):
 +
<pre class="host">
 +
  $ sudo mkfs.ext2 /dev/sdX1  (replace X with your MMC reader drive letter, if your Laptop has an integrated
 +
                                          MMC reader then use mmcblk0p1 instead of sdX1)
 +
</pre>
 +
* If not automatically detected/mounted by your distribution, mount your MMC/SD on your Host filesystem (for example in ''/media/mmc''):
 +
<pre class="host">
 +
  $ sudo mkdir -p /media/mmc
 +
  $ sudo mount /dev/sdX1 /media/mmc   (replace X with your MMC reader drive letter, if your Laptop has an integrated
 +
                                                  MMC reader then use mmcblk0p1 instead of sdX1)
 +
</pre>
 +
 
 +
===Put your rootfs and Linux kernel on the MMC/SD===
 +
* Buildroot should be configured by default to generate a tar-ed rootfs, '''if not''' (no *.tar in ''buildroot/output/images/'') then you can activate it with:
 +
<pre class="host">
 +
$ make menuconfig
 +
</pre>
 +
 
 +
<pre class="config">
 +
Filesystem images  --->
 +
...
 +
    [*] tar the root filesystem
 +
          Compression method (no compression) --->
 +
    ()    other random options to pass to tar
 +
...
 +
</pre>
 +
 
 +
<pre class="host">
 +
$ make
 +
</pre>
 +
* Then you have to uncompress the tar-ed rootfs to the MMC/SD card (mounted as ''/media/mmc'' on your PC in the following instructions).
 +
{{Note | The APF51 (with U-Boot version older than 2013.04) and the APF9328 do not load the kernel from the SD card but use the one in Flash instead. }}
 +
<pre class="host">
 +
$ make shell_env
 +
$ source armadeus_env.sh
 +
$ sudo tar xvf $ARMADEUS_ROOTFS_TAR -C /media/mmc
 +
</pre>
 +
* You can also copy the Linux kernel to the rootfs ''/boot'' folder and dtb files for recent kernel supporting it:
 +
<pre class="host">
 +
$ sudo mkdir -p /media/mmc/boot/dtbs
 +
$ sudo cp $ARMADEUS_BINARIES/$ARMADEUS_BOARD_NAME-linux.bin /media/mmc/boot/
 +
$ sudo cp $ARMADEUS_BINARIES/*.dtb /media/mmc/boot/dtbs/
 +
</pre>
 +
* Then umount your MMC/SD from your PC:
 +
<pre class="host">
 +
$ sudo umount /media/mmc
 +
</pre>
 +
 
 +
===Boot===
 +
* Insert the MMC/SD/microSD in the corresponding slot of your Armadeus board and then under U-Boot do:
 +
<pre class="apf">
 
  BIOS> run mmcboot
 
  BIOS> run mmcboot
* if you want to automatically boot from SD at each startup then replace default ''bootcmd'' U-Boot macro:
+
</pre>
 +
* if you want to automatically boot from SD at each startup, modify the ''bootcmd'' U-Boot macro:
 +
<pre class="apf">
 
  BIOS> setenv bootcmd run mmcboot
 
  BIOS> setenv bootcmd run mmcboot
 
  BIOS> saveenv
 
  BIOS> saveenv
(default bootcmd is ''run jffsboot'')
+
</pre>
 +
(default bootcmd when you receive your board is ''run jffsboot'' = boot from FLASH)
  
 
==Performances==
 
==Performances==
* [[MMC/SD#Supported_Cards]]
+
* [[MMC/SD#Supported_Cards| Show tested cards performances]]
  
 
==Troubleshots==
 
==Troubleshots==
 
===VFAT Code Page===
 
===VFAT Code Page===
If you encounter this message or something like that
+
If you encounter this message (or something similar):
 
  Unable to load NLS charset cp437
 
  Unable to load NLS charset cp437
 
  FAT: codepage cp437 not found
 
  FAT: codepage cp437 not found
you have to change the right charset for the current file system:
+
you have to add the charset to the supported kernel ones:
  make linux-menuconfig
+
  $ make linux-menuconfig
In ''Device Drivers->MMC/SD Card support->iMX Support''
+
<pre class="config">
 +
File systems  --->  
 +
    -*- Native language support --->
 +
        <*>  Codepage 437 (United States, Canada)
 +
        ...
 +
        <*>  NLS ISO 8859-1  (Latin 1; Western European Languages)
 +
        ...
 +
</pre>
  
In ''FileSystems->Native Language Support'' you can select the right charset:
+
==U-Boot usage==
ex: NLS ISO 8859-1  (Latin 1; Western European Languages)
+
  
==Installation (obsolete now because driver is staticly built in default Armadeus kernel)==
+
SD cards can also be used with U-Boot.
 +
The following commands are useful:
 +
* Scan the MMC:
 +
<pre class="apf">
 +
BIOS> mmc rescan
 +
</pre>
 +
* List the MMC content:
 +
<pre class="apf">
 +
BIOS> fatls mmc 0
 +
</pre>
 +
* Load the file xxx.bin in RAM:
 +
<pre class="apf">
 +
BIOS> fatload mmc 0 ${loadaddr} xxx.bin
 +
</pre>
  
When you build your kernel image, then modify its configuration:
+
On last APF/OPOS the eMMC mounted on board have the same behavior of SD Cards, but not formatted as with fat system files. Then to read partition '''ext2ls''' and '''ext4ls''' commands can be used (example on apf6):
[armadeus]$ make linux-menuconfig
+
in Device Drivers->MMC/SD Card support->iMX Support
+
In FileSystems, don't forget to add support for the filesystem you want to use on the MMC and if you activate FAT/VFAT, don't forget to activate Native Language Support (NLS)
+
otherwise you'll get errors like:  
+
Unable to load NLS charset cp437
+
FAT: codepage cp437 not found
+
  
Save your configuration and then rebuild your kernel image:
+
<pre class="apf">
[armadeus]$ make linux
+
BIOS> ext2ls mmc 0
now you should have following drivers in your kernel source tree:
+
<DIR>      1024 .
drivers/mmc/
+
<DIR>      1024 ..
Copy '''mmc_core.ko''', '''imxmmc.ko''' & '''mmc_block.ko''' to your target root filessytem in '''/lib/modules/''' or reflash the generated rootfs.
+
<DIR>      12288 lost+found
 
+
        4944000 apf6-linux.bin
If not already existing then create the MMC block devices:
+
<DIR>      1024 dtbs
# mknod /dev/mmcblk0 b 254 0
+
          36690 imx6q-apf6dev.dtb
# mknod /dev/mmcblk0p1 b 254 1
+
          33873 imx6dl-apf6dev.dtb
If not already existing then create the mount point (/mnt/mmc):
+
# or with partition number :
# mkdir -p /mnt/mmc
+
BIOS> ext2ls mmc 0:1
 +
</pre>
  
 
==Links==
 
==Links==
  
 
* http://en.wikipedia.org/wiki/MultiMedia_Card
 
* http://en.wikipedia.org/wiki/MultiMedia_Card
 
{{LanguageBar|MultiMediaCard|MultiMediaCard|MultiMediaCard}}
 
  
 
[[Category:MassStorage]]
 
[[Category:MassStorage]]

Latest revision as of 13:54, 7 July 2020

Instructions to use the MultiMediaCard (MMC/SD) on your Armadeus board

Introduction

You can use standard MMC/SD/miniSD/microSD cards with your Armadeus board:

All needed drivers are included in the standard Armadeus Linux image.

Card insertion

You should see something like that on the Linux console:

 # imx-mmc imx-mmc.0: card inserted
 mmc0: host does not support reading read-only switch. assuming write-enable.
 mmc0: new SD card at address 01b0
 mmcblk0: mmc0:01b0 SD512 500224KiB
  mmcblk0: p1

Mounting the MMC/SD from Linux

  • Just mount the MMC like you will do on your PC:
 # mount /dev/mmcblk0p1 /media/mmc             (on all APF *except* APF6)
 # mount /dev/mmcblk1p1 /media/mmc             (on APF6)
  • Then, you can access the MMC's files from the /media/mmc directory. Filesystem should be automagically detected.
  • Of course if you have several partitions on your MMC/SD they will be named p1/p2/p3...
  • If you have problems with vfat code page, include the missing code page into the kernel.

Booting from MMC/SD

When your rootfs is too big to be put on the APF Flash, you can always use a MMC/SD like a Hard Drive and boot from it (this is possible because standard Armadeus kernel is compiled with the MMC driver built in).

Prepare your card

  • On your APF board (to avoid to crash your Host HD), create a good partition table on MMC (X is the id of the device, for example 1 on APF6):
 # /sbin/fdisk /dev/mmcblkX

 Delete all existing partion with 'd'
 Create a primary partion: 'n' then 'p' then '1' then 2x'ENTER'
 Change bootflag to Linux: 't' then '83'
 Save partition table: 'w'
 (To quit without saving: 'm')
  • If your APF has the mkfs tools, then format your MMC:
 # mkfs.ext4 -O ^64bit /dev/mmcblkXp1
  • Otherwise, on your PC, format your MMC with Ext2 or Ext3/4 filesystems (booting on FAT is bad :-) ):
 $ sudo mkfs.ext2 /dev/sdX1   (replace X with your MMC reader drive letter, if your Laptop has an integrated
                                           MMC reader then use mmcblk0p1 instead of sdX1)
  • If not automatically detected/mounted by your distribution, mount your MMC/SD on your Host filesystem (for example in /media/mmc):
 $ sudo mkdir -p /media/mmc
 $ sudo mount /dev/sdX1 /media/mmc    (replace X with your MMC reader drive letter, if your Laptop has an integrated
                                                   MMC reader then use mmcblk0p1 instead of sdX1)

Put your rootfs and Linux kernel on the MMC/SD

  • Buildroot should be configured by default to generate a tar-ed rootfs, if not (no *.tar in buildroot/output/images/) then you can activate it with:
$ make menuconfig
Filesystem images  --->
...
    [*] tar the root filesystem
          Compression method (no compression)  --->
    ()    other random options to pass to tar
...
$ make
  • Then you have to uncompress the tar-ed rootfs to the MMC/SD card (mounted as /media/mmc on your PC in the following instructions).
Note Note: The APF51 (with U-Boot version older than 2013.04) and the APF9328 do not load the kernel from the SD card but use the one in Flash instead.
$ make shell_env
$ source armadeus_env.sh
$ sudo tar xvf $ARMADEUS_ROOTFS_TAR -C /media/mmc
  • You can also copy the Linux kernel to the rootfs /boot folder and dtb files for recent kernel supporting it:
$ sudo mkdir -p /media/mmc/boot/dtbs
$ sudo cp $ARMADEUS_BINARIES/$ARMADEUS_BOARD_NAME-linux.bin /media/mmc/boot/
$ sudo cp $ARMADEUS_BINARIES/*.dtb /media/mmc/boot/dtbs/
  • Then umount your MMC/SD from your PC:
$ sudo umount /media/mmc

Boot

  • Insert the MMC/SD/microSD in the corresponding slot of your Armadeus board and then under U-Boot do:
 BIOS> run mmcboot
  • if you want to automatically boot from SD at each startup, modify the bootcmd U-Boot macro:
 BIOS> setenv bootcmd run mmcboot
 BIOS> saveenv

(default bootcmd when you receive your board is run jffsboot = boot from FLASH)

Performances

Troubleshots

VFAT Code Page

If you encounter this message (or something similar):

Unable to load NLS charset cp437
FAT: codepage cp437 not found

you have to add the charset to the supported kernel ones:

$ make linux-menuconfig
File systems  ---> 
    -*- Native language support  --->
        <*>   Codepage 437 (United States, Canada)
        ...
        <*>   NLS ISO 8859-1  (Latin 1; Western European Languages)
        ...

U-Boot usage

SD cards can also be used with U-Boot. The following commands are useful:

  • Scan the MMC:
BIOS> mmc rescan
  • List the MMC content:
BIOS> fatls mmc 0
  • Load the file xxx.bin in RAM:
BIOS> fatload mmc 0 ${loadaddr} xxx.bin

On last APF/OPOS the eMMC mounted on board have the same behavior of SD Cards, but not formatted as with fat system files. Then to read partition ext2ls and ext4ls commands can be used (example on apf6):

BIOS> ext2ls mmc 0
<DIR>       1024 .
<DIR>       1024 ..
<DIR>      12288 lost+found
         4944000 apf6-linux.bin
<DIR>       1024 dtbs
           36690 imx6q-apf6dev.dtb
           33873 imx6dl-apf6dev.dtb
# or with partition number :
BIOS> ext2ls mmc 0:1

Links