Build an embedded Linux operating system

Source: Internet
Author: User
Tags temporary file storage

 

Development Environment

HOST: Linux 2.6.ora 2.6.27.5-117. fc10.i686
Cross-compiling environment: arm-linux-gcc-3.4.5 glibc-2.3.6
Software Tools: H-JTAG V1.0, segger J-link Commander v4.10i, codewarrior for ARM Developer Suite v1.2, busybox-1.19.2.tar.bz2
Kernel version: linux-2.6.28.7
Development Board hardware:
(Processor: ARM920T
(Nor FLASH: Intel js28f320j3 Bit Width 16 bit 4 MB
(Nand flash: Samsung k9f2g08 bits width: 8 bit, 128 MB * 2
(Main board: Feiling S3C2440
(NIC: dm9000 10/100 Mb/s

Procedure

[Build a cross-compilation environment]

 

First, build a cross-compiler environment. Here, I will unpack the cross compiler provided in the CD, put it in the corresponding directory, and then add the environment variables to specify the directory where the cross compiler is located.
Tar-jxvf arm-linux-gcc-3.4.5-glibc-2.3.6.tar.bz2

The general method to add environment variables is:
Export Path = $ path:/opt/work/tools/gcc-3.4.5-glibc-2.3.6/bin

For future convenience, you do not have to enter the Export Statement every time you start the system. You can write the preceding command into a file,
I name it env. Sh here. In the future, you only need to enter the following command:
Path of the. Env. Sh File

 

[Bootloader]


There are two recommended methods for Bootloader: U-boot or the bootloader that comes with the Development Board.
I will not describe how to port U-boot. The following describes how to burn bootloader to the flash of the Development Board.

First, check the Jumper description of the development board. Generally, the jumper is on the core board of the Development Board,
"The two jumper hats J2, J5, and J5 on fl2440 are used to set whether to start nandflash or norflash. If we want to start norflash, do not connect to the Jumper hat J5. If it is started from nandflash, it is necessary to short connect. If you want to start from norflash, The J5 jumper hat will be unplugged and The J2 will jump to 0"

Burn with H-JTAG
Connect the JTAG port of the Development Board to the port of the PC, open the board power, open the H-JTAG, select 'settings'-> 'usb/LPT selection 'in the menu, select LPT, click OK, the software will automatically detect the development board chip, if "unable to find target. please make sure that the hardware is properly connected and powered up. the reason may be that the parallel port is not properly connected, the parallel port driver is not installed, and the Board is not powered on.
After checking the Board Sub-chip, start H-flasher, select the flash corresponding to the Board in Flash selection (H-JTAG 1.0 has the nor flash and NAND Flash models of this development board ), fill in the ram start address in configuration, and then click check detection chip and flash in programming. After the detection is successful, the flash model is displayed. Then, select SRC file, which is the path of the bootloader, finally, click program, and wait until the writing is completed. After the writing is successful, successful is displayed.
In this case, if the power is down, unplug the JTAG connection, connect to the serial port, and then power on, you can see the information in the serial port.

Use J-link commander for writing
The init. binfile is a program used to initialize memory devices and can be downloaded online. This file is generally used.
Connect J-link to the JTAG port of the board, connect the USB of the PC to the other end, power the board first, open J-link commander, and enter the following commands in sequence below the command line:
Speed12000
Loadbin "F: \ Program Files \ TFTP \ init. bin" 0x40000000 // If NAND falsh is enabled, set the address to 0x0
Setpc 0x40000000
G
H
Loadbin "F: \ Program Files \ TFTP \ u-boot.bin" 0x33f80000
Setpc 0x33f80000
G
Now, you can see the uboot output in the serial port.
If the serial port does not have any output, the possible cause is that uboot is not successfully transplanted, resulting in incompatibility with the board.
The following will write uboot from the memory into flash, you can use J-link to download the u-boot.bin, you can also use the uboot command TFTP.
Note that you cannot use the file that has just been downloaded to the 0x33f80000 address, because once uboot runs, the data in the memory changes, so you must download it again to another unused memory address.
Use J-link:
H // first pause the running U-boot in the memory
Loadbin "F: \ Program Files \ TFTP \ u-boot.bin" 0x35000000
G // resume running

Use uboot:
TFTP 0x35000000 u-boot.bin // first make sure that the TFTP server on the PC is running and set the download directory
The following code is burned to flash,
For nor flash:
First, use flinfo to view the information of nor flash, determine the number of disks and the storage capacity of each block, and then execute the following command
Protect off all
Erase 0 3 FFFF
CP. B 0x35000000 0 40000
If you have any questions about erase and CP commands, can you enter them? Or help to view usage

For nand flash:
Nand erase 0 40000
Nand write 0x35000000 0 40000

So far, the bootloader has been burned out.

 

[Kernel]


The following describes how to port the kernel.
First, you need to understand the interaction between the kernel and Bootloader:
1. Address for storing the parameters passed to the kernel;
2. Format of parameters passed to the kernel;
3. Machine Type ID;
4. Start the command.

I will directly use the kernel in the CD, which contains a modified configuration file.
First, make sure that the cross compiler has provided
Decompress the kernel
Tar-zxvf 2440-linux-2.6.28.tar.gz
CD linux-2.6.28.7
Make menuconfig
Select 'Load an alternate configuration file' and load the configuration file.
Make zimage

The zimage image file is generated in the arch/ARM/boot directory.
For Fei Ling's bootloader, it divides wince into half of the NAND Flash. Because I don't need the wince system, so I need to modify the source code of the Bootloader and delete the wince partition. I need to modify the source file of the NAND. C.
Modify the following data structure

// You can modify or delete a partition. The partition name cannot be changed to static struct partition nandpart [] = {0, 0x00020000, "Boot "}, // 128 K one block {0x00020000, 0x00060000, "bootparam"}, // 384 K three blocks {0x00080000, 0x00100000, "pic "}, // 1 m {0x00180000, 0x00380000, "MyApp"}, // 3.5 m {0x00500000, 0x00300000, "kernel "}, // 3 m {0x00800000, 0x03c00000, "fs_yaffs"}, // 60 m {0x04400000, 0x00080000, "eboot "}, // 512 K {0x04480000, 0x03b80000, "wince"}, // 59.5 m {0, 0, 0 }};

 

Changed:

 

static struct Partition NandPart[] = {{0,  0x00020000, "boot"},//128K one block{0x00020000, 0x00060000, "bootParam"},//384K three blocks{0x00080000, 0x00100000, "pic"},//1M{0x00180000, 0x00380000, "MyApp"},//3.5M{0x00500000, 0x00300000, "kernel"},//3M{0x00800000, 0x0F800000, "fs_yaffs"},//248M//{0x0fe80000, 0x00080000, "eboot"},//512K//{0x0FF00000, 0x00100000, "wince"},//1M{0, 0         , 0}};

Then modify the kernel source file to match the bootloader. The modified source file path is
ARCH/ARM/plat-s3c24xx/common-smdk.c

Modify the following data structure:

static struct mtd_partition smdk_default_nand_part[] = {[0] = {                .name   = "Boot",                .size   = 0x00100000,                .offset = 0        },        [1] = {                .name   = "MyApp",                .size   = 0x003c0000,                .offset = 0x00140000,        },        [2] = {                .name   = "Kernel",                .size   = 0x00300000,                .offset = 0x00500000,        },        [3] = {                .name   = "fs_yaffs",                .size   = 0x0F800000,    //248M                .offset = 0x00800000,        }        /*        ,        [4] = {                .name   = "WINCE",                .size   = 0x00180000,                .offset = 0x0fe80000,        }        */};

Note that the starting address and size of the kernel and file system must correspond to the bootloader.

If the following error occurs after the kernel and file image are burned
Kernel panic-not syncing: VFS: Unable to mount root FS on unknown-block (31,3)
The possible cause is:
1. The yaffs file system is not patched;
2. The yaffs file system support is not selected during Kernel configuration;
3. The file system partition in the kernel does not correspond to the address written into flash;
4. The file system tool mkyaffs2image is inconsistent with the tool in Kernel Patching;
5. The original flash was not cleared before the file system was burned.

 

[File System]


Finally, let's talk about how to create a root file system.
The basic principle is to convert a Created directory into a file in a certain format, and then burn it to the starting position of the file system partition in NAND Flash.

A root file system is recommended to be created in the format specified by FHS. A minimum root file system should have the following directory

/
| _/Bin // stores basic commands that can be used by all users
| _/Sbin // stores commands that can only be used by administrators to start and repair the system.
| _/Dev // stores device files, including character devices and block Devices
| _/Etc // stores various configuration file startup scripts
| _/Lib // store shared libraries and load modules
| _/Home // user directory
| _/Root // root user directory
| _/Usr // contains the user program
| _/Var // store variable data
| _/Proc // It is usually an empty directory and is often used as a mount point of the proc file system.
| _/Mnt // used to temporarily mount the File System
| _/Tmp // temporary file storage, usually an empty directory

First, port busybox. This program integrates many Linux tools. After compilation and installation, the following files and directories will be generated.
Drwxr-XR-x 2 root Root 4096 Bin
Lrwxrwxrwx 1 Root 11 linuxrc-> bin/busybox
Drwxr-XR-x 2 root Root 4096 sbin
Drwxr-XR-x 4 Root 4096 USR

In fact, all the files are soft links of the bin/busybox.
To compile busybox, follow these steps:
Tar-jxvf busybox-1.19.2.tar.bz2
CD busybox-1.19.2
Make menuconfig
Make
Make install
After installation, the _ install directory will be generated under the directory of the current layer, which is the compiled executable file.

If an error occurs during compilation:
Miscutils/ionice. C: In function 'ioprio _ set ':
Miscutils/ionice. C: 16: Error: 'sys _ ioprio_set 'undeclared (first use inthis function)
The method is as follows:
When making menuconfig, deselect miscellaneous utilities ---> ionice.

Miscutils/ubi_tools.c: 63: 26: Error: MTD/ubi-user.h: no such file or directory
Miscutils/ubi_tools.c: In function 'ubi _ tools_main ':
Miscutils/ubi_tools.c: 133: Error: 'ubi _ dev_num_auto 'undeclared (first use in this function)
The method is as follows:
Copy the include \ MTD \ ubi-user.h in the kernel source code to include \ MTD under busybox.

Next, copy the glibc-2.3.6 loader and dynamic library to the/lib directory.
Make the startup script. These files must exist in the/etc directory.
The content of each file is as follows:

[Root @ wayos-fedora etc] # Cat inittab

: Sysinit:/etc/init. d/RCS
S3c2410_serial0: askfirst:-/bin/sh
: Restart:/sbin/init
: Ctrlaltdel:/sbin/reboot
: Shutdown:/bin/umount-a-r
: Shutdown:/sbin/swapoff-

[Root @ wayos-fedora etc] # Cat fstab
# Device Mount-point type options dump fsck order
Proc/proc defaults 0 0
Tmpfs/tmp tmpfs defaults 0 0
Sysfs/sys sysfs defaults 0 0
Tmpfs/dev tmpfs defaults 0 0

[Root @ wayos-fedora init. d] # Cat RCS
#! /Bin/sh
Ifconfig eth0 192.168.61.110 up
Ifconfig lo up
Mount-
Mkdir/dev/PTS
Mount-T devpts/dev/PTS
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Mdev-S

The dev directory is created by mdev. There must be two files in the/dev directory:
[Root @ wayos-fedora fs_mdev_busybox-1.19.2] # ls-l DEV/
Total 0
CrW-r -- 1 Root 5, 1 2011-11-25 14:27 Console
CrW-r -- 1 Root 1, 3 2011-11-25 14:27 null

By default, the user name and password are not required for serial port login. When using telnet to log on to the development board, you need to enter the user name and password. Currently, no user is created, to remotely log on to the development board, you need to create a user. We can create a root user by creating two files, group passwd, In the etc directory. The content is as follows:
[Root @ wayos-fedora etc] # Cat Group
Root: 0: Root
[Root @ wayos-fedora etc] # Cat passwd
Root: 0: 0: Root:/root:/bin/sh
The username is root and the password is empty. Log on to the/root directory by default.

After the root directory is ready, use the following command to create a file image:
./Mkyaffs2image./fs_mdev_busybox-1.19.2/./fs_mdev_busybox-1.19.2.yaffs
Then burn the image file to the Flash file partition.

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.