Sunday 3 February 2019

Common MTD commands : Boot EEPROM/ NAND flash access from Linux


Common MTD Commands use wisely

  •  cat /proc/mtd

dev:    size   erasesize  name
mtd0: 000c0000 00001000 "U-Boot"
mtd1: 00002000 00001000 "U-Boot Env"
mtd2: 00001000 00001000 "JFFS2"
mtd3: 0013d000 00001000 "my-data"
mtd4: 0013e000 00001000 "U-image/Kernel"
mtd5: 0013f000 00001000 "rootfs"
mtd6: 00140000 00001000 "mylog"
mtd7: 00141000 00001000 "mydata"

  •  mtdinfo -a
  • ls -l /dev/mtd*
  •  flash_unlock could be used to unlock the appropriate sectors.
  • flash_eraseall /dev/mtdchar0 
    •  cat /dev/mtdchar0 < new.bin  ( Erase and load new file)
  • cat /dev/mtdchar0 > /tmp/flash.bin ( Entire flash to file) 
  • flashcp to write to NOR flash
  • flash_eraseall -j /dev/mtd2
    mount -t jffs2 /dev/mtdblock2 /mnt/flash
  • flash_eraseall /dev/mtd0 ( erases everything, use rarely)
IOCTL Commands
  • MEMGETINFO Get layout and capabilities struct mtd_info_user *
  • MEMGETREGIONINFO struct region_info_user *
  • MEMWRITEOOB NAND only: write out-of-band info (ECC) struct mtd_oob_buf *
  • MEMERASE Erase flash blocks struct erase_info_user *
  • MEMLOCK Lock flash blocks to disallow changes struct erase_info_user *
  • MEMUNLOCK Unlock flash to allow changes struct erase_info_user *
  • MEMGETREGIONCOUNT Return number of erase block regions int *
  • MEMREADOOB NAND only: read out-of-band info (ECC) struct mtd_oob_buf *
  • MEMSETOOBSEL NAND only: set default OOB info struct nand_oobinfo*
  •  The exact flash layout may be determined using the MEMGETREGIONCOUNT and MEMGETREGIONINFO commands.
  • MEMERASE command may be issued to erase the desired blocks.




Difference between Raw Flashes (MTD) and Block Devices


Block Devices Examples 

  • SSD
  • MMC
  • eMMC
  • RS-MMC
  • SD
  • Mini/micro-SD
  • USB flash drive
  • CompactFlash
  • MemoryStick
  • MemoryStick Micro
  • Hard drives 

Ext2, ext3, XFS, JFS, FAT and conventional file systems work with block devices. 

Features
  • Block devices consists of sectors.
  • Sectors are small (512, 1024 bytes)
  • Maintains operations: read sector and write sector
  • Bad sectors are re-mapped and hidden by hardware (at least in modern LBA hard drives);
  • Sectors are devoid of the wear-out property 
 Bad sector re-mapping and wear out in case of FTL devices, it is the responsibility of FTL to provide this.

MTD (Memory Technology Devices) Examples ( Used for Raw Flash devices)

  • NAND
  • OneNAND
  • NOR 
  • AG-AND
  • ECC'd NOR
  • CFI (Common Flash Interface)  
  • Bare NAND Flashes with SW/HW
  • Legacy FTL/NFTL "translation layers"
  •  M-Systems' DiskOnChip 2000 and Millennium chips
  •  PCMCIA flashes (pcmciamtd driver).

 MTD subsystem provides an abstraction layer for raw flash devices to make use of the same API when working with different flash types and technologies. Also to use conventional files systems over an MTD device, we need a software layer known as Flash Translation Layers (FTLs) which enables them to behave like a block devices.

MTD Characteristics & Features

  • Consists of eraseblocks
  • Eraseblocks are larger (typically 128KiB)
  • Maintains : read from eraseblockwrite to eraseblock, and erase eraseblock
  • Bad eraseblocks are not hidden and should be dealt with in software.
  • Eraseblocks wear-out and become bad and unusable after about 103 (for MLC NAND) - 105 (NOR, SLC NAND) erase cycles

MTD Subsystem interfaces:

  • MTD character devices - These character devices provide I/O access to the raw flash and referred as /dev/mtd0, /dev/mtd1 etc. They support a number of ioctl calls for getting information about MTD devices.
  • The sysfs interface - It provides full information about each MTD device in the system and is easily extensible.
  • The /proc/mtd proc file system- This is a legacy interface and provides general MTD information. 
During Electronic Product Design & Development it is essential that hardware is designed in a way that it uses proper flash types & accordingly partitions are made.

For More information :http://www.linux-mtd.infradead.org

IPv6 CVS access with IPv4 Linux PC


Convert or get IPv6 address over IPv4 using with versions above RHL7


 echo NETWORKING_IPV6=yes >> /etc/sysconfig/network
 echo IPV6_DEFAULTDEV=tun6to4 >> /etc/sysconfig/network
 echo IPV6INIT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0
 echo IPV6TO4INIT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0
 /sbin/service network restart

Allow Firewall port 
    
Add rule to allow IP protocol #41 (IPv6 in IPv4) in and out.

GET IPv6 CVS Access over SSH 

          export CVS_RSH=`which ssh`
          cvs -d :ext:anoncvs@cvs.infradead.org:/home/cvs co mtd




Reference : http://www.linux-mtd.infradead.org/archive/index.html