[琪琪雜貨舖]

2015年12月23日 星期三

【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 5 _ MTD (MeMORY TECHNOLOGY DEVICE ) Introduction 



1. MTD overview (from http://www.linux-mtd.infradead.org/doc/general.html)

MTD subsystem (stands for Memory Technology Devices) provides an abstraction layer for raw flash devices. It makes it possible to use the same API when working with different flash types and technologies, e.g. NAND, OneNAND, NOR, AG-AND, ECC'd NOR, etc.
MTD subsystem does not deal with block devices like MMC, eMMC, SD, CompactFlash, etc. These devices are not raw flashes but they have a Flash Translation layer inside, which makes them look like block devices. These devices are the subject of the Linux block subsystem, not MTD. Please, refer to this FAQ section for a short list of the main differences between block and MTD devices. And the raw flash vs. FTL devices UBIFS section discusses this in more details.
MTD subsystem has the following interfaces.
  • MTD character devices - usually referred to as /dev/mtd0/dev/mtd1, and so on. These character devices provide I/O access to the raw flash. They support a number of ioctl calls for erasing eraseblocks, marking them as bad or checking if an eraseblock is bad, getting information about MTD devices, etc.
  • The sysfs interface is relatively newer and it provides full information about each MTD device in the system. This interface is easily extensible and developers are encouraged to use the sysfs interface instead of older ioctl or /proc/mtd interfaces, when possible. The sysfs interface for the mtd subsystem is documentated in the kernel, and currently can be found at Documentation/ABI/testing/sysfs-class-mtd.
  • The /proc/mtd proc file system file provides general MTD information. This is a legacy interface and the sysfs interface provides more information.
MTD subsystem supports bare NAND flashes with software and hardware ECC, OneNAND flashes, CFI (Common Flash Interface) NOR flashes, and other flash types.


2.  MTD driver (e.g. Kernel version 2.6.35.7) and support Files system drivers need to be added 

        Device Drivers  --->
                 <*> Memory Technology Device (MTD) support  --->
                               [*]   MTD partitioning support

        File systems  --->
                Miscellaneous filesystems  --->
                        <*> YAFFS2 file system support
                        <*> Journalling Flash File System v2 (JFFS2) support
                        <*> Compressed ROM file system support (cramfs)

3. partitions  definitions in a NAND flash (e.g. Tiger board QT210 NAND flash)

 code snppet in file "s3c_nand.c"

 struct mtd_partition s3c_partition_info[] = {

{
                .name           = "Bootloader",
                .offset         = 0,
                .size           = 0x00100000,
        },
        {
                .name           = "Kernel",
                .offset         = 0x00600000,
                .size           = 0x00500000,
        },
        {
                .name           = "cramfs",
                .offset         = 0x00B00000,
                .size           = 0x00300000,
        },
         {
                .name           = "DATA",
                .offset         = 0x00E00000,
                .size           = 0x04000000,
        },
        {
                .name           = "Jffs2",
                .offset         = 0x04E00000,
                .size           = 0x00f00000,
        },
      {
                .name           = "RAMDISK",
                .offset         = 0x0C640000,
                .size           = 0x00300000,
        },
        {
                .name           = "UBIFS",
                .offset         = 0x0CA00000,
                .size           = MTDPART_SIZ_FULL,
        }
}



4. kernel output message (dmesg) for notification of MTD partitions

                [    0.735000] Creating 7 MTD partitions on "s5pv210-nand":
                [    0.740000] 0x000000000000-0x000000100000 : "Bootloader"
                [    0.745000] 0x000000600000-0x000000b00000 : "Kernel"
                [    0.750000] 0x000000b00000-0x000000e00000 : "cramfs"
                [    0.755000] 0x000000e00000-0x000004e00000 : "DATA"
                [    0.770000] 0x000004e00000-0x000005d00000 : "Jffs2"
                [    0.775000] 0x00000c640000-0x00000c940000 : "RAMDISK"
                [    0.775000] 0x00000ca00000-0x000010000000 : "UBIFS"


5. device files created by MTD

[root@QT210 /]# ls /dev/mtd*
                /dev/mtd0       /dev/mtd2ro     /dev/mtd5       /dev/mtdblock1  /dev/mtdblock6
                /dev/mtd0ro     /dev/mtd3       /dev/mtd5ro     /dev/mtdblock2
                /dev/mtd1       /dev/mtd3ro     /dev/mtd6       /dev/mtdblock3
                /dev/mtd1ro     /dev/mtd4       /dev/mtd6ro     /dev/mtdblock4
                /dev/mtd2       /dev/mtd4ro     /dev/mtdblock0  /dev/mtdblock5




6. Erase one of the partitions as JFFS2 file system

                        [root@QT210 /]# flash_eraseall -j /dev/mtd3
                        Erasing 128 Kibyte @ 1260000 -- 28 % complete. Cleanmarker written at 1260000.
                        Skipping bad block at 0x01280000
                        Erasing 128 Kibyte @ 3e80000 -- 97 % complete. Cleanmarker written at 3e80000.
                        Skipping bad block at 0x03ea0000
                        Erasing 128 Kibyte @ 3fe0000 -- 99 % complete. Cleanmarker written at 3fe0000.

2015年12月22日 星期二

【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 2 _ DIY FILE SYSTEM _ SCRIPT FILE INTRODUCTION



1. Script file 
#/bin/sh
CURRENTDIR=`pwd`
ROOTFS=$CURRENTDIR/rootfs
BUSYBOX=../busybox-1.19.2
LIB=../lib


###################Create Folders###################
mkdir $ROOTFS/bin
mkdir $ROOTFS/dev
mkdir $ROOTFS/etc
mkdir $ROOTFS/lib
mkdir $ROOTFS/mnt
mkdir $ROOTFS/mnt/mtd0
mkdir $ROOTFS/mnt/mtd1
mkdir $ROOTFS/mnt/nfs
mkdir $ROOTFS/mnt/sdcard
mkdir $ROOTFS/mnt/udisk
mkdir $ROOTFS/proc
mkdir $ROOTFS/sbin
mkdir $ROOTFS/sys
mkdir $ROOTFS/tmp
mkdir $ROOTFS/usr
mkdir $ROOTFS/usr/bin
mkdir $ROOTFS/var
###########################################################

##################make node #####################
sudo mknod -m666 $ROOTFS/dev/console c 5 1
sudo mknod -m666 $ROOTFS/dev/null    c 1 5
###########################################################

##################Copy etc folder#########################
cp -a etc/* $ROOTFS/etc/
#########################################################

#################Copy Busybox###########################
cp -R -p $BUSYBOX/_install/* $ROOTFS
#######################################################

################Copy lib###############################
cp -a $LIB/* $ROOTFS/lib
#######################################################


2. run the script files and File System "rootfs" generated

jessicatai@ubuntu:rootfs_build$ ls
busybox-1.19.2  lib  toolfs
jessicatai@ubuntu:rootfs_build$ cd toolfs/
jessicatai@ubuntu:rootfs_build/toolfs$ ls
build.sh  etc  tools
jessicatai@ubuntu:rootfs_build/toolfs$ ls
build.sh  etc  rootfs tools




【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 4 _ Make File system Images



1. Make different type File system images

1-1 Cramfs image

#/bin/sh
CURRDIR=`pwd`
MKTOP=$CURRDIR/rootfs
FILEIMG=cramfs.img                                                                                                                 
    rm -rf $FILEIMG 2>/dev/null
   ./tools/mkcramfs $MKTOP $FILEIMG 

1-2 Jffs2 image

#/bin/sh
CURRDIR=`pwd`
MKTOP=$CURRDIR/rootfs
FILEIMG=jffs2.img       
                                                                                                          
    rm -rf $FILEIMG 2>/dev/null
   ./tools/mkfs.jffs2 -r $MKTOP -e 0x4000 -o $FILEIMG --pad=0xf00000 -n 


1-3 ramdisk file
#/bin/sh
CURRDIR=`pwd`
MKTOP=$CURRDIR/rootfs
RAMDISKSIZE=8192
FILEIMG=$CURRDIR/initrd.gz
TMPIMG=$CURRDIR/initrd.tmp
MOUNTPOINT=$CURRDIR/mnt
USE_GZIP=1                                                                                                                                                                     
sudo dd if=/dev/zero of=$TMPIMG bs=1k count=$RAMDISKSIZE
sudo /sbin/mke2fs -F -v -m0 $TMPIMG  $RAMDISKSIZE
sudo mount -o loop $TMPIMG $MOUNTPOINT
sudo cp -a $MKTOP/* $MOUNTPOINT
cd $MOUNTPOINT
sudo chown -R root.root *
cd $CURRDIR
sudo umount $MOUNTPOINT || exit 1
sudo rm -rf $FILEIMG
if [ "$USE_GZIP" = "1" ]; then
  gzip -c -9  $TMPIMG> $FILEIMG
else 
  FILEIMG=$CURRDIR/initrd.lzma
  rm -rf $FILEIMG
 ./tools/lzma e $TMPIMG $FILEIMG
fi
rm -rf $MOUNTPOINT $TMPIMG
ls -lh $FILEIMG


2 Running the script files and generated the images
jessicatai@ubuntu:rootfs_build/toolfs$ ls
initrd.gz  make_cramfs.sh  make_jffs2.sh  make_ramdisk.sh  rootfs  cramfs.img  jffs2.img

【CHICHI ETUTOR@ARM/MIPS/PPC】The Swiss Army Knife of Embedded Linux _ BUSYBOX



1. Download Busybox busybox-1.19.2.tar.bz2 "

        from http://busybox.net/downloads/

2. "basic" setup configuration

        $cd busybox-1.19.2
        busybox-1.19.2$  make menuconfig

        Busybox Settings  --->
                Build Options  --->
                        (arm-linux-) Cross Compiler prefix

                Busybox Library Tuning  --->
                         [*] Faster /proc scanning code (+100 bytes)
                         (255) History size
                         [*]   History saving
                         [*]   Tab completion


        //After which, you can enter the command configuration page to add/remove command as you want.


  │ │
           Archival Utilities  --->                                                                    
  │ │           Coreutils  --->                                                                                
  │ │           Console Utilities  --->                                                                  
  │ │           Debian Utilities  --->                                                                     
  │ │           Editors  --->                                                                                  
  │ │           Finding Utilities  --->                                                                  
  │ │           Init Utilities  --->                                                                            
  │ │           Login/Password Management Utilities  --->                              
  │ │           Linux Ext2 FS Progs  --->                                                            
  │ │           Linux Module Utilities  --->                                                         
  │ │           Linux System Utilities  --->                                                          
  │ │           Miscellaneous Utilities  --->                                                          
  │ │           Networking Utilities  --->                                                               
  │ │           Print Utilities  --->                                                                          
  │ │           Mail Utilities  --->                                                                          
  │ │           Process Utilities  --->                                                                   
  │ │           Runit Utilities  --->                                                                         
  │ │           Shells  --->                                                                                      
  │ │
           System Logging Utilities  --->

3. make and make install
        $make -j8

                //if you meet warning message like these, leave it and dont care it
                ================================================
                ................
                  LINK    busybox_unstripped
                Trying libraries: crypt m
                         Library crypt is not needed, excluding it
                         Library m is needed, can't exclude it (yet)
                        Final link with: m
                ...............
                ================================================

        $make install

        //There should be in folder called "_install" generate

                $cd _install
                _install$ ls
                bin  linuxrc  sbin  usr


4. copy these folders/files (bin linuxrc sbin usr) to be sub directory of File System  you prepare to build up




2015年12月16日 星期三

【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 3 _ DEMOSTRATION _ Ubuntu 13.04 in Samsung S5pv210 ARM platform



1. System Pictures


2. DEMO1 : DEMO_UBUNTU1304_desktop_UVC_Camera






3. DEMO2 : DEMO_UBUNTU1304_PLAY_VIDEO_VLC 




3. DEMO3 : DEMO_UBUNTU1310_desktop_KUBUNTU




4. How to install ubuntu ?
TO BE CONTINUED



【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 1 _ INTRODUCTION TO File System


1. What is "File System"
  • filesystem is the methods and data structures that an operating system uses to keep track of files on a disk or partition; that is, the way the files are organized on the disk. The word is also used to refer to a partition or disk that is used to store the files or the type of the filesystem.


2. Where it stores
  • File systems are based on block device e.g.  Hard disks , Flash
  • File system is stored on physical devices in partitions 


3. File system type
  • For Desktops  , EXT2 / EXT3 / EXT4 / FAT / NTFS
  • For embedded system , YAFFS2 / JFFS2 / CRAMFS / UBIFS
  • Pseudo file system , Proc / sysfs 
  • For HADOOP , HDFS
  • For google distributed system , GFS


4. Mounting a File system
  • Kernel must have been compiled to support file system type
  • have permission/right to access hardware device for mount
  • using mount for file system mounting. 
                   mount   /dev/sdb1 /mnt 



5. Root File System
  • mounted at the base of the file system hierarchy (FHS), designed as  /
  • contain programs and utilities to boot system initialize service, load device driver and mount additional file system



6. File System Hierarchy Standard (FHS)

  • establishes a minimum baseline of compatibility between Linux distributions and application program
  • allows your application software and developer to predict where certain system elements, including file and directories, can be found on the file system




7. Minimal File System

|-- bin

        |-- busybox

        |-- sh -> busybox
|-- dev
        |-- console
|-- etc
        |-- init.d
        |-- rcS
|-- lib
        |-- ld-2.3.2.so
        |-- ld-linux.so.2 -> ld-2.3.2.so
        |-- libc-2.3.2.so
        |-- libc.so.6 -> libc-2.3.2.so



8. Setting Up Root File System
  • Step 1: create file system hierarchy
        - mkdir all the folders
  • Step 2: create device files
        - mknod 
        - All the device files in a Linux root filesystem are located in the /dev directory
        - conserved system device node


Name |Descrption              |Type |Major |Minor |Permission
mem        |Physical memory access    |Char |1     |1        |600
null         |Null device              |Char |1        |3        |666
zero |Null byte source              |Char |1     |5        |666
Random   |random number generator |Char |1     |8        |664
tty0         |Current virtual console        |Char    |4       |0        |600
tty1           |First virtual console            |Char    |4        |1        |600
ttyS0        |First UART serial port         |Char    |4        |64      |600
tty             |Current TTY device            |Char    |4        |0        |666
console    |System console              |Char    |5        |1        |600


  • ™Step 3: install libraries and kernel modules
       -download library source code , compile , and copy to /lib 
       -download drivers for devices  , compile ,and copy to /lib/modules
  • ™Step 4: install system utilities
       -make busybox and copy to /bin
  • ™Step 5: make root file system image
       -mkfs.jffs2
       -mkfs.cramfs
       

9. What kernel did before "jump" to file system
  • Free the memory
  • Open a system console device
  • Start the first user space program
kernel code example



10. "init" Process in File system
  • "Init" is the ultimate parent of all userspace processes in a Linux system
  • "init" runs with scripts (/etc/rc.X) commonly called system V init
  • "init" has the concept of a runlevel





  • folders corresponding to RunLevel  (/etc)
./rcS.d
./rc0.d
./rc6.d
./rc5.d
./rc.local
./rc1.d
./rc2.d
./rc3.d
./rc4.d

  • script files in "rc0.d"
         -  basically soft link to files in /etc/init.d
         -  files with S point to service scripts, which invoked with startup instruction
         -  files with K point to service scripts, which invoked with shutdown   instruction


/etc/rc2.d$ ls -l
total 4
lrwxrwxrwx 1 root root  29 Aug  5 19:29 K10unattended-upgrades -> ../init.d/unattended-upgrades
lrwxrwxrwx 1 root root  20 Aug  5 19:29 K20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root  18 Oct  1 16:42 K20openipmi -> ../init.d/openipmi
lrwxrwxrwx 1 root root  15 Aug  5 19:29 K20rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root  27 Aug  5 19:29 K20speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx 1 root root  27 Oct 13 15:56 K80nfs-kernel-server -> ../init.d/nfs-kernel-server
-rw-r--r-- 1 root root 353 Mar 13  2014 README
lrwxrwxrwx 1 root root  18 Aug  5 19:29 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx 1 root root  17 Aug  5 19:29 S30urandom -> ../init.d/urandom
lrwxrwxrwx 1 root root  22 Aug  5 19:29 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx 1 root root  18 Aug  5 19:29 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx 1 root root  26 Aug  5 15:41 S59cryptdisks-early -> ../init.d/cryptdisks-early
lrwxrwxrwx 1 root root  20 Aug  5 19:29 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root  14 Aug  5 19:29 S90halt -> ../init.d/halt









[琪琪雜貨舖]