JFFS2 System Production 2

Source: Internet
Author: User
Tags touch command

Http://blog.chinaunix.net/uid-23208702-id-353022.html

1.2. Installing the Zlib Library

Because the Zlib.h file is required to cross-compile the MTD tool, install the Zlib library file before compiling. Download zlib-1.2.3.tar.gz extract from the Web

$ tar zxvf zlib-1.2.3.tar.gz

$ CD zlib-1.2.3

$./configure–prefix=/usr/local/arm/arm-linux--shared

Modify the makefile as follows:

CC=GCC (because my mkfs.jffs2 is used to make file systems under the host, there is no need for cross-compilation.) The ldshared below is also the same, do not need to use cross tools)

Ldshared=ld-shared

$ make all

$ make Install

Note: This is installed in the/usr/local/arm/arm-linux directory
1.3. Installing MTD

Download mtd-snapshot-20050519.tar.bz2 extract from the Web

$ tar jxvf mtd-snapshot-*

$ CD Mtd/util

Modify the makefile in this directory:

Sbindir=/usr/sbin

Mandir=/usr/man

Includedir=/usr/include

Ldflags=-l/usr/local/arm/arm-linux/lib the folder where the library files for the #zlib library are located

cross= #用于宿主机下

CC: = $ (cross) GCC

CFLAGS: =-I.. /include-i/usr/local/arm/arm-linux/include-o2-wall



$ make all

(plus-i/usr/local/arm/arm-linux/include is because, Zlib.h errors were found during compilation, plus Ldflags has the same error, so add the location of the folder where Zlib library files are located directly in Cflag. )

Then put the generated Flash_erase,flash_eraseall, MKFS.JFFS2 tool in the directory on the RAMDisk file system (I'll place it in the/bin directory). In addition, you need to copy the libz.so, libz.so.1, libz.so.1.2.3 files under the/arm-linux/lib directory to the RAMDisk directory of the/lib file system, otherwise the MKFS.JFFS2 tool cannot be used.
2. Mount and make JFFS2 file system

Here, in order to avoid the re-creation of the filesystem, I adopted the JFFS2 file system ANGSTROM-X11-IMAGE-DEMO-GLIBC-AT91.ROOTFS.JFFS2 from the MBS-SAM9G45 Development Board of the English company. During the whole process of making the JFFS2 file system, we used root permissions.
2.1. Mount the file system image

The JFFS2 file system is not a block device and cannot be directly mount and requires some intermediate steps. First, the kernel must support MTD and compile the two modules of Mtdram and Mtdblock. First create a virtual MTD device that is greater than or equal to the file system to be mounted. ANGSTROM-X11-IMAGE-DEMO-GLIBC-AT91.ROOTFS.JFFS2 file System is 28.2M, then I first set up a virtual MTD device that is greater than or equal to 28.2M. (to avoid adding large files to the file system during the production process, I set the MTD size to 50m*1024=50720k)

$ sudo modprobe mtdram total_size=50720

Where the unit of Total_size is KB, specifying the size of MTD.

Loading Mtdblock generates a virtual block device and writes the contents of the ANGSTROM-X11-IMAGE-DEMO-GLIBC-AT91.ROOTFS.JFFS2 to the generated virtual device:

$ sudo modprobe mtdblock

$ sudo dd if=/home/embest_sam9g45/angstrom-x11-image-demo-glibc-at91.rootfs.jffs2 of=/dev/mtdblock0

(Note: The DD command is a block copy file of the specified size, and the specified conversion is made at the same time as the copy.) If=file: Enter a file name, default to standard input. Of=file: Output file name, default is standard output. )

To create a mount point:

$mkdir/MNT/MTD

Now it's time to mount:

$ sudo mount-t jffs2/dev/mtdblock0/mnt/mtd

The file system can be modified after entering/MNT/MTD!
2.2. Making JFFS2 File system image

After modifying (in the next step) your own file system, fall back to the previous level of the well-done file system directory. For example, my file system mount point is/MNT/MTD, then back to the/mnt directory, with the MKFS.JFFS2 tool to make JFFS2 file system, as follows:

#mkfs. Jffs2-r rootfs-o fs.jffs2-e 0x20000--pad=0x500000-s 0x800–n-l

You can generate ROOTFS.JFFS2

The meanings of the MKFS.JFFS2 parameters are as follows:

-r: Specifies the name of the directory to be made image.

-O: Specifies the file name of the output image.

-E: Block size to erase each piece, the default is 64KB. Note that different flash, its block size will not be the same, Samsung's k9f2g08u0a block size is 0x20000 (from its datasheet can be found). Without the Add-e option, the following error occurs on startup: At91sam User.warn kernel:empty Flash at 0X00F0FFFC ends at 0x00f10000. Therefore, if you have a similar error, plus the-e option, and configure the Nandflash block size, you can eliminate it.

--pad (-P): Use 16 to indicate the size of the file to be output, that is, the size of the FS.JFFS2, if the actual size is not sufficient for the size of this setting, then 0xFF. Also can not use this option, the size of the resulting file system is the same size as itself, but it is not known and magical, but the addition of a lot of errors will occur.

-n,-no-cleanmarkers: Indicates that no clear mark is added (Nandflash has its own school check block and holds the relevant information). If the mount will appear similar to the following: Cleanmarker node found at 0x0042c000 have totlen 0xc! = Normal 0x0 warning, then plus-n will disappear.

-l,--little-endian: Specifies that the small-end format is used.

There are options, no need, you can see Help yourself! Mkfs.jffs2–h with the following command.
3. Modify the file System 3.1. Why you need to change

1, the system starts, will start a lot of projects, and many of the process is we do not need, through the modification of the file system, you can reduce the startup items, speed up the boot speed.

2, because the Development Board provides a comprehensive file system, including sound cards, graphics cards, games, LCD screen and many other drivers, but these are not needed, so by modifying the file system, we can reduce the need for drivers, library files and all the configuration files.

3, when the system starts, you need to join our own startup program. In this file system, added the Super User automatic login function, the wireless card driver self-booting and the FPGA interface drive automatic loading.
3.2. Remove the extra Startup items

All the startup items are implemented in INIT.D and are distributed in RC0.D~RC6.D and RCS.D according to different runlevel. RC?. The relationship between D and/etc/init.d, described in the following article is quite detailed, can refer to learning:

Http://wenku.baidu.com/view/8bdb9237ee06eff9aef8071b.html

RC?. D is a connection to a script in/ETC/INIT.D. In RC?. D, you can see two connections with the beginning of K and S. S starts with a start, and a k starts to indicate that it does not start. At startup, the system executes RC. All of the S in D start with the script file that you pointed to. Therefore, we only need to modify RC?. The connection in D and the script file in/etc/init.d, you can modify the startup project.

In this file system, I made the following changes:

RC2.D: Turn off S50usb-gadget.

RC3.D: Close S50usb-gadget, S10alsa-state, S10dropbear.

RC4.D: Turn off S50usb-gadget.

RCS.D: Turn off S00psplash (rotate progress bar, show boot progress), S02banner.

The method I use to close is MV S50usb-gadget K50usb-gadget, which turns off the Usb-gadget, which is also very convenient to start when you need to start it. Of course, such an operation does not significantly reduce the startup time.
3.3. root User login automatically

Each time the device starts or resets, it is necessary to manually enter root at the end of the boot to log into the system, while unattended, the root user is required to automatically log in and execute the program. The following changes can be made in/etc/inittab to enable the root user to log in automatically:

The default boot RunLevel is 5, which is Id:5:d efault

Comment out the line of code that is logged in, that is, #s:2345:respawn:/sbin/getty 115200 ttyS0

Add the following login code: S1:2345:respawn:/sbin/getty/usr/bin/autologin 115200 ttyS0. Start Autologin program need to complete their own,/usr/bin/is the location of autologin, this position can be arbitrarily selected.

Write the AUTOLOGIN.C program as follows:

#include <stdlib.h>

#include <stdio.h>



int main ()

{

EXECLP ("Login", "Login", "-F", "root", 0);

}

Then compile autologin.c, and note that you want to use the cross compiler.

$/usr/local/arm-2007q1/bin/arm-none-linux-gnueabi-gcc–o Autologin autologin

Copy the compiled Autologin executable file to the/usr/bin directory. can also be placed in other directories, the corresponding modification/etc/inittab can be.

At this point, after re-creating the file system image, burning into the Nandflash, you can automatically log on to the root user.
3.4. Add your own Startup items

Because RCS is an item that every system must start, adding a startup item to the RCS is the most straightforward approach. (There is no rc.local file in our system, there are many ways to add self-booting in rc.local)

I need to automatically load the wireless card driver, FPGA interface driver, and turn on the DHCP service.

First, the wireless network card and the FPGA driver and the DHCP executable files and configuration files are copied into the appropriate folder (executable folder can be set by itself, in the writing script to pay attention to the path, the configuration file needs to be placed in accordance with the rules). Here, I copy the wireless card driver Rt3070sta.ko to/USR/SRC, Rt3070sta.ko the configuration file that needs to be read after the driver is loaded RT2870STA.dat put in/etc/wireless/rt2870sta. The interface of the FPGA is driven Fpgadev copy to/usr/src. The DHCP service was added when the kernel was compiled, so the client uhdpc and the server UHDPD were placed in/sbin and/usr/sbin respectively, and the copy configuration file udhcpd.conf to/etc,/var/lib/ Misci under new (Touch command) a file udhcpd.leases. The permission to modify all files is 755 (chmod 755 xxx).

Second, you need to add the executed script file in the/ETC/INIT.D, and add the code you want to execute in this script file. Write the Autoset_sta script as follows:

#!/bin/sh



#Auto set Wireless card and FPGA driver

/sbin/insmod/usr/src/rt3070sta.ko

/sbin/insmod/usr/src/fpgadev.ko\



/sbin/udhcpc

Finally, modify the file permissions and add a connection to Init.d/autoset_sta in RCS.D.

$ chmod 755 Autoset_sta

$ CD. /rcs.d

$ LN–SF.. /nit.d/autoset_sta S99autoset_sta

Once the file system is created, these drivers and services are automatically loaded with a write-down restart.
3.5. Reduce File System volume

The original file system 28.2MB, after adding its own files, reached 30MB. Embedded storage resources are valuable, in order to reduce the resources involved, the file system must be thin.

Enter/etc to delete unnecessary startup script files, such as X11 files.

Go to/lib and delete the library file than needed.

Enter/usr to delete the games.

Go to/usr/bin and delete the useless commands.

Go to/usr/lib and delete the unused library files. Here the library files quite a lot, to reach the giant of 16M, and the inside is mostly we do not use the library, such as libaudiofile.so.0, libsoundgen.so.0, libmad*, Libice, as well as about the image and interface of the library, these can be deleted. When all is removed, the/usr/lib can be as small as 3m~6m. Of course, this depends on the specific application, to me, I use is network programming, multi-threading, wireless network card, SPI communication, serial communication and other things, so can delete a lot of unnecessary libraries. However, because the startup item is not clean enough, during the startup process, many libraries in/usr/lib will still be used, so there will be many errors, but it does not affect my operation.

Enter/usr/share, delete the unused doc and applications .....

Basic clipping is almost done, recompile the file system, the output size is about 16M.

(also need to well put the whole system to start the process of the call to clarify, this can also be greatly cropped)
4. Problems and Solutions

Q: The At91sam user.warn kernel:empty Flash at 0X00F0FFFC ends at 0x00f10000 problem occurs during startup

A: When MKFS.JFFS2, add-e 0x20000 Specifies the size of the erase block. -E is the size of the specified erase block, the block size of the Nandflash we use is 128K bytes, so the-e parameter is (128*1024) 10 = (20000) 16.



Q: When starting up, Cleanmarker node found at 0x00f10000 have totlen 0xc! = Normal 0x0 problem.

A: When MKFS.JFFS2, add the-n option. -N,--no-cleanmarkers. Indicates that no clear mark is added (NAND Flash has its own school check block, storing the relevant information.) If the mount appears similar to the following: Cleanmarker node found at 0x0042c000 have totlen 0xc! = Normal 0x0 warning, plus-n will disappear.



Q: Solution Jffs2_scan_eraseblock (): Magic bitmask 0x1985 not found in 0x01649298:0xa25e instead problem method

A: When MKFS.JFFS2, add-S 2048 (page size, determined by the chip) and-L (small end mode) two options. -S is the size of the page that we use, the size of the Nandflash page is 2048 bytes. -L is indicated as a small-end mode, generally embedded under the small-end mode.



Description
1.in the process of file system production, need to use root user rights;
2, generally embedded under the root user only login, so all files in the file system need to have root executable permissions, if you log in with another user, please ensure that the file system files (especially the files you added) the corresponding executable permissions.

JFFS2 System Production 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.